@azure/keyvault-admin 4.2.0 → 4.2.1-alpha.20220705.4

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.
Files changed (29) hide show
  1. package/dist/index.js +54 -93
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/keyvault-admin/src/accessControlClient.js +15 -14
  4. package/dist-esm/keyvault-admin/src/accessControlClient.js.map +1 -1
  5. package/dist-esm/keyvault-admin/src/backupClient.js +4 -2
  6. package/dist-esm/keyvault-admin/src/backupClient.js.map +1 -1
  7. package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js +12 -5
  8. package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js.map +1 -1
  9. package/dist-esm/keyvault-admin/src/constants.js +1 -5
  10. package/dist-esm/keyvault-admin/src/constants.js.map +1 -1
  11. package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js +1 -2
  12. package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js.map +1 -1
  13. package/dist-esm/keyvault-admin/src/lro/backup/operation.js +3 -7
  14. package/dist-esm/keyvault-admin/src/lro/backup/operation.js.map +1 -1
  15. package/dist-esm/keyvault-admin/src/lro/restore/operation.js +3 -7
  16. package/dist-esm/keyvault-admin/src/lro/restore/operation.js.map +1 -1
  17. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/operation.js +3 -7
  18. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/operation.js.map +1 -1
  19. package/dist-esm/keyvault-admin/src/tracing.js +10 -0
  20. package/dist-esm/keyvault-admin/src/tracing.js.map +1 -0
  21. package/dist-esm/keyvault-common/src/index.js +0 -1
  22. package/dist-esm/keyvault-common/src/index.js.map +1 -1
  23. package/dist-esm/keyvault-common/src/parseKeyvaultIdentifier.js.map +1 -1
  24. package/package.json +10 -10
  25. package/CHANGELOG.md +0 -106
  26. package/dist-esm/keyvault-admin/src/tracingHelpers.js +0 -42
  27. package/dist-esm/keyvault-admin/src/tracingHelpers.js.map +0 -1
  28. package/dist-esm/keyvault-common/src/tracingHelpers.js +0 -42
  29. package/dist-esm/keyvault-common/src/tracingHelpers.js.map +0 -1
@@ -2,15 +2,14 @@
2
2
  // Licensed under the MIT license.
3
3
  /// <reference lib="esnext.asynciterable" />
4
4
  import { __asyncDelegator, __asyncGenerator, __asyncValues, __await } from "tslib";
5
- import { LATEST_API_VERSION, authenticationScopes } from "./constants";
6
5
  import { KeyVaultClient } from "./generated/keyVaultClient";
6
+ import { LATEST_API_VERSION } from "./constants";
7
7
  import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
8
8
  import { createChallengeCallbacks } from "./challengeAuthenticationCallbacks";
9
- import { createTraceFunction } from "./tracingHelpers";
10
9
  import { logger } from "./log";
11
10
  import { mappings } from "./mappings";
11
+ import { tracingClient } from "./tracing";
12
12
  import { v4 as v4uuid } from "uuid";
13
- const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultAccessControlClient");
14
13
  /**
15
14
  * The KeyVaultAccessControlClient provides methods to manage
16
15
  * access control and role assignments in any given Azure Key Vault instance.
@@ -48,7 +47,9 @@ export class KeyVaultAccessControlClient {
48
47
  this.client = new KeyVaultClient(serviceVersion, clientOptions);
49
48
  this.client.pipeline.addPolicy(bearerTokenAuthenticationPolicy({
50
49
  credential,
51
- scopes: authenticationScopes,
50
+ // The scopes will be populated in the challenge callbacks based on the WWW-authenticate header
51
+ // returned by the challenge, so pass an empty array as a placeholder.
52
+ scopes: [],
52
53
  challengeCallbacks: createChallengeCallbacks(),
53
54
  }));
54
55
  }
@@ -70,7 +71,7 @@ export class KeyVaultAccessControlClient {
70
71
  * @param options - The optional parameters.
71
72
  */
