@azure/keyvault-admin 4.2.0-beta.1 → 4.2.1-alpha.20220325.3

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 (54) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +3 -0
  3. package/dist/index.js +311 -237
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/keyvault-admin/src/accessControlClient.js +14 -21
  6. package/dist-esm/keyvault-admin/src/accessControlClient.js.map +1 -1
  7. package/dist-esm/keyvault-admin/src/accessControlModels.js +2 -70
  8. package/dist-esm/keyvault-admin/src/accessControlModels.js.map +1 -1
  9. package/dist-esm/keyvault-admin/src/backupClient.js +7 -7
  10. package/dist-esm/keyvault-admin/src/backupClient.js.map +1 -1
  11. package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js +7 -29
  12. package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js.map +1 -1
  13. package/dist-esm/keyvault-admin/src/constants.js +2 -2
  14. package/dist-esm/keyvault-admin/src/constants.js.map +1 -1
  15. package/dist-esm/keyvault-admin/src/generated/keyVaultClient.js +2 -1
  16. package/dist-esm/keyvault-admin/src/generated/keyVaultClient.js.map +1 -1
  17. package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js +2 -2
  18. package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js.map +1 -1
  19. package/dist-esm/keyvault-admin/src/generated/models/index.js +99 -1
  20. package/dist-esm/keyvault-admin/src/generated/models/index.js.map +1 -1
  21. package/dist-esm/keyvault-admin/src/generated/operations/roleAssignments.js +1 -1
  22. package/dist-esm/keyvault-admin/src/generated/operations/roleAssignments.js.map +1 -1
  23. package/dist-esm/keyvault-admin/src/generated/operations/roleDefinitions.js +1 -1
  24. package/dist-esm/keyvault-admin/src/generated/operations/roleDefinitions.js.map +1 -1
  25. package/dist-esm/keyvault-admin/src/lro/backup/operation.js +4 -4
  26. package/dist-esm/keyvault-admin/src/lro/backup/operation.js.map +1 -1
  27. package/dist-esm/keyvault-admin/src/lro/backup/poller.js +2 -2
  28. package/dist-esm/keyvault-admin/src/lro/backup/poller.js.map +1 -1
  29. package/dist-esm/keyvault-admin/src/lro/keyVaultAdminPoller.js +2 -2
  30. package/dist-esm/keyvault-admin/src/lro/keyVaultAdminPoller.js.map +1 -1
  31. package/dist-esm/keyvault-admin/src/lro/restore/operation.js +5 -5
  32. package/dist-esm/keyvault-admin/src/lro/restore/operation.js.map +1 -1
  33. package/dist-esm/keyvault-admin/src/lro/restore/poller.js +2 -2
  34. package/dist-esm/keyvault-admin/src/lro/restore/poller.js.map +1 -1
  35. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/operation.js +4 -4
  36. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/operation.js.map +1 -1
  37. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/poller.js +2 -2
  38. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/poller.js.map +1 -1
  39. package/dist-esm/keyvault-admin/src/mappings.js +7 -7
  40. package/dist-esm/keyvault-admin/src/mappings.js.map +1 -1
  41. package/dist-esm/keyvault-admin/src/tracingHelpers.js +4 -4
  42. package/dist-esm/keyvault-admin/src/tracingHelpers.js.map +1 -1
  43. package/dist-esm/keyvault-common/src/challengeBasedAuthenticationPolicy.js +14 -25
  44. package/dist-esm/keyvault-common/src/challengeBasedAuthenticationPolicy.js.map +1 -1
  45. package/dist-esm/keyvault-common/src/index.js +1 -0
  46. package/dist-esm/keyvault-common/src/index.js.map +1 -1
  47. package/dist-esm/keyvault-common/src/parseKeyvaultIdentifier.js +1 -1
  48. package/dist-esm/keyvault-common/src/parseKeyvaultIdentifier.js.map +1 -1
  49. package/dist-esm/keyvault-common/src/parseWWWAuthenticate.js +52 -0
  50. package/dist-esm/keyvault-common/src/parseWWWAuthenticate.js.map +1 -0
  51. package/dist-esm/keyvault-common/src/tracingHelpers.js +4 -4
  52. package/dist-esm/keyvault-common/src/tracingHelpers.js.map +1 -1
  53. package/package.json +20 -37
  54. package/types/keyvault-admin.d.ts +54 -13
