def new(self, format='json'): params = validate_new_image(request.params) if params['user_name']: user_q = meta.Session.query(User) user = user_q.filter(User.user_name==params['user_name']).first() else: user = request.environ['REPOMAN_USER'] if not user: abort(400, '400 Bad Request') # check for conflict image_q = meta.Session.query(Image).filter(Image.name==params['name']) image = image_q.filter(Image.owner.has(User.user_name==user.user_name)).first() if image: abort(409, '409 Conflict') # TODO: setting these values is overly verbose. make it simple new_image = Image() # User settable values new_image.name = params['name'] new_image.os_variant = params['os_variant'] new_image.os_type = params['os_type'] new_image.os_arch = params['os_arch'] if params['hypervisor']: new_image.hypervisor = params['hypervisor'] else: new_image.hypervisor = 'xen' new_image.description = params['description'] new_image.expires = params['expires'] new_image.read_only = params['read_only'] new_image.unauthenticated_access = params['unauthenticated_access'] # Non-user settable values uuid = h.image_uuid() current_time = datetime.utcfromtimestamp(time()) file_name = uuid + '_' + new_image.name new_image.owner = user new_image.uuid = uuid new_image.uploaded = None new_image.modified = current_time new_image.path = file_name new_image.raw_uploaded = False meta.Session.add(new_image) meta.Session.commit() response.headers['content-type'] = app_globals.json_content_type response.headers['Location'] = url('get_raw_by_user', user=user.user_name, image=new_image.name, hypervisor='__hypervisor__') response.status = ("201 Object created. upload raw file(s) to 'Location'") return h.render_json(beautify.image(new_image))
def new(self, format='json'): params = validate_new_image(request.params) if params['user_name']: user_q = meta.Session.query(User) user = user_q.filter(User.user_name == params['user_name']).first() else: user = request.environ['REPOMAN_USER'] if not user: abort(400, '400 Bad Request') # check for conflict image_q = meta.Session.query(Image).filter( Image.name == params['name']) image = image_q.filter( Image.owner.has(User.user_name == user.user_name)).first() if image: abort(409, '409 Conflict') # TODO: setting these values is overly verbose. make it simple new_image = Image() # User settable values new_image.name = params['name'] new_image.os_variant = params['os_variant'] new_image.os_type = params['os_type'] new_image.os_arch = params['os_arch'] new_image.hypervisor = params['hypervisor'] new_image.description = params['description'] new_image.expires = params['expires'] new_image.read_only = params['read_only'] new_image.unauthenticated_access = params['unauthenticated_access'] # Non-user settable values uuid = h.image_uuid() current_time = datetime.utcfromtimestamp(time()) file_name = uuid + '_' + new_image.name new_image.owner = user new_image.uuid = uuid new_image.uploaded = current_time new_image.modified = current_time new_image.path = file_name new_image.raw_uploaded = False meta.Session.add(new_image) meta.Session.commit() response.headers['content-type'] = app_globals.json_content_type response.headers['Location'] = url('raw_by_user', user=user.user_name, image=new_image.name) response.status = ( "201 Object created. upload raw file to 'Location'") return h.render_json(beautify.image(new_image))
def show_meta_by_user(self, user, image, format="json"): image_q = meta.Session.query(Image) image = image_q.filter(Image.name == image).filter(Image.owner.has(User.user_name == user)).first() if image: inline_auth(AnyOf(OwnsImage(image), SharedWith(image)), auth_403) if format == "json": response.headers["content-type"] = app_globals.json_content_type return h.render_json(beautify.image(image)) else: abort(501, "501 Not Implemented") else: abort(404, "404 Not Found")
def new(self, format="json"): params = validate_new_image(request.params) if params["user_name"]: user_q = meta.Session.query(User) user = user_q.filter(User.user_name == params["user_name"]).first() else: user = request.environ["REPOMAN_USER"] if not user: abort(400, "400 Bad Request") # check for conflict image_q = meta.Session.query(Image).filter(Image.name == params["name"]) image = image_q.filter(Image.owner.has(User.user_name == user.user_name)).first() if image: abort(409, "409 Conflict") # TODO: setting these values is overly verbose. make it simple new_image = Image() # User settable values new_image.name = params["name"] new_image.os_variant = params["os_variant"] new_image.os_type = params["os_type"] new_image.os_arch = params["os_arch"] new_image.hypervisor = params["hypervisor"] new_image.description = params["description"] new_image.expires = params["expires"] new_image.read_only = params["read_only"] new_image.unauthenticated_access = params["unauthenticated_access"] # Non-user settable values uuid = h.image_uuid() current_time = datetime.utcfromtimestamp(time()) file_name = uuid + "_" + new_image.name new_image.owner = user new_image.uuid = uuid new_image.uploaded = current_time new_image.modified = current_time new_image.path = file_name new_image.raw_uploaded = False meta.Session.add(new_image) meta.Session.commit() response.headers["Location"] = url("raw_by_user", user=user.user_name, image=new_image.name) response.status = "201 Object created. upload raw file to 'Location'" return h.render_json(beautify.image(new_image))
def show_meta_by_user(self, user, image, format='json'): image_q = meta.Session.query(Image) image = image_q.filter(Image.name==image)\ .filter(Image.owner.has(User.user_name==user))\ .first() if image: inline_auth(AnyOf(OwnsImage(image), SharedWith(image)), auth_403) if format == 'json': response.headers[ 'content-type'] = app_globals.json_content_type return h.render_json(beautify.image(image)) else: abort(501, '501 Not Implemented') else: abort(404, '404 Not Found')