def post(self): """Create a new user. Requires project admin privileges.""" context = request.environ.get('context') project_id = g.json["project_id"] dbapi.projects_get_by_id(context, project_id) api_key = uuidutils.generate_uuid() g.json["api_key"] = api_key user_obj = dbapi.users_create(context, g.json) return jsonutils.to_primitive(user_obj), 200, None
def post(self, context, request_data): """Create a new user. Requires project admin privileges.""" json = util.copy_project_id_into_json(context, request_data) project_id = json["project_id"] dbapi.projects_get_by_id(context, project_id) api_key = uuidutils.generate_uuid() request_data["api_key"] = api_key user_obj = dbapi.users_create(context, json) location = v1.api.url_for(UserById, id=user_obj.id, _external=True) headers = {'Location': location} return jsonutils.to_primitive(user_obj), 201, headers
def post(self, context, request_data): """Create a new user. Requires project admin privileges.""" # NOTE(sulo): Instead of using context project_id from # header, here we always ensure, user create gets project_id # from request param. project_id = request_data["project_id"] dbapi.projects_get_by_id(context, project_id) api_key = uuidutils.generate_uuid() request_data["api_key"] = api_key user_obj = dbapi.users_create(context, request_data) location = v1.api.url_for(UserById, id=user_obj.id, _external=True) headers = {'Location': location} return jsonutils.to_primitive(user_obj), 201, headers
def post(self): """Create a new user. Requires project admin privileges.""" context = request.environ.get('context') try: project_id = g.json["project_id"] dbapi.projects_get_by_id(context, project_id) except exceptions.NotFound: return self.error_response(404, 'Project with given id not found') try: api_key = uuidutils.generate_uuid() g.json["api_key"] = api_key user_obj = dbapi.users_create(context, g.json) except exceptions.AdminRequired: return self.error_response(401, 'This is admin only resource.') except Exception as err: LOG.error("Error during user create: %s" % err) return self.error_response(500, 'Unknown Error') user = jsonutils.to_primitive(user_obj) return user, 200, None