@@ -1 +1 @@
1
- {"version":3,"file":"keyVaultAdminPoller.js","sourceRoot":"","sources":["../../../../src/lro/keyVaultAdminPoller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,MAAM,EAAqC,MAAM,iBAAiB,CAAC;AAwC5E;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,KAAa;IAEb,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,OAAgB,mBAGpB,SAAQ,MAAuB;IAHjC;;QAIE;;WAEG;QACI,iBAAY,GAAW,IAAI,CAAC;IAerC,CAAC;IAbC;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED;;OAEG;IACI,iBAAiB;QACtB,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAW,CAAC;IACpD,CAAC;CACF;AASD;;GAEG;AACH,MAAM,OAAO,0BAA0B;IAGrC,YAAmB,KAAa,EAAE,OAA0C;QAAzD,UAAK,GAAL,KAAK,CAAQ;QAC9B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM;QACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM;QACjB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { OperationOptions } from \"@azure/core-client\";\nimport { Poller, PollOperation, PollOperationState } from \"@azure/core-lro\";\nimport { KeyVaultClient } from \"../generated/keyVaultClient\";\n\n/**\n * Common parameters to a Key Vault Admin Poller.\n */\nexport interface KeyVaultAdminPollerOptions {\n vaultUrl: string;\n client: KeyVaultClient;\n requestOptions?: OperationOptions;\n intervalInMs?: number;\n resumeFrom?: string;\n}\n\n/**\n * An interface representing the state of a Key Vault Admin Poller's operation.\n */\nexport interface KeyVaultAdminPollOperationState<TResult> extends PollOperationState<TResult> {\n /**\n * Identifier for the full restore operation.\n */\n jobId?: string;\n /**\n * Status of the restore operation.\n */\n status?: string;\n /**\n * The status details of restore operation.\n */\n statusDetails?: string;\n /**\n * The start time of the restore operation in UTC\n */\n startTime?: Date;\n /**\n * The end time of the restore operation in UTC\n */\n endTime?: Date;\n}\n\n/**\n * Generates a version of the state with only public properties. At least those common for all of the Key Vault Admin pollers.\n */\nexport function cleanState<TState extends KeyVaultAdminPollOperationState<TResult>, TResult>(\n state: TState\n): KeyVaultAdminPollOperationState<TResult> {\n return {\n jobId: state.jobId,\n status: state.status,\n statusDetails: state.statusDetails,\n startTime: state.startTime,\n endTime: state.endTime,\n isStarted: state.isStarted,\n isCancelled: state.isCancelled,\n isCompleted: state.isCompleted,\n error: state.error,\n result: state.result\n };\n}\n\n/**\n * Common properties and methods of the Key Vault Admin Pollers.\n */\nexport abstract class KeyVaultAdminPoller<\n TState extends KeyVaultAdminPollOperationState<TResult>,\n TResult\n> extends Poller<TState, TResult> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n public intervalInMs: number = 2000;\n\n /**\n * The method used by the poller to wait before attempting to update its operation.\n */\n async delay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, this.intervalInMs));\n }\n\n /**\n * Gets the public state of the polling operation\n */\n public getOperationState(): TState {\n return cleanState(this.operation.state) as TState;\n }\n}\n\n/**\n * Optional parameters to the KeyVaultAdminPollOperation\n */\nexport interface KeyVaultAdminPollOperationOptions {\n cancelMessage: string;\n}\n\n/**\n * Common properties and methods of the Key Vault Admin Poller operations.\n */\nexport class KeyVaultAdminPollOperation<TState, TResult> implements PollOperation<TState, TResult> {\n private cancelMessage: string;\n\n constructor(public state: TState, options: KeyVaultAdminPollOperationOptions) {\n this.cancelMessage = options.cancelMessage;\n }\n\n /**\n * Meant to reach to the service and update the Poller operation.\n */\n public async update(): Promise<PollOperation<TState, TResult>> {\n throw new Error(\"Operation not supported.\");\n }\n\n /**\n * Meant to reach to the service and cancel the Poller operation.\n */\n public async cancel(): Promise<PollOperation<TState, TResult>> {\n throw new Error(this.cancelMessage);\n }\n\n /**\n * Serializes the Poller operation.\n */\n public toString(): string {\n return JSON.stringify({\n state: cleanState(this.state)\n });\n }\n}\n"]}
1
+ {"version":3,"file":"keyVaultAdminPoller.js","sourceRoot":"","sources":["../../../../src/lro/keyVaultAdminPoller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAqC,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAyC5E;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,KAAa;IAEb,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAA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L,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { PollOperation, PollOperationState, Poller } from \"@azure/core-lro\";\nimport { KeyVaultClient } from \"../generated/keyVaultClient\";\nimport { OperationOptions } from \"@azure/core-client\";\n\n/**\n * Common parameters to a Key Vault Admin Poller.\n */\nexport interface KeyVaultAdminPollerOptions {\n vaultUrl: string;\n client: KeyVaultClient;\n requestOptions?: OperationOptions;\n intervalInMs?: number;\n resumeFrom?: string;\n}\n\n/**\n * An interface representing the state of a Key Vault Admin Poller's operation.\n */\nexport interface KeyVaultAdminPollOperationState<TResult> extends PollOperationState<TResult> {\n /**\n * Identifier for the full restore operation.\n */\n jobId?: string;\n /**\n * Status of the restore operation.\n */\n status?: string;\n /**\n * The status details of restore operation.\n */\n statusDetails?: string;\n /**\n * The start time of the restore operation in UTC\n */\n startTime?: Date;\n /**\n * The end time of the restore operation in UTC\n */\n endTime?: Date;\n}\n\n/**\n * Generates a version of the state with only public properties. At least those common for all of the Key Vault Admin pollers.\n */\nexport function cleanState<TState extends KeyVaultAdminPollOperationState<TResult>, TResult>(\n state: TState\n): KeyVaultAdminPollOperationState<TResult> {\n return {\n jobId: state.jobId,\n status: state.status,\n statusDetails: state.statusDetails,\n startTime: state.startTime,\n endTime: state.endTime,\n isStarted: state.isStarted,\n isCancelled: state.isCancelled,\n isCompleted: state.isCompleted,\n error: state.error,\n result: state.result,\n };\n}\n\n/**\n * Common properties and methods of the Key Vault Admin Pollers.\n */\nexport abstract class KeyVaultAdminPoller<\n TState extends KeyVaultAdminPollOperationState<TResult>,\n TResult\n> extends Poller<TState, TResult> {\n /**\n * Defines how much time the poller is going to wait before making a new request to the service.\n */\n public intervalInMs: number = 2000;\n\n /**\n * The method used by the poller to wait before attempting to update its operation.\n */\n async delay(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, this.intervalInMs));\n }\n\n /**\n * Gets the public state of the polling operation\n */\n public getOperationState(): TState {\n return cleanState(this.operation.state) as TState;\n }\n}\n\n/**\n * Optional parameters to the KeyVaultAdminPollOperation\n */\nexport interface KeyVaultAdminPollOperationOptions {\n cancelMessage: string;\n}\n\n/**\n * Common properties and methods of the Key Vault Admin Poller operations.\n */\nexport class KeyVaultAdminPollOperation<TState, TResult> implements PollOperation<TState, TResult> {\n private cancelMessage: string;\n\n constructor(public state: TState, options: KeyVaultAdminPollOperationOptions) {\n this.cancelMessage = options.cancelMessage;\n }\n\n /**\n * Meant to reach to the service and update the Poller operation.\n */\n public async update(): Promise<PollOperation<TState, TResult>> {\n throw new Error(\"Operation not supported.\");\n }\n\n /**\n * Meant to reach to the service and cancel the Poller operation.\n */\n public async cancel(): Promise<PollOperation<TState, TResult>> {\n throw new Error(this.cancelMessage);\n }\n\n /**\n * Serializes the Poller operation.\n */\n public toString(): string {\n return JSON.stringify({\n state: cleanState(this.state),\n });\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { KeyVaultAdminPollOperation } from "../keyVaultAdminPoller";
3
+ import { KeyVaultAdminPollOperation, } from "../keyVaultAdminPoller";
4
4
  import { createTraceFunction } from "../../tracingHelpers";
5
5
  /**
6
6
  * @internal
@@ -12,7 +12,7 @@ const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultRestorePolle
12
12
  export class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation {
13
13
  constructor(state, vaultUrl, client, requestOptions = {}) {
14
14
  super(state, {
15
- cancelMessage: "Cancelling the restoration full Key Vault backup is not supported."
15
+ cancelMessage: "Cancelling the restoration full Key Vault backup is not supported.",
16
16
  });
17
17
  this.state = state;
18
18
  this.vaultUrl = vaultUrl;
@@ -45,8 +45,8 @@ export class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation {
45
45
  folderToRestore: folderName,
46
46
  sasTokenParameters: {
47
47
  storageResourceUri: folderUri,
48
- token: sasToken
49
- }
48
+ token: sasToken,
49
+ },
50
50
  } }));
51
51
  this.mapState(serviceOperation);
52
52
  }
@@ -78,7 +78,7 @@ export class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation {
78
78
  if (state.isCompleted) {
79
79
  state.result = {
80
80
  startTime,
81
- endTime
81
+ endTime,
82
82
  };
83
83
  }
84
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../../../src/lro/restore/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EACL,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAG3D;;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,GAAL,KAAK,CAAmC;QACvC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAgB;QACtB,mBAAc,GAAd,cAAc,CAAkC;IAK1D,CAAC;IAED;;OAEG;IACK,WAAW,CACjB,OAAyD;QAEzD,OAAO,SAAS,CAAC,aAAa,EAAE,OAAO,EAAE,CAAC,cAAc,EAAE,EAAE,CAC1D,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAChE,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,aAAa,CACzB,KAAa,EACb,OAAyB;QAEzB,OAAO,SAAS,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC,cAAc,EAAE,EAAE,CAC5D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,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MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,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;QAEpC,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;gBACT,OAAO;aACR,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { KeyVaultClient } from \"../../generated/keyVaultClient\";\nimport {\n KeyVaultClientFullRestoreOperationOptionalParams,\n KeyVaultClientRestoreStatusResponse,\n RestoreOperation\n} from \"../../generated/models\";\nimport { KeyVaultClientFullRestoreOperationResponse } from \"../../generated/models\";\nimport {\n KeyVaultAdminPollOperation,\n KeyVaultAdminPollOperationState\n} from \"../keyVaultAdminPoller\";\nimport { KeyVaultBeginRestoreOptions, KeyVaultRestoreResult } from \"../../backupClientModels\";\nimport { createTraceFunction } from \"../../tracingHelpers\";\nimport { OperationOptions } from \"@azure/core-client\";\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: KeyVaultClientFullRestoreOperationOptionalParams\n ): Promise<KeyVaultClientFullRestoreOperationResponse> {\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<KeyVaultClientRestoreStatusResponse> {\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,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,GAAL,KAAK,CAAmC;QACvC,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAgB;QAC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DAAkD,CAAC,CAAC;aACrE;YACD,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YACpF,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;SACjC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,QAAQ,CAAC,gBAAkC;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAgB,CAAC;QAErF,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,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;QAEpC,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;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 { 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,13 +1,13 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { KeyVaultRestorePollOperation } from "./operation";
4
3
  import { KeyVaultAdminPoller } from "../keyVaultAdminPoller";
4
+ import { KeyVaultRestorePollOperation, } from "./operation";
5
5
  /**
6
6
  * Class that creates a poller that waits until a Key Vault ends up being restored.
7
7
  */
8
8
  export class KeyVaultRestorePoller extends KeyVaultAdminPoller {
9
9
  constructor(options) {
10
- const { client, vaultUrl, folderUri, sasToken, folderName, requestOptions, intervalInMs = 2000, resumeFrom } = options;
10
+ const { client, vaultUrl, folderUri, sasToken, folderName, requestOptions, intervalInMs = 2000, resumeFrom, } = options;
11
11
  let state;
12
12
  if (resumeFrom) {
13
13
  state = JSON.parse(resumeFrom).state;
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../../../src/lro/restore/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,4BAA4B,EAG7B,MAAM,aAAa,CAAC;AACrB,OAAO,EAA8B,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AASzF;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,mBAG1C;IACC,YAAY,OAAqC;QAC/C,MAAM,EACJ,MAAM,EACN,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACd,YAAY,GAAG,IAAI,EACnB,UAAU,EACX,GAAG,OAAO,CAAC;QAEZ,IAAI,KAAoD,CAAC;QAEzD,IAAI,UAAU,EAAE;YACd,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC;SACtC;QAED,MAAM,SAAS,GAAG,IAAI,4BAA4B,iCAE3C,KAAK,KACR,SAAS;YACT,QAAQ;YACR,UAAU,KAEZ,QAAQ,EACR,MAAM,EACN,cAAc,CACf,CAAC;QAEF,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n KeyVaultRestorePollOperation,\n KeyVaultRestoreOperationState,\n KeyVaultRestorePollOperationState\n} from \"./operation\";\nimport { KeyVaultAdminPollerOptions, KeyVaultAdminPoller } from \"../keyVaultAdminPoller\";\nimport { KeyVaultRestoreResult } from \"../../backupClientModels\";\n\nexport interface KeyVaultRestorePollerOptions extends KeyVaultAdminPollerOptions {\n folderUri: string;\n sasToken: string;\n folderName: string;\n}\n\n/**\n * Class that creates a poller that waits until a Key Vault ends up being restored.\n */\nexport class KeyVaultRestorePoller extends KeyVaultAdminPoller<\n KeyVaultRestoreOperationState,\n KeyVaultRestoreResult\n> {\n constructor(options: KeyVaultRestorePollerOptions) {\n const {\n client,\n vaultUrl,\n folderUri,\n sasToken,\n folderName,\n requestOptions,\n intervalInMs = 2000,\n resumeFrom\n } = options;\n\n let state: KeyVaultRestorePollOperationState | undefined;\n\n if (resumeFrom) {\n state = JSON.parse(resumeFrom).state;\n }\n\n const operation = new KeyVaultRestorePollOperation(\n {\n ...state,\n folderUri,\n sasToken,\n folderName\n },\n vaultUrl,\n client,\n requestOptions\n );\n\n super(operation);\n\n this.intervalInMs = intervalInMs;\n }\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../../../src/lro/restore/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,mBAAmB,EAA8B,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAEL,4BAA4B,GAE7B,MAAM,aAAa,CAAC;AASrB;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,mBAG1C;IACC,YAAY,OAAqC;QAC/C,MAAM,EACJ,MAAM,EACN,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACd,YAAY,GAAG,IAAI,EACnB,UAAU,GACX,GAAG,OAAO,CAAC;QAEZ,IAAI,KAAoD,CAAC;QAEzD,IAAI,UAAU,EAAE;YACd,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC;SACtC;QAED,MAAM,SAAS,GAAG,IAAI,4BAA4B,iCAE3C,KAAK,KACR,SAAS;YACT,QAAQ;YACR,UAAU,KAEZ,QAAQ,EACR,MAAM,EACN,cAAc,CACf,CAAC;QAEF,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyVaultAdminPoller, KeyVaultAdminPollerOptions } from \"../keyVaultAdminPoller\";\nimport {\n KeyVaultRestoreOperationState,\n KeyVaultRestorePollOperation,\n KeyVaultRestorePollOperationState,\n} from \"./operation\";\nimport { KeyVaultRestoreResult } from \"../../backupClientModels\";\n\nexport interface KeyVaultRestorePollerOptions extends KeyVaultAdminPollerOptions {\n folderUri: string;\n sasToken: string;\n folderName: string;\n}\n\n/**\n * Class that creates a poller that waits until a Key Vault ends up being restored.\n */\nexport class KeyVaultRestorePoller extends KeyVaultAdminPoller<\n KeyVaultRestoreOperationState,\n KeyVaultRestoreResult\n> {\n constructor(options: KeyVaultRestorePollerOptions) {\n const {\n client,\n vaultUrl,\n folderUri,\n sasToken,\n folderName,\n requestOptions,\n intervalInMs = 2000,\n resumeFrom,\n } = options;\n\n let state: KeyVaultRestorePollOperationState | undefined;\n\n if (resumeFrom) {\n state = JSON.parse(resumeFrom).state;\n }\n\n const operation = new KeyVaultRestorePollOperation(\n {\n ...state,\n folderUri,\n sasToken,\n folderName,\n },\n vaultUrl,\n client,\n requestOptions\n );\n\n super(operation);\n\n this.intervalInMs = intervalInMs;\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { KeyVaultAdminPollOperation } from "../keyVaultAdminPoller";
3
+ import { KeyVaultAdminPollOperation, } from "../keyVaultAdminPoller";
4
4
  import { createTraceFunction } from "../../tracingHelpers";
5
5
  /**
6
6
  * @internal
@@ -43,8 +43,8 @@ export class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollO
43
43
  folder: folderName,
44
44
  sasTokenParameters: {
45
45
  storageResourceUri: folderUri,
46
- token: sasToken
47
- }
46
+ token: sasToken,
47
+ },
48
48
  } }));
49
49
  this.mapState(selectiveRestoreOperation);
50
50
  }
@@ -76,7 +76,7 @@ export class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollO
76
76
  if (state.isCompleted) {
77
77
  state.result = {
78
78
  startTime,
79
- endTime
79
+ endTime,
80
80
  };
81
81
  }
82
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../../../src/lro/selectiveKeyRestore/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EACL,0BAA0B,EAE3B,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;GAEG;AACH,MAAM,SAAS,GAAG,mBAAmB,CAAC,wDAAwD,CAAC,CAAC;AA8BhG;;GAEG;AACH,MAAM,OAAO,wCAAyC,SAAQ,0BAG7D;IACC,YACS,KAAoD,EACnD,QAAgB,EAChB,MAAsB,EACtB,iBAA0D,EAAE;QAEpE,KAAK,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,4DAA4D,EAAE,CAAC,CAAC;QALvF,UAAK,GAAL,KAAK,CAA+C;QACnD,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAgB;QACtB,mBAAc,GAAd,cAAc,CAA8C;IAGtE,CAAC;IAED;;OAEG;IACK,gBAAgB,CACtB,OAAe,EACf,OAAiE;QAEjE,OAAO,SAAS,CAAC,kBAAkB,EAAE,OAAO,EAAE,CAAC,cAAc,EAAE,EAAE,CAC/D,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,CAAC,CACjF,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,aAAa,CACnB,KAAa,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I,CAAC,KAAK,CAAC;QACzB,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAgB,CAAC;QAErF,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;SAC9E;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;gBACT,OAAO;aACR,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortSignalLike } from \"@azure/abort-controller\";\nimport { KeyVaultClient } from \"../../generated/keyVaultClient\";\nimport {\n KeyVaultClientRestoreStatusResponse,\n KeyVaultClientSelectiveKeyRestoreOperationOptionalParams,\n KeyVaultClientSelectiveKeyRestoreOperationResponse,\n RestoreOperation\n} from \"../../generated/models\";\nimport {\n KeyVaultAdminPollOperation,\n KeyVaultAdminPollOperationState\n} from \"../keyVaultAdminPoller\";\nimport {\n KeyVaultBeginSelectiveKeyRestoreOptions,\n KeyVaultSelectiveKeyRestoreResult\n} from \"../../backupClientModels\";\nimport { OperationOptions } from \"@azure/core-client\";\nimport { createTraceFunction } from \"../../tracingHelpers\";\n\n/**\n * @internal\n */\nconst withTrace = createTraceFunction(\"Azure.KeyVault.Admin.KeyVaultSelectiveKeyRestorePoller\");\n/**\n * An interface representing the publicly available properties of the state of a restore Key Vault's poll operation.\n */\nexport interface KeyVaultSelectiveKeyRestoreOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {}\n\n/**\n * An internal interface representing the state of a restore Key Vault's poll operation.\n */\nexport interface KeyVaultSelectiveKeyRestorePollOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {\n /**\n * The name of a Key Vault Key.\n */\n keyName: string;\n /**\n * The Folder name of the blob where the previous successful full backup was stored\n */\n folderName: string;\n /**\n * The URI of the blob storage account where the previous successful full backup was stored.\n */\n folderUri: string;\n /**\n * The SAS token.\n */\n sasToken: string;\n}\n\n/**\n * The selective restore Key Vault's poll operation.\n */\nexport class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollOperation<\n KeyVaultSelectiveKeyRestorePollOperationState,\n string\n> {\n constructor(\n public state: KeyVaultSelectiveKeyRestorePollOperationState,\n private vaultUrl: string,\n private client: KeyVaultClient,\n private requestOptions: KeyVaultBeginSelectiveKeyRestoreOptions = {}\n ) {\n super(state, { cancelMessage: \"Cancelling a selective Key Vault restore is not supported.\" });\n }\n\n /**\n * Tracing the selectiveRestore operation\n */\n private selectiveRestore(\n keyName: string,\n options: KeyVaultClientSelectiveKeyRestoreOperationOptionalParams\n ): Promise<KeyVaultClientSelectiveKeyRestoreOperationResponse> {\n return withTrace(\"selectiveRestore\", options, (updatedOptions) =>\n this.client.selectiveKeyRestoreOperation(this.vaultUrl, keyName, updatedOptions)\n );\n }\n\n /**\n * Tracing the restoreStatus operation.\n */\n private restoreStatus(\n jobId: string,\n options: OperationOptions\n ): Promise<KeyVaultClientRestoreStatusResponse> {\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 selective restore poll operation.\n */\n async update(\n options: {\n abortSignal?: AbortSignalLike;\n fireProgress?: (state: KeyVaultSelectiveKeyRestorePollOperationState) => void;\n } = {}\n ): Promise<KeyVaultSelectiveKeyRestorePollOperation> {\n const state = this.state;\n const { keyName, folderUri, sasToken, folderName } = state;\n\n if (options.abortSignal) {\n this.requestOptions.abortSignal = options.abortSignal;\n }\n\n if (!state.isStarted) {\n const selectiveRestoreOperation = await this.selectiveRestore(keyName, {\n ...this.requestOptions,\n restoreBlobDetails: {\n folder: folderName,\n sasTokenParameters: {\n storageResourceUri: folderUri,\n token: sasToken\n }\n }\n });\n this.mapState(selectiveRestoreOperation);\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(`Missing \"startTime\" from the selective restore operation.`);\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 startTime,\n endTime\n };\n }\n }\n}\n"]}
1
+ {"version":3,"file":"operation.js","sourceRoot":"","sources":["../../../../../src/lro/selectiveKeyRestore/operation.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,0BAA0B,GAE3B,MAAM,wBAAwB,CAAC;AAchC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;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K,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 KeyVaultAdminPollOperation,\n KeyVaultAdminPollOperationState,\n} from \"../keyVaultAdminPoller\";\nimport {\n KeyVaultBeginSelectiveKeyRestoreOptions,\n KeyVaultSelectiveKeyRestoreResult,\n} from \"../../backupClientModels\";\nimport {\n RestoreOperation,\n RestoreStatusResponse,\n SelectiveKeyRestoreOperationOptionalParams,\n SelectiveKeyRestoreOperationResponse,\n} from \"../../generated/models\";\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.KeyVaultSelectiveKeyRestorePoller\");\n/**\n * An interface representing the publicly available properties of the state of a restore Key Vault's poll operation.\n */\nexport interface KeyVaultSelectiveKeyRestoreOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {}\n\n/**\n * An internal interface representing the state of a restore Key Vault's poll operation.\n */\nexport interface KeyVaultSelectiveKeyRestorePollOperationState\n extends KeyVaultAdminPollOperationState<KeyVaultSelectiveKeyRestoreResult> {\n /**\n * The name of a Key Vault Key.\n */\n keyName: string;\n /**\n * The Folder name of the blob where the previous successful full backup was stored\n */\n folderName: string;\n /**\n * The URI of the blob storage account where the previous successful full backup was stored.\n */\n folderUri: string;\n /**\n * The SAS token.\n */\n sasToken: string;\n}\n\n/**\n * The selective restore Key Vault's poll operation.\n */\nexport class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollOperation<\n KeyVaultSelectiveKeyRestorePollOperationState,\n string\n> {\n constructor(\n public state: KeyVaultSelectiveKeyRestorePollOperationState,\n private vaultUrl: string,\n private client: KeyVaultClient,\n private requestOptions: KeyVaultBeginSelectiveKeyRestoreOptions = {}\n ) {\n super(state, { cancelMessage: \"Cancelling a selective Key Vault restore is not supported.\" });\n }\n\n /**\n * Tracing the selectiveRestore operation\n */\n private selectiveRestore(\n keyName: string,\n options: SelectiveKeyRestoreOperationOptionalParams\n ): Promise<SelectiveKeyRestoreOperationResponse> {\n return withTrace(\"selectiveRestore\", options, (updatedOptions) =>\n this.client.selectiveKeyRestoreOperation(this.vaultUrl, keyName, updatedOptions)\n );\n }\n\n /**\n * Tracing the restoreStatus operation.\n */\n private restoreStatus(jobId: string, options: OperationOptions): 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 selective restore poll operation.\n */\n async update(\n options: {\n abortSignal?: AbortSignalLike;\n fireProgress?: (state: KeyVaultSelectiveKeyRestorePollOperationState) => void;\n } = {}\n ): Promise<KeyVaultSelectiveKeyRestorePollOperation> {\n const state = this.state;\n const { keyName, folderUri, sasToken, folderName } = state;\n\n if (options.abortSignal) {\n this.requestOptions.abortSignal = options.abortSignal;\n }\n\n if (!state.isStarted) {\n const selectiveRestoreOperation = await this.selectiveRestore(keyName, {\n ...this.requestOptions,\n restoreBlobDetails: {\n folder: folderName,\n sasTokenParameters: {\n storageResourceUri: folderUri,\n token: sasToken,\n },\n },\n });\n this.mapState(selectiveRestoreOperation);\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(`Missing \"startTime\" from the selective restore operation.`);\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 startTime,\n endTime,\n };\n }\n }\n}\n"]}
@@ -1,13 +1,13 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { KeyVaultSelectiveKeyRestorePollOperation } from "./operation";
4
3
  import { KeyVaultAdminPoller } from "../keyVaultAdminPoller";
4
+ import { KeyVaultSelectiveKeyRestorePollOperation, } from "./operation";
5
5
  /**
6
6
  * Class that creates a poller that waits until a key of a Key Vault backup ends up being restored.
7
7
  */
8
8
  export class KeyVaultSelectiveKeyRestorePoller extends KeyVaultAdminPoller {
9
9
  constructor(options) {
10
- const { client, vaultUrl, keyName, folderUri, sasToken, folderName, requestOptions, intervalInMs = 2000, resumeFrom } = options;
10
+ const { client, vaultUrl, keyName, folderUri, sasToken, folderName, requestOptions, intervalInMs = 2000, resumeFrom, } = options;
11
11
  let state;
12
12
  if (resumeFrom) {
13
13
  state = JSON.parse(resumeFrom).state;
@@ -1 +1 @@
1
- {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../../../src/lro/selectiveKeyRestore/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,wCAAwC,EAGzC,MAAM,aAAa,CAAC;AACrB,OAAO,EAA8B,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAUzF;;GAEG;AACH,MAAM,OAAO,iCAAkC,SAAQ,mBAGtD;IACC,YAAY,OAAiD;QAC3D,MAAM,EACJ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACd,YAAY,GAAG,IAAI,EACnB,UAAU,EACX,GAAG,OAAO,CAAC;QAEZ,IAAI,KAAgE,CAAC;QAErE,IAAI,UAAU,EAAE;YACd,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC;SACtC;QAED,MAAM,SAAS,GAAG,IAAI,wCAAwC,iCAEvD,KAAK,KACR,OAAO,EACP,SAAS,EAAE,SAAS,EACpB,QAAQ;YACR,UAAU,KAEZ,QAAQ,EACR,MAAM,EACN,cAAc,CACf,CAAC;QAEF,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n KeyVaultSelectiveKeyRestorePollOperation,\n KeyVaultSelectiveKeyRestoreOperationState,\n KeyVaultSelectiveKeyRestorePollOperationState\n} from \"./operation\";\nimport { KeyVaultAdminPollerOptions, KeyVaultAdminPoller } from \"../keyVaultAdminPoller\";\nimport { KeyVaultSelectiveKeyRestoreResult } from \"../../backupClientModels\";\n\nexport interface KeyVaultSelectiveKeyRestorePollerOptions extends KeyVaultAdminPollerOptions {\n keyName: string;\n folderUri: string;\n sasToken: string;\n folderName: string;\n}\n\n/**\n * Class that creates a poller that waits until a key of a Key Vault backup ends up being restored.\n */\nexport class KeyVaultSelectiveKeyRestorePoller extends KeyVaultAdminPoller<\n KeyVaultSelectiveKeyRestoreOperationState,\n KeyVaultSelectiveKeyRestoreResult\n> {\n constructor(options: KeyVaultSelectiveKeyRestorePollerOptions) {\n const {\n client,\n vaultUrl,\n keyName,\n folderUri,\n sasToken,\n folderName,\n requestOptions,\n intervalInMs = 2000,\n resumeFrom\n } = options;\n\n let state: KeyVaultSelectiveKeyRestorePollOperationState | undefined;\n\n if (resumeFrom) {\n state = JSON.parse(resumeFrom).state;\n }\n\n const operation = new KeyVaultSelectiveKeyRestorePollOperation(\n {\n ...state,\n keyName,\n folderUri: folderUri,\n sasToken,\n folderName\n },\n vaultUrl,\n client,\n requestOptions\n );\n\n super(operation);\n\n this.intervalInMs = intervalInMs;\n }\n}\n"]}
1
+ {"version":3,"file":"poller.js","sourceRoot":"","sources":["../../../../../src/lro/selectiveKeyRestore/poller.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,mBAAmB,EAA8B,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAEL,wCAAwC,GAEzC,MAAM,aAAa,CAAC;AAUrB;;GAEG;AACH,MAAM,OAAO,iCAAkC,SAAQ,mBAGtD;IACC,YAAY,OAAiD;QAC3D,MAAM,EACJ,MAAM,EACN,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,EACR,UAAU,EACV,cAAc,EACd,YAAY,GAAG,IAAI,EACnB,UAAU,GACX,GAAG,OAAO,CAAC;QAEZ,IAAI,KAAgE,CAAC;QAErE,IAAI,UAAU,EAAE;YACd,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC;SACtC;QAED,MAAM,SAAS,GAAG,IAAI,wCAAwC,iCAEvD,KAAK,KACR,OAAO,EACP,SAAS,EAAE,SAAS,EACpB,QAAQ;YACR,UAAU,KAEZ,QAAQ,EACR,MAAM,EACN,cAAc,CACf,CAAC;QAEF,KAAK,CAAC,SAAS,CAAC,CAAC;QAEjB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { KeyVaultAdminPoller, KeyVaultAdminPollerOptions } from \"../keyVaultAdminPoller\";\nimport {\n KeyVaultSelectiveKeyRestoreOperationState,\n KeyVaultSelectiveKeyRestorePollOperation,\n KeyVaultSelectiveKeyRestorePollOperationState,\n} from \"./operation\";\nimport { KeyVaultSelectiveKeyRestoreResult } from \"../../backupClientModels\";\n\nexport interface KeyVaultSelectiveKeyRestorePollerOptions extends KeyVaultAdminPollerOptions {\n keyName: string;\n folderUri: string;\n sasToken: string;\n folderName: string;\n}\n\n/**\n * Class that creates a poller that waits until a key of a Key Vault backup ends up being restored.\n */\nexport class KeyVaultSelectiveKeyRestorePoller extends KeyVaultAdminPoller<\n KeyVaultSelectiveKeyRestoreOperationState,\n KeyVaultSelectiveKeyRestoreResult\n> {\n constructor(options: KeyVaultSelectiveKeyRestorePollerOptions) {\n const {\n client,\n vaultUrl,\n keyName,\n folderUri,\n sasToken,\n folderName,\n requestOptions,\n intervalInMs = 2000,\n resumeFrom,\n } = options;\n\n let state: KeyVaultSelectiveKeyRestorePollOperationState | undefined;\n\n if (resumeFrom) {\n state = JSON.parse(resumeFrom).state;\n }\n\n const operation = new KeyVaultSelectiveKeyRestorePollOperation(\n {\n ...state,\n keyName,\n folderUri: folderUri,\n sasToken,\n folderName,\n },\n vaultUrl,\n client,\n requestOptions\n );\n\n super(operation);\n\n this.intervalInMs = intervalInMs;\n }\n}\n"]}
@@ -12,10 +12,10 @@ export const mappings = {
12
12
  properties: {
13
13
  scope: scope,
14
14
  roleDefinitionId: roleDefinitionId,
15
- principalId: principalId
16
- }
15
+ principalId: principalId,
16
+ },
17
17
  };
18
- }
18
+ },
19
19
  },
