def render_PUT(self, request): # Put an object auth = util.getHeader(request, 'authorization') if not auth: return '' # Split the auth header 'blah key:sig' key, sig = auth.split()[-1].split(':', 1) secret = self.api.getSecret(key) # Get the HMAC sig we have sr = self.api.getSignRequest('PUT', request, secret) if sr != sig: return '' content = request.content contentType = util.getHeader(request, 'content-type', 'application/binary') path = self.api.getCanonicalPath(request).strip('/') # Figure out from here if it's an object put or bucket creation # Amazon's API is so "awesome" that there isn't much discernible difference if '/' in path: bucket, name = path.split('/',1) else: return "No bucket specified" # XXX This should stream the put into Riak somehow d = self.api.put(bucket, name, contentType, content.read()).addCallback( self.completeRequest, request ).addErrback( self.logError, request ) return server.NOT_DONE_YET
def getSignRequest(self, verb, request, secret): # Creates an HMAC sig for a request contentType = util.getHeader(request, 'content-type') contentMD5 = util.getHeader(request, 'content-md5') date = util.getHeader(request, 'date') amzDate = util.getHeader(request, 'x-amz-date') if amzDate: date = 'x-amz-date:%s' % amzDate path = self.getCanonicalPath(request) signData = ['PUT', contentMD5, contentType, date, path] sig = hmac.new( key = secret, msg = '\n'.join(signData), digestmod = hashlib.sha1 ).digest() return base64.b64encode(sig)