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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/index.js +54 -93
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/keyvault-admin/src/accessControlClient.js +15 -14
  4. package/dist-esm/keyvault-admin/src/accessControlClient.js.map +1 -1
  5. package/dist-esm/keyvault-admin/src/backupClient.js +4 -2
  6. package/dist-esm/keyvault-admin/src/backupClient.js.map +1 -1
  7. package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js +12 -5
  8. package/dist-esm/keyvault-admin/src/challengeAuthenticationCallbacks.js.map +1 -1
  9. package/dist-esm/keyvault-admin/src/constants.js +1 -5
  10. package/dist-esm/keyvault-admin/src/constants.js.map +1 -1
  11. package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js +1 -2
  12. package/dist-esm/keyvault-admin/src/generated/keyVaultClientContext.js.map +1 -1
  13. package/dist-esm/keyvault-admin/src/lro/backup/operation.js +3 -7
  14. package/dist-esm/keyvault-admin/src/lro/backup/operation.js.map +1 -1
  15. package/dist-esm/keyvault-admin/src/lro/restore/operation.js +3 -7
  16. package/dist-esm/keyvault-admin/src/lro/restore/operation.js.map +1 -1
  17. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/operation.js +3 -7
  18. package/dist-esm/keyvault-admin/src/lro/selectiveKeyRestore/operation.js.map +1 -1
  19. package/dist-esm/keyvault-admin/src/tracing.js +10 -0
  20. package/dist-esm/keyvault-admin/src/tracing.js.map +1 -0
  21. package/dist-esm/keyvault-common/src/index.js +0 -1
  22. package/dist-esm/keyvault-common/src/index.js.map +1 -1
  23. package/dist-esm/keyvault-common/src/parseKeyvaultIdentifier.js.map +1 -1
  24. package/package.json +10 -10
  25. package/CHANGELOG.md +0 -106
  26. package/dist-esm/keyvault-admin/src/tracingHelpers.js +0 -42
  27. package/dist-esm/keyvault-admin/src/tracingHelpers.js.map +0 -1
  28. package/dist-esm/keyvault-common/src/tracingHelpers.js +0 -42
  29. package/dist-esm/keyvault-common/src/tracingHelpers.js.map +0 -1
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var tslib = require('tslib');
6
6
  var coreClient = require('@azure/core-client');
7
7
  var coreRestPipeline = require('@azure/core-rest-pipeline');
8
- var coreTracing = require('@azure/core-tracing');
9
8
  var logger$1 = require('@azure/logger');
9
+ var coreTracing = require('@azure/core-tracing');
10
10
  var uuid = require('uuid');
11
11
  var coreLro = require('@azure/core-lro');
12
12
 