20
20
  roleDefinition: {
21
21
  generatedToPublic(roleDefinition) {
@@ -28,9 +28,9 @@ export const mappings = {
28
28
  description: description,
29
29
  roleType: roleType,
30
30
  permissions: permissions,
31
- assignableScopes: assignableScopes
31
+ assignableScopes: assignableScopes,
32
32
  };
33
- }
33
+ },
34
34
  },
35
35
  folderUriParts(folderUri) {
36
36
  const uriParts = folderUri.split("/");
@@ -41,8 +41,8 @@ export const mappings = {
41
41
  }
42
42
  return {
43
43
  folderName,
44
- folderUri: storageUri
44
+ folderUri: storageUri,
45
45
  };
46
- }
46
+ },
47
47
  };
48
48
  //# sourceMappingURL=mappings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mappings.js","sourceRoot":"","sources":["../../../src/mappings.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,cAAc,EAAE;QACd,iBAAiB,CAAC,cAA8B;YAC9C,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,cAAc,CAAC;YACtD,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,GAAG,UAAU,IAAI,EAAE,CAAC;YAClE,OAAO;gBACL,EAAE,EAAE,EAAG;gBACP,IAAI,EAAE,IAAK;gBACX,IAAI,EAAE,IAAK;gBACX,UAAU,EAAE;oBACV,KAAK,EAAE,KAA0B;oBACjC,gBAAgB,EAAE,gBAAiB;oBACnC,WAAW,EAAE,WAAY;iBAC1B;aACF,CAAC;QACJ,CAAC;KACF;IACD,cAAc,EAAE;QACd,iBAAiB,CAAC,cAA8B;YAC9C,MAAM,EACJ,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,WAAW,EACX,gBAAgB,EACjB,GAAG,cAAc,CAAC;YACnB,OAAO;gBACL,EAAE,EAAE,EAAG;gBACP,IAAI,EAAE,IAAK;gBACX,IAAI,EAAE,IAAK;gBACX,QAAQ,EAAE,QAAS;gBACnB,WAAW,EAAE,WAAY;gBACzB,QAAQ,EAAE,QAAS;gBACnB,WAAW,EAAE,WAAY;gBACzB,gBAAgB,EAAE,gBAAiB;aACpC,CAAC;QACJ,CAAC;KACF;IACD,cAAc,CAAC,SAAiB;QAC9B,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEtC,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;SACxE;QAED,OAAO;YACL,UAAU;YACV,SAAS,EAAE,UAAU;SACtB,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RoleAssignment, RoleDefinition } from \"./generated/models\";\nimport {\n KeyVaultRoleAssignment,\n KeyVaultRoleDefinition,\n KeyVaultRoleScope\n} from \"./accessControlModels\";\n\nexport const mappings = {\n roleAssignment: {\n generatedToPublic(roleAssignment: RoleAssignment): KeyVaultRoleAssignment {\n const { id, name, type, properties } = roleAssignment;\n const { scope, roleDefinitionId, principalId } = properties || {};\n return {\n id: id!,\n name: name!,\n kind: type!,\n properties: {\n scope: scope as KeyVaultRoleScope,\n roleDefinitionId: roleDefinitionId!,\n principalId: principalId!\n }\n };\n }\n },\n roleDefinition: {\n generatedToPublic(roleDefinition: RoleDefinition): KeyVaultRoleDefinition {\n const {\n id,\n name,\n type,\n roleName,\n description,\n roleType,\n permissions,\n assignableScopes\n } = roleDefinition;\n return {\n id: id!,\n name: name!,\n kind: type!,\n roleName: roleName!,\n description: description!,\n roleType: roleType!,\n permissions: permissions!,\n assignableScopes: assignableScopes!\n };\n }\n },\n folderUriParts(folderUri: string): { folderName: string; folderUri: string } {\n const uriParts = folderUri.split(\"/\");\n const folderName = uriParts.pop();\n const storageUri = uriParts.join(\"/\");\n\n if (!folderName) {\n throw new Error(\"The provided folder URI is missing the folder name.\");\n }\n\n return {\n folderName,\n folderUri: storageUri\n };\n }\n};\n"]}