72
73
  createRoleAssignment(roleScope, name, roleDefinitionId, principalId, options = {}) {
73
- return withTrace("createRoleAssignment", options, async (updatedOptions) => {
74
+ return tracingClient.withSpan("KeyVaultAccessControlClient.createRoleAssignment", options, async (updatedOptions) => {
74
75
  const response = await this.client.roleAssignments.create(this.vaultUrl, roleScope, name, {
75
76
  properties: {
76
77
  roleDefinitionId,
@@ -95,7 +96,7 @@ export class KeyVaultAccessControlClient {
95
96
  * @param options - The optional parameters.
96
97
  */
97
98
  deleteRoleAssignment(roleScope, name, options = {}) {
98
- return withTrace("deleteRoleAssignment", options, async (updatedOptions) => {
99
+ return tracingClient.withSpan("KeyVaultAccessControlClient.deleteRoleAssignment", options, async (updatedOptions) => {
99
100
  await this.client.roleAssignments.delete(this.vaultUrl, roleScope, name, updatedOptions);
100
101
  });
101
102
  }
@@ -115,7 +116,7 @@ export class KeyVaultAccessControlClient {
115
116
  * @param options - The optional parameters.
116
117
  */
117
118
  getRoleAssignment(roleScope, name, options = {}) {
118
- return withTrace("getRoleAssignment", options, async (updatedOptions) => {
119
+ return tracingClient.withSpan("KeyVaultAccessControlClient.getRoleAssignment", options, async (updatedOptions) => {
119
120
  const response = await this.client.roleAssignments.get(this.vaultUrl, roleScope, name, updatedOptions);
120
121
  return mappings.roleAssignment.generatedToPublic(response);
121
122
  });
@@ -130,7 +131,7 @@ export class KeyVaultAccessControlClient {
130
131
  return __asyncGenerator(this, arguments, function* listRoleAssignmentsPage_1() {
131
132
  if (!continuationState.continuationToken) {
132
133
  const optionsComplete = options || {};
133
- const currentSetResponse = yield __await(withTrace("listRoleAssignments", optionsComplete, async (updatedOptions) => {
134
+ const currentSetResponse = yield __await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleAssignmentsPage", optionsComplete, async (updatedOptions) => {
134
135
  return this.client.roleAssignments.listForScope(this.vaultUrl, roleScope, updatedOptions);
135
136
  }));
136
137
  continuationState.continuationToken = currentSetResponse.nextLink;
@@ -139,7 +140,7 @@ export class KeyVaultAccessControlClient {
139
140
  }
140
141
  }
141
142
  while (continuationState.continuationToken) {
142
- const currentSetResponse = yield __await(withTrace("listRoleAssignments", options || {}, async (updatedOptions) => {
143
+ const currentSetResponse = yield __await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleAssignmentsPage", options || {}, async (updatedOptions) => {
143
144
  return this.client.roleAssignments.listForScopeNext(this.vaultUrl, roleScope, continuationState.continuationToken, updatedOptions);
144
145
  }));
145
146
  continuationState.continuationToken = currentSetResponse.nextLink;
@@ -211,14 +212,14 @@ export class KeyVaultAccessControlClient {
211
212
  return __asyncGenerator(this, arguments, function* listRoleDefinitionsPage_1() {
212
213
  if (!continuationState.continuationToken) {
213
214
  const optionsComplete = options || {};
214
- const currentSetResponse = yield __await(withTrace("listRoleDefinitions", optionsComplete, (updatedOptions) => this.client.roleDefinitions.list(this.vaultUrl, roleScope, updatedOptions)));
215
+ const currentSetResponse = yield __await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleDefinitionsPage", optionsComplete, (updatedOptions) => this.client.roleDefinitions.list(this.vaultUrl, roleScope, updatedOptions)));
215
216
  continuationState.continuationToken = currentSetResponse.nextLink;
216
217
  if (currentSetResponse.value) {
217
218
  yield yield __await(currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this));
218
219
  }
219
220
  }
220
221
  while (continuationState.continuationToken) {
221
- const currentSetResponse = yield __await(withTrace("listRoleDefinitions", options, (updatedOptions) => this.client.roleDefinitions.listNext(this.vaultUrl, roleScope, continuationState.continuationToken, updatedOptions)));
222
+ const currentSetResponse = yield __await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleDefinitionsPage", options, (updatedOptions) => this.client.roleDefinitions.listNext(this.vaultUrl, roleScope, continuationState.continuationToken, updatedOptions)));
222
223
  continuationState.continuationToken = currentSetResponse.nextLink;
223
224
  if (currentSetResponse.value) {
224
225
  yield yield __await(currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this));
@@ -292,7 +293,7 @@ export class KeyVaultAccessControlClient {
292
293
  * @param options - The optional parameters.
293
294
  */
294
295
  getRoleDefinition(roleScope, name, options = {}) {
295
- return withTrace("getRoleDefinition", options, async (updatedOptions) => {
296
+ return tracingClient.withSpan("KeyVaultAccessControlClient.getRoleDefinition", options, async (updatedOptions) => {
296
297
  const response = await this.client.roleDefinitions.get(this.vaultUrl, roleScope, name, updatedOptions);
297
298
  return mappings.roleDefinition.generatedToPublic(response);
298
299
  });
@@ -312,7 +313,7 @@ export class KeyVaultAccessControlClient {
312
313
  * @param options - The optional parameters.
313
314
  */
314
315
  setRoleDefinition(roleScope, options = {}) {
315
- return withTrace("setRoleDefinition", options, async (updatedOptions) => {
316
+ return tracingClient.withSpan("KeyVaultAccessControlClient.setRoleDefinition", options, async (updatedOptions) => {
316
317
  const response = await this.client.roleDefinitions.createOrUpdate(this.vaultUrl, roleScope, options.roleDefinitionName || v4uuid(), {
317
318
  properties: {
318
319
  description: options.description,
@@ -339,7 +340,7 @@ export class KeyVaultAccessControlClient {
339
340
  * @param options - The optional parameters.
340
341
  */
341
342
  deleteRoleDefinition(roleScope, name, options = {}) {
342
- return withTrace("deleteRoleDefinition", options, async (updatedOptions) => {
343
+ return tracingClient.withSpan("KeyVaultAccessControlClient.deleteRoleDefinition", options, async (updatedOptions) => {
343
344
  await this.client.roleDefinitions.delete(this.vaultUrl, roleScope, name, updatedOptions);
344
345
  });
345
346
  }
@@ -1 +1 @@
1
- {"version":3,"file":"accessControlClient.js","sourceRoot":"","sources":["../../../src/accessControlClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,4CAA4C;;AAkB5C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAI5D,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,EAAE,IAAI,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ation.\n// Licensed under the MIT license.\n/// <reference lib=\"esnext.asynciterable\" />\n\nimport {\n AccessControlClientOptions,\n CreateRoleAssignmentOptions,\n DeleteRoleAssignmentOptions,\n DeleteRoleDefinitionOptions,\n GetRoleAssignmentOptions,\n GetRoleDefinitionOptions,\n KeyVaultRoleAssignment,\n KeyVaultRoleDefinition,\n KeyVaultRoleScope,\n ListRoleAssignmentsOptions,\n ListRoleAssignmentsPageSettings,\n ListRoleDefinitionsOptions,\n ListRoleDefinitionsPageSettings,\n SetRoleDefinitionOptions,\n} from \"./accessControlModels\";\nimport { LATEST_API_VERSION, authenticationScopes } from \"./constants\";\nimport { KeyVaultClient } from \"./generated/keyVaultClient\";\nimport { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport { RoleAssignmentsListForScopeOptionalParams } from \"./generated/models\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\nimport { createChallengeCallbacks } from \"./challengeAuthenticationCallbacks\";\nimport { createTraceFunction } from \"./tracingHelpers\";\nimport { logger } from \"./log\";\nimport { mappings } from \"./mappings\";\nimport { v4 as v4uuid } from \"uuid\";\n\nconst withTrace = createTraceFunction(\"Azure.KeyVault.Admin.KeyVaultAccessControlClient\");\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`\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 pipelineOptions - Pipeline options used to configure Key Vault API requests. Omit this parameter to use the default pipeline configuration.\n */\n constructor(\n vaultUrl: string,\n credential: TokenCredential,\n options: AccessControlClientOptions = {}\n ) {\n this.vaultUrl = vaultUrl;\n\n const serviceVersion = options.serviceVersion || LATEST_API_VERSION;\n\n const clientOptions = {\n ...options,\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [\n \"x-ms-keyvault-region\",\n \"x-ms-keyvault-network-info\",\n \"x-ms-keyvault-service-version\",\n ],\n },\n };\n\n this.client = new KeyVaultClient(serviceVersion, clientOptions);\n\n this.client.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential,\n scopes: authenticationScopes,\n challengeCallbacks: createChallengeCallbacks(),\n })\n );\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 withTrace(\"createRoleAssignment\", options, async (updatedOptions) => {\n const response = await this.client.roleAssignments.create(\n this.vaultUrl,\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 * 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 withTrace(\"deleteRoleAssignment\", options, async (updatedOptions) => {\n await this.client.roleAssignments.delete(this.vaultUrl, roleScope, name, updatedOptions);\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 withTrace(\"getRoleAssignment\", options, async (updatedOptions) => {\n const response = await this.client.roleAssignments.get(\n this.vaultUrl,\n roleScope,\n name,\n updatedOptions\n );\n return mappings.roleAssignment.generatedToPublic(response);\n });\n }\n\n /**\n * Deals with the pagination of {@link listRoleAssignments}.\n * @param roleScope - The scope of the role assignments.\n * @param continuationState - An object that indicates the position of the paginated request.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleAssignmentsPage(\n roleScope: KeyVaultRoleScope,\n continuationState: ListRoleAssignmentsPageSettings,\n options?: ListRoleAssignmentsOptions\n ): AsyncIterableIterator<KeyVaultRoleAssignment[]> {\n if (!continuationState.continuationToken) {\n const optionsComplete: RoleAssignmentsListForScopeOptionalParams = options || {};\n const currentSetResponse = await withTrace(\n \"listRoleAssignments\",\n optionsComplete,\n async (updatedOptions) => {\n return this.client.roleAssignments.listForScope(this.vaultUrl, roleScope, updatedOptions);\n }\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleAssignment.generatedToPublic, this);\n }\n }\n while (continuationState.continuationToken) {\n const currentSetResponse = await withTrace(\n \"listRoleAssignments\",\n options || {},\n async (updatedOptions) => {\n return this.client.roleAssignments.listForScopeNext(\n this.vaultUrl,\n roleScope,\n continuationState.continuationToken!,\n updatedOptions\n );\n }\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleAssignment.generatedToPublic, this);\n } else {\n break;\n }\n }\n }\n\n /**\n * Deals with the iteration of all the available results of {@link listRoleAssignments}.\n * @param roleScope - The scope of the role assignments.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleAssignmentsAll(\n roleScope: KeyVaultRoleScope,\n options?: ListRoleAssignmentsOptions\n ): AsyncIterableIterator<KeyVaultRoleAssignment> {\n for await (const page of this.listRoleAssignmentsPage(roleScope, {}, options)) {\n yield* page;\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 const iter = this.listRoleAssignmentsAll(roleScope, options);\n\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings: ListRoleAssignmentsPageSettings = {}) =>\n this.listRoleAssignmentsPage(roleScope, settings, options),\n };\n }\n\n /**\n * Deals with the pagination of {@link listRoleDefinitions}.\n * @param roleScope - The scope of the role definition.\n * @param continuationState - An object that indicates the position of the paginated request.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleDefinitionsPage(\n roleScope: KeyVaultRoleScope,\n continuationState: ListRoleDefinitionsPageSettings,\n options: ListRoleDefinitionsOptions = {}\n ): AsyncIterableIterator<KeyVaultRoleDefinition[]> {\n if (!continuationState.continuationToken) {\n const optionsComplete: RoleAssignmentsListForScopeOptionalParams = options || {};\n const currentSetResponse = await withTrace(\n \"listRoleDefinitions\",\n optionsComplete,\n (updatedOptions) =>\n this.client.roleDefinitions.list(this.vaultUrl, roleScope, updatedOptions)\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this);\n }\n }\n while (continuationState.continuationToken) {\n const currentSetResponse = await withTrace(\"listRoleDefinitions\", options, (updatedOptions) =>\n this.client.roleDefinitions.listNext(\n this.vaultUrl,\n roleScope,\n continuationState.continuationToken!,\n updatedOptions\n )\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this);\n } else {\n break;\n }\n }\n }\n\n /**\n * Deals with the iteration of all the available results of {@link listRoleDefinitions}.\n * @param roleScope - The scope of the role definition.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleDefinitionsAll(\n roleScope: KeyVaultRoleScope,\n options?: ListRoleDefinitionsOptions\n ): AsyncIterableIterator<KeyVaultRoleDefinition> {\n for await (const page of this.listRoleDefinitionsPage(roleScope, {}, options)) {\n yield* page;\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 const iter = this.listRoleDefinitionsAll(roleScope, options);\n\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings: ListRoleDefinitionsPageSettings = {}) =>\n this.listRoleDefinitionsPage(roleScope, settings, options),\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 withTrace(\"getRoleDefinition\", options, async (updatedOptions) => {\n const response = await this.client.roleDefinitions.get(\n this.vaultUrl,\n roleScope,\n name,\n updatedOptions\n );\n return mappings.roleDefinition.generatedToPublic(response);\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 withTrace(\"setRoleDefinition\", options, async (updatedOptions) => {\n const response = await this.client.roleDefinitions.createOrUpdate(\n this.vaultUrl,\n roleScope,\n options.roleDefinitionName || v4uuid(),\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 * 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 withTrace(\"deleteRoleDefinition\", options, async (updatedOptions) => {\n await this.client.roleDefinitions.delete(this.vaultUrl, roleScope, name, updatedOptions);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"accessControlClient.js","sourceRoot":"","sources":["../../../src/accessControlClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,4CAA4C;;AAkB5C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,kBAAk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C;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,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAC3F,CAAC,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/// <reference lib=\"esnext.asynciterable\" />\n\nimport {\n AccessControlClientOptions,\n CreateRoleAssignmentOptions,\n DeleteRoleAssignmentOptions,\n DeleteRoleDefinitionOptions,\n GetRoleAssignmentOptions,\n GetRoleDefinitionOptions,\n KeyVaultRoleAssignment,\n KeyVaultRoleDefinition,\n KeyVaultRoleScope,\n ListRoleAssignmentsOptions,\n ListRoleAssignmentsPageSettings,\n ListRoleDefinitionsOptions,\n ListRoleDefinitionsPageSettings,\n SetRoleDefinitionOptions,\n} from \"./accessControlModels\";\nimport { KeyVaultClient } from \"./generated/keyVaultClient\";\nimport { LATEST_API_VERSION } from \"./constants\";\nimport { PagedAsyncIterableIterator } from \"@azure/core-paging\";\nimport { RoleAssignmentsListForScopeOptionalParams } from \"./generated/models\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\nimport { createChallengeCallbacks } from \"./challengeAuthenticationCallbacks\";\nimport { logger } from \"./log\";\nimport { mappings } from \"./mappings\";\nimport { tracingClient } from \"./tracing\";\nimport { v4 as v4uuid } from \"uuid\";\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`\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 pipelineOptions - Pipeline options used to configure Key Vault API requests. Omit this parameter to use the default pipeline configuration.\n */\n constructor(\n vaultUrl: string,\n credential: TokenCredential,\n options: AccessControlClientOptions = {}\n ) {\n this.vaultUrl = vaultUrl;\n\n const serviceVersion = options.serviceVersion || LATEST_API_VERSION;\n\n const clientOptions = {\n ...options,\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [\n \"x-ms-keyvault-region\",\n \"x-ms-keyvault-network-info\",\n \"x-ms-keyvault-service-version\",\n ],\n },\n };\n\n this.client = new KeyVaultClient(serviceVersion, clientOptions);\n\n this.client.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential,\n // The scopes will be populated in the challenge callbacks based on the WWW-authenticate header\n // returned by the challenge, so pass an empty array as a placeholder.\n scopes: [],\n challengeCallbacks: createChallengeCallbacks(),\n })\n );\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 this.vaultUrl,\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 await this.client.roleAssignments.delete(this.vaultUrl, roleScope, name, updatedOptions);\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(\n this.vaultUrl,\n roleScope,\n name,\n updatedOptions\n );\n return mappings.roleAssignment.generatedToPublic(response);\n }\n );\n }\n\n /**\n * Deals with the pagination of {@link listRoleAssignments}.\n * @param roleScope - The scope of the role assignments.\n * @param continuationState - An object that indicates the position of the paginated request.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleAssignmentsPage(\n roleScope: KeyVaultRoleScope,\n continuationState: ListRoleAssignmentsPageSettings,\n options?: ListRoleAssignmentsOptions\n ): AsyncIterableIterator<KeyVaultRoleAssignment[]> {\n if (!continuationState.continuationToken) {\n const optionsComplete: RoleAssignmentsListForScopeOptionalParams = options || {};\n const currentSetResponse = await tracingClient.withSpan(\n \"KeyVaultAccessControlClient.listRoleAssignmentsPage\",\n optionsComplete,\n async (updatedOptions) => {\n return this.client.roleAssignments.listForScope(this.vaultUrl, roleScope, updatedOptions);\n }\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleAssignment.generatedToPublic, this);\n }\n }\n while (continuationState.continuationToken) {\n const currentSetResponse = await tracingClient.withSpan(\n \"KeyVaultAccessControlClient.listRoleAssignmentsPage\",\n options || {},\n async (updatedOptions) => {\n return this.client.roleAssignments.listForScopeNext(\n this.vaultUrl,\n roleScope,\n continuationState.continuationToken!,\n updatedOptions\n );\n }\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleAssignment.generatedToPublic, this);\n } else {\n break;\n }\n }\n }\n\n /**\n * Deals with the iteration of all the available results of {@link listRoleAssignments}.\n * @param roleScope - The scope of the role assignments.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleAssignmentsAll(\n roleScope: KeyVaultRoleScope,\n options?: ListRoleAssignmentsOptions\n ): AsyncIterableIterator<KeyVaultRoleAssignment> {\n for await (const page of this.listRoleAssignmentsPage(roleScope, {}, options)) {\n yield* page;\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 const iter = this.listRoleAssignmentsAll(roleScope, options);\n\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings: ListRoleAssignmentsPageSettings = {}) =>\n this.listRoleAssignmentsPage(roleScope, settings, options),\n };\n }\n\n /**\n * Deals with the pagination of {@link listRoleDefinitions}.\n * @param roleScope - The scope of the role definition.\n * @param continuationState - An object that indicates the position of the paginated request.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleDefinitionsPage(\n roleScope: KeyVaultRoleScope,\n continuationState: ListRoleDefinitionsPageSettings,\n options: ListRoleDefinitionsOptions = {}\n ): AsyncIterableIterator<KeyVaultRoleDefinition[]> {\n if (!continuationState.continuationToken) {\n const optionsComplete: RoleAssignmentsListForScopeOptionalParams = options || {};\n const currentSetResponse = await tracingClient.withSpan(\n \"KeyVaultAccessControlClient.listRoleDefinitionsPage\",\n optionsComplete,\n (updatedOptions) =>\n this.client.roleDefinitions.list(this.vaultUrl, roleScope, updatedOptions)\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this);\n }\n }\n while (continuationState.continuationToken) {\n const currentSetResponse = await tracingClient.withSpan(\n \"KeyVaultAccessControlClient.listRoleDefinitionsPage\",\n options,\n (updatedOptions) =>\n this.client.roleDefinitions.listNext(\n this.vaultUrl,\n roleScope,\n continuationState.continuationToken!,\n updatedOptions\n )\n );\n continuationState.continuationToken = currentSetResponse.nextLink;\n if (currentSetResponse.value) {\n yield currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this);\n } else {\n break;\n }\n }\n }\n\n /**\n * Deals with the iteration of all the available results of {@link listRoleDefinitions}.\n * @param roleScope - The scope of the role definition.\n * @param options - Common options for the iterative endpoints.\n */\n private async *listRoleDefinitionsAll(\n roleScope: KeyVaultRoleScope,\n options?: ListRoleDefinitionsOptions\n ): AsyncIterableIterator<KeyVaultRoleDefinition> {\n for await (const page of this.listRoleDefinitionsPage(roleScope, {}, options)) {\n yield* page;\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 const iter = this.listRoleDefinitionsAll(roleScope, options);\n\n return {\n next() {\n return iter.next();\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n byPage: (settings: ListRoleDefinitionsPageSettings = {}) =>\n this.listRoleDefinitionsPage(roleScope, settings, options),\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(\n this.vaultUrl,\n roleScope,\n name,\n updatedOptions\n );\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 this.vaultUrl,\n roleScope,\n options.roleDefinitionName || v4uuid(),\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 await this.client.roleDefinitions.delete(this.vaultUrl, roleScope, name, updatedOptions);\n }\n );\n }\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { LATEST_API_VERSION, authenticationScopes } from "./constants";
4
3
  import { KeyVaultBackupPoller } from "./lro/backup/poller";
5
4
  import { KeyVaultClient } from "./generated/keyVaultClient";
6
5
  import { KeyVaultRestorePoller } from "./lro/restore/poller";
7
6
  import { KeyVaultSelectiveKeyRestorePoller } from "./lro/selectiveKeyRestore/poller";
7
+ import { LATEST_API_VERSION } from "./constants";
8
8
  import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
9
9
  import { createChallengeCallbacks } from "./challengeAuthenticationCallbacks";
10
10
  import { logger } from "./log";
@@ -47,7 +47,9 @@ export class KeyVaultBackupClient {
47
47
  this.client = new KeyVaultClient(apiVersion, clientOptions);
48
48
  this.client.pipeline.addPolicy(bearerTokenAuthenticationPolicy({
49
49
  credential,
50
- scopes: authenticationScopes,
50
+ // The scopes will be populated in the challenge callbacks based on the WWW-authenticate header
51
+ // returned by the challenge, so pass an empty array as a placeholder.
52
+ scopes: [],
51
53
  challengeCallbacks: createChallengeCallbacks(),
52
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AC,KACrC,OAAO;YACP,QAAQ,EACR,MAAM,EAAE,IAAI,CAAC,MAAM,EACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,YAAY,EAAE,OAAO,CAAC,YAAY,EAClC,UAAU,EAAE,OAAO,CAAC,UAAU,EAC9B,cAAc,EAAE,OAAO,IACvB,CAAC;QAEH,8EAA8E;QAC9E,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n KeyVaultBackupClientOptions,\n KeyVaultBackupResult,\n KeyVaultBeginBackupOptions,\n KeyVaultBeginRestoreOptions,\n KeyVaultBeginSelectiveKeyRestoreOptions,\n KeyVaultRestoreResult,\n KeyVaultSelectiveKeyRestoreResult,\n} from \"./backupClientModels\";\nimport { LATEST_API_VERSION, authenticationScopes } from \"./constants\";\nimport { KeyVaultAdminPollOperationState } from \"./lro/keyVaultAdminPoller\";\nimport { KeyVaultBackupOperationState } from \"./lro/backup/operation\";\nimport { KeyVaultBackupPoller } from \"./lro/backup/poller\";\nimport { KeyVaultClient } from \"./generated/keyVaultClient\";\nimport { KeyVaultRestoreOperationState } from \"./lro/restore/operation\";\nimport { KeyVaultRestorePoller } from \"./lro/restore/poller\";\nimport { KeyVaultSelectiveKeyRestoreOperationState } from \"./lro/selectiveKeyRestore/operation\";\nimport { KeyVaultSelectiveKeyRestorePoller } from \"./lro/selectiveKeyRestore/poller\";\nimport { PollerLike } from \"@azure/core-lro\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\nimport { createChallengeCallbacks } from \"./challengeAuthenticationCallbacks\";\nimport { logger } from \"./log\";\nimport { mappings } from \"./mappings\";\n\nexport {\n KeyVaultBackupOperationState,\n KeyVaultRestoreOperationState,\n KeyVaultSelectiveKeyRestoreOperationState,\n KeyVaultAdminPollOperationState,\n};\n\n/**\n * The KeyVaultBackupClient provides methods to generate backups\n * and restore backups of any given Azure Key Vault instance.\n * This client supports generating full backups, selective restores of specific keys\n * and full restores of Key Vault instances.\n */\nexport class KeyVaultBackupClient {\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 KeyVaultBackupClient.\n *\n * Example usage:\n * ```ts\n * import { KeyVaultBackupClient } 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 KeyVaultBackupClient(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`\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.\n */\n constructor(\n vaultUrl: string,\n credential: TokenCredential,\n options: KeyVaultBackupClientOptions = {}\n ) {\n this.vaultUrl = vaultUrl;\n\n const apiVersion = options.serviceVersion || LATEST_API_VERSION;\n\n const clientOptions = {\n ...options,\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [\n \"x-ms-keyvault-region\",\n \"x-ms-keyvault-network-info\",\n \"x-ms-keyvault-service-version\",\n ],\n },\n };\n\n this.client = new KeyVaultClient(apiVersion, clientOptions);\n this.client.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential,\n scopes: authenticationScopes,\n challengeCallbacks: createChallengeCallbacks(),\n })\n );\n }\n\n /**\n * Starts generating a backup of an Azure Key Vault on the specified Storage Blob account.\n *\n * This function returns a Long Running Operation poller that allows you to wait indefinitely until the Key Vault backup is generated.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultBackupClient(url, credentials);\n *\n * const blobStorageUri = \"<blob-storage-uri>\"; // <Blob storage URL>/<folder name>\n * const sasToken = \"<sas-token>\";\n * const poller = await client.beginBackup(blobStorageUri, sasToken);\n *\n * // Serializing the poller\n * //\n * // const serialized = poller.toString();\n * //\n * // A new poller can be created with:\n * //\n * // await client.beginBackup(blobStorageUri, sasToken, { resumeFrom: serialized });\n * //\n *\n * // Waiting until it's done\n * const backupUri = await poller.pollUntilDone();\n * console.log(backupUri);\n * ```\n * Starts a full backup operation.\n * @param blobStorageUri - The URL of the blob storage resource, including the path to the container where the backup will end up being stored.\n * @param sasToken - The SAS token.\n * @param options - The optional parameters.\n */\n public async beginBackup(\n blobStorageUri: string,\n sasToken: string,\n options: KeyVaultBeginBackupOptions = {}\n ): Promise<PollerLike<KeyVaultBackupOperationState, KeyVaultBackupResult>> {\n const poller = new KeyVaultBackupPoller({\n blobStorageUri,\n sasToken,\n client: this.client,\n vaultUrl: this.vaultUrl,\n intervalInMs: options.intervalInMs,\n resumeFrom: options.resumeFrom,\n requestOptions: options,\n });\n\n // This will initialize the poller's operation (the generation of the backup).\n await poller.poll();\n\n return poller;\n }\n\n /**\n * Starts restoring all key materials using the SAS token pointing to a previously stored Azure Blob storage\n * backup folder.\n *\n * This function returns a Long Running Operation poller that allows you to wait indefinitely until the Key Vault restore operation is complete.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultBackupClient(url, credentials);\n *\n * const blobStorageUri = \"<blob-storage-uri>\"; // <Blob storage URL>/<folder name>\n * const sasToken = \"<sas-token>\";\n * const poller = await client.beginRestore(blobStorageUri, sasToken);\n *\n * // The poller can be serialized with:\n * //\n * // const serialized = poller.toString();\n * //\n * // A new poller can be created with:\n * //\n * // await client.beginRestore(blobStorageUri, sasToken, { resumeFrom: serialized });\n * //\n *\n * // Waiting until it's done\n * const backupUri = await poller.pollUntilDone();\n * console.log(backupUri);\n * ```\n * Starts a full restore operation.\n * @param folderUri - The URL of the blob storage resource where the previous successful full backup was stored.\n * @param sasToken - The SAS token.\n * @param options - The optional parameters.\n */\n public async beginRestore(\n folderUri: string,\n sasToken: string,\n options: KeyVaultBeginRestoreOptions = {}\n ): Promise<PollerLike<KeyVaultRestoreOperationState, KeyVaultRestoreResult>> {\n const poller = new KeyVaultRestorePoller({\n ...mappings.folderUriParts(folderUri),\n sasToken,\n client: this.client,\n vaultUrl: this.vaultUrl,\n intervalInMs: options.intervalInMs,\n resumeFrom: options.resumeFrom,\n requestOptions: options,\n });\n\n // This will initialize the poller's operation (the generation of the backup).\n await poller.poll();\n\n return poller;\n }\n\n /**\n * Starts restoring all key versions of a given key using user supplied SAS token pointing to a previously\n * stored Azure Blob storage backup folder.\n *\n * This function returns a Long Running Operation poller that allows you to wait indefinitely until the Key Vault selective restore is complete.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultBackupClient(url, credentials);\n *\n * const blobStorageUri = \"<blob-storage-uri>\";\n * const sasToken = \"<sas-token>\";\n * const keyName = \"<key-name>\";\n * const poller = await client.beginSelectiveKeyRestore(keyName, blobStorageUri, sasToken);\n *\n * // Serializing the poller\n * //\n * // const serialized = poller.toString();\n * //\n * // A new poller can be created with:\n * //\n * // await client.beginSelectiveKeyRestore(keyName, blobStorageUri, sasToken, { resumeFrom: serialized });\n * //\n *\n * // Waiting until it's done\n * await poller.pollUntilDone();\n * ```\n * Creates a new role assignment.\n * @param keyName - The name of the key that wants to be restored.\n * @param folderUri - The URL of the blob storage resource, with the folder name of the blob where the previous successful full backup was stored.\n * @param sasToken - The SAS token.\n * @param options - The optional parameters.\n */\n public async beginSelectiveKeyRestore(\n keyName: string,\n folderUri: string,\n sasToken: string,\n options: KeyVaultBeginSelectiveKeyRestoreOptions = {}\n ): Promise<\n PollerLike<KeyVaultSelectiveKeyRestoreOperationState, KeyVaultSelectiveKeyRestoreResult>\n > {\n const poller = new KeyVaultSelectiveKeyRestorePoller({\n ...mappings.folderUriParts(folderUri),\n keyName,\n sasToken,\n client: this.client,\n vaultUrl: this.vaultUrl,\n intervalInMs: options.intervalInMs,\n resumeFrom: options.resumeFrom,\n requestOptions: options,\n });\n\n // This will initialize the poller's operation (the generation of the backup).\n await poller.poll();\n\n return poller;\n }\n}\n"]}
1
+ {"version":3,"file":"backupClient.js","sourceRoot":"","sources":["../../../src/backupClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAalC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,kCAAkC,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAStC;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAW/B;;;;;;;;;;;;;;;;OAgBG;IACH,YACE,QAAgB,EAChB,UAA2B,EAC3B,UAAuC,EAAE;QAEzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,MAAM,UAAU,GAAG,OAAO,CAAC,cAAc,IAAI,kBAAkB,CAAC;QAEhE,MAAM,aAAa,mCACd,OAAO,KACV,cAAc,EAAE;gBACd,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,4BAA4B,EAAE;oBAC5B,sBAAsB;oBACtB,4BAA4B;oBAC5B,+BAA+B;iBAChC;aACF,GACF,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAC5B,+BAA+B,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;QAIrD,MAAM,MAAM,GAAG,IAAI,iCAAiC,iCAC/C,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,KACrC,OAAO;YACP,QAAQ,EACR,MAAM,EAAE,IAAI,CAAC,MAAM,EACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,YAAY,EAAE,OAAO,CAAC,YAAY,EAClC,UAAU,EAAE,OAAO,CAAC,UAAU,EAC9B,cAAc,EAAE,OAAO,IACvB,CAAC;QAEH,8EAA8E;QAC9E,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n KeyVaultBackupClientOptions,\n KeyVaultBackupResult,\n KeyVaultBeginBackupOptions,\n KeyVaultBeginRestoreOptions,\n KeyVaultBeginSelectiveKeyRestoreOptions,\n KeyVaultRestoreResult,\n KeyVaultSelectiveKeyRestoreResult,\n} from \"./backupClientModels\";\nimport { KeyVaultAdminPollOperationState } from \"./lro/keyVaultAdminPoller\";\nimport { KeyVaultBackupOperationState } from \"./lro/backup/operation\";\nimport { KeyVaultBackupPoller } from \"./lro/backup/poller\";\nimport { KeyVaultClient } from \"./generated/keyVaultClient\";\nimport { KeyVaultRestoreOperationState } from \"./lro/restore/operation\";\nimport { KeyVaultRestorePoller } from \"./lro/restore/poller\";\nimport { KeyVaultSelectiveKeyRestoreOperationState } from \"./lro/selectiveKeyRestore/operation\";\nimport { KeyVaultSelectiveKeyRestorePoller } from \"./lro/selectiveKeyRestore/poller\";\nimport { LATEST_API_VERSION } from \"./constants\";\nimport { PollerLike } from \"@azure/core-lro\";\nimport { TokenCredential } from \"@azure/core-auth\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\nimport { createChallengeCallbacks } from \"./challengeAuthenticationCallbacks\";\nimport { logger } from \"./log\";\nimport { mappings } from \"./mappings\";\n\nexport {\n KeyVaultBackupOperationState,\n KeyVaultRestoreOperationState,\n KeyVaultSelectiveKeyRestoreOperationState,\n KeyVaultAdminPollOperationState,\n};\n\n/**\n * The KeyVaultBackupClient provides methods to generate backups\n * and restore backups of any given Azure Key Vault instance.\n * This client supports generating full backups, selective restores of specific keys\n * and full restores of Key Vault instances.\n */\nexport class KeyVaultBackupClient {\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 KeyVaultBackupClient.\n *\n * Example usage:\n * ```ts\n * import { KeyVaultBackupClient } 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 KeyVaultBackupClient(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`\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.\n */\n constructor(\n vaultUrl: string,\n credential: TokenCredential,\n options: KeyVaultBackupClientOptions = {}\n ) {\n this.vaultUrl = vaultUrl;\n\n const apiVersion = options.serviceVersion || LATEST_API_VERSION;\n\n const clientOptions = {\n ...options,\n loggingOptions: {\n logger: logger.info,\n additionalAllowedHeaderNames: [\n \"x-ms-keyvault-region\",\n \"x-ms-keyvault-network-info\",\n \"x-ms-keyvault-service-version\",\n ],\n },\n };\n\n this.client = new KeyVaultClient(apiVersion, clientOptions);\n this.client.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential,\n // The scopes will be populated in the challenge callbacks based on the WWW-authenticate header\n // returned by the challenge, so pass an empty array as a placeholder.\n scopes: [],\n challengeCallbacks: createChallengeCallbacks(),\n })\n );\n }\n\n /**\n * Starts generating a backup of an Azure Key Vault on the specified Storage Blob account.\n *\n * This function returns a Long Running Operation poller that allows you to wait indefinitely until the Key Vault backup is generated.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultBackupClient(url, credentials);\n *\n * const blobStorageUri = \"<blob-storage-uri>\"; // <Blob storage URL>/<folder name>\n * const sasToken = \"<sas-token>\";\n * const poller = await client.beginBackup(blobStorageUri, sasToken);\n *\n * // Serializing the poller\n * //\n * // const serialized = poller.toString();\n * //\n * // A new poller can be created with:\n * //\n * // await client.beginBackup(blobStorageUri, sasToken, { resumeFrom: serialized });\n * //\n *\n * // Waiting until it's done\n * const backupUri = await poller.pollUntilDone();\n * console.log(backupUri);\n * ```\n * Starts a full backup operation.\n * @param blobStorageUri - The URL of the blob storage resource, including the path to the container where the backup will end up being stored.\n * @param sasToken - The SAS token.\n * @param options - The optional parameters.\n */\n public async beginBackup(\n blobStorageUri: string,\n sasToken: string,\n options: KeyVaultBeginBackupOptions = {}\n ): Promise<PollerLike<KeyVaultBackupOperationState, KeyVaultBackupResult>> {\n const poller = new KeyVaultBackupPoller({\n blobStorageUri,\n sasToken,\n client: this.client,\n vaultUrl: this.vaultUrl,\n intervalInMs: options.intervalInMs,\n resumeFrom: options.resumeFrom,\n requestOptions: options,\n });\n\n // This will initialize the poller's operation (the generation of the backup).\n await poller.poll();\n\n return poller;\n }\n\n /**\n * Starts restoring all key materials using the SAS token pointing to a previously stored Azure Blob storage\n * backup folder.\n *\n * This function returns a Long Running Operation poller that allows you to wait indefinitely until the Key Vault restore operation is complete.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultBackupClient(url, credentials);\n *\n * const blobStorageUri = \"<blob-storage-uri>\"; // <Blob storage URL>/<folder name>\n * const sasToken = \"<sas-token>\";\n * const poller = await client.beginRestore(blobStorageUri, sasToken);\n *\n * // The poller can be serialized with:\n * //\n * // const serialized = poller.toString();\n * //\n * // A new poller can be created with:\n * //\n * // await client.beginRestore(blobStorageUri, sasToken, { resumeFrom: serialized });\n * //\n *\n * // Waiting until it's done\n * const backupUri = await poller.pollUntilDone();\n * console.log(backupUri);\n * ```\n * Starts a full restore operation.\n * @param folderUri - The URL of the blob storage resource where the previous successful full backup was stored.\n * @param sasToken - The SAS token.\n * @param options - The optional parameters.\n */\n public async beginRestore(\n folderUri: string,\n sasToken: string,\n options: KeyVaultBeginRestoreOptions = {}\n ): Promise<PollerLike<KeyVaultRestoreOperationState, KeyVaultRestoreResult>> {\n const poller = new KeyVaultRestorePoller({\n ...mappings.folderUriParts(folderUri),\n sasToken,\n client: this.client,\n vaultUrl: this.vaultUrl,\n intervalInMs: options.intervalInMs,\n resumeFrom: options.resumeFrom,\n requestOptions: options,\n });\n\n // This will initialize the poller's operation (the generation of the backup).\n await poller.poll();\n\n return poller;\n }\n\n /**\n * Starts restoring all key versions of a given key using user supplied SAS token pointing to a previously\n * stored Azure Blob storage backup folder.\n *\n * This function returns a Long Running Operation poller that allows you to wait indefinitely until the Key Vault selective restore is complete.\n *\n * Example usage:\n * ```ts\n * const client = new KeyVaultBackupClient(url, credentials);\n *\n * const blobStorageUri = \"<blob-storage-uri>\";\n * const sasToken = \"<sas-token>\";\n * const keyName = \"<key-name>\";\n * const poller = await client.beginSelectiveKeyRestore(keyName, blobStorageUri, sasToken);\n *\n * // Serializing the poller\n * //\n * // const serialized = poller.toString();\n * //\n * // A new poller can be created with:\n * //\n * // await client.beginSelectiveKeyRestore(keyName, blobStorageUri, sasToken, { resumeFrom: serialized });\n * //\n *\n * // Waiting until it's done\n * await poller.pollUntilDone();\n * ```\n * Creates a new role assignment.\n * @param keyName - The name of the key that wants to be restored.\n * @param folderUri - The URL of the blob storage resource, with the folder name of the blob where the previous successful full backup was stored.\n * @param sasToken - The SAS token.\n * @param options - The optional parameters.\n */\n public async beginSelectiveKeyRestore(\n keyName: string,\n folderUri: string,\n sasToken: string,\n options: KeyVaultBeginSelectiveKeyRestoreOptions = {}\n ): Promise<\n PollerLike<KeyVaultSelectiveKeyRestoreOperationState, KeyVaultSelectiveKeyRestoreResult>\n > {\n const poller = new KeyVaultSelectiveKeyRestorePoller({\n ...mappings.folderUriParts(folderUri),\n keyName,\n sasToken,\n client: this.client,\n vaultUrl: this.vaultUrl,\n intervalInMs: options.intervalInMs,\n resumeFrom: options.resumeFrom,\n requestOptions: options,\n });\n\n // This will initialize the poller's operation (the generation of the backup).\n await poller.poll();\n\n return poller;\n }\n}\n"]}
@@ -27,7 +27,7 @@ export function createChallengeCallbacks() {
27
27
  };
28
28
  }
29
29
  async function authorizeRequest(options) {
30
- const { scopes, request } = options;
30
+ const { request } = options;
31
31
  const requestOptions = requestToOptions(request);
32
32
  switch (challengeState.status) {
33
33
  case "none":
@@ -40,7 +40,7 @@ export function createChallengeCallbacks() {
40
40
  case "started":
41
41
  break; // Retry, we should not overwrite the original body
42
42
  case "complete": {
43
- const token = await options.getAccessToken(scopes, requestOptions);
43
+ const token = await options.getAccessToken(challengeState.scopes, requestOptions);
44
44
  if (token) {
45
45
  request.headers.set("authorization", `Bearer ${token.token}`);
46
46
  }
@@ -50,7 +50,7 @@ export function createChallengeCallbacks() {
50
50
  return Promise.resolve();
51
51
  }
52
52
  async function authorizeRequestOnChallenge(options) {
53
- const { scopes, request, response } = options;
53
+ const { request, response } = options;
54
54
  if (request.body === null && challengeState.status === "started") {
55
55
  // Reset the original body before doing anything else.
56
56
  // Note: If successful status will be "complete", otherwise "none" will
@@ -62,14 +62,21 @@ export function createChallengeCallbacks() {
62
62
  if (!challenge) {
63
63
  throw new Error("Missing challenge.");
64
64
  }
65
- const parsedChallenge = parseWWWAuthenticate(challenge) || [];
66
- const accessToken = await options.getAccessToken(parsedChallenge.scope ? [parsedChallenge.scope] : scopes, Object.assign(Object.assign({}, getTokenOptions), { tenantId: parsedChallenge.tenantId }));
65
+ const parsedChallenge = parseWWWAuthenticate(challenge) || {};
66
+ const scope = parsedChallenge.resource
67
+ ? parsedChallenge.resource + "/.default"
68
+ : parsedChallenge.scope;
69
+ if (!scope) {
70
+ throw new Error("Missing scope.");
71
+ }
72
+ const accessToken = await options.getAccessToken([scope], Object.assign(Object.assign({}, getTokenOptions), { tenantId: parsedChallenge.tenantId }));
67
73
  if (!accessToken) {
68
74
  return false;
69
75
  }
70
76
  options.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
71
77
  challengeState = {
72
78
  status: "complete",
79
+ scopes: [scope],
73
80
  };
74
81
  return true;
75
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"challengeAuthenticationCallbacks.js","sourceRoot":"","sources":["../../../src/challengeAuthenticationCallbacks.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAyB,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA4BxF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,wBAAwB;IACtC,IAAI,cAAc,GAAmB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAExD,SAAS,gBAAgB,CAAC,OAAwB;QAChD,OAAO;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE;gBACd,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB;YACD,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC;IACJ,CAAC;IAED,KAAK,UAAU,gBAAgB,CAAC,OAAgC;QAC9D,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QACpC,MAAM,cAAc,GAAoB,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAElE,QAAQ,cAAc,CAAC,MAAM,EAAE;YAC7B,KAAK,MAAM;gBACT,cAAc,GAAG;oBACf,MAAM,EAAE,SAAS;oBACjB,YAAY,EAAE,OAAO,CAAC,IAAI;iBAC3B,CAAC;gBACF,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;gBACpB,MAAM;YACR,KAAK,SAAS;gBACZ,MAAM,CAAC,mDAAmD;YAC5D,KAAK,UAAU,CAAC,CAAC;gBACf,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,cAAc,CA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f,MAAM,EAAE,UAAU;SACnB,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,gBAAgB;QAChB,2BAA2B;KAC5B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AuthorizeRequestOnChallengeOptions,\n AuthorizeRequestOptions,\n ChallengeCallbacks,\n PipelineRequest,\n RequestBodyType,\n} from \"@azure/core-rest-pipeline\";\nimport { ParsedWWWAuthenticate, parseWWWAuthenticate } from \"../../keyvault-common/src\";\n\nimport { GetTokenOptions } from \"@azure/core-auth\";\n\n/**\n * @internal\n * Holds the state of Challenge Auth.\n * When making the first request we force Key Vault to begin a challenge\n * by clearing out the request body and storing it locally.\n *\n * Later on, the authorizeRequestOnChallenge callback will process the\n * challenge and, if ready to resend the original request, reset the body\n * so that it may be sent again.\n *\n * Once a client has succeeded once, we can start skipping CAE.\n */\ntype ChallengeState =\n | {\n status: \"none\";\n }\n | {\n status: \"started\";\n originalBody?: RequestBodyType;\n }\n | {\n status: \"complete\";\n };\n\n/**\n * @internal\n *\n * Creates challenge callback handlers to manage CAE lifecycle in Azure Key Vault.\n *\n * Key Vault supports other authentication schemes, but we ensure challenge authentication\n * is used by first sending a copy of the request, without authorization or content.\n *\n * when the challenge is received, it will be authenticated and used to send the original\n * request with authorization.\n *\n * Following the first request of a client, follow-up requests will get the cached token\n * if possible.\n */\nexport function createChallengeCallbacks(): ChallengeCallbacks {\n let challengeState: ChallengeState = { status: \"none\" };\n\n function requestToOptions(request: PipelineRequest): GetTokenOptions {\n return {\n abortSignal: request.abortSignal,\n requestOptions: {\n timeout: request.timeout,\n },\n tracingOptions: request.tracingOptions,\n };\n }\n\n async function authorizeRequest(options: AuthorizeRequestOptions) {\n const { scopes, request } = options;\n const requestOptions: GetTokenOptions = requestToOptions(request);\n\n switch (challengeState.status) {\n case \"none\":\n challengeState = {\n status: \"started\",\n originalBody: request.body,\n };\n request.body = null;\n break;\n case \"started\":\n break; // Retry, we should not overwrite the original body\n case \"complete\": {\n const token = await options.getAccessToken(scopes, requestOptions);\n if (token) {\n request.headers.set(\"authorization\", `Bearer ${token.token}`);\n }\n break;\n }\n }\n return Promise.resolve();\n }\n\n async function authorizeRequestOnChallenge(\n options: AuthorizeRequestOnChallengeOptions\n ): Promise<boolean> {\n const { scopes, request, response } = options;\n\n if (request.body === null && challengeState.status === \"started\") {\n // Reset the original body before doing anything else.\n // Note: If successful status will be \"complete\", otherwise \"none\" will\n // restart the process.\n request.body = challengeState.originalBody;\n }\n\n const getTokenOptions = requestToOptions(request);\n\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (!challenge) {\n throw new Error(\"Missing challenge.\");\n }\n const parsedChallenge: ParsedWWWAuthenticate = parseWWWAuthenticate(challenge) || [];\n\n const accessToken = await options.getAccessToken(\n parsedChallenge.scope ? [parsedChallenge.scope] : scopes,\n { ...getTokenOptions, tenantId: parsedChallenge.tenantId }\n );\n\n if (!accessToken) {\n return false;\n }\n\n options.request.headers.set(\"Authorization\", `Bearer ${accessToken.token}`);\n\n challengeState = {\n status: \"complete\",\n };\n\n return true;\n }\n\n return {\n authorizeRequest,\n authorizeRequestOnChallenge,\n };\n}\n"]}
1
+ {"version":3,"file":"challengeAuthenticationCallbacks.js","sourceRoot":"","sources":["../../../src/challengeAuthenticationCallbacks.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAyB,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA6BxF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,wBAAwB;IACtC,IAAI,cAAc,GAAmB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAExD,SAAS,gBAAgB,CAAC,OAAwB;QAChD,OAAO;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,cAAc,EAAE;gBACd,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB;YACD,cAAc,EAAE,OAAO,CAAC,c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AI,KAAK,CAAC,oBAAoB,CAAC,CAAC;SACvC;QACD,MAAM,eAAe,GAA0B,oBAAoB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAErF,MAAM,KAAK,GAAG,eAAe,CAAC,QAAQ;YACpC,CAAC,CAAC,eAAe,CAAC,QAAQ,GAAG,WAAW;YACxC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC;QAE1B,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;SACnC;QAED,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,kCACnD,eAAe,KAClB,QAAQ,EAAE,eAAe,CAAC,QAAQ,IAClC,CAAC;QAEH,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,KAAK,CAAC;SACd;QAED,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;QAE5E,cAAc,GAAG;YACf,MAAM,EAAE,UAAU;YAClB,MAAM,EAAE,CAAC,KAAK,CAAC;SAChB,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,gBAAgB;QAChB,2BAA2B;KAC5B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n AuthorizeRequestOnChallengeOptions,\n AuthorizeRequestOptions,\n ChallengeCallbacks,\n PipelineRequest,\n RequestBodyType,\n} from \"@azure/core-rest-pipeline\";\nimport { ParsedWWWAuthenticate, parseWWWAuthenticate } from \"../../keyvault-common/src\";\n\nimport { GetTokenOptions } from \"@azure/core-auth\";\n\n/**\n * @internal\n * Holds the state of Challenge Auth.\n * When making the first request we force Key Vault to begin a challenge\n * by clearing out the request body and storing it locally.\n *\n * Later on, the authorizeRequestOnChallenge callback will process the\n * challenge and, if ready to resend the original request, reset the body\n * so that it may be sent again.\n *\n * Once a client has succeeded once, we can start skipping CAE.\n */\ntype ChallengeState =\n | {\n status: \"none\";\n }\n | {\n status: \"started\";\n originalBody?: RequestBodyType;\n }\n | {\n status: \"complete\";\n scopes: string[];\n };\n\n/**\n * @internal\n *\n * Creates challenge callback handlers to manage CAE lifecycle in Azure Key Vault.\n *\n * Key Vault supports other authentication schemes, but we ensure challenge authentication\n * is used by first sending a copy of the request, without authorization or content.\n *\n * when the challenge is received, it will be authenticated and used to send the original\n * request with authorization.\n *\n * Following the first request of a client, follow-up requests will get the cached token\n * if possible.\n */\nexport function createChallengeCallbacks(): ChallengeCallbacks {\n let challengeState: ChallengeState = { status: \"none\" };\n\n function requestToOptions(request: PipelineRequest): GetTokenOptions {\n return {\n abortSignal: request.abortSignal,\n requestOptions: {\n timeout: request.timeout,\n },\n tracingOptions: request.tracingOptions,\n };\n }\n\n async function authorizeRequest(options: AuthorizeRequestOptions) {\n const { request } = options;\n const requestOptions: GetTokenOptions = requestToOptions(request);\n\n switch (challengeState.status) {\n case \"none\":\n challengeState = {\n status: \"started\",\n originalBody: request.body,\n };\n request.body = null;\n break;\n case \"started\":\n break; // Retry, we should not overwrite the original body\n case \"complete\": {\n const token = await options.getAccessToken(challengeState.scopes, requestOptions);\n if (token) {\n request.headers.set(\"authorization\", `Bearer ${token.token}`);\n }\n break;\n }\n }\n return Promise.resolve();\n }\n\n async function authorizeRequestOnChallenge(\n options: AuthorizeRequestOnChallengeOptions\n ): Promise<boolean> {\n const { request, response } = options;\n\n if (request.body === null && challengeState.status === \"started\") {\n // Reset the original body before doing anything else.\n // Note: If successful status will be \"complete\", otherwise \"none\" will\n // restart the process.\n request.body = challengeState.originalBody;\n }\n\n const getTokenOptions = requestToOptions(request);\n\n const challenge = response.headers.get(\"WWW-Authenticate\");\n if (!challenge) {\n throw new Error(\"Missing challenge.\");\n }\n const parsedChallenge: ParsedWWWAuthenticate = parseWWWAuthenticate(challenge) || {};\n\n const scope = parsedChallenge.resource\n ? parsedChallenge.resource + \"/.default\"\n : parsedChallenge.scope;\n\n if (!scope) {\n throw new Error(\"Missing scope.\");\n }\n\n const accessToken = await options.getAccessToken([scope], {\n ...getTokenOptions,\n tenantId: parsedChallenge.tenantId,\n });\n\n if (!accessToken) {\n return false;\n }\n\n options.request.headers.set(\"Authorization\", `Bearer ${accessToken.token}`);\n\n challengeState = {\n status: \"complete\",\n scopes: [scope],\n };\n\n return true;\n }\n\n return {\n authorizeRequest,\n authorizeRequestOnChallenge,\n };\n}\n"]}
@@ -3,13 +3,9 @@
3
3
  /**
4
4
  * Current version of the Key Vault Admin SDK.
5
5
  */
6
- export const SDK_VERSION = "4.2.0";
6
+ export const SDK_VERSION = "4.2.1";
7
7
  /**
8
8
  * The latest supported Key Vault service API version.
9
9
  */
10
10
  export const LATEST_API_VERSION = "7.3";
11
- /**
12
- * Authentication scopes
13
- */
14
- export const authenticationScopes = ["https://managedhsm.azure.net/.default"];
15
11
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,OAAO,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAOxC;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,uCAAuC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Current version of the Key Vault Admin SDK.\n */\nexport const SDK_VERSION: string = \"4.2.0\";\n\n/**\n * The latest supported Key Vault service API version.\n */\nexport const LATEST_API_VERSION = \"7.3\";\n\n/**\n * Supported API versions\n */\nexport type SUPPORTED_API_VERSIONS = \"7.2\" | \"7.3\";\n\n/**\n * Authentication scopes\n */\nexport const authenticationScopes = [\"https://managedhsm.azure.net/.default\"];\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW,OAAO,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Current version of the Key Vault Admin SDK.\n */\nexport const SDK_VERSION: string = \"4.2.1\";\n\n/**\n * The latest supported Key Vault service API version.\n */\nexport const LATEST_API_VERSION = \"7.3\";\n\n/**\n * Supported API versions\n */\nexport type SUPPORTED_API_VERSIONS = \"7.2\" | \"7.3\";\n"]}
@@ -6,7 +6,6 @@
6
6
  * Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
7
  */
8
8
  import * as coreClient from "@azure/core-client";
9
- export const packageVersion = "4.2.0";
10
9
  export class KeyVaultClientContext extends coreClient.ServiceClient {
11
10
  /**
12
11
  * Initializes a new instance of the KeyVaultClientContext class.
@@ -24,7 +23,7 @@ export class KeyVaultClientContext extends coreClient.ServiceClient {
24
23
  const defaults = {
25
24
  requestContentType: "application/json; charset=utf-8"
26
25
  };
27
- const packageDetails = `azsdk-js-keyvault-admin/4.2.0`;
26
+ const packageDetails = `azsdk-js-keyvault-admin/4.2.1`;
28
27
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
29
28
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
30
29
  : `${packageDetails}`;
@@ -1 +1 @@
1
- {"version":3,"file":"keyVaultClientContext.js","sourceRoot":"","sources":["../../../../src/generated/keyVaultClientContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAGjD,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,MAAM,OAAO,qBAAsB,SAAQ,UAAU,CAAC,aAAa;IAGjE;;;;OAIG;IACH,YACE,UAAwB,EACxB,OAAsC;QAEtC,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;QAED,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QACD,MAAM,QAAQ,GAAiC;YAC7C,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,+BAA+B,CAAC;QACvD,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;YAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,cAAc,EAAE;YACjE,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;QAE1B,MAAM,mBAAmB,iDACpB,QAAQ,GACR,OAAO,KACV,gBAAgB,EAAE;gBAChB,eAAe;aAChB,EACD,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,gBAAgB,GAC9C,CAAC;QACF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,wBAAwB;QACxB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport { ApiVersion73, KeyVaultClientOptionalParams } from \"./models\";\n\nexport const packageVersion = \"4.2.0\";\n\nexport class KeyVaultClientContext extends coreClient.ServiceClient {\n apiVersion: ApiVersion73;\n\n /**\n * Initializes a new instance of the KeyVaultClientContext class.\n * @param apiVersion Api Version\n * @param options The parameter options\n */\n constructor(\n apiVersion: ApiVersion73,\n options?: KeyVaultClientOptionalParams\n ) {\n if (apiVersion === undefined) {\n throw new Error(\"'apiVersion' cannot be null\");\n }\n\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: KeyVaultClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-keyvault-admin/4.2.0`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint || \"{vaultBaseUrl}\"\n };\n super(optionsWithDefaults);\n // Parameter assignments\n this.apiVersion = apiVersion;\n }\n}\n"]}
1
+ {"version":3,"file":"keyVaultClientContext.js","sourceRoot":"","sources":["../../../../src/generated/keyVaultClientContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAGjD,MAAM,OAAO,qBAAsB,SAAQ,UAAU,CAAC,aAAa;IAGjE;;;;OAIG;IACH,YACE,UAAwB,EACxB,OAAsC;QAEtC,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;QAED,0CAA0C;QAC1C,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,EAAE,CAAC;SACd;QACD,MAAM,QAAQ,GAAiC;YAC7C,kBAAkB,EAAE,iCAAiC;SACtD,CAAC;QAEF,MAAM,cAAc,GAAG,+BAA+B,CAAC;QACvD,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;YAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,cAAc,EAAE;YACjE,CAAC,CAAC,GAAG,cAAc,EAAE,CAAC;QAE1B,MAAM,mBAAmB,iDACpB,QAAQ,GACR,OAAO,KACV,gBAAgB,EAAE;gBAChB,eAAe;aAChB,EACD,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,gBAAgB,GAC9C,CAAC;QACF,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,wBAAwB;QACxB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * Code generated by Microsoft (R) AutoRest Code Generator.\n * Changes may cause incorrect behavior and will be lost if the code is regenerated.\n */\n\nimport * as coreClient from \"@azure/core-client\";\nimport { ApiVersion73, KeyVaultClientOptionalParams } from \"./models\";\n\nexport class KeyVaultClientContext extends coreClient.ServiceClient {\n apiVersion: ApiVersion73;\n\n /**\n * Initializes a new instance of the KeyVaultClientContext class.\n * @param apiVersion Api Version\n * @param options The parameter options\n */\n constructor(\n apiVersion: ApiVersion73,\n options?: KeyVaultClientOptionalParams\n ) {\n if (apiVersion === undefined) {\n throw new Error(\"'apiVersion' cannot be null\");\n }\n\n // Initializing default values for options\n if (!options) {\n options = {};\n }\n const defaults: KeyVaultClientOptionalParams = {\n requestContentType: \"application/json; charset=utf-8\"\n };\n\n const packageDetails = `azsdk-js-keyvault-admin/4.2.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`\n : `${packageDetails}`;\n\n const optionsWithDefaults = {\n ...defaults,\n ...options,\n userAgentOptions: {\n userAgentPrefix\n },\n baseUri: options.endpoint || \"{vaultBaseUrl}\"\n };\n super(optionsWithDefaults);\n // Parameter assignments\n this.apiVersion = apiVersion;\n }\n}\n"]}
@@ -1,11 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
3
  import { KeyVaultAdminPollOperation, } from "../keyVaultAdminPoller";
4
- import { createTraceFunction } from "../../tracingHelpers";
5
- /**
6
- * @internal
7
- */
8
- const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultBackupPoller");
4
+ import { tracingClient } from "../../tracing";
9
5
  /**
10
6
  * The backup Key Vault's poll operation.
11
7
  */
@@ -21,13 +17,13 @@ export class KeyVaultBackupPollOperation extends KeyVaultAdminPollOperation {
21
17
  * Tracing the fullBackup operation
22
18
  */
23
19
  fullBackup(options) {
24
- return withTrace("fullBackup", options, (updatedOptions) => this.client.fullBackup(this.vaultUrl, updatedOptions));
20
+ return tracingClient.withSpan("KeyVaultBackupPoller.fullBackup", options, (updatedOptions) => this.client.fullBackup(this.vaultUrl, updatedOptions));
25
21
  }
26
22
  /**
27
23
  * Tracing the fullBackupStatus operation
28
24
  */
29
25
  fullBackupStatus(jobId, options) {
30
- return withTrace("fullBackupStatus", options, (updatedOptions) => this.client.fullBackupStatus(this.vaultUrl, jobId, updatedOptions));
26
+ return tracingClient.withSpan("KeyVaultBackupPoller.fullBackupStatus", options, (updatedOptions) => this.client.fullBackupStatus(this.vaultUrl, jobId, updatedOptions));
31
27
  }
32
28
  /**
33
29
  * Reaches to the service and updates the backup's poll operation.
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../../../src/lro/backup/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EACL,0BAA0B,GAE3B,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;GAEG;AACH,MAAM,SAAS,GAAG,mBAAmB,CAAC,2CAA2C,CAAC,CAAC;AAsBnF;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,0BAGhD;IACC,YACS,KAAuC,EACtC,QAAgB,EAChB,MAAsB,EACtB,iBAA6C,EAAE;QAEvD,KAAK,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,sDAAsD,EAAE,CAAC,CAAC;QALjF,UAAK,GAAL,KAAK,CAAkC;QACtC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,G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IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YACvF,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;SACjC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,QAAQ,CAAC,gBAAqC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,MAAM,EACJ,SAAS,EACT,KAAK,EACL,4BAA4B,EAC5B,OAAO,EACP,KAAK,EACL,MAAM,EACN,aAAa,GACd,GAAG,gBAAgB,CAAC;QACrB,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAC;SACH;QAED,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;QACvB,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;QACpB,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;QACxB,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;QAC5B,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;QACtB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;QACpC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,OAAO,CAAC;QAE9B,IAAI,KAAK,CAAC,WAAW,KAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAA,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,aAAa,CAAC,CAAC;SAClD;QAED,IAAI,KAAK,CAAC,WAAW,EAAE;YACrB,KAAK,CAAC,MAAM,GAAG;gBACb,SAAS,EAAE,4BAA4B;gBACvC,SAAS;gBACT,OAAO;aACR,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FullBackupOperation,\n FullBackupOptionalParams,\n FullBackupResponse,\n FullBackupStatusResponse,\n} from \"../../generated/models\";\nimport {\n KeyVaultAdminPollOperation,\n KeyVaultAdminPollOperationState,\n} from \"../keyVaultAdminPoller\";\nimport { KeyVaultBackupResult, KeyVaultBeginBackupOptions } from \"../../backupClientModels\";\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { KeyVaultClient } from \"../../generated/keyVaultClient\";\nimport { createTraceFunction } from \"../../tracingHelpers\";\n\n/**\n * @internal\n */\nconst withTrace = createTraceFunction(\"Azure.KeyVault.Admin.KeyVaultBackupPoller\");\n\n/**\n * An interface representing the publicly available properties of the state of a backup Key Vault's poll operation.\n */\nexport type KeyVaultBackupOperationState = KeyVaultAdminPollOperationState<KeyVaultBackupResult>;\n\n/**\n * An internal interface representing the state of a backup Key Vault's poll operation.\n */\nexport interface KeyVaultBackupPollOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultBackupResult> {\n /**\n * The URI of the blob storage account.\n */\n blobStorageUri: string;\n /**\n * The SAS token.\n */\n sasToken: string;\n}\n\n/**\n * The backup Key Vault's poll operation.\n */\nexport class KeyVaultBackupPollOperation extends KeyVaultAdminPollOperation<\n KeyVaultBackupPollOperationState,\n string\n> {\n constructor(\n public state: KeyVaultBackupPollOperationState,\n private vaultUrl: string,\n private client: KeyVaultClient,\n private requestOptions: KeyVaultBeginBackupOptions = {}\n ) {\n super(state, { cancelMessage: \"Cancelling a full Key Vault backup is not supported.\" });\n }\n\n /**\n * Tracing the fullBackup operation\n */\n private fullBackup(options: FullBackupOptionalParams): Promise<FullBackupResponse> {\n return withTrace(\"fullBackup\", options, (updatedOptions) =>\n this.client.fullBackup(this.vaultUrl, updatedOptions)\n );\n }\n\n /**\n * Tracing the fullBackupStatus operation\n */\n private fullBackupStatus(\n jobId: string,\n options: KeyVaultBeginBackupOptions\n ): Promise<FullBackupStatusResponse> {\n return withTrace(\"fullBackupStatus\", options, (updatedOptions) =>\n this.client.fullBackupStatus(this.vaultUrl, jobId, updatedOptions)\n );\n }\n\n /**\n * Reaches to the service and updates the backup's poll operation.\n */\n async update(\n options: {\n abortSignal?: AbortSignalLike;\n fireProgress?: (state: KeyVaultBackupPollOperationState) => void;\n } = {}\n ): Promise<KeyVaultBackupPollOperation> {\n const state = this.state;\n const { blobStorageUri, sasToken } = state;\n\n if (options.abortSignal) {\n this.requestOptions.abortSignal = options.abortSignal;\n }\n\n if (!state.isStarted) {\n const serviceOperation = await this.fullBackup({\n ...this.requestOptions,\n azureStorageBlobContainerUri: {\n storageResourceUri: blobStorageUri!,\n token: sasToken!,\n },\n });\n\n this.mapState(serviceOperation);\n } else if (!state.isCompleted) {\n if (!state.jobId) {\n throw new Error(`Missing \"jobId\" from the full backup operation.`);\n }\n const serviceOperation = await this.fullBackupStatus(state.jobId, this.requestOptions);\n this.mapState(serviceOperation);\n }\n\n return this;\n }\n\n private mapState(serviceOperation: FullBackupOperation): void {\n const state = this.state;\n const {\n startTime,\n jobId,\n azureStorageBlobContainerUri,\n endTime,\n error,\n status,\n statusDetails,\n } = serviceOperation;\n if (!startTime) {\n throw new Error(\n `Missing \"startTime\" from the full backup operation. Full backup did not start successfully.`\n );\n }\n\n state.isStarted = true;\n state.jobId = jobId;\n state.endTime = endTime;\n state.startTime = startTime;\n state.status = status;\n state.statusDetails = statusDetails;\n state.isCompleted = !!endTime;\n\n if (state.isCompleted && error?.code) {\n throw new Error(error?.message || statusDetails);\n }\n\n if (state.isCompleted) {\n state.result = {\n folderUri: azureStorageBlobContainerUri,\n startTime,\n endTime,\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../../../src/lro/backup/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EACL,0BAA0B,GAE3B,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAsB9C;;GAEG;AACH,MAAM,OAAO,2BAA4B,SAAQ,0BAGhD;IACC,YACS,KAAuC,EACtC,QAAgB,EAChB,MAAsB,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b,SAAS,EAAE,4BAA4B;gBACvC,SAAS;gBACT,OAAO;aACR,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FullBackupOperation,\n FullBackupOptionalParams,\n FullBackupResponse,\n FullBackupStatusResponse,\n} from \"../../generated/models\";\nimport {\n KeyVaultAdminPollOperation,\n KeyVaultAdminPollOperationState,\n} from \"../keyVaultAdminPoller\";\nimport { KeyVaultBackupResult, KeyVaultBeginBackupOptions } from \"../../backupClientModels\";\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { KeyVaultClient } from \"../../generated/keyVaultClient\";\nimport { tracingClient } from \"../../tracing\";\n\n/**\n * An interface representing the publicly available properties of the state of a backup Key Vault's poll operation.\n */\nexport type KeyVaultBackupOperationState = KeyVaultAdminPollOperationState<KeyVaultBackupResult>;\n\n/**\n * An internal interface representing the state of a backup Key Vault's poll operation.\n */\nexport interface KeyVaultBackupPollOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultBackupResult> {\n /**\n * The URI of the blob storage account.\n */\n blobStorageUri: string;\n /**\n * The SAS token.\n */\n sasToken: string;\n}\n\n/**\n * The backup Key Vault's poll operation.\n */\nexport class KeyVaultBackupPollOperation extends KeyVaultAdminPollOperation<\n KeyVaultBackupPollOperationState,\n string\n> {\n constructor(\n public state: KeyVaultBackupPollOperationState,\n private vaultUrl: string,\n private client: KeyVaultClient,\n private requestOptions: KeyVaultBeginBackupOptions = {}\n ) {\n super(state, { cancelMessage: \"Cancelling a full Key Vault backup is not supported.\" });\n }\n\n /**\n * Tracing the fullBackup operation\n */\n private fullBackup(options: FullBackupOptionalParams): Promise<FullBackupResponse> {\n return tracingClient.withSpan(\"KeyVaultBackupPoller.fullBackup\", options, (updatedOptions) =>\n this.client.fullBackup(this.vaultUrl, updatedOptions)\n );\n }\n\n /**\n * Tracing the fullBackupStatus operation\n */\n private fullBackupStatus(\n jobId: string,\n options: KeyVaultBeginBackupOptions\n ): Promise<FullBackupStatusResponse> {\n return tracingClient.withSpan(\n \"KeyVaultBackupPoller.fullBackupStatus\",\n options,\n (updatedOptions) => this.client.fullBackupStatus(this.vaultUrl, jobId, updatedOptions)\n );\n }\n\n /**\n * Reaches to the service and updates the backup's poll operation.\n */\n async update(\n options: {\n abortSignal?: AbortSignalLike;\n fireProgress?: (state: KeyVaultBackupPollOperationState) => void;\n } = {}\n ): Promise<KeyVaultBackupPollOperation> {\n const state = this.state;\n const { blobStorageUri, sasToken } = state;\n\n if (options.abortSignal) {\n this.requestOptions.abortSignal = options.abortSignal;\n }\n\n if (!state.isStarted) {\n const serviceOperation = await this.fullBackup({\n ...this.requestOptions,\n azureStorageBlobContainerUri: {\n storageResourceUri: blobStorageUri!,\n token: sasToken!,\n },\n });\n\n this.mapState(serviceOperation);\n } else if (!state.isCompleted) {\n if (!state.jobId) {\n throw new Error(`Missing \"jobId\" from the full backup operation.`);\n }\n const serviceOperation = await this.fullBackupStatus(state.jobId, this.requestOptions);\n this.mapState(serviceOperation);\n }\n\n return this;\n }\n\n private mapState(serviceOperation: FullBackupOperation): void {\n const state = this.state;\n const {\n startTime,\n jobId,\n azureStorageBlobContainerUri,\n endTime,\n error,\n status,\n statusDetails,\n } = serviceOperation;\n if (!startTime) {\n throw new Error(\n `Missing \"startTime\" from the full backup operation. Full backup did not start successfully.`\n );\n }\n\n state.isStarted = true;\n state.jobId = jobId;\n state.endTime = endTime;\n state.startTime = startTime;\n state.status = status;\n state.statusDetails = statusDetails;\n state.isCompleted = !!endTime;\n\n if (state.isCompleted && error?.code) {\n throw new Error(error?.message || statusDetails);\n }\n\n if (state.isCompleted) {\n state.result = {\n folderUri: azureStorageBlobContainerUri,\n startTime,\n endTime,\n };\n }\n }\n}\n"]}
@@ -1,11 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
3
  import { KeyVaultAdminPollOperation, } from "../keyVaultAdminPoller";
4
- import { createTraceFunction } from "../../tracingHelpers";
5
- /**
6
- * @internal
7
- */
8
- const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultRestorePoller");
4
+ import { tracingClient } from "../../tracing";
9
5
  /**
10
6
  * An interface representing a restore Key Vault's poll operation.
11
7
  */
@@ -23,13 +19,13 @@ export class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation {
23
19
  * Tracing the fullRestore operation
24
20
  */
25
21
  fullRestore(options) {
26
- return withTrace("fullRestore", options, (updatedOptions) => this.client.fullRestoreOperation(this.vaultUrl, updatedOptions));
22
+ return tracingClient.withSpan("KeyVaultRestorePoller.fullRestore", options, (updatedOptions) => this.client.fullRestoreOperation(this.vaultUrl, updatedOptions));
27
23
  }
28
24
  /**
29
25
  * Tracing the restoreStatus operation.
30
26
  */
31
27
  async restoreStatus(jobId, options) {
32
- return withTrace("restoreStatus", options, (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions));
28
+ return tracingClient.withSpan("KeyVaultRestorePoller.restoreStatus", options, (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions));
33
29
  }
34
30
  /**
35
31
  * Reaches to the service and updates the restore poll operation.
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../../../src/lro/restore/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,EACL,0BAA0B,GAE3B,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;GAEG;AACH,MAAM,SAAS,GAAG,mBAAmB,CAAC,4CAA4C,CAAC,CAAC;AA4BpF;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,0BAGjD;IACC,YACS,KAAwC,EACvC,QAAgB,EAChB,MAAsB,EACtB,iBAA8C,EAAE;QAExD,KAAK,CAAC,KAAK,EAAE;YACX,aAAa,EAAE,oEAAoE;SACpF,CAAC,CAAC;QAPI,UAAK,GAA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soft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FullRestoreOperationOptionalParams,\n FullRestoreOperationResponse,\n RestoreOperation,\n RestoreStatusResponse,\n} from \"../../generated/models\";\nimport {\n KeyVaultAdminPollOperation,\n KeyVaultAdminPollOperationState,\n} from \"../keyVaultAdminPoller\";\nimport { KeyVaultBeginRestoreOptions, KeyVaultRestoreResult } from \"../../backupClientModels\";\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { KeyVaultClient } from \"../../generated/keyVaultClient\";\nimport { OperationOptions } from \"@azure/core-client\";\nimport { createTraceFunction } from \"../../tracingHelpers\";\n\n/**\n * @internal\n */\nconst withTrace = createTraceFunction(\"Azure.KeyVault.Admin.KeyVaultRestorePoller\");\n\n/**\n * An interface representing the publicly available properties of the state of a restore Key Vault's poll operation.\n */\nexport interface KeyVaultRestoreOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {}\n\n/**\n * An internal interface representing the state of a restore Key Vault's poll operation.\n * @internal\n */\nexport interface KeyVaultRestorePollOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {\n /**\n * The URI of the blob storage account.\n */\n folderUri: string;\n /**\n * The SAS token.\n */\n sasToken: string;\n /**\n * The Folder name of the blob where the previous successful full backup was stored\n */\n folderName: string;\n}\n\n/**\n * An interface representing a restore Key Vault's poll operation.\n */\nexport class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation<\n KeyVaultRestorePollOperationState,\n KeyVaultRestoreResult\n> {\n constructor(\n public state: KeyVaultRestorePollOperationState,\n private vaultUrl: string,\n private client: KeyVaultClient,\n private requestOptions: KeyVaultBeginRestoreOptions = {}\n ) {\n super(state, {\n cancelMessage: \"Cancelling the restoration full Key Vault backup is not supported.\",\n });\n }\n\n /**\n * Tracing the fullRestore operation\n */\n private fullRestore(\n options: FullRestoreOperationOptionalParams\n ): Promise<FullRestoreOperationResponse> {\n return withTrace(\"fullRestore\", options, (updatedOptions) =>\n this.client.fullRestoreOperation(this.vaultUrl, updatedOptions)\n );\n }\n\n /**\n * Tracing the restoreStatus operation.\n */\n private async restoreStatus(\n jobId: string,\n options: OperationOptions\n ): Promise<RestoreStatusResponse> {\n return withTrace(\"restoreStatus\", options, (updatedOptions) =>\n this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions)\n );\n }\n\n /**\n * Reaches to the service and updates the restore poll operation.\n */\n async update(\n options: {\n abortSignal?: AbortSignalLike;\n fireProgress?: (state: KeyVaultRestorePollOperationState) => void;\n } = {}\n ): Promise<KeyVaultRestorePollOperation> {\n const state = this.state;\n const { folderUri, sasToken, folderName } = state;\n\n if (options.abortSignal) {\n this.requestOptions.abortSignal = options.abortSignal;\n }\n\n if (!state.isStarted) {\n const serviceOperation = await this.fullRestore({\n ...this.requestOptions,\n restoreBlobDetails: {\n folderToRestore: folderName,\n sasTokenParameters: {\n storageResourceUri: folderUri,\n token: sasToken,\n },\n },\n });\n\n this.mapState(serviceOperation);\n } else if (!state.isCompleted) {\n if (!state.jobId) {\n throw new Error(`Missing \"jobId\" from the full restore operation.`);\n }\n const serviceOperation = await this.restoreStatus(state.jobId, this.requestOptions);\n this.mapState(serviceOperation);\n }\n\n return this;\n }\n\n private mapState(serviceOperation: RestoreOperation): void {\n const state = this.state;\n const { startTime, jobId, endTime, error, status, statusDetails } = serviceOperation;\n\n if (!startTime) {\n throw new Error(\n `Missing \"startTime\" from the full restore operation. Restore did not start successfully.`\n );\n }\n\n state.isStarted = true;\n state.jobId = jobId;\n state.endTime = endTime;\n state.startTime = startTime;\n state.status = status;\n state.statusDetails = statusDetails;\n\n state.isCompleted = !!endTime;\n\n if (state.isCompleted && error?.code) {\n throw new Error(error?.message || statusDetails);\n }\n\n if (state.isCompleted) {\n state.result = {\n startTime,\n endTime,\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../../../src/lro/restore/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OA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I,KAAK,CAAC,WAAW,KAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAA,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,KAAI,aAAa,CAAC,CAAC;SAClD;QAED,IAAI,KAAK,CAAC,WAAW,EAAE;YACrB,KAAK,CAAC,MAAM,GAAG;gBACb,SAAS;gBACT,OAAO;aACR,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FullRestoreOperationOptionalParams,\n FullRestoreOperationResponse,\n RestoreOperation,\n RestoreStatusResponse,\n} from \"../../generated/models\";\nimport {\n KeyVaultAdminPollOperation,\n KeyVaultAdminPollOperationState,\n} from \"../keyVaultAdminPoller\";\nimport { KeyVaultBeginRestoreOptions, KeyVaultRestoreResult } from \"../../backupClientModels\";\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { KeyVaultClient } from \"../../generated/keyVaultClient\";\nimport { OperationOptions } from \"@azure/core-client\";\nimport { tracingClient } from \"../../tracing\";\n\n/**\n * An interface representing the publicly available properties of the state of a restore Key Vault's poll operation.\n */\nexport interface KeyVaultRestoreOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {}\n\n/**\n * An internal interface representing the state of a restore Key Vault's poll operation.\n * @internal\n */\nexport interface KeyVaultRestorePollOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultRestoreResult> {\n /**\n * The URI of the blob storage account.\n */\n folderUri: string;\n /**\n * The SAS token.\n */\n sasToken: string;\n /**\n * The Folder name of the blob where the previous successful full backup was stored\n */\n folderName: string;\n}\n\n/**\n * An interface representing a restore Key Vault's poll operation.\n */\nexport class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation<\n KeyVaultRestorePollOperationState,\n KeyVaultRestoreResult\n> {\n constructor(\n public state: KeyVaultRestorePollOperationState,\n private vaultUrl: string,\n private client: KeyVaultClient,\n private requestOptions: KeyVaultBeginRestoreOptions = {}\n ) {\n super(state, {\n cancelMessage: \"Cancelling the restoration full Key Vault backup is not supported.\",\n });\n }\n\n /**\n * Tracing the fullRestore operation\n */\n private fullRestore(\n options: FullRestoreOperationOptionalParams\n ): Promise<FullRestoreOperationResponse> {\n return tracingClient.withSpan(\"KeyVaultRestorePoller.fullRestore\", options, (updatedOptions) =>\n this.client.fullRestoreOperation(this.vaultUrl, updatedOptions)\n );\n }\n\n /**\n * Tracing the restoreStatus operation.\n */\n private async restoreStatus(\n jobId: string,\n options: OperationOptions\n ): Promise<RestoreStatusResponse> {\n return tracingClient.withSpan(\n \"KeyVaultRestorePoller.restoreStatus\",\n options,\n (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions)\n );\n }\n\n /**\n * Reaches to the service and updates the restore poll operation.\n */\n async update(\n options: {\n abortSignal?: AbortSignalLike;\n fireProgress?: (state: KeyVaultRestorePollOperationState) => void;\n } = {}\n ): Promise<KeyVaultRestorePollOperation> {\n const state = this.state;\n const { folderUri, sasToken, folderName } = state;\n\n if (options.abortSignal) {\n this.requestOptions.abortSignal = options.abortSignal;\n }\n\n if (!state.isStarted) {\n const serviceOperation = await this.fullRestore({\n ...this.requestOptions,\n restoreBlobDetails: {\n folderToRestore: folderName,\n sasTokenParameters: {\n storageResourceUri: folderUri,\n token: sasToken,\n },\n },\n });\n\n this.mapState(serviceOperation);\n } else if (!state.isCompleted) {\n if (!state.jobId) {\n throw new Error(`Missing \"jobId\" from the full restore operation.`);\n }\n const serviceOperation = await this.restoreStatus(state.jobId, this.requestOptions);\n this.mapState(serviceOperation);\n }\n\n return this;\n }\n\n private mapState(serviceOperation: RestoreOperation): void {\n const state = this.state;\n const { startTime, jobId, endTime, error, status, statusDetails } = serviceOperation;\n\n if (!startTime) {\n throw new Error(\n `Missing \"startTime\" from the full restore operation. Restore did not start successfully.`\n );\n }\n\n state.isStarted = true;\n state.jobId = jobId;\n state.endTime = endTime;\n state.startTime = startTime;\n state.status = status;\n state.statusDetails = statusDetails;\n\n state.isCompleted = !!endTime;\n\n if (state.isCompleted && error?.code) {\n throw new Error(error?.message || statusDetails);\n }\n\n if (state.isCompleted) {\n state.result = {\n startTime,\n endTime,\n };\n }\n }\n}\n"]}