def __init__(self, backend_name): self.backend_name = backend_name self.conn = boto.connect_s3(c(backend_name, 'credentials.username'), c(backend_name, 'credentials.password')) # create a new bucket - just in case self.cdmi_bucket_name = c(backend_name, 'aws.bucket_name') # change to Location.USWest for the corresponding zone try: self.conn.create_bucket(self.cdmi_bucket_name, location=Location.EU) except S3CreateError: log.msg("S3 bucket already created. Using it.")
def render_GET(self, request, bodyless=False): """GET returns contents of a blob""" # process path and extract potential containers/fnm _, __, fullpath = parse_path(request.path) log.msg("Getting blob (non-cdmi) %s" % fullpath) tre_header = request.getHeader('tre-enabled') tre_request = tre_header is not None and tre_header.lower() == 'true' # perform operation on ADT status, vals = blob.read(self.avatar, fullpath, tre_request) # construct response request.setResponseCode(status) set_common_headers(request, False) if tre_request and status == FOUND: request.setHeader('Location', "/".join([c('general', 'tre_server'), str(vals['uid'])])) if status is OK: # XXX: hack - some-why the response just hangs if to simply path # mimetype as a content_object type mimetype = vals['mimetype'] actual_type = 'text/plain' if mimetype == 'text/plain' else str(mimetype) request.setHeader('Content-Type', actual_type) request.setLastModified(float(vals['mtime'])) if not bodyless: request.setHeader('Content-Length', str(vals['size'])) producer = self.makeProducer(request, vals['content']) producer.start() return NOT_DONE_YET else: return '' return ''
def move_to_tre_server(self, fnm): b = self.conn.get_bucket(self.cdmi_bucket_name) k = Key(b) k.key = fnm # read in the content to a temporary file on disk fp = NamedTemporaryFile(prefix="aws_s3", suffix=".buffer", delete=False) k.get_contents_to_file(fp) source = os.path.join(c(self.backend_name, 'blob.datadir'), fp.name) target = os.path.join(c('general', 'tre_data_folder'), fnm) try: os.symlink(os.path.abspath(source), os.path.abspath(target)) except OSError, ex: if ex.errno == 17: pass
def authorize(avatar, resource, action, acls=None): """ Top-level authorize function dispatching calls to the configured authZ mechanism. """ try: result = mechanisms[c('general', 'server.authz')](avatar, resource, action, acls) log.err("Authorized request: %s" % result) return result except KeyError: log.err("Requested authZ mechanism %s was not found.") return False # default failover
def render_GET(self, request, bodyless=False): """GET operation corresponds to reading of the blob object""" # process path and extract potential containers/fnm _, __, fullpath = parse_path(request.path) tre_header = request.getHeader('tre-enabled') tre_request = tre_header is not None and tre_header.lower() == 'true' log.msg("Request for TRE-enabled download received.") # perform operation on ADT status, vals = blob.read(self.avatar, fullpath, tre_request) # construct response request.setResponseCode(status) request.setHeader('Content-Type', CDMI_OBJECT) if tre_request and status == FOUND: request.setHeader('Location', "/".join([c('general', 'tre_server'), str(vals['uid'])])) request.setLastModified(float(vals['mtime'])) set_common_headers(request) if status == OK: request.setLastModified(float(vals['mtime'])) if not bodyless: valueencoding = vals['valuetransferencoding'] # for content we want to read in the full object into memory content = (vals['content'].read() if valueencoding == 'utf-8' else base64.b64encode(vals['content'].read())) # construct body response_body = { 'completionStatus': 'Complete', 'mimetype': vals['mimetype'], 'metadata': vals['metadata'], 'valuetransferencoding': valueencoding, 'value': content, 'actual_uri': vals.get('actual_uri'), 'capabilitiesURI': '/cdmi_capabilities/dataobject' } response_body.update(get_common_body(request, str(vals['uid']), fullpath)) return json.dumps(response_body) return ''