1
+ {"version":3,"file":"mappings.js","sourceRoot":"","sources":["../../../src/mappings.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,cAAc,EAAE;QACd,iBAAiB,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Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n KeyVaultRoleAssignment,\n KeyVaultRoleDefinition,\n KeyVaultRoleScope,\n} from \"./accessControlModels\";\nimport { RoleAssignment, RoleDefinition } from \"./generated/models\";\n\nexport const mappings = {\n roleAssignment: {\n generatedToPublic(roleAssignment: RoleAssignment): KeyVaultRoleAssignment {\n const { id, name, type, properties } = roleAssignment;\n const { scope, roleDefinitionId, principalId } = properties || {};\n return {\n id: id!,\n name: name!,\n kind: type!,\n properties: {\n scope: scope as KeyVaultRoleScope,\n roleDefinitionId: roleDefinitionId!,\n principalId: principalId!,\n },\n };\n },\n },\n roleDefinition: {\n generatedToPublic(roleDefinition: RoleDefinition): KeyVaultRoleDefinition {\n const { id, name, type, roleName, description, roleType, permissions, assignableScopes } =\n roleDefinition;\n return {\n id: id!,\n name: name!,\n kind: type!,\n roleName: roleName!,\n description: description!,\n roleType: roleType!,\n permissions: permissions!,\n assignableScopes: assignableScopes!,\n };\n },\n },\n folderUriParts(folderUri: string): { folderName: string; folderUri: string } {\n const uriParts = folderUri.split(\"/\");\n const folderName = uriParts.pop();\n const storageUri = uriParts.join(\"/\");\n\n if (!folderName) {\n throw new Error(\"The provided folder URI is missing the folder name.\");\n }\n\n return {\n folderName,\n folderUri: storageUri,\n };\n },\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
- import { createSpanFunction, SpanStatusCode } from "@azure/core-tracing";
3
+ import { SpanStatusCode, createSpanFunction } from "@azure/core-tracing";
4
4
  /**
5
5
  * Returns a function that can be used for tracing options.
6
6
  *
@@ -13,7 +13,7 @@ import { createSpanFunction, SpanStatusCode } from "@azure/core-tracing";
13
13
  export function createTraceFunction(prefix) {
14
14
  const createSpan = createSpanFunction({
15
15
  namespace: "Microsoft.KeyVault",
16
- packagePrefix: prefix
16
+ packagePrefix: prefix,
17
17
  });
18
18
  return async function (operationName, options, cb) {
19
19
  const { updatedOptions, span } = createSpan(operationName, options);
@@ -23,14 +23,14 @@ export function createTraceFunction(prefix) {
23
23
  const result = await cb(updatedOptions, span);
24
24
  // otel 0.16+ needs this or else the code ends up being set as UNSET
25
25
  span.setStatus({
26
- code: SpanStatusCode.OK
26
+ code: SpanStatusCode.OK,
27
27
  });
28
28
  return result;
29
29
  }
30
30
  catch (err) {
31
31
  span.setStatus({
32
32
  code: SpanStatusCode.ERROR,
33
- message: err.message
33
+ message: err.message,
34
34
  });
35
35
  throw err;
36
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tracingHelpers.js","sourceRoot":"","sources":["../../../src/tracingHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,kBAAkB,EAAQ,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAqB/E;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,MAAM,UAAU,GAAG,kBAAkB,CAAC;QACpC,SAAS,EAAE,oBAAoB;QAC/B,aAAa,EAAE,MAAM;KACtB,CAAC,CAAC;IAEH,OAAO,KAAK,WAAU,aAAa,EAAE,OAAO,EAAE,EAAE;QAC9C,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAEpE,IAAI;YACF,6GAA6G;YAC7G,kBAAkB;YAClB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;YAE9C,oEAAoE;YACpE,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,cAAc,CAAC,EAAE;aACxB,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,cAAc,CAAC,KAAK;gBAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;aACrB,CAAC,CAAC;YACH,MAAM,GAAG,CAAC;SACX;gBAAS;YACR,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { OperationOptions } from \"@azure/core-client\";\nimport { createSpanFunction, Span, SpanStatusCode } from \"@azure/core-tracing\";\n\n/**\n * An interface representing a function that is traced.\n *\n * A traced function will automatically create and close tracing '\n * spans as needed and will handle setting the status / errors as a\n * result of calling the underlying callback.\n *\n * use {@link createTraceFunction} to add tracing to a block of code.\n *\n * @internal\n */\nexport interface TracedFunction {\n <TOptions extends OperationOptions, TReturn>(\n operationName: string,\n options: TOptions,\n cb: (options: TOptions, span: Span) => Promise<TReturn>\n ): Promise<TReturn>;\n}\n\n/**\n * Returns a function that can be used for tracing options.\n *\n * @param prefix - The prefix to use, likely the name of the class / client.\n *\n * @example const withTrace = createTraceFunction(\"Azure.KeyVault.Certificates.CertificateClient\")\n *\n * @internal\n */\nexport function createTraceFunction(prefix: string): TracedFunction {\n const createSpan = createSpanFunction({\n namespace: \"Microsoft.KeyVault\",\n packagePrefix: prefix\n });\n\n return async function(operationName, options, cb) {\n const { updatedOptions, span } = createSpan(operationName, options);\n\n try {\n // NOTE: we really do need to await on this function here so we can handle any exceptions thrown and properly\n // close the span.\n const result = await cb(updatedOptions, span);\n\n // otel 0.16+ needs this or else the code ends up being set as UNSET\n span.setStatus({\n code: SpanStatusCode.OK\n });\n return result;\n } catch (err) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message\n });\n throw err;\n } finally {\n span.end();\n }\n };\n}\n"]}
1
+ {"version":3,"file":"tracingHelpers.js","sourceRoot":"","sources":["../../../src/tracingHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAQ,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAsB/E;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,MAAM,UAAU,GAAG,kBAAkB,CAAC;QACpC,SAAS,EAAE,oBAAoB;QAC/B,aAAa,EAAE,MAAM;KACtB,CAAC,CAAC;IAEH,OAAO,KAAK,WAAW,aAAa,EAAE,OAAO,EAAE,EAAE;QAC/C,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAEpE,IAAI;YACF,6GAA6G;YAC7G,kBAAkB;YAClB,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;YAE9C,oEAAoE;YACpE,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,cAAc,CAAC,EAAE;aACxB,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,CAAC,SAAS,CAAC;gBACb,IAAI,EAAE,cAAc,CAAC,KAAK;gBAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;aACrB,CAAC,CAAC;YACH,MAAM,GAAG,CAAC;SACX;gBAAS;YACR,IAAI,CAAC,GAAG,EAAE,CAAC;SACZ;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Span, SpanStatusCode, createSpanFunction } from \"@azure/core-tracing\";\nimport { OperationOptions } from \"@azure/core-client\";\n\n/**\n * An interface representing a function that is traced.\n *\n * A traced function will automatically create and close tracing '\n * spans as needed and will handle setting the status / errors as a\n * result of calling the underlying callback.\n *\n * use {@link createTraceFunction} to add tracing to a block of code.\n *\n * @internal\n */\nexport interface TracedFunction {\n <TOptions extends OperationOptions, TReturn>(\n operationName: string,\n options: TOptions,\n cb: (options: TOptions, span: Span) => Promise<TReturn>\n ): Promise<TReturn>;\n}\n\n/**\n * Returns a function that can be used for tracing options.\n *\n * @param prefix - The prefix to use, likely the name of the class / client.\n *\n * @example const withTrace = createTraceFunction(\"Azure.KeyVault.Certificates.CertificateClient\")\n *\n * @internal\n */\nexport function createTraceFunction(prefix: string): TracedFunction {\n const createSpan = createSpanFunction({\n namespace: \"Microsoft.KeyVault\",\n packagePrefix: prefix,\n });\n\n return async function (operationName, options, cb) {\n const { updatedOptions, span } = createSpan(operationName, options);\n\n try {\n // NOTE: we really do need to await on this function here so we can handle any exceptions thrown and properly\n // close the span.\n const result = await cb(updatedOptions, span);\n\n // otel 0.16+ needs this or else the code ends up being set as UNSET\n span.setStatus({\n code: SpanStatusCode.OK,\n });\n return result;\n } catch (err) {\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n });\n throw err;\n } finally {\n span.end();\n }\n };\n}\n"]}
@@ -1,16 +1,18 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
3
  /* eslint-disable @azure/azure-sdk/ts-use-interface-parameters */
4
- import { BaseRequestPolicy } from "@azure/core-http";
5
- import { Constants } from "@azure/core-http";
6
4
  import { ExpiringAccessTokenCache } from "@azure/core-http";
5
+ import { BaseRequestPolicy, } from "@azure/core-http";
6
+ import { parseWWWAuthenticate } from "./parseWWWAuthenticate";
7
+ import { Constants } from "@azure/core-http";
7
8
  /**
8
9
  * Representation of the Authentication Challenge
9
10
  */
10
11
  export class AuthenticationChallenge {
11
- constructor(authorization, scope) {
12
+ constructor(authorization, scope, tenantId) {
12
13
  this.authorization = authorization;
13
14
  this.scope = scope;
15
+ this.tenantId = tenantId;
14
16
  }
15
17
  /**
16
18
  * Checks that this AuthenticationChallenge is equal to another one given.
@@ -20,9 +22,11 @@ export class AuthenticationChallenge {
20
22
  * @param other - The other AuthenticationChallenge
21
23
  */
22
24
  equalTo(other) {
25
+ var _a, _b;
23
26
  return other
24
27
  ? this.scope.toLowerCase() === other.scope.toLowerCase() &&
25
- this.authorization.toLowerCase() === other.authorization.toLowerCase()
28
+ this.authorization.toLowerCase() === other.authorization.toLowerCase() &&
29
+ ((_a = this.tenantId) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = other.tenantId) === null || _b === void 0 ? void 0 : _b.toLowerCase())
26
30
  : false;
27
31
  }
28
32
  }
@@ -46,27 +50,9 @@ export function challengeBasedAuthenticationPolicy(credential) {
46
50
  return {
47
51
  create: (nextPolicy, options) => {
48
52
  return new ChallengeBasedAuthenticationPolicy(nextPolicy, options, credential, tokenCache, challengeCache);
49
- }
53
+ },
50
54
  };
51
55
  }
52
- /**
53
- * Parses an WWW-Authenticate response.
54
- * This transforms a string value like:
55
- * `Bearer authorization="some_authorization", resource="https://some.url"`
56
- * into an object like:
57
- * `{ authorization: "some_authorization", resource: "https://some.url" }`
58
- * @param wwwAuthenticate - String value in the WWW-Authenticate header
59
- */
60
- export function parseWWWAuthenticate(wwwAuthenticate) {
61
- // First we split the string by either `, ` or ` `.
62
- const parts = wwwAuthenticate.split(/,* +/);
63
- // Then we only keep the strings with an equal sign after a word and before a quote.
64
- // also splitting these sections by their equal sign
65
- const keyValues = parts.reduce((acc, str) => (str.match(/\w="/) ? [...acc, str.split("=")] : acc), []);
66
- // Then we transform these key-value pairs back into an object.
67
- const parsed = keyValues.reduce((result, [key, value]) => (Object.assign(Object.assign({}, result), { [key]: value.slice(1, -1) })), {});
68
- return parsed;
69
- }
70
56
  /**
71
57
  *
72
58
  * Provides a RequestPolicy that can request a token from a TokenCredential
@@ -97,7 +83,9 @@ export class ChallengeBasedAuthenticationPolicy extends BaseRequestPolicy {
97
83
  let accessToken = this.tokenCache.getCachedToken();
98
84
  // If there's no cached token in the cache, we try to get a new one.
99
85
  if (accessToken === undefined) {
100
- const receivedToken = await this.credential.getToken(this.challengeCache.challenge.scope);
86
+ const receivedToken = await this.credential.getToken(this.challengeCache.challenge.scope, {
87
+ tenantId: this.challengeCache.challenge.tenantId,
88
+ });
101
89
  accessToken = receivedToken || undefined;
102
90
  this.tokenCache.setCachedToken(accessToken);
103
91
  }
@@ -120,10 +108,11 @@ export class ChallengeBasedAuthenticationPolicy extends BaseRequestPolicy {
120
108
  const parsedWWWAuth = this.parseWWWAuthenticate(wwwAuthenticate);
121
109
  const authorization = parsedWWWAuth.authorization;
122
110
  const resource = parsedWWWAuth.resource || parsedWWWAuth.scope;
111
+ const tenantId = parsedWWWAuth.tenantId;
123
112
  if (!(authorization && resource)) {
124
113
  return this._nextPolicy.sendRequest(webResource);
125
114
  }
126
- const challenge = new AuthenticationChallenge(authorization, resource + "/.default");
115
+ const challenge = new AuthenticationChallenge(authorization, resource + "/.default", tenantId);
127
116
  // Either if there's no cached challenge at this point (could have happen in parallel),
128
117
  // or if the cached challenge has a different scope,
129
118
  // we store the just received challenge and reset the cached token, to force a re-authentication.
@@ -1 +1 @@
1
- {"version":3,"file":"challengeBasedAuthenticationPolicy.js","sourceRoot":"","sources":["../../../../keyvault-common/src/challengeBasedAuthenticationPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAClC,iEAAiE;AAGjE,OAAO,EACL,iBAAiB,EAIlB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAoB,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAe9E;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAClC,YAAmB,aAAqB,EAAS,KAAa;QAA3C,kBAAa,GAAb,aAAa,CAAQ;QAAS,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAElE;;;;;;OAMG;IACI,OAAO,CAAC,KAA0C;QACvD,OAAO,KAAK;YACV,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE;gBACpD,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,aAAa,CAAC,WAAW,EAAE;YAC1E,CAAC,CAAC,KAAK,CAAC;IACZ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IAGhC,kBAAkB,CAAC,SAAk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GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;SAC5D;QAED,yDAAyD;QACzD,gGAAgG;QAChG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YAC3B,OAAO,QAAQ,CAAC;SACjB;QAED,oGAAoG;QACpG,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QACjE,IAAI,CAAC,eAAe,EAAE;YACpB,OAAO,QAAQ,CAAC;SACjB;QAED,sEAAsE;QACtE,OAAO,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable @azure/azure-sdk/ts-use-interface-parameters */\n\nimport { TokenCredential } from \"@azure/core-http\";\nimport {\n BaseRequestPolicy,\n RequestPolicy,\n RequestPolicyOptions,\n RequestPolicyFactory\n} from \"@azure/core-http\";\nimport { Constants } from \"@azure/core-http\";\nimport { HttpOperationResponse } from \"@azure/core-http\";\nimport { WebResource } from \"@azure/core-http\";\nimport { AccessTokenCache, ExpiringAccessTokenCache } from \"@azure/core-http\";\n\ntype ValidParsedWWWAuthenticateProperties =\n // \"authorization_uri\" was used in the track 1 version of KeyVault.\n // This is not a relevant property anymore, since the service is consistently answering with \"authorization\".\n // | \"authorization_uri\"\n | \"authorization\"\n // Even though the service is moving to \"scope\", both \"resource\" and \"scope\" should be supported.\n | \"resource\"\n | \"scope\";\n\ntype ParsedWWWAuthenticate = {\n [Key in ValidParsedWWWAuthenticateProperties]?: string;\n};\n\n/**\n * Representation of the Authentication Challenge\n */\nexport class AuthenticationChallenge {\n constructor(public authorization: string, public scope: string) {}\n\n /**\n * Checks that this AuthenticationChallenge is equal to another one given.\n * Only compares the scope.\n * This is exactly what C# is doing, as we can see here:\n * https://github.com/Azure/azure-sdk-for-net/blob/70e54b878ff1d01a45266fb3674a396b4ab9c1d2/sdk/keyvault/Azure.Security.KeyVault.Shared/src/ChallengeBasedAuthenticationPolicy.cs#L143-L147\n * @param other - The other AuthenticationChallenge\n */\n public equalTo(other: AuthenticationChallenge | undefined): boolean {\n return other\n ? this.scope.toLowerCase() === other.scope.toLowerCase() &&\n this.authorization.toLowerCase() === other.authorization.toLowerCase()\n : false;\n }\n}\n\n/**\n * Helps keep a copy of any previous authentication challenges,\n * so that we can compare on any further request.\n */\nexport class AuthenticationChallengeCache {\n public challenge?: AuthenticationChallenge;\n\n public setCachedChallenge(challenge: AuthenticationChallenge): void {\n this.challenge = challenge;\n }\n}\n\n/**\n * Creates a new ChallengeBasedAuthenticationPolicy factory.\n *\n * @param credential - The TokenCredential implementation that can supply the challenge token.\n */\nexport function challengeBasedAuthenticationPolicy(\n credential: TokenCredential\n): RequestPolicyFactory {\n const tokenCache: AccessTokenCache = new ExpiringAccessTokenCache();\n const challengeCache = new AuthenticationChallengeCache();\n return {\n create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {\n return new ChallengeBasedAuthenticationPolicy(\n nextPolicy,\n options,\n credential,\n tokenCache,\n challengeCache\n );\n }\n };\n}\n\n/**\n * Parses an WWW-Authenticate response.\n * This transforms a string value like:\n * `Bearer authorization=\"some_authorization\", resource=\"https://some.url\"`\n * into an object like:\n * `{ authorization: \"some_authorization\", resource: \"https://some.url\" }`\n * @param wwwAuthenticate - String value in the WWW-Authenticate header\n */\nexport function parseWWWAuthenticate(wwwAuthenticate: string): ParsedWWWAuthenticate {\n // First we split the string by either `, ` or ` `.\n const parts = wwwAuthenticate.split(/,* +/);\n // Then we only keep the strings with an equal sign after a word and before a quote.\n // also splitting these sections by their equal sign\n const keyValues = parts.reduce<string[][]>(\n (acc, str) => (str.match(/\\w=\"/) ? [...acc, str.split(\"=\")] : acc),\n []\n );\n // Then we transform these key-value pairs back into an object.\n const parsed = keyValues.reduce<ParsedWWWAuthenticate>(\n (result, [key, value]: string[]) => ({\n ...result,\n [key]: value.slice(1, -1)\n }),\n {}\n );\n return parsed;\n}\n\n/**\n *\n * Provides a RequestPolicy that can request a token from a TokenCredential\n * implementation and then apply it to the Authorization header of a request\n * as a Bearer token.\n *\n */\nexport class ChallengeBasedAuthenticationPolicy extends BaseRequestPolicy {\n private parseWWWAuthenticate: (\n wwwAuthenticate: string\n ) => ParsedWWWAuthenticate = parseWWWAuthenticate;\n\n /**\n * Creates a new ChallengeBasedAuthenticationPolicy object.\n *\n * @param nextPolicy - The next RequestPolicy in the request pipeline.\n * @param options - Options for this RequestPolicy.\n * @param credential - The TokenCredential implementation that can supply the bearer token.\n * @param tokenCache - The cache for the most recent AccessToken returned by the TokenCredential.\n */\n constructor(\n nextPolicy: RequestPolicy,\n options: RequestPolicyOptions,\n private credential: TokenCredential,\n private tokenCache: AccessTokenCache,\n private challengeCache: AuthenticationChallengeCache\n ) {\n super(nextPolicy, options);\n }\n\n /**\n * Gets or updates the token from the token cache into the headers of the received web resource.\n */\n private async loadToken(webResource: WebResource): Promise<void> {\n let accessToken = this.tokenCache.getCachedToken();\n\n // If there's no cached token in the cache, we try to get a new one.\n if (accessToken === undefined) {\n const receivedToken = await this.credential.getToken(this.challengeCache.challenge!.scope);\n accessToken = receivedToken || undefined;\n this.tokenCache.setCachedToken(accessToken);\n }\n\n if (accessToken) {\n webResource.headers.set(\n Constants.HeaderConstants.AUTHORIZATION,\n `Bearer ${accessToken.token}`\n );\n }\n }\n\n /**\n * Parses the given WWW-Authenticate header, generates a new AuthenticationChallenge,\n * then if the challenge is different from the one cached, resets the token and forces\n * a re-authentication, otherwise continues with the existing challenge and token.\n * @param wwwAuthenticate - Value of the incoming WWW-Authenticate header.\n * @param webResource - Ongoing HTTP request.\n */\n private async regenerateChallenge(\n wwwAuthenticate: string,\n webResource: WebResource\n ): Promise<HttpOperationResponse> {\n // The challenge based authentication will contain both:\n // - An authorization URI with a token,\n // - The resource to which that token is valid against (also called the scope).\n const parsedWWWAuth = this.parseWWWAuthenticate(wwwAuthenticate);\n const authorization = parsedWWWAuth.authorization!;\n const resource = parsedWWWAuth.resource! || parsedWWWAuth.scope!;\n\n if (!(authorization && resource)) {\n return this._nextPolicy.sendRequest(webResource);\n }\n\n const challenge = new AuthenticationChallenge(authorization, resource + \"/.default\");\n\n // Either if there's no cached challenge at this point (could have happen in parallel),\n // or if the cached challenge has a different scope,\n // we store the just received challenge and reset the cached token, to force a re-authentication.\n if (!this.challengeCache.challenge?.equalTo(challenge)) {\n this.challengeCache.setCachedChallenge(challenge);\n this.tokenCache.setCachedToken(undefined);\n }\n\n await this.loadToken(webResource);\n return this._nextPolicy.sendRequest(webResource);\n }\n\n /**\n * Applies the Bearer token to the request through the Authorization header.\n * @param webResource - Ongoing HTTP request.\n */\n public async sendRequest(webResource: WebResource): Promise<HttpOperationResponse> {\n // Ensure that we're about to use a secure connection.\n if (!webResource.url.startsWith(\"https:\")) {\n throw new Error(\"The resource address for authorization must use the 'https' protocol.\");\n }\n\n // The next request will happen differently whether we have a challenge or not.\n let response: HttpOperationResponse;\n\n if (\n this.challengeCache.challenge === undefined ||\n this.challengeCache.challenge === undefined\n ) {\n // If there's no challenge in cache, a blank body will start the challenge.\n const originalBody = webResource.body;\n webResource.body = \"\";\n try {\n response = await this._nextPolicy.sendRequest(webResource);\n } finally {\n webResource.body = originalBody;\n }\n } else {\n // If we did have a challenge in memory,\n // we attempt to load the token from the cache into the request before we try to send the request.\n await this.loadToken(webResource);\n response = await this._nextPolicy.sendRequest(webResource);\n }\n\n // If we don't receive a response with a 401 status code,\n // then we can assume this response has nothing to do with the challenge authentication process.\n if (response.status !== 401) {\n return response;\n }\n\n // If the response status is 401, we only re-authenticate if the WWW-Authenticate header is present.\n const wwwAuthenticate = response.headers.get(\"WWW-Authenticate\");\n if (!wwwAuthenticate) {\n return response;\n }\n\n // We re-generate the challenge and see if we have to re-authenticate.\n return this.regenerateChallenge(wwwAuthenticate, webResource);\n }\n}\n"]}
1
+ {"version":3,"file":"challengeBasedAuthen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AI,CAAC,cAAc,CAAC,SAAS,KAAK,SAAS,EAC3C;YACA,2EAA2E;YAC3E,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC;YACtC,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;YACtB,IAAI;gBACF,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;aAC5D;oBAAS;gBACR,WAAW,CAAC,IAAI,GAAG,YAAY,CAAC;aACjC;SACF;aAAM;YACL,wCAAwC;YACxC,kGAAkG;YAClG,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;YAClC,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;SAC5D;QAED,yDAAyD;QACzD,gGAAgG;QAChG,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YAC3B,OAAO,QAAQ,CAAC;SACjB;QAED,oGAAoG;QACpG,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QACjE,IAAI,CAAC,eAAe,EAAE;YACpB,OAAO,QAAQ,CAAC;SACjB;QAED,sEAAsE;QACtE,OAAO,IAAI,CAAC,mBAAmB,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n/* eslint-disable @azure/azure-sdk/ts-use-interface-parameters */\n\nimport { AccessTokenCache, ExpiringAccessTokenCache } from \"@azure/core-http\";\nimport {\n BaseRequestPolicy,\n RequestPolicy,\n RequestPolicyFactory,\n RequestPolicyOptions,\n} from \"@azure/core-http\";\nimport { ParsedWWWAuthenticate, parseWWWAuthenticate } from \"./parseWWWAuthenticate\";\nimport { Constants } from \"@azure/core-http\";\nimport { HttpOperationResponse } from \"@azure/core-http\";\nimport { TokenCredential } from \"@azure/core-http\";\nimport { WebResource } from \"@azure/core-http\";\n\n/**\n * Representation of the Authentication Challenge\n */\nexport class AuthenticationChallenge {\n constructor(public authorization: string, public scope: string, public tenantId?: string) {}\n\n /**\n * Checks that this AuthenticationChallenge is equal to another one given.\n * Only compares the scope.\n * This is exactly what C# is doing, as we can see here:\n * https://github.com/Azure/azure-sdk-for-net/blob/70e54b878ff1d01a45266fb3674a396b4ab9c1d2/sdk/keyvault/Azure.Security.KeyVault.Shared/src/ChallengeBasedAuthenticationPolicy.cs#L143-L147\n * @param other - The other AuthenticationChallenge\n */\n public equalTo(other: AuthenticationChallenge | undefined): boolean {\n return other\n ? this.scope.toLowerCase() === other.scope.toLowerCase() &&\n this.authorization.toLowerCase() === other.authorization.toLowerCase() &&\n this.tenantId?.toLowerCase() === other.tenantId?.toLowerCase()\n : false;\n }\n}\n\n/**\n * Helps keep a copy of any previous authentication challenges,\n * so that we can compare on any further request.\n */\nexport class AuthenticationChallengeCache {\n public challenge?: AuthenticationChallenge;\n\n public setCachedChallenge(challenge: AuthenticationChallenge): void {\n this.challenge = challenge;\n }\n}\n\n/**\n * Creates a new ChallengeBasedAuthenticationPolicy factory.\n *\n * @param credential - The TokenCredential implementation that can supply the challenge token.\n */\nexport function challengeBasedAuthenticationPolicy(\n credential: TokenCredential\n): RequestPolicyFactory {\n const tokenCache: AccessTokenCache = new ExpiringAccessTokenCache();\n const challengeCache = new AuthenticationChallengeCache();\n return {\n create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {\n return new ChallengeBasedAuthenticationPolicy(\n nextPolicy,\n options,\n credential,\n tokenCache,\n challengeCache\n );\n },\n };\n}\n\n/**\n *\n * Provides a RequestPolicy that can request a token from a TokenCredential\n * implementation and then apply it to the Authorization header of a request\n * as a Bearer token.\n *\n */\nexport class ChallengeBasedAuthenticationPolicy extends BaseRequestPolicy {\n private parseWWWAuthenticate: (wwwAuthenticate: string) => ParsedWWWAuthenticate =\n parseWWWAuthenticate;\n\n /**\n * Creates a new ChallengeBasedAuthenticationPolicy object.\n *\n * @param nextPolicy - The next RequestPolicy in the request pipeline.\n * @param options - Options for this RequestPolicy.\n * @param credential - The TokenCredential implementation that can supply the bearer token.\n * @param tokenCache - The cache for the most recent AccessToken returned by the TokenCredential.\n */\n constructor(\n nextPolicy: RequestPolicy,\n options: RequestPolicyOptions,\n private credential: TokenCredential,\n private tokenCache: AccessTokenCache,\n private challengeCache: AuthenticationChallengeCache\n ) {\n super(nextPolicy, options);\n }\n\n /**\n * Gets or updates the token from the token cache into the headers of the received web resource.\n */\n private async loadToken(webResource: WebResource): Promise<void> {\n let accessToken = this.tokenCache.getCachedToken();\n\n // If there's no cached token in the cache, we try to get a new one.\n if (accessToken === undefined) {\n const receivedToken = await this.credential.getToken(this.challengeCache.challenge!.scope, {\n tenantId: this.challengeCache.challenge!.tenantId,\n });\n accessToken = receivedToken || undefined;\n this.tokenCache.setCachedToken(accessToken);\n }\n\n if (accessToken) {\n webResource.headers.set(\n Constants.HeaderConstants.AUTHORIZATION,\n `Bearer ${accessToken.token}`\n );\n }\n }\n\n /**\n * Parses the given WWW-Authenticate header, generates a new AuthenticationChallenge,\n * then if the challenge is different from the one cached, resets the token and forces\n * a re-authentication, otherwise continues with the existing challenge and token.\n * @param wwwAuthenticate - Value of the incoming WWW-Authenticate header.\n * @param webResource - Ongoing HTTP request.\n */\n private async regenerateChallenge(\n wwwAuthenticate: string,\n webResource: WebResource\n ): Promise<HttpOperationResponse> {\n // The challenge based authentication will contain both:\n // - An authorization URI with a token,\n // - The resource to which that token is valid against (also called the scope).\n const parsedWWWAuth = this.parseWWWAuthenticate(wwwAuthenticate);\n const authorization = parsedWWWAuth.authorization!;\n const resource = parsedWWWAuth.resource! || parsedWWWAuth.scope!;\n const tenantId = parsedWWWAuth.tenantId;\n\n if (!(authorization && resource)) {\n return this._nextPolicy.sendRequest(webResource);\n }\n\n const challenge = new AuthenticationChallenge(authorization, resource + \"/.default\", tenantId);\n\n // Either if there's no cached challenge at this point (could have happen in parallel),\n // or if the cached challenge has a different scope,\n // we store the just received challenge and reset the cached token, to force a re-authentication.\n if (!this.challengeCache.challenge?.equalTo(challenge)) {\n this.challengeCache.setCachedChallenge(challenge);\n this.tokenCache.setCachedToken(undefined);\n }\n\n await this.loadToken(webResource);\n return this._nextPolicy.sendRequest(webResource);\n }\n\n /**\n * Applies the Bearer token to the request through the Authorization header.\n * @param webResource - Ongoing HTTP request.\n */\n public async sendRequest(webResource: WebResource): Promise<HttpOperationResponse> {\n // Ensure that we're about to use a secure connection.\n if (!webResource.url.startsWith(\"https:\")) {\n throw new Error(\"The resource address for authorization must use the 'https' protocol.\");\n }\n\n // The next request will happen differently whether we have a challenge or not.\n let response: HttpOperationResponse;\n\n if (\n this.challengeCache.challenge === undefined ||\n this.challengeCache.challenge === undefined\n ) {\n // If there's no challenge in cache, a blank body will start the challenge.\n const originalBody = webResource.body;\n webResource.body = \"\";\n try {\n response = await this._nextPolicy.sendRequest(webResource);\n } finally {\n webResource.body = originalBody;\n }\n } else {\n // If we did have a challenge in memory,\n // we attempt to load the token from the cache into the request before we try to send the request.\n await this.loadToken(webResource);\n response = await this._nextPolicy.sendRequest(webResource);\n }\n\n // If we don't receive a response with a 401 status code,\n // then we can assume this response has nothing to do with the challenge authentication process.\n if (response.status !== 401) {\n return response;\n }\n\n // If the response status is 401, we only re-authenticate if the WWW-Authenticate header is present.\n const wwwAuthenticate = response.headers.get(\"WWW-Authenticate\");\n if (!wwwAuthenticate) {\n return response;\n }\n\n // We re-generate the challenge and see if we have to re-authenticate.\n return this.regenerateChallenge(wwwAuthenticate, webResource);\n }\n}\n"]}
@@ -3,4 +3,5 @@
3
3
  export * from "./challengeBasedAuthenticationPolicy";
4
4
  export * from "./parseKeyvaultIdentifier";
5
5
  export * from "./tracingHelpers";
6
+ export * from "./parseWWWAuthenticate";
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../keyvault-common/src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport * from \"./challengeBasedAuthenticationPolicy\";\nexport * from \"./parseKeyvaultIdentifier\";\nexport * from \"./tracingHelpers\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../keyvault-common/src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport * from \"./challengeBasedAuthenticationPolicy\";\nexport * from \"./parseKeyvaultIdentifier\";\nexport * from \"./tracingHelpers\";\nexport * from \"./parseWWWAuthenticate\";\n"]}
@@ -29,7 +29,7 @@ export function parseKeyvaultIdentifier(collection, identifier) {
29
29
  return {
30
30
  vaultUrl,
31
31
  name,
32
- version
32
+ version,
33
33
  };
34
34
  }
