Пример #1
0
 def setUp(self):
     super(HTTPClientTest, self).setUp()
     osprofiler.profiler.init(None)
     self.client = httpclient.HTTPClient(API_BASE_URL,
                                         auth_token=AUTH_TOKEN,
                                         project_id=PROJECT_ID,
                                         user_id=USER_ID)
Пример #2
0
    def __init__(self, auth_type='keystone', **kwargs):
        req = copy.deepcopy(kwargs)
        mistral_url = req.get('mistral_url')
        profile = req.get('profile')

        if mistral_url and not isinstance(mistral_url, six.string_types):
            raise RuntimeError('Mistral url should be a string.')

        auth_handler = auth.get_auth_handler(auth_type)
        auth_response = auth_handler.authenticate(req) or {}

        req.update(auth_response)

        mistral_url = auth_response.get('mistral_url') or mistral_url

        if not mistral_url:
            mistral_url = _DEFAULT_MISTRAL_URL

        if profile:
            osprofiler_profiler.init(profile)

        http_client = httpclient.HTTPClient(mistral_url, **req)

        # Create all resource managers.
        self.workbooks = workbooks.WorkbookManager(http_client)
        self.executions = executions.ExecutionManager(http_client)
        self.tasks = tasks.TaskManager(http_client)
        self.actions = actions.ActionManager(http_client)
        self.workflows = workflows.WorkflowManager(http_client)
        self.cron_triggers = cron_triggers.CronTriggerManager(http_client)
        self.environments = environments.EnvironmentManager(http_client)
        self.action_executions = action_executions.ActionExecutionManager(
            http_client)
        self.services = services.ServiceManager(http_client)
        self.members = members.MemberManager(http_client)
 def setUp(self):
     super(HTTPClientTest, self).setUp()
     self.client = httpclient.HTTPClient(API_BASE_URL,
                                         auth_token=AUTH_TOKEN,
                                         project_id=PROJECT_ID,
                                         user_id=USER_ID,
                                         region_name=REGION_NAME)
Пример #4
0
    def __init__(self, auth_type='keystone', **kwargs):
        # We get the session at this point, as some instances of session
        # objects might have mutexes that can't be deep-copied.
        session = kwargs.pop('session', None)
        req = copy.deepcopy(kwargs)
        mistral_url = req.get('mistral_url')
        profile = req.get('profile')

        if mistral_url and not isinstance(mistral_url, str):
            raise RuntimeError('Mistral url should be a string.')

        # If auth url was provided then we perform an authentication, otherwise
        # just ignore this step
        if req.get('auth_url') or req.get('target_auth_url'):
            auth_handler = auth.get_auth_handler(auth_type)
            auth_response = auth_handler.authenticate(req, session=session)
        else:
            auth_response = {}

        if session is None:
            # If the session was None and we're using keystone auth, it will be
            # created by the auth_handler.
            session = auth_response.pop('session', None)

        req.update(auth_response)

        mistral_url = auth_response.get('mistral_url') or mistral_url

        if not mistral_url:
            mistral_url = _DEFAULT_MISTRAL_URL

        if profile:
            osprofiler_profiler.init(profile)

        http_client = httpclient.HTTPClient(mistral_url,
                                            session=session,
                                            **req)

        # Create all resource managers.
        self.workbooks = workbooks.WorkbookManager(http_client)
        self.executions = executions.ExecutionManager(http_client)
        self.tasks = tasks.TaskManager(http_client)
        self.actions = actions.ActionManager(http_client)
        self.workflows = workflows.WorkflowManager(http_client)
        self.cron_triggers = cron_triggers.CronTriggerManager(http_client)
        self.event_triggers = event_triggers.EventTriggerManager(http_client)
        self.environments = environments.EnvironmentManager(http_client)
        self.action_executions = action_executions.ActionExecutionManager(
            http_client)
        self.services = services.ServiceManager(http_client)
        self.members = members.MemberManager(http_client)
        self.code_sources = code_sources.CodeSourceManager(http_client)
        self.dynamic_actions = dynamic_actions.DynamicActionManager(
            http_client)
