def _generate_assignment_rid(self, url, environ): resource_id = '' # for role assignment or revocation, the URL is of format: # /v3/projects/{project_id}/users/{user_id}/roles/{role_id} # We need to extract all ID parameters from the URL role_id = proxy_utils.get_routing_match_value(environ, 'role_id') proj_id = proxy_utils.get_routing_match_value(environ, 'project_id') user_id = proxy_utils.get_routing_match_value(environ, 'user_id') if (not role_id or not proj_id or not user_id): LOG.error("Malformed Role Assignment or Revocation URL: %s", url) else: resource_id = "{}_{}_{}".format(proj_id, user_id, role_id) return resource_id
def _process_keypairs(self, **kwargs): resource_info = {} user_id = None environ = kwargs.get('environ') operation_type = kwargs.get('operation_type') if operation_type == consts.OPERATION_TYPE_POST: operation_type = consts.OPERATION_TYPE_CREATE request = json.loads(kwargs.get('request_body')) resource_info = request[kwargs.get('resource_type')] if 'public_key' not in resource_info: # need to get the public_key from response resp = json.loads(kwargs.get('response_body')) resp_info = resp.get(kwargs.get('resource_type')) resource_info['public_key'] = resp_info.get('public_key') if 'user_id' in resource_info: user_id = resource_info['user_id'] resource_id = resource_info['name'] else: resource_id = proxy_utils.get_routing_match_value( environ, consts.RESOURCE_TYPE_COMPUTE_KEYPAIR) user_id = proxy_utils.get_user_id(environ) if user_id is None: user_id = environ.get('HTTP_X_USER_ID', '') # resource_id = "name/user_id" resource_id = utils.keypair_construct_id(resource_id, user_id) resource_info = json.dumps(resource_info) LOG.info("Operation:(%s), resource_id:(%s), resource_info:(%s)", operation_type, resource_id, resource_info) return operation_type, resource_id, resource_info
def process_response(self, request, response): if CONF.show_response: LOG.info("Response: (%s)", str(response)) LOG.info("Response status: (%s)", response.status) action = proxy_utils.get_routing_match_value(request.environ, 'action') if self.ok_response(response) and action in self.response_hander_map: handler = self.response_hander_map[action] return handler(request, response) else: return response
def patch_delete_req(self, request, response): patch_ids = proxy_utils.get_routing_match_value( request.environ, 'patch_id') LOG.info("Deleting patches: %s", patch_ids) patch_list = os.path.normpath(patch_ids).split(os.path.sep) for patch_file in patch_list: LOG.debug("Patch file:(%s)", patch_file) self.delete_patch_from_version_vault( os.path.basename(patch_file) + '.patch') return response
def _process_extra_spec(self, **kwargs): environ = kwargs.get('environ') resource_id = self._get_flavor_id_from_environ(environ) operation_type = kwargs.get('operation_type') if operation_type == consts.OPERATION_TYPE_DELETE: extra_spec = proxy_utils.get_routing_match_value( environ, 'extra_spec') resource_dict = {consts.ACTION_EXTRASPECS_DELETE: extra_spec} resource_info = json.dumps(resource_dict) else: resource_info = kwargs.get('request_body') LOG.info("Operation:(%s), resource_id:(%s), resource_info:(%s)", operation_type, resource_id, resource_info) return consts.OPERATION_TYPE_ACTION, resource_id, resource_info
def _get_resource_type_from_environ(request_environ): return proxy_utils.get_routing_match_value(request_environ, 'action')
def _get_flavor_id_from_environ(environ): return proxy_utils.get_routing_match_value(environ, 'flavor_id')