35
35
  //# sourceMappingURL=parseKeyvaultIdentifier.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseKeyvaultIdentifier.js","sourceRoot":"","sources":["../../../../keyvault-common/src/parseKeyvaultIdentifier.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAgB3B,MAAM,UAAU,uBAAuB,CACrC,UAAkB,EAClB,UAA8B;IAE9B,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE;QACvE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;KAChD;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,CA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url\";\n\nexport interface ParsedKeyVaultEntityIdentifier {\n /**\n * The vault URI.\n */\n vaultUrl: string;\n /**\n * The version of key/secret/certificate. May be undefined.\n */\n version?: string;\n /**\n * The name of key/secret/certificate.\n */\n name: string;\n}\nexport function parseKeyvaultIdentifier(\n collection: string,\n identifier: string | undefined\n): ParsedKeyVaultEntityIdentifier {\n if (typeof collection !== \"string\" || !(collection = collection.trim())) {\n throw new Error(\"Invalid collection argument\");\n }\n\n if (typeof identifier !== \"string\" || !(identifier = identifier.trim())) {\n throw new Error(\"Invalid identifier argument\");\n }\n\n let baseUri;\n try {\n baseUri = url.parse(identifier, true, true);\n } catch (e) {\n throw new Error(`Invalid ${collection} identifier: ${identifier}. Not a valid URI`);\n }\n\n // Path is of the form '/collection/name[/version]'\n const segments = (baseUri.pathname || \"\").split(\"/\");\n if (segments.length !== 3 && segments.length !== 4) {\n throw new Error(\n `Invalid ${collection} identifier: ${identifier}. Bad number of segments: ${segments.length}`\n );\n }\n\n if (collection !== segments[1]) {\n throw new Error(\n `Invalid ${collection} identifier: ${identifier}. segment [1] should be \"${collection}\", found \"${segments[1]}\"`\n );\n }\n\n const vaultUrl = `${baseUri.protocol}//${baseUri.host}`;\n const name = segments[2];\n const version = segments.length === 4 ? segments[3] : undefined;\n return {\n vaultUrl,\n name,\n version\n };\n}\n"]}