Пример #5
0
    def test_get_request_options_with_headers_for_get(self):
        m = self.requests_mock.get(EXPECTED_URL, text='text')
        target_auth_url = uuidutils.generate_uuid()
        target_auth_token = uuidutils.generate_uuid()
        target_user_id = 'target_user'
        target_project_id = 'target_project'
        target_service_catalog = 'this should be there'
        target_insecure = 'target insecure'
        target_region = 'target region name'
        target_user_domain_name = 'target user domain name'
        target_project_domain_name = 'target project domain name'

        target_client = httpclient.HTTPClient(
            API_BASE_URL,
            auth_token=AUTH_TOKEN,
            project_id=PROJECT_ID,
            user_id=USER_ID,
            region_name=REGION_NAME,
            target_auth_url=target_auth_url,
            target_auth_token=target_auth_token,
            target_project_id=target_project_id,
            target_user_id=target_user_id,
            target_service_catalog=target_service_catalog,
            target_region_name=target_region,
            target_user_domain_name=target_user_domain_name,
            target_project_domain_name=target_project_domain_name,
            target_insecure=target_insecure
        )

        target_client.get(API_URL)

        self.assertTrue(m.called_once)
        headers = self.assertExpectedAuthHeaders()
        self.assertEqual(target_auth_url, headers['X-Target-Auth-Uri'])
        self.assertEqual(target_auth_token, headers['X-Target-Auth-Token'])
        self.assertEqual(target_user_id, headers['X-Target-User-Id'])
        self.assertEqual(target_project_id, headers['X-Target-Project-Id'])
        self.assertEqual(str(target_insecure), headers['X-Target-Insecure'])
        self.assertEqual(target_region, headers['X-Target-Region-Name'])
        self.assertEqual(target_user_domain_name,
                         headers['X-Target-User-Domain-Name'])
        self.assertEqual(target_project_domain_name,
                         headers['X-Target-Project-Domain-Name'])

        catalog = base64.b64encode(target_service_catalog.encode('utf-8'))
        self.assertEqual(catalog, headers['X-Target-Service-Catalog'])
Пример #6
0
    def test_get_request_options_with_headers_for_get(self):
        target_auth_url = uuidutils.generate_uuid()
        target_auth_token = uuidutils.generate_uuid()
        target_user_id = 'target_user'
        target_project_id = 'target_project'
        target_service_catalog = 'this should be there'
        target_insecure = 'target insecure'
        target_region = 'target region name'
        target_user_domain_name = 'target user domain name'
        target_project_domain_name = 'target project domain name'

        target_client = httpclient.HTTPClient(
            API_BASE_URL,
            auth_token=AUTH_TOKEN,
            project_id=PROJECT_ID,
            user_id=USER_ID,
            target_auth_url=target_auth_url,
            target_auth_token=target_auth_token,
            target_project_id=target_project_id,
            target_user_id=target_user_id,
            target_service_catalog=target_service_catalog,
            target_region_name=target_region,
            target_user_domain_name=target_user_domain_name,
            target_project_domain_name=target_project_domain_name,
            target_insecure=target_insecure)

        target_client.get(API_URL)

        expected_options = copy.deepcopy(EXPECTED_REQ_OPTIONS)

        headers = expected_options["headers"]

        headers["X-Target-Auth-Uri"] = target_auth_url
        headers["X-Target-Auth-Token"] = target_auth_token
        headers["X-Target-Insecure"] = target_insecure
        headers["X-Target-User-Id"] = target_user_id
        headers["X-Target-Project-Id"] = target_project_id
        headers["X-Target-Region-Name"] = target_region
        headers["X-Target-User-Domain-Name"] = target_user_domain_name
        headers["X-Target-Project-Domain-Name"] = target_project_domain_name

        catalog = base64.b64encode(target_service_catalog.encode('utf-8'))
        headers["X-Target-Service-Catalog"] = catalog

        requests.get.assert_called_with(EXPECTED_URL, **expected_options)
Пример #7
0
    def test_get_request_options_with_headers_for_get(self):
        target_auth_uri = str(uuid.uuid4())
        target_token = str(uuid.uuid4())

        target_client = httpclient.HTTPClient(API_BASE_URL,
                                              AUTH_TOKEN,
                                              PROJECT_ID,
                                              USER_ID,
                                              target_auth_uri=target_auth_uri,
                                              target_token=target_token)

        target_client.get(API_URL)

        expected_options = copy.deepcopy(EXPECTED_REQ_OPTIONS)
        expected_options["headers"]["X-Target-Auth-Uri"] = target_auth_uri
        expected_options["headers"]["X-Target-Auth-Token"] = target_token

        requests.get.assert_called_with(EXPECTED_URL, **expected_options)
    def __init__(self,
                 mistral_url=None,
                 username=None,
                 api_key=None,
                 project_name=None,
                 auth_url=None,
                 project_id=None,
                 endpoint_type='publicURL',
                 service_type='workflowv2',
                 auth_token=None,
                 user_id=None,
                 cacert=None,
                 insecure=False):

        if mistral_url and not isinstance(mistral_url, six.string_types):
            raise RuntimeError('Mistral url should be string')

        if auth_url:
            (mistral_url, auth_token, project_id,
             user_id) = (self.authenticate(mistral_url, username, api_key,
                                           project_name, auth_url, project_id,
                                           endpoint_type, service_type,
                                           auth_token, user_id, cacert,
                                           insecure))

        if not mistral_url:
            mistral_url = "http://localhost:8989/v2"

        self.http_client = httpclient.HTTPClient(mistral_url, auth_token,
                                                 project_id, user_id)

        # Create all resource managers.
        self.workbooks = workbooks.WorkbookManager(self)
        self.executions = executions.ExecutionManager(self)
        self.tasks = tasks.TaskManager(self)
        self.actions = actions.ActionManager(self)
        self.workflows = workflows.WorkflowManager(self)
        self.cron_triggers = cron_triggers.CronTriggerManager(self)
        self.environments = environments.EnvironmentManager(self)
        self.action_executions = action_executions.ActionExecutionManager(self)
        self.services = services.ServiceManager(self)