@@ -30,21 +30,6 @@ function _interopNamespace(e) {
30
30
 
31
31
  var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
32
32
 
33
- // Copyright (c) Microsoft Corporation.
34
- // Licensed under the MIT license.
35
- /**
36
- * Current version of the Key Vault Admin SDK.
37
- */
38
- const SDK_VERSION = "4.2.0";
39
- /**
40
- * The latest supported Key Vault service API version.
41
- */
42
- const LATEST_API_VERSION = "7.3";
43
- /**
44
- * Authentication scopes
45
- */
46
- const authenticationScopes = ["https://managedhsm.azure.net/.default"];
47
-
48
33
  /*
49
34
  * Copyright (c) Microsoft Corporation.
50
35
  * Licensed under the MIT License.
@@ -1260,7 +1245,7 @@ class KeyVaultClientContext extends coreClient__namespace.ServiceClient {
1260
1245
  const defaults = {
1261
1246
  requestContentType: "application/json; charset=utf-8"
1262
1247
  };
1263
- const packageDetails = `azsdk-js-keyvault-admin/4.2.0`;
1248
+ const packageDetails = `azsdk-js-keyvault-admin/4.2.1`;
1264
1249
  const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
1265
1250
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
1266
1251
  : `${packageDetails}`;
@@ -1430,6 +1415,17 @@ const selectiveKeyRestoreOperationOperationSpec = {
1430
1415
  serializer
1431
1416
  };
1432
1417
 
1418
+ // Copyright (c) Microsoft Corporation.
1419
+ // Licensed under the MIT license.
1420
+ /**
1421
+ * Current version of the Key Vault Admin SDK.
1422
+ */
1423
+ const SDK_VERSION = "4.2.1";
1424
+ /**
1425
+ * The latest supported Key Vault service API version.
1426
+ */
1427
+ const LATEST_API_VERSION = "7.3";
1428
+
1433
1429
  // Copyright (c) Microsoft Corporation.
1434
1430
  // Licensed under the MIT license.
1435
1431
  /**
@@ -1509,7 +1505,7 @@ function createChallengeCallbacks() {
1509
1505
  };
1510
1506
  }
1511
1507
  async function authorizeRequest(options) {
1512
- const { scopes, request } = options;
1508
+ const { request } = options;
1513
1509
  const requestOptions = requestToOptions(request);
1514
1510
  switch (challengeState.status) {
1515
1511
  case "none":
@@ -1522,7 +1518,7 @@ function createChallengeCallbacks() {
1522
1518
  case "started":
1523
1519
  break; // Retry, we should not overwrite the original body
1524
1520
  case "complete": {
1525
- const token = await options.getAccessToken(scopes, requestOptions);
1521
+ const token = await options.getAccessToken(challengeState.scopes, requestOptions);
1526
1522
  if (token) {
1527
1523
  request.headers.set("authorization", `Bearer ${token.token}`);
1528
1524
  }
@@ -1532,7 +1528,7 @@ function createChallengeCallbacks() {
1532
1528
  return Promise.resolve();
1533
1529
  }
1534
1530
  async function authorizeRequestOnChallenge(options) {
1535
- const { scopes, request, response } = options;
1531
+ const { request, response } = options;
1536
1532
  if (request.body === null && challengeState.status === "started") {
1537
1533
  // Reset the original body before doing anything else.
1538
1534
  // Note: If successful status will be "complete", otherwise "none" will
@@ -1544,14 +1540,21 @@ function createChallengeCallbacks() {
1544
1540
  if (!challenge) {
1545
1541
  throw new Error("Missing challenge.");
1546
1542
  }
1547
- const parsedChallenge = parseWWWAuthenticate(challenge) || [];
1548
- const accessToken = await options.getAccessToken(parsedChallenge.scope ? [parsedChallenge.scope] : scopes, Object.assign(Object.assign({}, getTokenOptions), { tenantId: parsedChallenge.tenantId }));
1543
+ const parsedChallenge = parseWWWAuthenticate(challenge) || {};
1544
+ const scope = parsedChallenge.resource
1545
+ ? parsedChallenge.resource + "/.default"
1546
+ : parsedChallenge.scope;
1547
+ if (!scope) {
1548
+ throw new Error("Missing scope.");
1549
+ }
1550
+ const accessToken = await options.getAccessToken([scope], Object.assign(Object.assign({}, getTokenOptions), { tenantId: parsedChallenge.tenantId }));
1549
1551
  if (!accessToken) {
1550
1552
  return false;
1551
1553
  }
1552
1554
  options.request.headers.set("Authorization", `Bearer ${accessToken.token}`);
1553
1555
  challengeState = {
1554
1556
  status: "complete",
1557
+ scopes: [scope],
1555
1558
  };
1556
1559
  return true;
1557
1560
  }
@@ -1561,46 +1564,6 @@ function createChallengeCallbacks() {
1561
1564
  };
1562
1565
  }
1563
1566
 
1564
- // Copyright (c) Microsoft Corporation.
1565
- /**
1566
- * Returns a function that can be used for tracing options.
1567
- *
1568
- * @param prefix - The prefix to use, likely the name of the class / client.
1569
- *
1570
- * @example const withTrace = createTraceFunction("Azure.KeyVault.Certificates.CertificateClient")
1571
- *
1572
- * @internal
1573
- */
1574
- function createTraceFunction(prefix) {
1575
- const createSpan = coreTracing.createSpanFunction({
1576
- namespace: "Microsoft.KeyVault",
1577
- packagePrefix: prefix,
1578
- });
1579
- return async function (operationName, options, cb) {
1580
- const { updatedOptions, span } = createSpan(operationName, options);
1581
- try {
1582
- // NOTE: we really do need to await on this function here so we can handle any exceptions thrown and properly
1583
- // close the span.
1584
- const result = await cb(updatedOptions, span);
1585
- // otel 0.16+ needs this or else the code ends up being set as UNSET
1586
- span.setStatus({
1587
- code: coreTracing.SpanStatusCode.OK,
1588
- });
1589
- return result;
1590
- }
1591
- catch (err) {
1592
- span.setStatus({
1593
- code: coreTracing.SpanStatusCode.ERROR,
1594
- message: err.message,
1595
- });
1596
- throw err;
1597
- }
1598
- finally {
1599
- span.end();
1600
- }
1601
- };
1602
- }
1603
-
1604
1567
  // Copyright (c) Microsoft Corporation.
1605
1568
  /**
1606
1569
  * The \@azure/logger configuration for this package.
@@ -1656,7 +1619,13 @@ const mappings = {
1656
1619
  };
1657
1620
 
1658
1621
  // Copyright (c) Microsoft Corporation.
1659
- const withTrace$3 = createTraceFunction("Azure.KeyVault.Admin.KeyVaultAccessControlClient");
1622
+ const tracingClient = coreTracing.createTracingClient({
1623
+ namespace: "Microsoft.KeyVault",
1624
+ packageName: "@azure/keyvault-admin",
1625
+ packageVersion: SDK_VERSION,
1626
+ });
1627
+
1628
+ // Copyright (c) Microsoft Corporation.
1660
1629
  /**
1661
1630
  * The KeyVaultAccessControlClient provides methods to manage
1662
1631
  * access control and role assignments in any given Azure Key Vault instance.
@@ -1694,7 +1663,9 @@ class KeyVaultAccessControlClient {
1694
1663
  this.client = new KeyVaultClient(serviceVersion, clientOptions);
1695
1664
  this.client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
1696
1665
  credential,
1697
- scopes: authenticationScopes,
1666
+ // The scopes will be populated in the challenge callbacks based on the WWW-authenticate header
1667
+ // returned by the challenge, so pass an empty array as a placeholder.
1668
+ scopes: [],
1698
1669
  challengeCallbacks: createChallengeCallbacks(),
1699
1670
  }));
1700
1671
  }
@@ -1716,7 +1687,7 @@ class KeyVaultAccessControlClient {
1716
1687
  * @param options - The optional parameters.
1717
1688
  */
1718
1689
  createRoleAssignment(roleScope, name, roleDefinitionId, principalId, options = {}) {
1719
- return withTrace$3("createRoleAssignment", options, async (updatedOptions) => {
1690
+ return tracingClient.withSpan("KeyVaultAccessControlClient.createRoleAssignment", options, async (updatedOptions) => {
1720
1691
  const response = await this.client.roleAssignments.create(this.vaultUrl, roleScope, name, {
1721
1692
  properties: {
1722
1693
  roleDefinitionId,
@@ -1741,7 +1712,7 @@ class KeyVaultAccessControlClient {
1741
1712
  * @param options - The optional parameters.
1742
1713
  */
1743
1714
  deleteRoleAssignment(roleScope, name, options = {}) {
1744
- return withTrace$3("deleteRoleAssignment", options, async (updatedOptions) => {
1715
+ return tracingClient.withSpan("KeyVaultAccessControlClient.deleteRoleAssignment", options, async (updatedOptions) => {
1745
1716
  await this.client.roleAssignments.delete(this.vaultUrl, roleScope, name, updatedOptions);
1746
1717
  });
1747
1718
  }
@@ -1761,7 +1732,7 @@ class KeyVaultAccessControlClient {
1761
1732
  * @param options - The optional parameters.
1762
1733
  */
1763
1734
  getRoleAssignment(roleScope, name, options = {}) {
1764
- return withTrace$3("getRoleAssignment", options, async (updatedOptions) => {
1735
+ return tracingClient.withSpan("KeyVaultAccessControlClient.getRoleAssignment", options, async (updatedOptions) => {
1765
1736
  const response = await this.client.roleAssignments.get(this.vaultUrl, roleScope, name, updatedOptions);
1766
1737
  return mappings.roleAssignment.generatedToPublic(response);
1767
1738
  });
@@ -1776,7 +1747,7 @@ class KeyVaultAccessControlClient {
1776
1747
  return tslib.__asyncGenerator(this, arguments, function* listRoleAssignmentsPage_1() {
1777
1748
  if (!continuationState.continuationToken) {
1778
1749
  const optionsComplete = options || {};
1779
- const currentSetResponse = yield tslib.__await(withTrace$3("listRoleAssignments", optionsComplete, async (updatedOptions) => {
1750
+ const currentSetResponse = yield tslib.__await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleAssignmentsPage", optionsComplete, async (updatedOptions) => {
1780
1751
  return this.client.roleAssignments.listForScope(this.vaultUrl, roleScope, updatedOptions);
1781
1752
  }));
1782
1753
  continuationState.continuationToken = currentSetResponse.nextLink;
@@ -1785,7 +1756,7 @@ class KeyVaultAccessControlClient {
1785
1756
  }
1786
1757
  }
1787
1758
  while (continuationState.continuationToken) {
1788
- const currentSetResponse = yield tslib.__await(withTrace$3("listRoleAssignments", options || {}, async (updatedOptions) => {
1759
+ const currentSetResponse = yield tslib.__await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleAssignmentsPage", options || {}, async (updatedOptions) => {
1789
1760
  return this.client.roleAssignments.listForScopeNext(this.vaultUrl, roleScope, continuationState.continuationToken, updatedOptions);
1790
1761
  }));
1791
1762
  continuationState.continuationToken = currentSetResponse.nextLink;
@@ -1857,14 +1828,14 @@ class KeyVaultAccessControlClient {
1857
1828
  return tslib.__asyncGenerator(this, arguments, function* listRoleDefinitionsPage_1() {
1858
1829
  if (!continuationState.continuationToken) {
1859
1830
  const optionsComplete = options || {};
1860
- const currentSetResponse = yield tslib.__await(withTrace$3("listRoleDefinitions", optionsComplete, (updatedOptions) => this.client.roleDefinitions.list(this.vaultUrl, roleScope, updatedOptions)));
1831
+ const currentSetResponse = yield tslib.__await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleDefinitionsPage", optionsComplete, (updatedOptions) => this.client.roleDefinitions.list(this.vaultUrl, roleScope, updatedOptions)));
1861
1832
  continuationState.continuationToken = currentSetResponse.nextLink;
1862
1833
  if (currentSetResponse.value) {
1863
1834
  yield yield tslib.__await(currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this));
1864
1835
  }
1865
1836
  }
1866
1837
  while (continuationState.continuationToken) {
1867
- const currentSetResponse = yield tslib.__await(withTrace$3("listRoleDefinitions", options, (updatedOptions) => this.client.roleDefinitions.listNext(this.vaultUrl, roleScope, continuationState.continuationToken, updatedOptions)));
1838
+ const currentSetResponse = yield tslib.__await(tracingClient.withSpan("KeyVaultAccessControlClient.listRoleDefinitionsPage", options, (updatedOptions) => this.client.roleDefinitions.listNext(this.vaultUrl, roleScope, continuationState.continuationToken, updatedOptions)));
1868
1839
  continuationState.continuationToken = currentSetResponse.nextLink;
1869
1840
  if (currentSetResponse.value) {
1870
1841
  yield yield tslib.__await(currentSetResponse.value.map(mappings.roleDefinition.generatedToPublic, this));
@@ -1938,7 +1909,7 @@ class KeyVaultAccessControlClient {
1938
1909
  * @param options - The optional parameters.
1939
1910
  */
1940
1911
  getRoleDefinition(roleScope, name, options = {}) {
1941
- return withTrace$3("getRoleDefinition", options, async (updatedOptions) => {
1912
+ return tracingClient.withSpan("KeyVaultAccessControlClient.getRoleDefinition", options, async (updatedOptions) => {
1942
1913
  const response = await this.client.roleDefinitions.get(this.vaultUrl, roleScope, name, updatedOptions);
1943
1914
  return mappings.roleDefinition.generatedToPublic(response);
1944
1915
  });
@@ -1958,7 +1929,7 @@ class KeyVaultAccessControlClient {
1958
1929
  * @param options - The optional parameters.
1959
1930
  */
1960
1931
  setRoleDefinition(roleScope, options = {}) {
1961
- return withTrace$3("setRoleDefinition", options, async (updatedOptions) => {
1932
+ return tracingClient.withSpan("KeyVaultAccessControlClient.setRoleDefinition", options, async (updatedOptions) => {
1962
1933
  const response = await this.client.roleDefinitions.createOrUpdate(this.vaultUrl, roleScope, options.roleDefinitionName || uuid.v4(), {
1963
1934
  properties: {
1964
1935
  description: options.description,
@@ -1985,7 +1956,7 @@ class KeyVaultAccessControlClient {
1985
1956
  * @param options - The optional parameters.
1986
1957
  */
1987
1958
  deleteRoleDefinition(roleScope, name, options = {}) {
1988
- return withTrace$3("deleteRoleDefinition", options, async (updatedOptions) => {
1959
+ return tracingClient.withSpan("KeyVaultAccessControlClient.deleteRoleDefinition", options, async (updatedOptions) => {
1989
1960
  await this.client.roleDefinitions.delete(this.vaultUrl, roleScope, name, updatedOptions);
1990
1961
  });
1991
1962
  }
@@ -2171,10 +2142,6 @@ class KeyVaultAdminPollOperation {
2171
2142
  }
2172
2143
 
2173
2144
  // Copyright (c) Microsoft Corporation.
2174
- /**
2175
- * @internal
2176
- */
2177
- const withTrace$2 = createTraceFunction("Azure.KeyVault.Admin.KeyVaultBackupPoller");
2178
2145
  /**
2179
2146
  * The backup Key Vault's poll operation.
2180
2147
  */
@@ -2190,13 +2157,13 @@ class KeyVaultBackupPollOperation extends KeyVaultAdminPollOperation {
2190
2157
  * Tracing the fullBackup operation
2191
2158
  */
2192
2159
  fullBackup(options) {
2193
- return withTrace$2("fullBackup", options, (updatedOptions) => this.client.fullBackup(this.vaultUrl, updatedOptions));
2160
+ return tracingClient.withSpan("KeyVaultBackupPoller.fullBackup", options, (updatedOptions) => this.client.fullBackup(this.vaultUrl, updatedOptions));
2194
2161
  }
2195
2162
  /**
2196
2163
  * Tracing the fullBackupStatus operation
2197
2164
  */
2198
2165
  fullBackupStatus(jobId, options) {
2199
- return withTrace$2("fullBackupStatus", options, (updatedOptions) => this.client.fullBackupStatus(this.vaultUrl, jobId, updatedOptions));
2166
+ return tracingClient.withSpan("KeyVaultBackupPoller.fullBackupStatus", options, (updatedOptions) => this.client.fullBackupStatus(this.vaultUrl, jobId, updatedOptions));
2200
2167
  }
2201
2168
  /**
2202
2169
  * Reaches to the service and updates the backup's poll operation.
@@ -2268,10 +2235,6 @@ class KeyVaultBackupPoller extends KeyVaultAdminPoller {
2268
2235
  }
2269
2236
 
2270
2237
  // Copyright (c) Microsoft Corporation.
2271
- /**
2272
- * @internal
2273
- */
2274
- const withTrace$1 = createTraceFunction("Azure.KeyVault.Admin.KeyVaultRestorePoller");
2275
2238
  /**
2276
2239
  * An interface representing a restore Key Vault's poll operation.
2277
2240
  */
@@ -2289,13 +2252,13 @@ class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation {
2289
2252
  * Tracing the fullRestore operation
2290
2253
  */
2291
2254
  fullRestore(options) {
2292
- return withTrace$1("fullRestore", options, (updatedOptions) => this.client.fullRestoreOperation(this.vaultUrl, updatedOptions));
2255
+ return tracingClient.withSpan("KeyVaultRestorePoller.fullRestore", options, (updatedOptions) => this.client.fullRestoreOperation(this.vaultUrl, updatedOptions));
2293
2256
  }
2294
2257
  /**
2295
2258
  * Tracing the restoreStatus operation.
2296
2259
  */
2297
2260
  async restoreStatus(jobId, options) {
2298
- return withTrace$1("restoreStatus", options, (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions));
2261
+ return tracingClient.withSpan("KeyVaultRestorePoller.restoreStatus", options, (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions));
2299
2262
  }
2300
2263
  /**
2301
2264
  * Reaches to the service and updates the restore poll operation.
@@ -2370,10 +2333,6 @@ class KeyVaultRestorePoller extends KeyVaultAdminPoller {
2370
2333
  }
2371
2334
 
2372
2335
  // Copyright (c) Microsoft Corporation.
2373
- /**
2374
- * @internal
2375
- */
2376
- const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultSelectiveKeyRestorePoller");
2377
2336
  /**
2378
2337
  * The selective restore Key Vault's poll operation.
2379
2338
  */
@@ -2389,13 +2348,13 @@ class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollOperatio
2389
2348
  * Tracing the selectiveRestore operation
2390
2349
  */
2391
2350
  selectiveRestore(keyName, options) {
2392
- return withTrace("selectiveRestore", options, (updatedOptions) => this.client.selectiveKeyRestoreOperation(this.vaultUrl, keyName, updatedOptions));
2351
+ return tracingClient.withSpan("KeyVaultSelectiveKeyRestorePoller.selectiveRestore", options, (updatedOptions) => this.client.selectiveKeyRestoreOperation(this.vaultUrl, keyName, updatedOptions));
2393
2352
  }
2394
2353
  /**
2395
2354
  * Tracing the restoreStatus operation.
2396
2355
  */
2397
2356
  restoreStatus(jobId, options) {
2398
- return withTrace("restoreStatus", options, (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions));
2357
+ return tracingClient.withSpan("KeyVaultSelectiveKeyRestorePoller.restoreStatus", options, (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions));
2399
2358
  }
2400
2359
  /**
2401
2360
  * Reaches to the service and updates the selective restore poll operation.
@@ -2507,7 +2466,9 @@ class KeyVaultBackupClient {
2507
2466
  this.client = new KeyVaultClient(apiVersion, clientOptions);
2508
2467
  this.client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
2509
2468
  credential,
2510
- scopes: authenticationScopes,
2469
+ // The scopes will be populated in the challenge callbacks based on the WWW-authenticate header
2470
+ // returned by the challenge, so pass an empty array as a placeholder.
2471
+ scopes: [],
2511
2472
  challengeCallbacks: createChallengeCallbacks(),
2512
2473
  }));
2513
2474
  }