1
+ {"version":3,"file":"parseKeyvaultIdentifier.js","sourceRoot":"","sources":["../../../../keyvault-common/src/parseKeyvaultIdentifier.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAgB3B,MAAM,UAAU,uBAAuB,CACrC,UAAkB,EAClB,UAA8B;IAE9B,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE;QACvE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;KAChD;IAED,IAAI,OAAO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poration.\n// Licensed under the MIT license.\n\nimport * as url from \"url\";\n\nexport interface ParsedKeyVaultEntityIdentifier {\n /**\n * The vault URI.\n */\n vaultUrl: string;\n /**\n * The version of key/secret/certificate. May be undefined.\n */\n version?: string;\n /**\n * The name of key/secret/certificate.\n */\n name: string;\n}\nexport function parseKeyvaultIdentifier(\n collection: string,\n identifier: string | undefined\n): ParsedKeyVaultEntityIdentifier {\n if (typeof collection !== \"string\" || !(collection = collection.trim())) {\n throw new Error(\"Invalid collection argument\");\n }\n\n if (typeof identifier !== \"string\" || !(identifier = identifier.trim())) {\n throw new Error(\"Invalid identifier argument\");\n }\n\n let baseUri;\n try {\n baseUri = url.parse(identifier, true, true);\n } catch (e) {\n throw new Error(`Invalid ${collection} identifier: ${identifier}. Not a valid URI`);\n }\n\n // Path is of the form '/collection/name[/version]'\n const segments = (baseUri.pathname || \"\").split(\"/\");\n if (segments.length !== 3 && segments.length !== 4) {\n throw new Error(\n `Invalid ${collection} identifier: ${identifier}. Bad number of segments: ${segments.length}`\n );\n }\n\n if (collection !== segments[1]) {\n throw new Error(\n `Invalid ${collection} identifier: ${identifier}. segment [1] should be \"${collection}\", found \"${segments[1]}\"`\n );\n }\n\n const vaultUrl = `${baseUri.protocol}//${baseUri.host}`;\n const name = segments[2];\n const version = segments.length === 4 ? segments[3] : undefined;\n return {\n vaultUrl,\n name,\n version,\n };\n}\n"]}
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * @internal
5
+ *
6
+ * Valid key names in WWW-Authenticate header.
7
+ */
8
+ const validParsedWWWAuthenticateProperties = [
9
+ "authorization",
10
+ "authorization_url",
11
+ "resource",
12
+ "scope",
13
+ "tenantId",
14
+ ];
15
+ /**
16
+ * Parses an WWW-Authenticate response.
17
+ * This transforms a string value like:
18
+ * `Bearer authorization="https://some.url/tenantId", resource="https://some.url"`
19
+ * into an object like:
20
+ * `{ authorization: "https://some.url/tenantId", resource: "https://some.url" }`
21
+ * @param wwwAuthenticate - String value in the WWW-Authenticate header
22
+ */
23
+ export function parseWWWAuthenticate(wwwAuthenticate) {
24
+ const pairDelimiter = /,? +/;
25
+ const parsed = wwwAuthenticate
26
+ .split(pairDelimiter)
27
+ .reduce((kvPairs, p) => {
28
+ if (p.match(/\w="/)) {
29
+ // 'sampleKey="sample_value"' -> [sampleKey, "sample_value"] -> { sampleKey: sample_value }
30
+ const [key, value] = p.split("=");
31
+ if (validParsedWWWAuthenticateProperties.includes(key)) {
32
+ // The values will be wrapped in quotes, which need to be stripped out.
33
+ return Object.assign(Object.assign({}, kvPairs), { [key]: value.slice(1, -1) });
34
+ }
35
+ }
36
+ return kvPairs;
37
+ }, {});
38
+ // Finally, we pull the tenantId from the authorization header to support multi-tenant authentication.
39
+ if (parsed.authorization) {
40
+ try {
41
+ const tenantId = new URL(parsed.authorization).pathname.substring(1);
42
+ if (tenantId) {
43
+ parsed.tenantId = tenantId;
44
+ }
45
+ }
46
+ catch (_) {
47
+ throw new Error(`The challenge authorization URI '${parsed.authorization}' is invalid.`);
48
+ }
49
+ }
50
+ return parsed;
51
+ }
52
+ //# sourceMappingURL=parseWWWAuthenticate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseWWWAuthenticate.js","sourceRoot":"","sources":["../../../../keyvault-common/src/parseWWWAuthenticate.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;GAIG;AACH,MAAM,oCAAoC,GAAG;IAC3C,eAAe;IACf,mBAAmB;IACnB,UAAU;IACV,OAAO;IACP,UAAU;CACF,CAAC;AAmBX;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,eAAuB;IAC1D,MAAM,aAAa,GAAG,MAAM,CAAC;IAC7B,MAAM,MAAM,GAAG,eAAe;SAC3B,KAAK,CAAC,aAAa,CAAC;SACpB,MAAM,CAAwB,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;QAC5C,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YACnB,2FAA2F;YAC3F,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClC,IACE,oCAAoC,CAAC,QAAQ,CAAC,GAA2C,CAAC,EAC1F;gBACA,uEAAuE;gBACvE,uCAAY,OAAO,KAAE,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAG;aAClD;SACF;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAET,sGAAsG;IACtG,IAAI,MAAM,CAAC,aAAa,EAAE;QACxB,IAAI;YACF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACrE,IAAI,QAAQ,EAAE;gBACZ,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;aAC5B;SACF;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,oCAAoC,MAAM,CAAC,aAAa,eAAe,CAAC,CAAC;SAC1F;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * @internal\n *\n * Valid key names in WWW-Authenticate header.\n */\nconst validParsedWWWAuthenticateProperties = [\n \"authorization\",\n \"authorization_url\",\n \"resource\",\n \"scope\",\n \"tenantId\",\n] as const;\n\n/**\n * @internal\n *\n * A union type representing all valid key names in WWW-Authenticate header.\n */\ntype ValidParsedWWWAuthenticateProperties = typeof validParsedWWWAuthenticateProperties[number];\n\n/**\n * @internal\n *\n * Holds the known WWWAuthenticate keys and their values as a result of\n * parsing a WWW-Authenticate header.\n */\nexport type ParsedWWWAuthenticate = {\n [Key in ValidParsedWWWAuthenticateProperties]?: string;\n};\n\n/**\n * Parses an WWW-Authenticate response.\n * This transforms a string value like:\n * `Bearer authorization=\"https://some.url/tenantId\", resource=\"https://some.url\"`\n * into an object like:\n * `{ authorization: \"https://some.url/tenantId\", resource: \"https://some.url\" }`\n * @param wwwAuthenticate - String value in the WWW-Authenticate header\n */\nexport function parseWWWAuthenticate(wwwAuthenticate: string): ParsedWWWAuthenticate {\n const pairDelimiter = /,? +/;\n const parsed = wwwAuthenticate\n .split(pairDelimiter)\n .reduce<ParsedWWWAuthenticate>((kvPairs, p) => {\n if (p.match(/\\w=\"/)) {\n // 'sampleKey=\"sample_value\"' -> [sampleKey, \"sample_value\"] -> { sampleKey: sample_value }\n const [key, value] = p.split(\"=\");\n if (\n validParsedWWWAuthenticateProperties.includes(key as ValidParsedWWWAuthenticateProperties)\n ) {\n // The values will be wrapped in quotes, which need to be stripped out.\n return { ...kvPairs, [key]: value.slice(1, -1) };\n }\n }\n return kvPairs;\n }, {});\n\n // Finally, we pull the tenantId from the authorization header to support multi-tenant authentication.\n if (parsed.authorization) {\n try {\n const tenantId = new URL(parsed.authorization).pathname.substring(1);\n if (tenantId) {\n parsed.tenantId = tenantId;\n }\n } catch (_) {\n throw new Error(`The challenge authorization URI '${parsed.authorization}' is invalid.`);\n }\n }\n\n return parsed;\n}\n"]}