1212
1313if TYPE_CHECKING :
1414 # pylint:disable=ungrouped-imports
15- from typing import Any , Union
15+ from typing import Any , Iterable , Union
1616 from uuid import UUID
1717 from azure .core .paging import ItemPaged
18- from ._models import KeyVaultRoleScope
18+ from ._enums import KeyVaultRoleScope
19+ from ._models import KeyVaultPermission
1920
2021
2122class KeyVaultAccessControlClient (KeyVaultClientBase ):
@@ -83,7 +84,7 @@ def get_role_assignment(self, role_scope, role_assignment_name, **kwargs):
8384 :param role_scope: the assignment's scope, for example "/", "/keys", or "/keys/<specific key identifier>"
8485 :class:`KeyVaultRoleScope` defines common broad scopes. Specify a narrower scope as a string.
8586 :type role_scope: str or KeyVaultRoleScope
86- :param role_assignment_name: the assignment's name. Must be a UUID.
87+ :param role_assignment_name: the assignment's name.
8788 :type role_assignment_name: str or uuid.UUID
8889 :rtype: KeyVaultRoleAssignment
8990 """
@@ -109,6 +110,84 @@ def list_role_assignments(self, role_scope, **kwargs):
109110 ** kwargs
110111 )
111112
113+ @distributed_trace
114+ def set_role_definition (self , role_scope , permissions , ** kwargs ):
115+ # type: (Union[str, KeyVaultRoleScope], Iterable[KeyVaultPermission], **Any) -> KeyVaultRoleDefinition
116+ """Creates or updates a custom role definition.
117+
118+ :param role_scope: scope of the role definition. :class:`KeyVaultRoleScope` defines common broad scopes.
119+ Specify a narrower scope as a string. Managed HSM only supports '/', or KeyVaultRoleScope.global_value.
120+ :type role_scope: str or KeyVaultRoleScope
121+ :param permissions: the role definition's permissions. An empty list results in a role definition with no action
122+ permissions.
123+ :type permissions: Iterable[KeyVaultPermission]
124+ :keyword role_definition_name: the role definition's name. Must be a UUID.
125+ :type role_definition_name: str or uuid.UUID
126+ :keyword assignable_scopes: the role definition's assignable scopes.
127+ :type assignable_scopes: list[str]
128+ :returns: The created or updated role definition
129+ :rtype: KeyVaultRoleDefinition
130+ """
131+ role_definition_name = kwargs .pop ("role_definition_name" , None ) or uuid4 ()
132+ permissions = [
133+ self ._client .role_definitions .models .Permission (
134+ actions = p .allowed_actions ,
135+ not_actions = p .denied_actions ,
136+ data_actions = p .allowed_data_actions ,
137+ not_data_actions = p .denied_data_actions ,
138+ )
139+ for p in permissions
140+ ]
141+
142+ properties = self ._client .role_definitions .models .RoleDefinitionProperties (
143+ role_name = role_definition_name , permissions = permissions , ** kwargs
144+ )
145+ parameters = self ._client .role_definitions .models .RoleDefinitionCreateParameters (properties = properties )
146+
147+ definition = self ._client .role_definitions .create_or_update (
148+ vault_base_url = self ._vault_url ,
149+ scope = role_scope ,
150+ role_definition_name = role_definition_name ,
151+ parameters = parameters ,
152+ ** kwargs
153+ )
154+ return KeyVaultRoleDefinition ._from_generated (definition )
155+
156+ @distributed_trace
157+ def get_role_definition (self , role_scope , role_definition_name , ** kwargs ):
158+ # type: (Union[str, KeyVaultRoleScope], Union[str, UUID], **Any) -> KeyVaultRoleDefinition
159+ """Get the specified role definition.
160+
161+ :param role_scope: scope of the role definition. :class:`KeyVaultRoleScope` defines common broad scopes.
162+ Specify a narrower scope as a string. Managed HSM only supports '/', or KeyVaultRoleScope.global_value.
163+ :type role_scope: str or KeyVaultRoleScope
164+ :param role_definition_name: the role definition's name.
165+ :type role_definition_name: str or uuid.UUID
166+ :rtype: KeyVaultRoleDefinition
167+ """
168+ definition = self ._client .role_definitions .get (
169+ vault_base_url = self ._vault_url , scope = role_scope , role_definition_name = str (role_definition_name ), ** kwargs
170+ )
171+ return KeyVaultRoleDefinition ._from_generated (definition )
172+
173+ @distributed_trace
174+ def delete_role_definition (self , role_scope , role_definition_name , ** kwargs ):
175+ # type: (Union[str, KeyVaultRoleScope], Union[str, UUID], **Any) -> KeyVaultRoleDefinition
176+ """Deletes a custom role definition.
177+
178+ :param role_scope: scope of the role definition. :class:`KeyVaultRoleScope` defines common broad scopes.
179+ Specify a narrower scope as a string. Managed HSM only supports '/', or KeyVaultRoleScope.global_value.
180+ :type role_scope: str or KeyVaultRoleScope
181+ :param role_definition_name: the role definition's name. Must be a UUID.
182+ :type role_definition_name: str or uuid.UUID
183+ :returns: the deleted role definition
184+ :rtype: KeyVaultRoleDefinition
185+ """
186+ definition = self ._client .role_definitions .delete (
187+ vault_base_url = self ._vault_url , scope = role_scope , role_definition_name = str (role_definition_name ), ** kwargs
188+ )
189+ return KeyVaultRoleDefinition ._from_generated (definition )
190+
112191 @distributed_trace
113192 def list_role_definitions (self , role_scope , ** kwargs ):
114193 # type: (Union[str, KeyVaultRoleScope], **Any) -> ItemPaged[KeyVaultRoleDefinition]
0 commit comments