@azure/keyvault-admin 4.6.1-alpha.20250206.1 → 4.6.1-alpha.20250211.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,26 +55,26 @@ You can find more information on different ways of authenticating and their corr
55
55
 
56
56
  Once you've authenticated with [the authentication method that suits you best][default_azure_credential], you can create a `KeyVaultAccessControlClient` as follows, substituting in your Managed HSM URL in the constructor:
57
57
 
58
- ```javascript
59
- const { DefaultAzureCredential } = require("@azure/identity");
60
- const { KeyVaultAccessControlClient } = require("@azure/keyvault-admin");
58
+ ```ts snippet:ReadmeSampleCreateAccessControlClient
59
+ import { DefaultAzureCredential } from "@azure/identity";
60
+ import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
61
61
 
62
+ const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
62
63
  const credentials = new DefaultAzureCredential();
63
-
64
- const client = new KeyVaultAccessControlClient(`<your Managed HSM URL>`, credentials);
64
+ const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
65
65
  ```
66
66
 
67
67
  ### Create KeyVaultBackupClient
68
68
 
69
69
  Once you've authenticated with [the authentication method that suits you best][default_azure_credential], you can create a `KeyVaultBackupClient` as follows, substituting in your Managed HSM URL in the constructor:
70
70
 
71
- ```javascript
72
- const { DefaultAzureCredential } = require("@azure/identity");
73
- const { KeyVaultBackupClient } = require("@azure/keyvault-admin");
71
+ ```ts snippet:ReadmeSampleCreateBackupClient
72
+ import { DefaultAzureCredential } from "@azure/identity";
73
+ import { KeyVaultBackupClient } from "@azure/keyvault-admin";
74
74
 
75
+ const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
75
76
  const credentials = new DefaultAzureCredential();
76
-
77
- const client = new KeyVaultBackupClient(`<your Managed HSM URL>`, credentials);
77
+ const client = new KeyVaultBackupClient(vaultUrl, credentials);
78
78
  ```
79
79
 
80
80
  ## Key concepts