Пример #9
0
 def setUp(self):
     super(HTTPClientTest, self).setUp()
     osprofiler.profiler.init(None)
     self.client = httpclient.HTTPClient(API_BASE_URL, AUTH_TOKEN,
                                         PROJECT_ID, USER_ID)
Пример #10
0
    def __init__(self, mistral_url=None, username=None, api_key=None,
                 project_name=None, auth_url=None, project_id=None,
                 endpoint_type='publicURL', service_type='workflowv2',
                 auth_token=None, user_id=None, cacert=None, insecure=False,
                 profile=None, auth_type=auth_types.KEYSTONE, client_id=None,
                 client_secret=None, target_username=None, target_api_key=None,
                 target_project_name=None, target_auth_url=None,
                 target_project_id=None, target_auth_token=None,
                 target_user_id=None, target_cacert=None,
                 target_insecure=False, **kwargs):

        if mistral_url and not isinstance(mistral_url, six.string_types):
            raise RuntimeError('Mistral url should be a string.')

        if auth_url:
            if auth_type == auth_types.KEYSTONE:
                (mistral_url, auth_token, project_id, user_id) = (
                    keystone.authenticate(
                        mistral_url,
                        username,
                        api_key,
                        project_name,
                        auth_url,
                        project_id,
                        endpoint_type,
                        service_type,
                        auth_token,
                        user_id,
                        cacert,
                        insecure
                    )
                )
            elif auth_type == auth_types.KEYCLOAK_OIDC:
                auth_token = keycloak.authenticate(
                    auth_url,
                    client_id,
                    client_secret,
                    project_name,
                    username,
                    api_key,
                    auth_token,
                    cacert,
                    insecure
                )

                # In case of KeyCloak OpenID Connect we can treat project
                # name and id in the same way because KeyCloak realm is
                # essentially a different OpenID Connect Issuer which in
                # KeyCloak is represented just as a URL path component
                # (see http://openid.net/specs/openid-connect-core-1_0.html).
                project_id = project_name
            else:
                raise RuntimeError(
                    'Invalid authentication type [value=%s, valid_values=%s]'
                    % (auth_type, auth_types.ALL)
                )

        if not mistral_url:
            mistral_url = _DEFAULT_MISTRAL_URL

        if profile:
            osprofiler_profiler.init(profile)

        if target_auth_url:
            keystone.authenticate(
                mistral_url,
                target_username,
                target_api_key,
                target_project_name,
                target_auth_url,
                target_project_id,
                endpoint_type,
                service_type,
                target_auth_token,
                target_user_id,
                target_cacert,
                target_insecure
            )

        http_client = httpclient.HTTPClient(
            mistral_url,
            auth_token,
            project_id,
            user_id,
            cacert=cacert,
            insecure=insecure,
            target_token=target_auth_token,
            target_auth_uri=target_auth_url,
            **kwargs
        )

        # Create all resource managers.
        self.workbooks = workbooks.WorkbookManager(http_client)
        self.executions = executions.ExecutionManager(http_client)
        self.tasks = tasks.TaskManager(http_client)
        self.actions = actions.ActionManager(http_client)
        self.workflows = workflows.WorkflowManager(http_client)
        self.cron_triggers = cron_triggers.CronTriggerManager(http_client)
        self.environments = environments.EnvironmentManager(http_client)
        self.action_executions = action_executions.ActionExecutionManager(
            http_client)
        self.services = services.ServiceManager(http_client)
        self.members = members.MemberManager(http_client)