Skip to content

Add service principal resource #1809

Add service principal resource

Add service principal resource #1809

GitHub Actions / JUnit Test Report failed Dec 18, 2024 in 0s

110 tests run, 0 skipped, 6 failed.

Annotations

Check failure on line 222 in aws-lambda/tests/resources/service_principals/test_service_principal.py

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_service_principal.test_delete_service_principal

botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the GetParameter operation: The security token included in the request is invalid.
Raw output
patched_get_workspace_client = <MagicMock name='get_workspace_client' id='139818896173264'>
workspace_client = <MagicMock name='get_workspace_client()' spec='WorkspaceClient' id='139818896171344'>

    @patch("databricks_cdk.resources.service_principals.service_principal.get_workspace_client")
    def test_delete_service_principal(patched_get_workspace_client, workspace_client):
        patched_get_workspace_client.return_value = workspace_client
        mock_properties = ServicePrincipalProperties(
            workspace_url="https://test.cloud.databricks.com",
            service_principal=ServicePrincipal(
                active=True,
                display_name="mock_name",
                id="some_id",
            ),
        )
>       response = delete_service_principal(mock_properties, "some_id")

tests/resources/service_principals/test_service_principal.py:222: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/databricks_cdk/resources/service_principals/service_principal.py:107: in delete_service_principal
    account_client = get_account_client()
src/databricks_cdk/utils.py:191: in get_account_client
    client_id=get_client_id(),
src/databricks_cdk/utils.py:83: in get_client_id
    return get_param(CLIENT_ID_PARAM, required=True)
