def process_request(self, req): # We only handle POST requests if req.method != 'POST': return # Extract webhook (receiver) ID and params results = self._parse_url(req.url) if not results: return (receiver_id, params) = results api_version = str(req.version_request) ctx = context.RequestContext(is_admin=True, api_version=api_version) req.context = ctx obj = util.parse_request( 'ReceiverGetRequest', req, {'identity': receiver_id}) rpcc = rpc.EngineClient() receiver = rpcc.call(ctx, 'receiver_get', obj) svc_ctx = context.get_service_credentials() kwargs = { 'auth_url': svc_ctx['auth_url'], 'username': svc_ctx['username'], 'user_domain_name': svc_ctx['user_domain_name'], 'password': svc_ctx['password'] } kwargs.update(receiver['actor']) # Get token and fill it into the request header token = self._get_token(**kwargs) req.headers['X-Auth-Token'] = token
def _get_base_url(self): base = None service_cred = senlin_context.get_service_credentials() kc = driver_base.SenlinDriver().identity(service_cred) try: base = kc.get_senlin_endpoint() except exception.InternalError as ex: LOG.warning('Senlin endpoint can not be found: %s.', ex) return base
def _init_context(self): profile_context = {} if self.CONTEXT in self.properties: profile_context = self.properties[self.CONTEXT] or {} ctx_dict = context.get_service_credentials(**profile_context) ctx_dict.pop('project_name', None) ctx_dict.pop('project_domain_name', None) return ctx_dict
def _get_trust(self, req): """List trusts with current user as the trustor. :param req: The WSGI request object. :return: ID of the trust or exception of InternalError. """ rpcc = rpc.EngineClient() ctx = req.context params = {'user': ctx.user_id, 'project': ctx.project_id} obj = util.parse_request('CredentialGetRequest', req, params) res = rpcc.call(ctx, 'credential_get', obj) if res: trust_id = res.get('trust', None) if trust_id: return trust_id params = { 'auth_url': ctx.auth_url, 'token': ctx.auth_token, 'project_id': ctx.project_id, 'user_id': ctx.user_id, } kc = driver_base.SenlinDriver().identity(params) service_cred = context.get_service_credentials() admin_id = kc.get_user_id(**service_cred) try: trust = kc.trust_get_by_trustor(ctx.user_id, admin_id, ctx.project_id) except exception.InternalError as ex: if ex.code == 400: trust = None else: raise if not trust: # Create a trust if no existing one found trust = kc.trust_create(ctx.user_id, admin_id, ctx.project_id, ctx.roles) # If credential not exists, create it, otherwise update it. cred = {'openstack': {'trust': trust.id}} params = {'cred': cred} obj = util.parse_request('CredentialCreateRequest', req, params) rpcc.call(ctx, 'credential_create', obj) return trust.id
def _build_conn_params(self, user, project): """Build trust-based connection parameters. :param user: the user for which the trust will be checked. :param project: the user for which the trust will be checked. """ service_creds = senlin_context.get_service_credentials() params = { 'username': service_creds.get('username'), 'password': service_creds.get('password'), 'auth_url': service_creds.get('auth_url'), 'user_domain_name': service_creds.get('user_domain_name') } cred = co.Credential.get(oslo_context.get_current(), user, project) if cred is None: raise exception.TrustNotFound(trustor=user) params['trust_id'] = cred.cred['openstack']['trust'] return params
def _build_conn_params(self, user, project): """Build connection params for specific user and project. :param user: The ID of the user for which a trust will be used. :param project: The ID of the project for which a trust will be used. :returns: A dict containing the required parameters for connection creation. """ service_creds = senlin_context.get_service_credentials() params = { 'username': service_creds.get('username'), 'password': service_creds.get('password'), 'auth_url': service_creds.get('auth_url'), 'user_domain_name': service_creds.get('user_domain_name') } cred = co.Credential.get(oslo_context.get_current(), user, project) if cred is None: raise exception.TrustNotFound(trustor=user) params['trust_id'] = cred.cred['openstack']['trust'] return params