Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KeyVault] Handle Role Definition UUID Name Internally #14218

Merged
merged 5 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License.
# ------------------------------------
from typing import TYPE_CHECKING
from uuid import uuid4

from azure.core.tracing.decorator import distributed_trace

Expand All @@ -27,18 +28,18 @@ class KeyVaultAccessControlClient(KeyVaultClientBase):
# pylint:disable=protected-access

@distributed_trace
def create_role_assignment(self, role_scope, role_assignment_name, role_definition_id, principal_id, **kwargs):
# type: (Union[str, KeyVaultRoleScope], Union[str, UUID], str, str, **Any) -> KeyVaultRoleAssignment
def create_role_assignment(self, role_scope, role_definition_id, principal_id, **kwargs):
# type: (Union[str, KeyVaultRoleScope], str, str, **Any) -> KeyVaultRoleAssignment
"""Create a role assignment.

:param role_scope: scope the role assignment will apply over. :class:`KeyVaultRoleScope` defines common
broad scopes. Specify a narrower scope as a string.
:type role_scope: str or KeyVaultRoleScope
:param role_assignment_name: a name for the role assignment. Must be a UUID.
:type role_assignment_name: str or uuid.UUID
:param str role_definition_id: ID of the role's definition
:param str principal_id: Azure Active Directory object ID of the principal which will be assigned the role. The
principal can be a user, service principal, or security group.
:keyword role_assignment_name: a name for the role assignment. Must be a UUID.
:type role_assignment_name: str or uuid.UUID
:rtype: KeyVaultRoleAssignment
"""
create_parameters = self._client.role_assignments.models.RoleAssignmentCreateParameters(
Expand All @@ -49,7 +50,7 @@ def create_role_assignment(self, role_scope, role_assignment_name, role_definiti
assignment = self._client.role_assignments.create(
vault_base_url=self._vault_url,
scope=role_scope,
role_assignment_name=role_assignment_name,
role_assignment_name=kwargs.pop("role_assignment_name", None) or uuid4(),
parameters=create_parameters,
**kwargs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License.
# ------------------------------------
from typing import TYPE_CHECKING
from uuid import uuid4

from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async
Expand All @@ -29,23 +30,18 @@ class KeyVaultAccessControlClient(AsyncKeyVaultClientBase):

@distributed_trace_async
async def create_role_assignment(
self,
role_scope: "Union[str, KeyVaultRoleScope]",
role_assignment_name: "Union[str, UUID]",
role_definition_id: str,
principal_id: str,
**kwargs: "Any"
self, role_scope: "Union[str, KeyVaultRoleScope]", role_definition_id: str, principal_id: str, **kwargs: "Any"
) -> KeyVaultRoleAssignment:
"""Create a role assignment.

:param role_scope: scope the role assignment will apply over. :class:`KeyVaultRoleScope` defines common broad
scopes. Specify a narrower scope as a string.
:type role_scope: str or KeyVaultRoleScope
:param role_assignment_name: a name for the role assignment. Must be a UUID.
:type role_assignment_name: str or uuid.UUID
:param str role_definition_id: ID of the role's definition
:param str principal_id: Azure Active Directory object ID of the principal which will be assigned the role. The
principal can be a user, service principal, or security group.
:keyword role_assignment_name: a name for the role assignment. Must be a UUID.
:type role_assignment_name: str or uuid.UUID
:rtype: KeyVaultRoleAssignment
"""
create_parameters = self._client.role_assignments.models.RoleAssignmentCreateParameters(
Expand All @@ -56,7 +52,7 @@ async def create_role_assignment(
assignment = await self._client.role_assignments.create(
vault_base_url=self._vault_url,
scope=role_scope,
role_assignment_name=role_assignment_name,
role_assignment_name=kwargs.pop("role_assignment_name", None) or uuid4(),
parameters=create_parameters,
**kwargs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_role_assignment(self, client):
principal_id = self.get_service_principal_id()
name = self.get_replayable_uuid("some-uuid")

created = client.create_role_assignment(scope, name, definition.id, principal_id)
created = client.create_role_assignment(scope, definition.id, principal_id, role_assignment_name=name)
assert created.name == name
assert created.principal_id == principal_id
assert created.role_definition_id == definition.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def test_role_assignment(self, client):
principal_id = self.get_service_principal_id()
name = self.get_replayable_uuid("some-uuid")

created = await client.create_role_assignment(scope, name, definition.id, principal_id)
created = await client.create_role_assignment(scope, definition.id, principal_id, role_assignment_name=name)
assert created.name == name
assert created.principal_id == principal_id
assert created.role_definition_id == definition.id
Expand Down