@@ -122,8 +122,8 @@ See our [troubleshooting guide](https://github.com/Azure/azure-sdk-for-js/blob/m
122
122
 
123
123
  Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
124
124
 
125
- ```javascript
126
- const { setLogLevel } = require("@azure/logger");
125
+ ```ts snippet:SetLogLevel
126
+ import { setLogLevel } from "@azure/logger";
127
127
 
128
128
  setLogLevel("info");
129
129
  ```
@@ -140,8 +140,6 @@ You can find more code samples through the following links:
140
140
 
141
141
  If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.
142
142
 
143
-
144
-
145
143
  <!-- LINKS -->
146
144
 
147
145
  [compiler-options]: https://www.typescriptlang.org/docs/handbook/compiler-options.html
@@ -19,14 +19,13 @@ export declare class KeyVaultAccessControlClient {
19
19
  * Creates an instance of the KeyVaultAccessControlClient.
20
20
  *
21
21
  * Example usage:
22
- * ```ts
23
- * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
22
+ * ```ts snippet:ReadmeSampleCreateAccessControlClient
24
23
  * import { DefaultAzureCredential } from "@azure/identity";
24
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
25
25
  *
26
- * let vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
27
- * let credentials = new DefaultAzureCredential();
28
- *
29
- * let client = new KeyVaultAccessControlClient(vaultUrl, credentials);
26
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
27
+ * const credentials = new DefaultAzureCredential();
28
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
30
29
  * ```
31
30
  * @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net`. You should validate that this URL references a valid Key Vault or Managed HSM resource. See https://aka.ms/azsdk/blog/vault-uri for details.
32
31
  * @param credential - An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the \@azure/identity package to create a credential that suits your needs.
@@ -37,11 +36,23 @@ export declare class KeyVaultAccessControlClient {
37
36
  * Creates a role assignment in an Azure Key Vault.
38
37
  *
39
38
  * Example usage:
40
- * ```ts
41
- * const client = new KeyVaultAccessControlClient(url, credentials);
42
- * const roleDefinition = await client.listRoleDefinitions("/").next();
39
+ * ```ts snippet:ReadmeSampleCreateRoleAssignment
40
+ * import { DefaultAzureCredential } from "@azure/identity";
41
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
42
+ *
43
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
44
+ * const credentials = new DefaultAzureCredential();
45
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
46
+ *
47
+ * const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
48
+ *
43
49
  * const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
44
- * const result = await client.createRoleAssignment("/", "295c179b-9ad3-4117-99cd-b1aa66cf4517", roleDefinition, principalId);
50
+ * const result = await client.createRoleAssignment(
51
+ * "/",
52
+ * "295c179b-9ad3-4117-99cd-b1aa66cf4517",
53
+ * roleDefinition.id,
54
+ * principalId,
55
+ * );
45
56
  * ```
46
57
  * Creates a new role assignment.
47
58
  * @param roleScope - The scope of the role assignment.
@@ -55,10 +66,25 @@ export declare class KeyVaultAccessControlClient {
55
66
  * Deletes role assignments previously created in an Azure Key Vault.
56
67
  *
57
68
  * Example usage:
58
- * ```ts
59
- * const client = new KeyVaultAccessControlClient(url, credentials);
60
- * const roleAssignment = await client.createRoleAssignment("/", "295c179b-9ad3-4117-99cd-b1aa66cf4517");
61
- * await client.deleteRoleAssignment(roleAssignment.properties.roleScope, roleAssignment.name);
69
+ * ```ts snippet:ReadmeSampleDeleteRoleAssignment
70
+ * import { DefaultAzureCredential } from "@azure/identity";
71
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
72
+ *
73
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
74
+ * const credentials = new DefaultAzureCredential();
75
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
76
+ *
77
+ * const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
78
+ * const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
79
+ *
80
+ * const roleAssignment = await client.createRoleAssignment(
81
+ * "/",
82
+ * "295c179b-9ad3-4117-99cd-b1aa66cf4517",
83
+ * roleDefinition.id,
84
+ * principalId,
85
+ * );
86
+ *
87
+ * await client.deleteRoleAssignment(roleAssignment.properties.scope, roleAssignment.name);
62
88
  * ```
63
89
  * Deletes an existing role assignment.
64
90
  * @param roleScope - The scope of the role assignment.
@@ -70,10 +96,28 @@ export declare class KeyVaultAccessControlClient {
70
96
  * Gets a role assignments previously created in an Azure Key Vault.
71
97
  *
72
98
  * Example usage:
73
- * ```ts
74
- * const client = new KeyVaultAccessControlClient(url, credentials);
75
- * let roleAssignment = await client.createRoleAssignment("/", "295c179b-9ad3-4117-99cd-b1aa66cf4517");
76
- * roleAssignment = const await client.getRoleAssignment(roleAssignment.properties.roleScope, roleAssignment.name);
99
+ * ```ts snippet:ReadmeSampleGetRoleAssignment
100
+ * import { DefaultAzureCredential } from "@azure/identity";
101
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
102
+ *
103
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
104
+ * const credentials = new DefaultAzureCredential();
105
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
106
+ *
107
+ * const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
108
+ * const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
109
+ *
110
+ * let roleAssignment = await client.createRoleAssignment(
111
+ * "/",
112
+ * "295c179b-9ad3-4117-99cd-b1aa66cf4517",
113
+ * roleDefinition.id,
114
+ * principalId,
115
+ * );
116
+ *
117
+ * roleAssignment = await client.getRoleAssignment(
118
+ * roleAssignment.properties.scope,
119
+ * roleAssignment.name,
120
+ * );
77
121
  * console.log(roleAssignment);
78
122
  * ```
79
123
  * Gets an existing role assignment.
@@ -86,8 +130,14 @@ export declare class KeyVaultAccessControlClient {
86
130
  * Iterates over all of the available role assignments in an Azure Key Vault.
87
131
  *
88
132
  * Example usage:
89
- * ```ts
90
- * let client = new KeyVaultAccessControlClient(url, credentials);
133
+ * ```ts snippet:ReadmeSampleListRoleAssignments
134
+ * import { DefaultAzureCredential } from "@azure/identity";
135
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
136
+ *
137
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
138
+ * const credentials = new DefaultAzureCredential();
139
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
140
+ *
91
141
  * for await (const roleAssignment of client.listRoleAssignments("/")) {
92
142
  * console.log("Role assignment: ", roleAssignment);
93
143
  * }
@@ -101,8 +151,14 @@ export declare class KeyVaultAccessControlClient {
101
151
  * Iterates over all of the available role definitions in an Azure Key Vault.
102
152
  *
103
153
  * Example usage:
104
- * ```ts
105
- * let client = new KeyVaultAccessControlClient(url, credentials);
154
+ * ```ts snippet:ReadmeSampleListRoleDefinitions
155
+ * import { DefaultAzureCredential } from "@azure/identity";
156
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
157
+ *
158
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
159
+ * const credentials = new DefaultAzureCredential();
160
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
161
+ *
106
162
  * for await (const roleDefinitions of client.listRoleDefinitions("/")) {
107
163
  * console.log("Role definition: ", roleDefinitions);
108
164
  * }
@@ -116,8 +172,14 @@ export declare class KeyVaultAccessControlClient {
116
172
  * Gets a role definition from Azure Key Vault.
117
173
  *
118
174
  * Example usage:
119
- * ```
120
- * const client = new KeyVaultAccessControlClient(url, credentials);
175
+ * ```ts snippet:ReadmeSampleGetRoleDefinition
176
+ * import { DefaultAzureCredential } from "@azure/identity";
177
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
178
+ *
179
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
180
+ * const credentials = new DefaultAzureCredential();
181
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
182
+ *
121
183
  * const roleDefinition = await client.getRoleDefinition("/", "b86a8fe4-44ce-4948-aee5-eccb2c155cd7");
122
184
  * console.log(roleDefinition);
123
185
  * ```
@@ -130,11 +192,24 @@ export declare class KeyVaultAccessControlClient {
130
192
  * Creates or updates a role definition in an Azure Key Vault.
131
193
  *
132
194
  * Example usage:
133
- * ```ts
134
- * const client = new KeyVaultAccessControlClient(url, credentials);
195
+ * ```ts snippet:ReadmeSampleSetRoleDefinition
196
+ * import { DefaultAzureCredential } from "@azure/identity";
197
+ * import {
198
+ * KeyVaultAccessControlClient,
199
+ * KnownKeyVaultDataAction,
200
+ * KnownKeyVaultRoleScope,
201
+ * } from "@azure/keyvault-admin";
202
+ *
203
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
204
+ * const credentials = new DefaultAzureCredential();
205
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
206
+ *
135
207
  * const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];
136
208
  * const roleDefinitionName = "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a";
137
- * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, { permissions, roleDefinitionName });
209
+ * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {
210
+ * permissions,
211
+ * roleDefinitionName,
212
+ * });
138
213
  * console.log(roleDefinition);
139
214
  * ```
140
215
  * @param roleScope - The scope of the role definition.
@@ -145,9 +220,25 @@ export declare class KeyVaultAccessControlClient {
145
220
  * Deletes a custom role definition previously created in an Azure Key Vault.
146
221
  *
147
222
  * Example usage:
148
- * ```ts
149
- * const client = new KeyVaultAccessControlClient(url, credentials);
150
- * const roleDefinition = await client.setRoleDefinition("/", "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a", []);
223
+ * ```ts snippet:ReadmeSampleDeleteRoleDefinition
224
+ * import { DefaultAzureCredential } from "@azure/identity";
225
+ * import {
226
+ * KeyVaultAccessControlClient,
227
+ * KnownKeyVaultDataAction,
228
+ * KnownKeyVaultRoleScope,
229
+ * } from "@azure/keyvault-admin";
230
+ *
231
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
232
+ * const credentials = new DefaultAzureCredential();
233
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
234
+ *
235
+ * const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];
236
+ * const roleDefinitionName = "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a";
237
+ * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {
238
+ * permissions,
239
+ * roleDefinitionName,
240
+ * });
241
+ *
151
242
  * await client.deleteRoleDefinition("/", roleDefinition.name);
152
243
  * ```
153
244
  * @param roleScope - The scope of the role definition.
@@ -1 +1 @@
1
- {"version":3,"file":"accessControlClient.d.ts","sourceRoot":"","sources":["../../src/accessControlClient.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,0BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,EAC1B,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMxD;;;;GAIG;AACH,qBAAa,2BAA2B;IACtC;;OAEG;IACH,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAEjC;;OAEG;IACH,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gCG;IACI,iBAAiB,CACtB,SAAS,EAAE,iBAAiB,EAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,sBAAsB,CAAC;IAWlC;;;;;;;;;;;;;;;;;;;OAmBG;IACI,mBAAmB,CACxB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,0BAA+B,GACvC,0BAA0B,CAAC,sBAAsB,CAAC;IAQrD;;;;;;;;;;;;;;;;;;;OAmBG;IACI,mBAAmB,CACxB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,0BAA+B,GACvC,0BAA0B,CAAC,sBAAsB,CAAC;IAQrD;;;;;;;;;;;;;;;;;;OAkBG;IACI,iBAAiB,CACtB,SAAS,EAAE,iBAAiB,EAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,sBAAsB,CAAC;IAWlC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACI,iBAAiB,CACtB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,sBAAsB,CAAC;IAwBlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACI,oBAAoB,CACzB,SAAS,EAAE,iBAAiB,EAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,IAAI,CAAC;CAgBjB"}
@@ -18,14 +18,13 @@ class KeyVaultAccessControlClient {
18
18
  * Creates an instance of the KeyVaultAccessControlClient.
19
19
  *
20
20
  * Example usage:
21
- * ```ts
22
- * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
21
+ * ```ts snippet:ReadmeSampleCreateAccessControlClient
23
22
  * import { DefaultAzureCredential } from "@azure/identity";
23
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
24
24
  *
25
- * let vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
26
- * let credentials = new DefaultAzureCredential();
27
- *
28
- * let client = new KeyVaultAccessControlClient(vaultUrl, credentials);
25
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
26
+ * const credentials = new DefaultAzureCredential();
27
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
29
28
  * ```
30
29
  * @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net`. You should validate that this URL references a valid Key Vault or Managed HSM resource. See https://aka.ms/azsdk/blog/vault-uri for details.
31
30
  * @param credential - An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the \@azure/identity package to create a credential that suits your needs.
@@ -41,11 +40,23 @@ class KeyVaultAccessControlClient {
41
40
  * Creates a role assignment in an Azure Key Vault.
42
41
  *
43
42
  * Example usage:
44
- * ```ts
45
- * const client = new KeyVaultAccessControlClient(url, credentials);
46
- * const roleDefinition = await client.listRoleDefinitions("/").next();
43
+ * ```ts snippet:ReadmeSampleCreateRoleAssignment
44
+ * import { DefaultAzureCredential } from "@azure/identity";
45
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
46
+ *
47
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
48
+ * const credentials = new DefaultAzureCredential();
49
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
50
+ *
51
+ * const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
52
+ *
47
53
  * const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
48
- * const result = await client.createRoleAssignment("/", "295c179b-9ad3-4117-99cd-b1aa66cf4517", roleDefinition, principalId);
54
+ * const result = await client.createRoleAssignment(
55
+ * "/",
56
+ * "295c179b-9ad3-4117-99cd-b1aa66cf4517",
57
+ * roleDefinition.id,
58
+ * principalId,
59
+ * );
49
60
  * ```
50
61
  * Creates a new role assignment.
51
62
  * @param roleScope - The scope of the role assignment.
@@ -69,10 +80,25 @@ class KeyVaultAccessControlClient {
69
80
  * Deletes role assignments previously created in an Azure Key Vault.
70
81
  *
71
82
  * Example usage:
72
- * ```ts
73
- * const client = new KeyVaultAccessControlClient(url, credentials);
74
- * const roleAssignment = await client.createRoleAssignment("/", "295c179b-9ad3-4117-99cd-b1aa66cf4517");
75
- * await client.deleteRoleAssignment(roleAssignment.properties.roleScope, roleAssignment.name);
83
+ * ```ts snippet:ReadmeSampleDeleteRoleAssignment
84
+ * import { DefaultAzureCredential } from "@azure/identity";
85
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
86
+ *
87
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
88
+ * const credentials = new DefaultAzureCredential();
89
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
90
+ *
91
+ * const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
92
+ * const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
93
+ *
94
+ * const roleAssignment = await client.createRoleAssignment(
95
+ * "/",
96
+ * "295c179b-9ad3-4117-99cd-b1aa66cf4517",
97
+ * roleDefinition.id,
98
+ * principalId,
99
+ * );
100
+ *
101
+ * await client.deleteRoleAssignment(roleAssignment.properties.scope, roleAssignment.name);
76
102
  * ```
77
103
  * Deletes an existing role assignment.
78
104
  * @param roleScope - The scope of the role assignment.
@@ -96,10 +122,28 @@ class KeyVaultAccessControlClient {
96
122
  * Gets a role assignments previously created in an Azure Key Vault.
97
123
  *
98
124
  * Example usage:
99
- * ```ts
100
- * const client = new KeyVaultAccessControlClient(url, credentials);
101
- * let roleAssignment = await client.createRoleAssignment("/", "295c179b-9ad3-4117-99cd-b1aa66cf4517");
102
- * roleAssignment = const await client.getRoleAssignment(roleAssignment.properties.roleScope, roleAssignment.name);
125
+ * ```ts snippet:ReadmeSampleGetRoleAssignment
126
+ * import { DefaultAzureCredential } from "@azure/identity";
127
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
128
+ *
129
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
130
+ * const credentials = new DefaultAzureCredential();
131
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
132
+ *
133
+ * const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
134
+ * const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
135
+ *
136
+ * let roleAssignment = await client.createRoleAssignment(
137
+ * "/",
138
+ * "295c179b-9ad3-4117-99cd-b1aa66cf4517",
139
+ * roleDefinition.id,
140
+ * principalId,
141
+ * );
142
+ *
143
+ * roleAssignment = await client.getRoleAssignment(
144
+ * roleAssignment.properties.scope,
145
+ * roleAssignment.name,
146
+ * );
103
147
  * console.log(roleAssignment);
104
148
  * ```
105
149
  * Gets an existing role assignment.
@@ -117,8 +161,14 @@ class KeyVaultAccessControlClient {
117
161
  * Iterates over all of the available role assignments in an Azure Key Vault.
118
162
  *
119
163
  * Example usage:
120
- * ```ts
121
- * let client = new KeyVaultAccessControlClient(url, credentials);
164
+ * ```ts snippet:ReadmeSampleListRoleAssignments
165
+ * import { DefaultAzureCredential } from "@azure/identity";
166
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
167
+ *
168
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
169
+ * const credentials = new DefaultAzureCredential();
170
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
171
+ *
122
172
  * for await (const roleAssignment of client.listRoleAssignments("/")) {
123
173
  * console.log("Role assignment: ", roleAssignment);
124
174
  * }
@@ -134,8 +184,14 @@ class KeyVaultAccessControlClient {
134
184
  * Iterates over all of the available role definitions in an Azure Key Vault.
135
185
  *
136
186
  * Example usage:
137
- * ```ts
138
- * let client = new KeyVaultAccessControlClient(url, credentials);
187
+ * ```ts snippet:ReadmeSampleListRoleDefinitions
188
+ * import { DefaultAzureCredential } from "@azure/identity";
189
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
190
+ *
191
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
192
+ * const credentials = new DefaultAzureCredential();
193
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
194
+ *
139
195
  * for await (const roleDefinitions of client.listRoleDefinitions("/")) {
140
196
  * console.log("Role definition: ", roleDefinitions);
141
197
  * }
@@ -151,8 +207,14 @@ class KeyVaultAccessControlClient {
151
207
  * Gets a role definition from Azure Key Vault.
152
208
  *
153
209
  * Example usage:
154
- * ```
155
- * const client = new KeyVaultAccessControlClient(url, credentials);
210
+ * ```ts snippet:ReadmeSampleGetRoleDefinition
211
+ * import { DefaultAzureCredential } from "@azure/identity";
212
+ * import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
213
+ *
214
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
215
+ * const credentials = new DefaultAzureCredential();
216
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
217
+ *
156
218
  * const roleDefinition = await client.getRoleDefinition("/", "b86a8fe4-44ce-4948-aee5-eccb2c155cd7");
157
219
  * console.log(roleDefinition);
158
220
  * ```
@@ -170,11 +232,24 @@ class KeyVaultAccessControlClient {
170
232
  * Creates or updates a role definition in an Azure Key Vault.
171
233
  *
172
234
  * Example usage:
173
- * ```ts
174
- * const client = new KeyVaultAccessControlClient(url, credentials);
235
+ * ```ts snippet:ReadmeSampleSetRoleDefinition
236
+ * import { DefaultAzureCredential } from "@azure/identity";
237
+ * import {
238
+ * KeyVaultAccessControlClient,
239
+ * KnownKeyVaultDataAction,
240
+ * KnownKeyVaultRoleScope,
241
+ * } from "@azure/keyvault-admin";
242
+ *
243
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
244
+ * const credentials = new DefaultAzureCredential();
245
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
246
+ *
175
247
  * const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];
176
248
  * const roleDefinitionName = "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a";
177
- * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, { permissions, roleDefinitionName });
249
+ * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {
250
+ * permissions,
251
+ * roleDefinitionName,
252
+ * });
178
253
  * console.log(roleDefinition);
179
254
  * ```
180
255
  * @param roleScope - The scope of the role definition.
@@ -198,9 +273,25 @@ class KeyVaultAccessControlClient {
198
273
  * Deletes a custom role definition previously created in an Azure Key Vault.
199
274
  *
200
275
  * Example usage:
201
- * ```ts
202
- * const client = new KeyVaultAccessControlClient(url, credentials);
203
- * const roleDefinition = await client.setRoleDefinition("/", "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a", []);
276
+ * ```ts snippet:ReadmeSampleDeleteRoleDefinition
277
+ * import { DefaultAzureCredential } from "@azure/identity";
278
+ * import {
279
+ * KeyVaultAccessControlClient,
280
+ * KnownKeyVaultDataAction,
281
+ * KnownKeyVaultRoleScope,
282
+ * } from "@azure/keyvault-admin";
283
+ *
284
+ * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
285
+ * const credentials = new DefaultAzureCredential();
286
+ * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
287
+ *
288
+ * const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];
289
+ * const roleDefinitionName = "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a";
290
+ * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {
291
+ * permissions,
292
+ * roleDefinitionName,
293
+ * });
294
+ *
204
295
  * await client.deleteRoleDefinition("/", roleDefinition.name);
205
296
  * ```
206
297
  * @param roleScope - The scope of the role definition.
@@ -1 +1 @@
1
- {"version":3,"file":"accessControlClient.js","sourceRoot":"","sources":["../../src/accessControlClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;AAClC,4CAA4C;;;AAmB5C,+CAAgE;AAChE,6CAA6C;AAC7C,gDAA8C;AAC9C,uEAAiE;AAEjE;;;;GAIG;AACH,MAAa,2BAA2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AAK,GAAG,EAAE,CAAC;oBAC3B,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA5SD,kEA4SC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n/// <reference lib=\"esnext.asynciterable\" />\n\nimport type {\n AccessControlClientOptions,\n CreateRoleAssignmentOptions,\n DeleteRoleAssignmentOptions,\n DeleteRoleDefinitionOptions,\n GetRoleAssignmentOptions,\n GetRoleDefinitionOptions,\n KeyVaultRoleAssignment,\n KeyVaultRoleDefinition,\n KeyVaultRoleScope,\n ListRoleAssignmentsOptions,\n ListRoleDefinitionsOptions,\n SetRoleDefinitionOptions,\n} from \"./accessControlModels.js\";\nimport type { KeyVaultClient } from \"./generated/keyVaultClient.js\";\nimport type { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport { mapPagedAsyncIterable, mappings } from \"./mappings.js\";\nimport { tracingClient } from \"./tracing.js\";\nimport { randomUUID } from \"@azure/core-util\";\nimport { createKeyVaultClient } from \"./createKeyVaultClient.js\";\n\n/**\n * The KeyVaultAccessControlClient provides methods to manage\n * access control and role assignments in any given Azure Key Vault instance.\n * The client supports creating, retrieving and deleting roles.\n */\nexport class KeyVaultAccessControlClient {\n /**\n * The base URL to the vault\n */\n public readonly vaultUrl: string;\n\n /**\n * A reference to the auto-generated Key Vault HTTP client.\n */\n private readonly client: KeyVaultClient;\n\n /**\n * Creates an instance of the KeyVaultAccessControlClient.\n *\n * Example usage:\n * ```ts\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * let vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * let credentials = new DefaultAzureCredential();\n *\n * let client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n * ```\n * @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net`. You should validate that this URL references a valid Key Vault or Managed HSM resource. See https://aka.ms/azsdk/blog/vault-uri for details.\n * @param credential - An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the \\@azure/identity package to create a credential that suits your needs.\n * @param options - Options used to configure Key Vault API requests. Omit this parameter to use the default configuration.\n */\n constructor(\n vaultUrl: string,\n credential: TokenCredential,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: AccessControlClientOptions = {},\n ) {\n this.vaultUrl = vaultUrl;\n\n this.client = createKeyVaultClient(vaultUrl, credential, options);\n }\n\n /**\n * Creates a role assignment in an Azure Key Vault.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultAccessControlClient(url, credentials);\n * const roleDefinition = await client.listRoleDefinitions(\"/\").next();\n * const principalId = \"4871f6a6-374f-4b6b-8b0c-f5d84db823f6\";\n * const result = await client.createRoleAssignment(\"/\", \"295c179b-9ad3-4117-99cd-b1aa66cf4517\", roleDefinition, principalId);\n * ```\n * Creates a new role assignment.\n * @param roleScope - The scope of the role assignment.\n * @param name - The name of the role assignment. Must be a UUID.\n * @param roleDefinitionId - The role definition ID used in the role assignment.\n * @param principalId - The principal ID assigned to the role. This maps to the ID inside the Active Directory. It can point to a user, service principal, or security group.\n * @param options - The optional parameters.\n */\n public createRoleAssignment(\n roleScope: KeyVaultRoleScope,\n name: string,\n roleDefinitionId: string,\n principalId: string,\n options: CreateRoleAssignmentOptions = {},\n ): Promise<KeyVaultRoleAssignment> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.createRoleAssignment\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleAssignments.create(\n roleScope,\n name,\n {\n properties: {\n roleDefinitionId,\n principalId,\n },\n },\n updatedOptions,\n );\n return mappings.roleAssignment.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Deletes role assignments previously created in an Azure Key Vault.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultAccessControlClient(url, credentials);\n * const roleAssignment = await client.createRoleAssignment(\"/\", \"295c179b-9ad3-4117-99cd-b1aa66cf4517\");\n * await client.deleteRoleAssignment(roleAssignment.properties.roleScope, roleAssignment.name);\n * ```\n * Deletes an existing role assignment.\n * @param roleScope - The scope of the role assignment.\n * @param name - The name of the role assignment.\n * @param options - The optional parameters.\n */\n public deleteRoleAssignment(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: DeleteRoleAssignmentOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.deleteRoleAssignment\",\n options,\n async (updatedOptions) => {\n try {\n await this.client.roleAssignments.delete(roleScope, name, updatedOptions);\n } catch (err: any) {\n // If the role assignment doesn't exist, we can consider it deleted.\n if (err.statusCode !== 404) {\n throw err;\n }\n }\n },\n );\n }\n\n /**\n * Gets a role assignments previously created in an Azure Key Vault.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultAccessControlClient(url, credentials);\n * let roleAssignment = await client.createRoleAssignment(\"/\", \"295c179b-9ad3-4117-99cd-b1aa66cf4517\");\n * roleAssignment = const await client.getRoleAssignment(roleAssignment.properties.roleScope, roleAssignment.name);\n * console.log(roleAssignment);\n * ```\n * Gets an existing role assignment.\n * @param roleScope - The scope of the role assignment.\n * @param name - The name of the role assignment.\n * @param options - The optional parameters.\n */\n public getRoleAssignment(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: GetRoleAssignmentOptions = {},\n ): Promise<KeyVaultRoleAssignment> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.getRoleAssignment\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleAssignments.get(roleScope, name, updatedOptions);\n return mappings.roleAssignment.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Iterates over all of the available role assignments in an Azure Key Vault.\n *\n * Example usage:\n * ```ts\n * let client = new KeyVaultAccessControlClient(url, credentials);\n * for await (const roleAssignment of client.listRoleAssignments(\"/\")) {\n * console.log(\"Role assignment: \", roleAssignment);\n * }\n * ```\n * Lists all of the role assignments in a given scope.\n * @param roleScope - The scope of the role assignments.\n * @param options - The optional parameters.\n */\n public listRoleAssignments(\n roleScope: KeyVaultRoleScope,\n options: ListRoleAssignmentsOptions = {},\n ): PagedAsyncIterableIterator<KeyVaultRoleAssignment> {\n return mapPagedAsyncIterable(\n options,\n (mappedOptions) => this.client.roleAssignments.listForScope(roleScope, mappedOptions),\n mappings.roleAssignment.generatedToPublic,\n );\n }\n\n /**\n * Iterates over all of the available role definitions in an Azure Key Vault.\n *\n * Example usage:\n * ```ts\n * let client = new KeyVaultAccessControlClient(url, credentials);\n * for await (const roleDefinitions of client.listRoleDefinitions(\"/\")) {\n * console.log(\"Role definition: \", roleDefinitions);\n * }\n * ```\n * Lists all of the role definition in a given scope.\n * @param roleScope - The scope of the role definition.\n * @param options - The optional parameters.\n */\n public listRoleDefinitions(\n roleScope: KeyVaultRoleScope,\n options: ListRoleDefinitionsOptions = {},\n ): PagedAsyncIterableIterator<KeyVaultRoleDefinition> {\n return mapPagedAsyncIterable(\n options,\n (mappedOptions) => this.client.roleDefinitions.list(roleScope, mappedOptions),\n mappings.roleDefinition.generatedToPublic,\n );\n }\n\n /**\n * Gets a role definition from Azure Key Vault.\n *\n * Example usage:\n * ```\n * const client = new KeyVaultAccessControlClient(url, credentials);\n * const roleDefinition = await client.getRoleDefinition(\"/\", \"b86a8fe4-44ce-4948-aee5-eccb2c155cd7\");\n * console.log(roleDefinition);\n * ```\n * @param roleScope - The scope of the role definition.\n * @param name - The name of the role definition.\n * @param options - The optional parameters.\n */\n public getRoleDefinition(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: GetRoleDefinitionOptions = {},\n ): Promise<KeyVaultRoleDefinition> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.getRoleDefinition\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleDefinitions.get(roleScope, name, updatedOptions);\n return mappings.roleDefinition.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Creates or updates a role definition in an Azure Key Vault.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultAccessControlClient(url, credentials);\n * const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];\n * const roleDefinitionName = \"23b8bb1a-39c0-4c89-a85b-dd3c99273a8a\";\n * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, { permissions, roleDefinitionName });\n * console.log(roleDefinition);\n * ```\n * @param roleScope - The scope of the role definition.\n * @param options - The optional parameters.\n */\n public setRoleDefinition(\n roleScope: KeyVaultRoleScope,\n options: SetRoleDefinitionOptions = {},\n ): Promise<KeyVaultRoleDefinition> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.setRoleDefinition\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleDefinitions.createOrUpdate(\n roleScope,\n options.roleDefinitionName || randomUUID(),\n {\n properties: {\n description: options.description,\n permissions: options.permissions,\n assignableScopes: [roleScope],\n roleName: options.roleName,\n roleType: \"CustomRole\",\n },\n },\n updatedOptions,\n );\n return mappings.roleDefinition.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Deletes a custom role definition previously created in an Azure Key Vault.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultAccessControlClient(url, credentials);\n * const roleDefinition = await client.setRoleDefinition(\"/\", \"23b8bb1a-39c0-4c89-a85b-dd3c99273a8a\", []);\n * await client.deleteRoleDefinition(\"/\", roleDefinition.name);\n * ```\n * @param roleScope - The scope of the role definition.\n * @param name - The name of the role definition to delete.\n * @param options - The optional parameters.\n */\n public deleteRoleDefinition(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: DeleteRoleDefinitionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.deleteRoleDefinition\",\n options,\n async (updatedOptions) => {\n try {\n await this.client.roleDefinitions.delete(roleScope, name, updatedOptions);\n } catch (err: any) {\n // If the role definition doesn't exist, we can consider it deleted.\n if (err.statusCode !== 404) {\n throw err;\n }\n }\n },\n );\n }\n}\n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5B,IAAY,EACZ,UAAuC,EAAE;QAEzC,OAAO,0BAAa,CAAC,QAAQ,CAC3B,kDAAkD,EAClD,OAAO,EACP,KAAK,EAAE,cAAc,EAAE,EAAE;YACvB,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;YAC5E,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,oEAAoE;gBACpE,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;oBAC3B,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAvYD,kEAuYC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n/// <reference lib=\"esnext.asynciterable\" />\n\nimport type {\n AccessControlClientOptions,\n CreateRoleAssignmentOptions,\n DeleteRoleAssignmentOptions,\n DeleteRoleDefinitionOptions,\n GetRoleAssignmentOptions,\n GetRoleDefinitionOptions,\n KeyVaultRoleAssignment,\n KeyVaultRoleDefinition,\n KeyVaultRoleScope,\n ListRoleAssignmentsOptions,\n ListRoleDefinitionsOptions,\n SetRoleDefinitionOptions,\n} from \"./accessControlModels.js\";\nimport type { KeyVaultClient } from \"./generated/keyVaultClient.js\";\nimport type { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport type { TokenCredential } from \"@azure/core-auth\";\nimport { mapPagedAsyncIterable, mappings } from \"./mappings.js\";\nimport { tracingClient } from \"./tracing.js\";\nimport { randomUUID } from \"@azure/core-util\";\nimport { createKeyVaultClient } from \"./createKeyVaultClient.js\";\n\n/**\n * The KeyVaultAccessControlClient provides methods to manage\n * access control and role assignments in any given Azure Key Vault instance.\n * The client supports creating, retrieving and deleting roles.\n */\nexport class KeyVaultAccessControlClient {\n /**\n * The base URL to the vault\n */\n public readonly vaultUrl: string;\n\n /**\n * A reference to the auto-generated Key Vault HTTP client.\n */\n private readonly client: KeyVaultClient;\n\n /**\n * Creates an instance of the KeyVaultAccessControlClient.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleCreateAccessControlClient\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n * ```\n * @param vaultUrl - the URL of the Key Vault. It should have this shape: `https://${your-key-vault-name}.vault.azure.net`. You should validate that this URL references a valid Key Vault or Managed HSM resource. See https://aka.ms/azsdk/blog/vault-uri for details.\n * @param credential - An object that implements the `TokenCredential` interface used to authenticate requests to the service. Use the \\@azure/identity package to create a credential that suits your needs.\n * @param options - Options used to configure Key Vault API requests. Omit this parameter to use the default configuration.\n */\n constructor(\n vaultUrl: string,\n credential: TokenCredential,\n // eslint-disable-next-line @azure/azure-sdk/ts-naming-options\n options: AccessControlClientOptions = {},\n ) {\n this.vaultUrl = vaultUrl;\n\n this.client = createKeyVaultClient(vaultUrl, credential, options);\n }\n\n /**\n * Creates a role assignment in an Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleCreateRoleAssignment\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * const { value: roleDefinition } = await client.listRoleDefinitions(\"/\").next();\n *\n * const principalId = \"4871f6a6-374f-4b6b-8b0c-f5d84db823f6\";\n * const result = await client.createRoleAssignment(\n * \"/\",\n * \"295c179b-9ad3-4117-99cd-b1aa66cf4517\",\n * roleDefinition.id,\n * principalId,\n * );\n * ```\n * Creates a new role assignment.\n * @param roleScope - The scope of the role assignment.\n * @param name - The name of the role assignment. Must be a UUID.\n * @param roleDefinitionId - The role definition ID used in the role assignment.\n * @param principalId - The principal ID assigned to the role. This maps to the ID inside the Active Directory. It can point to a user, service principal, or security group.\n * @param options - The optional parameters.\n */\n public createRoleAssignment(\n roleScope: KeyVaultRoleScope,\n name: string,\n roleDefinitionId: string,\n principalId: string,\n options: CreateRoleAssignmentOptions = {},\n ): Promise<KeyVaultRoleAssignment> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.createRoleAssignment\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleAssignments.create(\n roleScope,\n name,\n {\n properties: {\n roleDefinitionId,\n principalId,\n },\n },\n updatedOptions,\n );\n return mappings.roleAssignment.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Deletes role assignments previously created in an Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleDeleteRoleAssignment\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * const { value: roleDefinition } = await client.listRoleDefinitions(\"/\").next();\n * const principalId = \"4871f6a6-374f-4b6b-8b0c-f5d84db823f6\";\n *\n * const roleAssignment = await client.createRoleAssignment(\n * \"/\",\n * \"295c179b-9ad3-4117-99cd-b1aa66cf4517\",\n * roleDefinition.id,\n * principalId,\n * );\n *\n * await client.deleteRoleAssignment(roleAssignment.properties.scope, roleAssignment.name);\n * ```\n * Deletes an existing role assignment.\n * @param roleScope - The scope of the role assignment.\n * @param name - The name of the role assignment.\n * @param options - The optional parameters.\n */\n public deleteRoleAssignment(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: DeleteRoleAssignmentOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.deleteRoleAssignment\",\n options,\n async (updatedOptions) => {\n try {\n await this.client.roleAssignments.delete(roleScope, name, updatedOptions);\n } catch (err: any) {\n // If the role assignment doesn't exist, we can consider it deleted.\n if (err.statusCode !== 404) {\n throw err;\n }\n }\n },\n );\n }\n\n /**\n * Gets a role assignments previously created in an Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleGetRoleAssignment\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * const { value: roleDefinition } = await client.listRoleDefinitions(\"/\").next();\n * const principalId = \"4871f6a6-374f-4b6b-8b0c-f5d84db823f6\";\n *\n * let roleAssignment = await client.createRoleAssignment(\n * \"/\",\n * \"295c179b-9ad3-4117-99cd-b1aa66cf4517\",\n * roleDefinition.id,\n * principalId,\n * );\n *\n * roleAssignment = await client.getRoleAssignment(\n * roleAssignment.properties.scope,\n * roleAssignment.name,\n * );\n * console.log(roleAssignment);\n * ```\n * Gets an existing role assignment.\n * @param roleScope - The scope of the role assignment.\n * @param name - The name of the role assignment.\n * @param options - The optional parameters.\n */\n public getRoleAssignment(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: GetRoleAssignmentOptions = {},\n ): Promise<KeyVaultRoleAssignment> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.getRoleAssignment\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleAssignments.get(roleScope, name, updatedOptions);\n return mappings.roleAssignment.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Iterates over all of the available role assignments in an Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleListRoleAssignments\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * for await (const roleAssignment of client.listRoleAssignments(\"/\")) {\n * console.log(\"Role assignment: \", roleAssignment);\n * }\n * ```\n * Lists all of the role assignments in a given scope.\n * @param roleScope - The scope of the role assignments.\n * @param options - The optional parameters.\n */\n public listRoleAssignments(\n roleScope: KeyVaultRoleScope,\n options: ListRoleAssignmentsOptions = {},\n ): PagedAsyncIterableIterator<KeyVaultRoleAssignment> {\n return mapPagedAsyncIterable(\n options,\n (mappedOptions) => this.client.roleAssignments.listForScope(roleScope, mappedOptions),\n mappings.roleAssignment.generatedToPublic,\n );\n }\n\n /**\n * Iterates over all of the available role definitions in an Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleListRoleDefinitions\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * for await (const roleDefinitions of client.listRoleDefinitions(\"/\")) {\n * console.log(\"Role definition: \", roleDefinitions);\n * }\n * ```\n * Lists all of the role definition in a given scope.\n * @param roleScope - The scope of the role definition.\n * @param options - The optional parameters.\n */\n public listRoleDefinitions(\n roleScope: KeyVaultRoleScope,\n options: ListRoleDefinitionsOptions = {},\n ): PagedAsyncIterableIterator<KeyVaultRoleDefinition> {\n return mapPagedAsyncIterable(\n options,\n (mappedOptions) => this.client.roleDefinitions.list(roleScope, mappedOptions),\n mappings.roleDefinition.generatedToPublic,\n );\n }\n\n /**\n * Gets a role definition from Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleGetRoleDefinition\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import { KeyVaultAccessControlClient } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * const roleDefinition = await client.getRoleDefinition(\"/\", \"b86a8fe4-44ce-4948-aee5-eccb2c155cd7\");\n * console.log(roleDefinition);\n * ```\n * @param roleScope - The scope of the role definition.\n * @param name - The name of the role definition.\n * @param options - The optional parameters.\n */\n public getRoleDefinition(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: GetRoleDefinitionOptions = {},\n ): Promise<KeyVaultRoleDefinition> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.getRoleDefinition\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleDefinitions.get(roleScope, name, updatedOptions);\n return mappings.roleDefinition.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Creates or updates a role definition in an Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleSetRoleDefinition\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import {\n * KeyVaultAccessControlClient,\n * KnownKeyVaultDataAction,\n * KnownKeyVaultRoleScope,\n * } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];\n * const roleDefinitionName = \"23b8bb1a-39c0-4c89-a85b-dd3c99273a8a\";\n * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {\n * permissions,\n * roleDefinitionName,\n * });\n * console.log(roleDefinition);\n * ```\n * @param roleScope - The scope of the role definition.\n * @param options - The optional parameters.\n */\n public setRoleDefinition(\n roleScope: KeyVaultRoleScope,\n options: SetRoleDefinitionOptions = {},\n ): Promise<KeyVaultRoleDefinition> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.setRoleDefinition\",\n options,\n async (updatedOptions) => {\n const response = await this.client.roleDefinitions.createOrUpdate(\n roleScope,\n options.roleDefinitionName || randomUUID(),\n {\n properties: {\n description: options.description,\n permissions: options.permissions,\n assignableScopes: [roleScope],\n roleName: options.roleName,\n roleType: \"CustomRole\",\n },\n },\n updatedOptions,\n );\n return mappings.roleDefinition.generatedToPublic(response);\n },\n );\n }\n\n /**\n * Deletes a custom role definition previously created in an Azure Key Vault.\n *\n * Example usage:\n * ```ts snippet:ReadmeSampleDeleteRoleDefinition\n * import { DefaultAzureCredential } from \"@azure/identity\";\n * import {\n * KeyVaultAccessControlClient,\n * KnownKeyVaultDataAction,\n * KnownKeyVaultRoleScope,\n * } from \"@azure/keyvault-admin\";\n *\n * const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;\n * const credentials = new DefaultAzureCredential();\n * const client = new KeyVaultAccessControlClient(vaultUrl, credentials);\n *\n * const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];\n * const roleDefinitionName = \"23b8bb1a-39c0-4c89-a85b-dd3c99273a8a\";\n * const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {\n * permissions,\n * roleDefinitionName,\n * });\n *\n * await client.deleteRoleDefinition(\"/\", roleDefinition.name);\n * ```\n * @param roleScope - The scope of the role definition.\n * @param name - The name of the role definition to delete.\n * @param options - The optional parameters.\n */\n public deleteRoleDefinition(\n roleScope: KeyVaultRoleScope,\n name: string,\n options: DeleteRoleDefinitionOptions = {},\n ): Promise<void> {\n return tracingClient.withSpan(\n \"KeyVaultAccessControlClient.deleteRoleDefinition\",\n options,\n async (updatedOptions) => {\n try {\n await this.client.roleDefinitions.delete(roleScope, name, updatedOptions);\n } catch (err: any) {\n // If the role definition doesn't exist, we can consider it deleted.\n if (err.statusCode !== 404) {\n throw err;\n }\n }\n },\n );\n }\n}\n"]}