@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 +12 -14
- package/dist/commonjs/accessControlClient.d.ts +121 -30
- package/dist/commonjs/accessControlClient.d.ts.map +1 -1
- package/dist/commonjs/accessControlClient.js +121 -30
- package/dist/commonjs/accessControlClient.js.map +1 -1
- package/dist/commonjs/backupClient.d.ts +68 -58
- package/dist/commonjs/backupClient.d.ts.map +1 -1
- package/dist/commonjs/backupClient.js +5 -6
- package/dist/commonjs/backupClient.js.map +1 -1
- package/dist/commonjs/settingsClient.d.ts +5 -6
- package/dist/commonjs/settingsClient.d.ts.map +1 -1
- package/dist/commonjs/settingsClient.js +5 -6
- package/dist/commonjs/settingsClient.js.map +1 -1
- package/dist/esm/accessControlClient.d.ts +121 -30
- package/dist/esm/accessControlClient.d.ts.map +1 -1
- package/dist/esm/accessControlClient.js +121 -30
- package/dist/esm/accessControlClient.js.map +1 -1
- package/dist/esm/backupClient.d.ts +68 -58
- package/dist/esm/backupClient.d.ts.map +1 -1
- package/dist/esm/backupClient.js +5 -6
- package/dist/esm/backupClient.js.map +1 -1
- package/dist/esm/settingsClient.d.ts +5 -6
- package/dist/esm/settingsClient.d.ts.map +1 -1
- package/dist/esm/settingsClient.js +5 -6
- package/dist/esm/settingsClient.js.map +1 -1
- package/package.json +16 -16
|
@@ -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
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
42
|
-
*
|
|
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(
|
|
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
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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, {
|
|
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
|
-
*
|
|
150
|
-
*
|
|
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;;OA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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"}
|
|
@@ -15,14 +15,13 @@ export class KeyVaultAccessControlClient {
|
|
|
15
15
|
* Creates an instance of the KeyVaultAccessControlClient.
|
|
16
16
|
*
|
|
17
17
|
* Example usage:
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
18
|
+
* ```ts snippet:ReadmeSampleCreateAccessControlClient
|
|
20
19
|
* import { DefaultAzureCredential } from "@azure/identity";
|
|
20
|
+
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* let client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
22
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
23
|
+
* const credentials = new DefaultAzureCredential();
|
|
24
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
26
25
|
* ```
|
|
27
26
|
* @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.
|
|
28
27
|
* @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.
|
|
@@ -38,11 +37,23 @@ export class KeyVaultAccessControlClient {
|
|
|
38
37
|
* Creates a role assignment in an Azure Key Vault.
|
|
39
38
|
*
|
|
40
39
|
* Example usage:
|
|
41
|
-
* ```ts
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
* ```ts snippet:ReadmeSampleCreateRoleAssignment
|
|
41
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
42
|
+
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
43
|
+
*
|
|
44
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
45
|
+
* const credentials = new DefaultAzureCredential();
|
|
46
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
47
|
+
*
|
|
48
|
+
* const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
|
|
49
|
+
*
|
|
44
50
|
* const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
|
|
45
|
-
* const result = await client.createRoleAssignment(
|
|
51
|
+
* const result = await client.createRoleAssignment(
|
|
52
|
+
* "/",
|
|
53
|
+
* "295c179b-9ad3-4117-99cd-b1aa66cf4517",
|
|
54
|
+
* roleDefinition.id,
|
|
55
|
+
* principalId,
|
|
56
|
+
* );
|
|
46
57
|
* ```
|
|
47
58
|
* Creates a new role assignment.
|
|
48
59
|
* @param roleScope - The scope of the role assignment.
|
|
@@ -66,10 +77,25 @@ export class KeyVaultAccessControlClient {
|
|
|
66
77
|
* Deletes role assignments previously created in an Azure Key Vault.
|
|
67
78
|
*
|
|
68
79
|
* Example usage:
|
|
69
|
-
* ```ts
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
80
|
+
* ```ts snippet:ReadmeSampleDeleteRoleAssignment
|
|
81
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
82
|
+
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
83
|
+
*
|
|
84
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
85
|
+
* const credentials = new DefaultAzureCredential();
|
|
86
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
87
|
+
*
|
|
88
|
+
* const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
|
|
89
|
+
* const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
|
|
90
|
+
*
|
|
91
|
+
* const roleAssignment = await client.createRoleAssignment(
|
|
92
|
+
* "/",
|
|
93
|
+
* "295c179b-9ad3-4117-99cd-b1aa66cf4517",
|
|
94
|
+
* roleDefinition.id,
|
|
95
|
+
* principalId,
|
|
96
|
+
* );
|
|
97
|
+
*
|
|
98
|
+
* await client.deleteRoleAssignment(roleAssignment.properties.scope, roleAssignment.name);
|
|
73
99
|
* ```
|
|
74
100
|
* Deletes an existing role assignment.
|
|
75
101
|
* @param roleScope - The scope of the role assignment.
|
|
@@ -93,10 +119,28 @@ export class KeyVaultAccessControlClient {
|
|
|
93
119
|
* Gets a role assignments previously created in an Azure Key Vault.
|
|
94
120
|
*
|
|
95
121
|
* Example usage:
|
|
96
|
-
* ```ts
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
122
|
+
* ```ts snippet:ReadmeSampleGetRoleAssignment
|
|
123
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
124
|
+
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
125
|
+
*
|
|
126
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
127
|
+
* const credentials = new DefaultAzureCredential();
|
|
128
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
129
|
+
*
|
|
130
|
+
* const { value: roleDefinition } = await client.listRoleDefinitions("/").next();
|
|
131
|
+
* const principalId = "4871f6a6-374f-4b6b-8b0c-f5d84db823f6";
|
|
132
|
+
*
|
|
133
|
+
* let roleAssignment = await client.createRoleAssignment(
|
|
134
|
+
* "/",
|
|
135
|
+
* "295c179b-9ad3-4117-99cd-b1aa66cf4517",
|
|
136
|
+
* roleDefinition.id,
|
|
137
|
+
* principalId,
|
|
138
|
+
* );
|
|
139
|
+
*
|
|
140
|
+
* roleAssignment = await client.getRoleAssignment(
|
|
141
|
+
* roleAssignment.properties.scope,
|
|
142
|
+
* roleAssignment.name,
|
|
143
|
+
* );
|
|
100
144
|
* console.log(roleAssignment);
|
|
101
145
|
* ```
|
|
102
146
|
* Gets an existing role assignment.
|
|
@@ -114,8 +158,14 @@ export class KeyVaultAccessControlClient {
|
|
|
114
158
|
* Iterates over all of the available role assignments in an Azure Key Vault.
|
|
115
159
|
*
|
|
116
160
|
* Example usage:
|
|
117
|
-
* ```ts
|
|
118
|
-
*
|
|
161
|
+
* ```ts snippet:ReadmeSampleListRoleAssignments
|
|
162
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
163
|
+
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
164
|
+
*
|
|
165
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
166
|
+
* const credentials = new DefaultAzureCredential();
|
|
167
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
168
|
+
*
|
|
119
169
|
* for await (const roleAssignment of client.listRoleAssignments("/")) {
|
|
120
170
|
* console.log("Role assignment: ", roleAssignment);
|
|
121
171
|
* }
|
|
@@ -131,8 +181,14 @@ export class KeyVaultAccessControlClient {
|
|
|
131
181
|
* Iterates over all of the available role definitions in an Azure Key Vault.
|
|
132
182
|
*
|
|
133
183
|
* Example usage:
|
|
134
|
-
* ```ts
|
|
135
|
-
*
|
|
184
|
+
* ```ts snippet:ReadmeSampleListRoleDefinitions
|
|
185
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
186
|
+
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
187
|
+
*
|
|
188
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
189
|
+
* const credentials = new DefaultAzureCredential();
|
|
190
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
191
|
+
*
|
|
136
192
|
* for await (const roleDefinitions of client.listRoleDefinitions("/")) {
|
|
137
193
|
* console.log("Role definition: ", roleDefinitions);
|
|
138
194
|
* }
|
|
@@ -148,8 +204,14 @@ export class KeyVaultAccessControlClient {
|
|
|
148
204
|
* Gets a role definition from Azure Key Vault.
|
|
149
205
|
*
|
|
150
206
|
* Example usage:
|
|
151
|
-
* ```
|
|
152
|
-
*
|
|
207
|
+
* ```ts snippet:ReadmeSampleGetRoleDefinition
|
|
208
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
209
|
+
* import { KeyVaultAccessControlClient } from "@azure/keyvault-admin";
|
|
210
|
+
*
|
|
211
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
212
|
+
* const credentials = new DefaultAzureCredential();
|
|
213
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
214
|
+
*
|
|
153
215
|
* const roleDefinition = await client.getRoleDefinition("/", "b86a8fe4-44ce-4948-aee5-eccb2c155cd7");
|
|
154
216
|
* console.log(roleDefinition);
|
|
155
217
|
* ```
|
|
@@ -167,11 +229,24 @@ export class KeyVaultAccessControlClient {
|
|
|
167
229
|
* Creates or updates a role definition in an Azure Key Vault.
|
|
168
230
|
*
|
|
169
231
|
* Example usage:
|
|
170
|
-
* ```ts
|
|
171
|
-
*
|
|
232
|
+
* ```ts snippet:ReadmeSampleSetRoleDefinition
|
|
233
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
234
|
+
* import {
|
|
235
|
+
* KeyVaultAccessControlClient,
|
|
236
|
+
* KnownKeyVaultDataAction,
|
|
237
|
+
* KnownKeyVaultRoleScope,
|
|
238
|
+
* } from "@azure/keyvault-admin";
|
|
239
|
+
*
|
|
240
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
241
|
+
* const credentials = new DefaultAzureCredential();
|
|
242
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
243
|
+
*
|
|
172
244
|
* const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];
|
|
173
245
|
* const roleDefinitionName = "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a";
|
|
174
|
-
* const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {
|
|
246
|
+
* const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {
|
|
247
|
+
* permissions,
|
|
248
|
+
* roleDefinitionName,
|
|
249
|
+
* });
|
|
175
250
|
* console.log(roleDefinition);
|
|
176
251
|
* ```
|
|
177
252
|
* @param roleScope - The scope of the role definition.
|
|
@@ -195,9 +270,25 @@ export class KeyVaultAccessControlClient {
|
|
|
195
270
|
* Deletes a custom role definition previously created in an Azure Key Vault.
|
|
196
271
|
*
|
|
197
272
|
* Example usage:
|
|
198
|
-
* ```ts
|
|
199
|
-
*
|
|
200
|
-
*
|
|
273
|
+
* ```ts snippet:ReadmeSampleDeleteRoleDefinition
|
|
274
|
+
* import { DefaultAzureCredential } from "@azure/identity";
|
|
275
|
+
* import {
|
|
276
|
+
* KeyVaultAccessControlClient,
|
|
277
|
+
* KnownKeyVaultDataAction,
|
|
278
|
+
* KnownKeyVaultRoleScope,
|
|
279
|
+
* } from "@azure/keyvault-admin";
|
|
280
|
+
*
|
|
281
|
+
* const vaultUrl = `https://<MY KEY VAULT HERE>.vault.azure.net`;
|
|
282
|
+
* const credentials = new DefaultAzureCredential();
|
|
283
|
+
* const client = new KeyVaultAccessControlClient(vaultUrl, credentials);
|
|
284
|
+
*
|
|
285
|
+
* const permissions = [{ dataActions: [KnownKeyVaultDataAction.BackupHsmKeys] }];
|
|
286
|
+
* const roleDefinitionName = "23b8bb1a-39c0-4c89-a85b-dd3c99273a8a";
|
|
287
|
+
* const roleDefinition = await client.setRoleDefinition(KnownKeyVaultRoleScope.Global, {
|
|
288
|
+
* permissions,
|
|
289
|
+
* roleDefinitionName,
|
|
290
|
+
* });
|
|
291
|
+
*
|
|
201
292
|
* await client.deleteRoleDefinition("/", roleDefinition.name);
|
|
202
293
|
* ```
|
|
203
294
|
* @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,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;;GAIG;AACH,MAAM,OAAO,2BAA2B;IAWtC;;;;;;;;;;;;;;;;OAgBG;IACH,YACE,QAAgB,EAChB,UAA2B;IAC3B,8DAA8D;IAC9D,UAAsC,EAAE;QAExC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,MAAM,GAAG,oBAAoB,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;I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OAAO,aAAa,CAAC,QAAQ,CAC3B,+CAA+C,EAC/C,OAAO,EACP,KAAK,EAAE,cAAc,EAAE,EAAE;YACvB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,cAAc,CAC/D,SAAS,EACT,OAAO,CAAC,kBAAkB,IAAI,UAAU,EAAE,EAC1C;gBACE,UAAU,EAAE;oBACV,WAAW,EAAE,OAAO,CAAC,WAAW;oBAChC,WAAW,EAAE,OAAO,CAAC,WAAW;oBAChC,gBAAgB,EAAE,CAAC,SAAS,CAAC;oBAC7B,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,QAAQ,EAAE,YAAY;iBACvB;aACF,EACD,cAAc,CACf,CAAC;YACF,OAAO,QAAQ,CAAC,cAAc,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC7D,CAAC,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,oBAAoB,CACzB,SAA4B,EAC5B,IAAY,EACZ,UAAuC,EAAE;QAEzC,OAAO,aAAa,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","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"]}
|
|
1
|
+
{"version":3,"file":"accessControlClient.js","sourceRoot":"","sources":["../../src/accessControlClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,4CAA4C;AAmB5C,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,C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AAC,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","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"]}
|