src/databricks_cdk/utils.py:39: in get_param
    response = ssm.get_parameter(
../../../../.cache/pypoetry/virtualenvs/databricks-cdk-B2166n-E-py3.11/lib/python3.11/site-packages/botocore/client.py:569: in _api_call
    return self._make_api_call(operation_name, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <botocore.client.SSM object at 0x7f2a1f945650>
operation_name = 'GetParameter'
api_params = {'Name': '/databricks/deploy/client-id', 'WithDecryption': True}

    def _make_api_call(self, operation_name, api_params):
        operation_model = self._service_model.operation_model(operation_name)
        service_name = self._service_model.service_name
        history_recorder.record(
            'API_CALL',
            {
                'service': service_name,
                'operation': operation_name,
                'params': api_params,
            },
        )
        if operation_model.deprecated:
            logger.debug(
                'Warning: %s.%s() is deprecated', service_name, operation_name
            )
        request_context = {
            'client_region': self.meta.region_name,
            'client_config': self.meta.config,
            'has_streaming_input': operation_model.has_streaming_input,
            'auth_type': operation_model.resolved_auth_type,
            'unsigned_payload': operation_model.unsigned_payload,
        }
    
        api_params = self._emit_api_params(
            api_params=api_params,
            operation_model=operation_model,
            context=request_context,
        )
        (
            endpoint_url,
            additional_headers,
            properties,
        ) = self._resolve_endpoint_ruleset(
            operation_model, api_params, request_context
        )
        if properties:
            # Pass arbitrary endpoint info with the Request
            # for use during construction.
            request_context['endpoint_properties'] = properties
        request_dict = self._convert_to_request_dict(
            api_params=api_params,
            operation_model=operation_model,
            endpoint_url=endpoint_url,
            context=request_context,
            headers=additional_headers,
        )
        resolve_checksum_context(request_dict, operation_model, api_params)
    
        service_id = self._service_model.service_id.hyphenize()
        handler, event_response = self.meta.events.emit_until_response(
            f'before-call.{service_id}.{operation_name}',
            model=operation_model,
            params=request_dict,
            request_signer=self._request_signer,
            context=request_context,
        )
    
        if event_response is not None:
            http, parsed_response = event_response
        else:
            maybe_compress_request(
                self.meta.config, request_dict, operation_model
            )
            apply_request_checksum(request_dict)
            http, parsed_response = self._make_request(
                operation_model, request_dict, request_context
            )
    
        self.meta.events.emit(
            f'after-call.{service_id}.{operation_name}',
            http_response=http,
            parsed=parsed_response,
            model=operation_model,
            context=request_context,
        )
    
        if http.status_code >= 300:
            error_info = parsed_response.get("Error", {})
            error_code = error_info.get("QueryErrorCode") or error_info.get(
                "Code"
            )
            error_class = self.exceptions.from_code(error_code)
>           raise error_class(parsed_response, operation_name)
E           botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the GetParameter operation: The security token included in the request is invalid.

../../../../.cache/pypoetry/virtualenvs/databricks-cdk-B2166n-E-py3.11/lib/python3.11/site-packages/botocore/client.py:1023: ClientError

Check failure on line 1 in aws-lambda/tests/resources/service_principals/test_service_principal_secrets.py

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_service_principal_secrets.test_create_or_update_service_principal_secrets_create

AttributeError: module 'databricks_cdk.resources.service_principals' has no attribute 'secrets'
Raw output
args = ()
keywargs = {'account_client': <MagicMock spec='AccountClient' id='139818884808784'>}

    @wraps(func)
    def patched(*args, **keywargs):
>       with self.decoration_helper(patched,
                                    args,
                                    keywargs) as (newargs, newkeywargs):

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1375: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/contextlib.py:137: in __enter__
    return next(self.gen)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1357: in decoration_helper
    arg = exit_stack.enter_context(patching)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/contextlib.py:517: in enter_context
    result = _enter(cm)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1430: in __enter__
    self.target = self.getter()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'databricks_cdk.resources.service_principals.secrets'

    def resolve_name(name):
        """
        Resolve a name to an object.
    
        It is expected that `name` will be a string in one of the following
        formats, where W is shorthand for a valid Python identifier and dot stands
        for a literal period in these pseudo-regexes:
    
        W(.W)*
        W(.W)*:(W(.W)*)?
    
        The first form is intended for backward compatibility only. It assumes that
        some part of the dotted name is a package, and the rest is an object
        somewhere within that package, possibly nested inside other objects.
        Because the place where the package stops and the object hierarchy starts
        can't be inferred by inspection, repeated attempts to import must be done
        with this form.
    
        In the second form, the caller makes the division point clear through the
        provision of a single colon: the dotted name to the left of the colon is a
        package to be imported, and the dotted name to the right is the object
        hierarchy within that package. Only one import is needed in this form. If
        it ends with the colon, then a module object is returned.
    
        The function will return an object (which might be a module), or raise one
        of the following exceptions:
    
        ValueError - if `name` isn't in a recognised format
        ImportError - if an import failed when it shouldn't have
        AttributeError - if a failure occurred when traversing the object hierarchy
                         within the imported package to get to the desired object.
        """
        global _NAME_PATTERN
        if _NAME_PATTERN is None:
            # Lazy import to speedup Python startup time
            import re
            dotted_words = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
            _NAME_PATTERN = re.compile(f'^(?P<pkg>{dotted_words})'
                                       f'(?P<cln>:(?P<obj>{dotted_words})?)?$',
                                       re.UNICODE)
    
        m = _NAME_PATTERN.match(name)
        if not m:
            raise ValueError(f'invalid format: {name!r}')
        gd = m.groupdict()
        if gd.get('cln'):
            # there is a colon - a one-step import is all that's needed
            mod = importlib.import_module(gd['pkg'])
            parts = gd.get('obj')
            parts = parts.split('.') if parts else []
        else:
            # no colon - have to iterate to find the package boundary
            parts = name.split('.')
            modname = parts.pop(0)
            # first part *must* be a module/package.
            mod = importlib.import_module(modname)
            while parts:
                p = parts[0]
                s = f'{modname}.{p}'
                try:
                    mod = importlib.import_module(s)
                    parts.pop(0)
                    modname = s
                except ImportError:
                    break
        # if we reach this point, mod is the module, already imported, and
        # parts is the list of parts in the object hierarchy to be traversed, or
        # an empty list if just the module is wanted.
        result = mod
        for p in parts:
>           result = getattr(result, p)
E           AttributeError: module 'databricks_cdk.resources.service_principals' has no attribute 'secrets'

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/pkgutil.py:715: AttributeError

Check failure on line 1 in aws-lambda/tests/resources/service_principals/test_service_principal_secrets.py

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_service_principal_secrets.test_create_or_update_service_principal_secrets_update

AttributeError: module 'databricks_cdk.resources.service_principals' has no attribute 'secrets'
Raw output
args = ()
keywargs = {'account_client': <MagicMock spec='AccountClient' id='139818895796816'>}

    @wraps(func)
    def patched(*args, **keywargs):
>       with self.decoration_helper(patched,
                                    args,
                                    keywargs) as (newargs, newkeywargs):

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1375: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/contextlib.py:137: in __enter__
    return next(self.gen)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1357: in decoration_helper
    arg = exit_stack.enter_context(patching)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/contextlib.py:517: in enter_context
    result = _enter(cm)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1430: in __enter__
    self.target = self.getter()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'databricks_cdk.resources.service_principals.secrets'

    def resolve_name(name):
        """
        Resolve a name to an object.
    
        It is expected that `name` will be a string in one of the following
        formats, where W is shorthand for a valid Python identifier and dot stands
        for a literal period in these pseudo-regexes:
    
        W(.W)*
        W(.W)*:(W(.W)*)?
    
        The first form is intended for backward compatibility only. It assumes that
        some part of the dotted name is a package, and the rest is an object
        somewhere within that package, possibly nested inside other objects.
        Because the place where the package stops and the object hierarchy starts
        can't be inferred by inspection, repeated attempts to import must be done
        with this form.
    
        In the second form, the caller makes the division point clear through the
        provision of a single colon: the dotted name to the left of the colon is a
        package to be imported, and the dotted name to the right is the object
        hierarchy within that package. Only one import is needed in this form. If
        it ends with the colon, then a module object is returned.
    
        The function will return an object (which might be a module), or raise one
        of the following exceptions:
    
        ValueError - if `name` isn't in a recognised format
        ImportError - if an import failed when it shouldn't have
        AttributeError - if a failure occurred when traversing the object hierarchy
                         within the imported package to get to the desired object.
        """
        global _NAME_PATTERN
        if _NAME_PATTERN is None:
            # Lazy import to speedup Python startup time
            import re
            dotted_words = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
            _NAME_PATTERN = re.compile(f'^(?P<pkg>{dotted_words})'
                                       f'(?P<cln>:(?P<obj>{dotted_words})?)?$',
                                       re.UNICODE)
    
        m = _NAME_PATTERN.match(name)
        if not m:
            raise ValueError(f'invalid format: {name!r}')
        gd = m.groupdict()
        if gd.get('cln'):
            # there is a colon - a one-step import is all that's needed
            mod = importlib.import_module(gd['pkg'])
            parts = gd.get('obj')
            parts = parts.split('.') if parts else []
        else:
            # no colon - have to iterate to find the package boundary
            parts = name.split('.')
            modname = parts.pop(0)
            # first part *must* be a module/package.
            mod = importlib.import_module(modname)
            while parts:
                p = parts[0]
                s = f'{modname}.{p}'
                try:
                    mod = importlib.import_module(s)
                    parts.pop(0)
                    modname = s
                except ImportError:
                    break
        # if we reach this point, mod is the module, already imported, and
        # parts is the list of parts in the object hierarchy to be traversed, or
        # an empty list if just the module is wanted.
        result = mod
        for p in parts:
>           result = getattr(result, p)
E           AttributeError: module 'databricks_cdk.resources.service_principals' has no attribute 'secrets'

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/pkgutil.py:715: AttributeError

Check failure on line 96 in aws-lambda/tests/resources/service_principals/test_service_principal_secrets.py

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_service_principal_secrets.test_create_service_principal_secrets

AttributeError: Mock object has no attribute 'service_principals'
Raw output
account_client = <MagicMock spec='AccountClient' id='139818883158160'>

    def test_create_service_principal_secrets(account_client):
        mock_properties = ServicePrincipalSecretsProperties(service_principal_id=1)
        account_client.service_principal_secrets.create.return_value = CreateServicePrincipalSecretResponse(id="some_id")
>       response = create_service_principal_secrets(mock_properties, account_client)

tests/resources/service_principals/test_service_principal_secrets.py:96: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/databricks_cdk/resources/service_principals/service_principal_secrets.py:71: in create_service_principal_secrets
    service_principal = get_service_principal(properties.service_principal_id, account_client)
src/databricks_cdk/resources/service_principals/service_principal.py:52: in get_service_principal
    service_principal = workspace_client.service_principals.get(id=physical_resource_id)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock spec='AccountClient' id='139818883158160'>
name = 'service_principals'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
>               raise AttributeError("Mock object has no attribute %r" % name)
E               AttributeError: Mock object has no attribute 'service_principals'

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:653: AttributeError

Check failure on line 109 in aws-lambda/tests/resources/service_principals/test_service_principal_secrets.py

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_service_principal_secrets.test_create_service_principal_secrets_error

AttributeError: Mock object has no attribute 'service_principals'
Raw output
account_client = <MagicMock spec='AccountClient' id='139818897966608'>

    def test_create_service_principal_secrets_error(account_client):
        mock_properties = ServicePrincipalSecretsProperties(service_principal_id=1)
        account_client.service_principal_secrets.create.return_value = CreateServicePrincipalSecretResponse(id=None)
    
        with pytest.raises(ServicePrincipalSecretsCreationError):
>           create_service_principal_secrets(mock_properties, account_client)

tests/resources/service_principals/test_service_principal_secrets.py:109: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/databricks_cdk/resources/service_principals/service_principal_secrets.py:71: in create_service_principal_secrets
    service_principal = get_service_principal(properties.service_principal_id, account_client)
src/databricks_cdk/resources/service_principals/service_principal.py:52: in get_service_principal
    service_principal = workspace_client.service_principals.get(id=physical_resource_id)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock spec='AccountClient' id='139818897966608'>
name = 'service_principals'

    def __getattr__(self, name):
        if name in {'_mock_methods', '_mock_unsafe'}:
            raise AttributeError(name)
        elif self._mock_methods is not None:
            if name not in self._mock_methods or name in _all_magics:
>               raise AttributeError("Mock object has no attribute %r" % name)
E               AttributeError: Mock object has no attribute 'service_principals'

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:653: AttributeError

Check failure on line 1 in aws-lambda/tests/resources/service_principals/test_service_principal_secrets.py

See this annotation in the file changed.

@github-actions github-actions / JUnit Test Report

test_service_principal_secrets.test_delete_service_principal

AttributeError: module 'databricks_cdk.resources.service_principals' has no attribute 'secrets'
Raw output
args = ()
keywargs = {'account_client': <MagicMock spec='AccountClient' id='139818887344848'>}

    @wraps(func)
    def patched(*args, **keywargs):
>       with self.decoration_helper(patched,
                                    args,
                                    keywargs) as (newargs, newkeywargs):

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1375: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/contextlib.py:137: in __enter__
    return next(self.gen)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1357: in decoration_helper
    arg = exit_stack.enter_context(patching)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/contextlib.py:517: in enter_context
    result = _enter(cm)
/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/unittest/mock.py:1430: in __enter__
    self.target = self.getter()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'databricks_cdk.resources.service_principals.secrets'

    def resolve_name(name):
        """
        Resolve a name to an object.
    
        It is expected that `name` will be a string in one of the following
        formats, where W is shorthand for a valid Python identifier and dot stands
        for a literal period in these pseudo-regexes:
    
        W(.W)*
        W(.W)*:(W(.W)*)?
    
        The first form is intended for backward compatibility only. It assumes that
        some part of the dotted name is a package, and the rest is an object
        somewhere within that package, possibly nested inside other objects.
        Because the place where the package stops and the object hierarchy starts
        can't be inferred by inspection, repeated attempts to import must be done
        with this form.
    
        In the second form, the caller makes the division point clear through the
        provision of a single colon: the dotted name to the left of the colon is a
        package to be imported, and the dotted name to the right is the object
        hierarchy within that package. Only one import is needed in this form. If
        it ends with the colon, then a module object is returned.
    
        The function will return an object (which might be a module), or raise one
        of the following exceptions:
    
        ValueError - if `name` isn't in a recognised format
        ImportError - if an import failed when it shouldn't have
        AttributeError - if a failure occurred when traversing the object hierarchy
                         within the imported package to get to the desired object.
        """
        global _NAME_PATTERN
        if _NAME_PATTERN is None:
            # Lazy import to speedup Python startup time
            import re
            dotted_words = r'(?!\d)(\w+)(\.(?!\d)(\w+))*'
            _NAME_PATTERN = re.compile(f'^(?P<pkg>{dotted_words})'
                                       f'(?P<cln>:(?P<obj>{dotted_words})?)?$',
                                       re.UNICODE)
    
        m = _NAME_PATTERN.match(name)
        if not m:
            raise ValueError(f'invalid format: {name!r}')
        gd = m.groupdict()
        if gd.get('cln'):
            # there is a colon - a one-step import is all that's needed
            mod = importlib.import_module(gd['pkg'])
            parts = gd.get('obj')
            parts = parts.split('.') if parts else []
        else:
            # no colon - have to iterate to find the package boundary
            parts = name.split('.')
            modname = parts.pop(0)
            # first part *must* be a module/package.
            mod = importlib.import_module(modname)
            while parts:
                p = parts[0]
                s = f'{modname}.{p}'
                try:
                    mod = importlib.import_module(s)
                    parts.pop(0)
                    modname = s
                except ImportError:
                    break
        # if we reach this point, mod is the module, already imported, and
        # parts is the list of parts in the object hierarchy to be traversed, or
        # an empty list if just the module is wanted.
        result = mod
        for p in parts:
>           result = getattr(result, p)
E           AttributeError: module 'databricks_cdk.resources.service_principals' has no attribute 'secrets'

/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/pkgutil.py:715: AttributeError