diff --git a/common/config/rush/common-versions.json b/common/config/rush/common-versions.json index 83304b3912fd..a9ba42820513 100644 --- a/common/config/rush/common-versions.json +++ b/common/config/rush/common-versions.json @@ -71,12 +71,10 @@ "@azure/ms-rest-nodeauth": ["^0.9.2"], // Idenity is moving from v1 to v2. Moving all packages to v2 is going to take a bit of time, in the mean time we could use v2 on the perf-identity tests. "@azure/identity": ["^2.0.0-beta.4", "2.0.0-beta.3", "^1.1.0"], - // App Config uses keyvault-secrets in a sample, switch to latest once the preview becomes GA // Issue #14771 tracks updating to these versions "@microsoft/api-extractor": ["7.13.2"], "prettier": ["2.2.1"], // All packages should move to 1.0.0 once core-rest-pipeline 1.1.0 GAs "@azure/core-tracing": ["1.0.0-preview.11"] - } } diff --git a/sdk/communication/communication-identity/package.json b/sdk/communication/communication-identity/package.json index f8dd78cee1ff..efbb4ef2f049 100644 --- a/sdk/communication/communication-identity/package.json +++ b/sdk/communication/communication-identity/package.json @@ -77,7 +77,7 @@ "@azure/communication-common": "^1.0.0", "@azure/core-auth": "^1.3.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.12", "@azure/logger": "^1.0.0", diff --git a/sdk/communication/communication-phone-numbers/package.json b/sdk/communication/communication-phone-numbers/package.json index dd384db1e6d2..b8097778687a 100644 --- a/sdk/communication/communication-phone-numbers/package.json +++ b/sdk/communication/communication-phone-numbers/package.json @@ -65,7 +65,7 @@ "@azure/abort-controller": "^1.0.0", "@azure/core-auth": "^1.3.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.12", "@azure/logger": "^1.0.0", diff --git a/sdk/formrecognizer/ai-form-recognizer/package.json b/sdk/formrecognizer/ai-form-recognizer/package.json index a35b7cf0556f..b2c66d679bc9 100644 --- a/sdk/formrecognizer/ai-form-recognizer/package.json +++ b/sdk/formrecognizer/ai-form-recognizer/package.json @@ -79,7 +79,7 @@ "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", "dependencies": { "@azure/core-auth": "^1.3.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", "@azure/core-tracing": "1.0.0-preview.12", diff --git a/sdk/keyvault/keyvault-admin/package.json b/sdk/keyvault/keyvault-admin/package.json index 1bbfe7e3580d..65cd07c9b75b 100644 --- a/sdk/keyvault/keyvault-admin/package.json +++ b/sdk/keyvault/keyvault-admin/package.json @@ -104,17 +104,21 @@ "sideEffects": false, "dependencies": { "@azure/abort-controller": "^1.0.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-client": "^1.0.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.12", + "@azure/core-rest-pipeline": "1.1.0-beta.4", + "@azure/core-tracing": "1.0.0-preview.11", "@azure/logger": "^1.0.0", "@types/uuid": "^8.0.0", - "uuid": "^8.3.0", - "tslib": "^2.2.0" + "tslib": "^2.2.0", + "uuid": "^8.3.0" }, "devDependencies": { "@azure/abort-controller": "^1.0.0", + "@azure/core-util": "^1.0.0-beta.1", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@azure/identity": "2.0.0-beta.4", @@ -128,9 +132,9 @@ "@rollup/plugin-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/chai-as-promised": "^7.1.0", - "@types/sinon": "^9.0.4", "@types/mocha": "^7.0.2", "@types/node": "^8.0.0", + "@types/sinon": "^9.0.4", "assert": "^1.4.1", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", @@ -150,7 +154,7 @@ "rollup-plugin-visualizer": "^4.0.4", "sinon": "^9.0.2", "source-map-support": "^0.5.9", - "typescript": "~4.2.0", - "typedoc": "0.15.2" + "typedoc": "0.15.2", + "typescript": "~4.2.0" } } diff --git a/sdk/keyvault/keyvault-admin/review/keyvault-admin.api.md b/sdk/keyvault/keyvault-admin/review/keyvault-admin.api.md index dfcc077593f7..a73d9fbb9b96 100644 --- a/sdk/keyvault/keyvault-admin/review/keyvault-admin.api.md +++ b/sdk/keyvault/keyvault-admin/review/keyvault-admin.api.md @@ -4,35 +4,36 @@ ```ts -import * as coreHttp from '@azure/core-http'; +import { CommonClientOptions } from '@azure/core-client'; +import { OperationOptions } from '@azure/core-client'; import { PagedAsyncIterableIterator } from '@azure/core-paging'; import { PollerLike } from '@azure/core-lro'; import { PollOperationState } from '@azure/core-lro'; -import { TokenCredential } from '@azure/core-http'; +import { TokenCredential } from '@azure/core-auth'; // @public -export interface AccessControlClientOptions extends coreHttp.PipelineOptions { +export interface AccessControlClientOptions extends CommonClientOptions { serviceVersion?: SUPPORTED_API_VERSIONS; } // @public -export interface CreateRoleAssignmentOptions extends coreHttp.OperationOptions { +export interface CreateRoleAssignmentOptions extends OperationOptions { } // @public -export interface DeleteRoleAssignmentOptions extends coreHttp.OperationOptions { +export interface DeleteRoleAssignmentOptions extends OperationOptions { } // @public -export interface DeleteRoleDefinitionOptions extends coreHttp.OperationOptions { +export interface DeleteRoleDefinitionOptions extends OperationOptions { } // @public -export interface GetRoleAssignmentOptions extends coreHttp.OperationOptions { +export interface GetRoleAssignmentOptions extends OperationOptions { } // @public -export interface GetRoleDefinitionOptions extends coreHttp.OperationOptions { +export interface GetRoleDefinitionOptions extends OperationOptions { } // @public @@ -68,7 +69,7 @@ export class KeyVaultBackupClient { } // @public -export interface KeyVaultBackupClientOptions extends coreHttp.PipelineOptions { +export interface KeyVaultBackupClientOptions extends CommonClientOptions { serviceVersion?: SUPPORTED_API_VERSIONS; } @@ -76,7 +77,7 @@ export interface KeyVaultBackupClientOptions extends coreHttp.PipelineOptions { export type KeyVaultBackupOperationState = KeyVaultAdminPollOperationState; // @public -export interface KeyVaultBackupPollerOptions extends coreHttp.OperationOptions { +export interface KeyVaultBackupPollerOptions extends OperationOptions { intervalInMs?: number; resumeFrom?: string; } @@ -204,7 +205,7 @@ export enum KnownKeyVaultRoleScope { export const LATEST_API_VERSION = "7.2"; // @public -export interface ListRoleAssignmentsOptions extends coreHttp.OperationOptions { +export interface ListRoleAssignmentsOptions extends OperationOptions { } // @public @@ -213,7 +214,7 @@ export interface ListRoleAssignmentsPageSettings { } // @public -export interface ListRoleDefinitionsOptions extends coreHttp.OperationOptions { +export interface ListRoleDefinitionsOptions extends OperationOptions { } // @public @@ -225,7 +226,7 @@ export interface ListRoleDefinitionsPageSettings { export const SDK_VERSION: string; // @public -export interface SetRoleDefinitionOptions extends coreHttp.OperationOptions { +export interface SetRoleDefinitionOptions extends OperationOptions { assignableScopes?: KeyVaultRoleScope[]; description?: string; permissions?: KeyVaultPermission[]; diff --git a/sdk/keyvault/keyvault-admin/src/accessControlClient.ts b/sdk/keyvault/keyvault-admin/src/accessControlClient.ts index 00076f18f6be..8111382d9822 100644 --- a/sdk/keyvault/keyvault-admin/src/accessControlClient.ts +++ b/sdk/keyvault/keyvault-admin/src/accessControlClient.ts @@ -2,21 +2,12 @@ // Licensed under the MIT license. /// -import { - TokenCredential, - isTokenCredential, - signingPolicy, - createPipelineFromOptions, - InternalPipelineOptions -} from "@azure/core-http"; +import { TokenCredential } from "@azure/core-auth"; import { PagedAsyncIterableIterator } from "@azure/core-paging"; -import { challengeBasedAuthenticationPolicy, createTraceFunction } from "../../keyvault-common/src"; +import { createTraceFunction } from "./tracingHelpers"; import { KeyVaultClient } from "./generated/keyVaultClient"; -import { - KeyVaultClientOptionalParams, - RoleAssignmentsListForScopeOptionalParams -} from "./generated/models"; +import { RoleAssignmentsListForScopeOptionalParams } from "./generated/models"; import { CreateRoleAssignmentOptions, @@ -35,10 +26,12 @@ import { DeleteRoleDefinitionOptions } from "./accessControlModels"; -import { SDK_VERSION, LATEST_API_VERSION } from "./constants"; +import { SDK_VERSION, LATEST_API_VERSION, authenticationScopes } from "./constants"; import { mappings } from "./mappings"; import { logger } from "./log"; import { v4 as v4uuid } from "uuid"; +import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline"; +import { createChallengeCallbacks } from "./challengeAuthenticationCallbacks"; const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultAccessControlClient"); @@ -94,15 +87,13 @@ export class KeyVaultAccessControlClient { : libInfo }; - const authPolicy = isTokenCredential(credential) - ? challengeBasedAuthenticationPolicy(credential) - : signingPolicy(credential); + const serviceVersion = options.serviceVersion || LATEST_API_VERSION; - const internalPipelineOptions: InternalPipelineOptions = { + const clientOptions = { ...options, loggingOptions: { logger: logger.info, - allowedHeaderNames: [ + additionalAllowedHeaderNames: [ "x-ms-keyvault-region", "x-ms-keyvault-network-info", "x-ms-keyvault-service-version" @@ -110,12 +101,15 @@ export class KeyVaultAccessControlClient { } }; - const params: KeyVaultClientOptionalParams = createPipelineFromOptions( - internalPipelineOptions, - authPolicy + this.client = new KeyVaultClient(serviceVersion, clientOptions); + + this.client.pipeline.addPolicy( + bearerTokenAuthenticationPolicy({ + credential, + scopes: authenticationScopes, + challengeCallbacks: createChallengeCallbacks() + }) ); - params.apiVersion = options.serviceVersion || LATEST_API_VERSION; - this.client = new KeyVaultClient(params); } /** diff --git a/sdk/keyvault/keyvault-admin/src/accessControlModels.ts b/sdk/keyvault/keyvault-admin/src/accessControlModels.ts index c2f0bc79e3dc..6445e425d978 100644 --- a/sdk/keyvault/keyvault-admin/src/accessControlModels.ts +++ b/sdk/keyvault/keyvault-admin/src/accessControlModels.ts @@ -1,27 +1,95 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import * as coreHttp from "@azure/core-http"; +import { CommonClientOptions, OperationOptions } from "@azure/core-client"; import { SUPPORTED_API_VERSIONS } from "./constants"; import { DataAction as KeyVaultDataAction, - KnownDataAction as KnownKeyVaultDataAction, - KnownRoleScope as KnownKeyVaultRoleScope, RoleScope as KeyVaultRoleScope } from "./generated/index"; -export { KeyVaultDataAction, KnownKeyVaultDataAction, KeyVaultRoleScope, KnownKeyVaultRoleScope }; +export { KeyVaultDataAction, KeyVaultRoleScope }; /** * The optional parameters accepted by the Key Vault's AccessControlClient */ -export interface AccessControlClientOptions extends coreHttp.PipelineOptions { +export interface AccessControlClientOptions extends CommonClientOptions { /** * The accepted versions of the Key Vault's service API. */ serviceVersion?: SUPPORTED_API_VERSIONS; } +/** Known values of {@link DataAction} that the service accepts. */ +export enum KnownKeyVaultDataAction { + /** Read HSM key metadata. */ + ReadHsmKey = "Microsoft.KeyVault/managedHsm/keys/read/action", + /** Update an HSM key. */ + WriteHsmKey = "Microsoft.KeyVault/managedHsm/keys/write/action", + /** Read deleted HSM key. */ + ReadDeletedHsmKey = "Microsoft.KeyVault/managedHsm/keys/deletedKeys/read/action", + /** Recover deleted HSM key. */ + RecoverDeletedHsmKey = "Microsoft.KeyVault/managedHsm/keys/deletedKeys/recover/action", + /** Backup HSM keys. */ + BackupHsmKeys = "Microsoft.KeyVault/managedHsm/keys/backup/action", + /** Restore HSM keys. */ + RestoreHsmKeys = "Microsoft.KeyVault/managedHsm/keys/restore/action", + /** Delete role assignment. */ + DeleteRoleAssignment = "Microsoft.KeyVault/managedHsm/roleAssignments/delete/action", + /** Get role assignment. */ + GetRoleAssignment = "Microsoft.KeyVault/managedHsm/roleAssignments/read/action", + /** Create or update role assignment. */ + WriteRoleAssignment = "Microsoft.KeyVault/managedHsm/roleAssignments/write/action", + /** Get role definition. */ + ReadRoleDefinition = "Microsoft.KeyVault/managedHsm/roleDefinitions/read/action", + /** Encrypt using an HSM key. */ + EncryptHsmKey = "Microsoft.KeyVault/managedHsm/keys/encrypt/action", + /** Decrypt using an HSM key. */ + DecryptHsmKey = "Microsoft.KeyVault/managedHsm/keys/decrypt/action", + /** Wrap using an HSM key. */ + WrapHsmKey = "Microsoft.KeyVault/managedHsm/keys/wrap/action", + /** Unwrap using an HSM key. */ + UnwrapHsmKey = "Microsoft.KeyVault/managedHsm/keys/unwrap/action", + /** Sign using an HSM key. */ + SignHsmKey = "Microsoft.KeyVault/managedHsm/keys/sign/action", + /** Verify using an HSM key. */ + VerifyHsmKey = "Microsoft.KeyVault/managedHsm/keys/verify/action", + /** Create an HSM key. */ + CreateHsmKey = "Microsoft.KeyVault/managedHsm/keys/create", + /** Delete an HSM key. */ + DeleteHsmKey = "Microsoft.KeyVault/managedHsm/keys/delete", + /** Export an HSM key. */ + ExportHsmKey = "Microsoft.KeyVault/managedHsm/keys/export/action", + /** Import an HSM key. */ + ImportHsmKey = "Microsoft.KeyVault/managedHsm/keys/import/action", + /** Purge a deleted HSM key. */ + PurgeDeletedHsmKey = "Microsoft.KeyVault/managedHsm/keys/deletedKeys/delete", + /** Download an HSM security domain. */ + DownloadHsmSecurityDomain = "Microsoft.KeyVault/managedHsm/securitydomain/download/action", + /** Upload an HSM security domain. */ + UploadHsmSecurityDomain = "Microsoft.KeyVault/managedHsm/securitydomain/upload/action", + /** Check the status of the HSM security domain exchange file. */ + ReadHsmSecurityDomainStatus = "Microsoft.KeyVault/managedHsm/securitydomain/upload/read", + /** Download an HSM security domain transfer key. */ + ReadHsmSecurityDomainTransferKey = "Microsoft.KeyVault/managedHsm/securitydomain/transferkey/read", + /** Start an HSM backup. */ + StartHsmBackup = "Microsoft.KeyVault/managedHsm/backup/start/action", + /** Start an HSM restore. */ + StartHsmRestore = "Microsoft.KeyVault/managedHsm/restore/start/action", + /** Read an HSM backup status. */ + ReadHsmBackupStatus = "Microsoft.KeyVault/managedHsm/backup/status/action", + /** Read an HSM restore status. */ + ReadHsmRestoreStatus = "Microsoft.KeyVault/managedHsm/restore/status/action" +} + +/** Known values of {@link RoleScope} that the service accepts. */ +export enum KnownKeyVaultRoleScope { + /** Global scope */ + Global = "/", + /** Keys scope */ + Keys = "/keys" +} + /** * A Key Vault role assignment. */ @@ -126,39 +194,39 @@ export interface KeyVaultRoleAssignmentProperties { * An interface representing the optional parameters that can be * passed to {@link createRoleAssignment} */ -export interface CreateRoleAssignmentOptions extends coreHttp.OperationOptions {} +export interface CreateRoleAssignmentOptions extends OperationOptions {} /** * An interface representing the optional parameters that can be * passed to {@link deleteRoleAssignment} */ -export interface DeleteRoleAssignmentOptions extends coreHttp.OperationOptions {} +export interface DeleteRoleAssignmentOptions extends OperationOptions {} /** * An interface representing the optional parameters that can be * passed to {@link getRoleAssignment} */ -export interface GetRoleAssignmentOptions extends coreHttp.OperationOptions {} +export interface GetRoleAssignmentOptions extends OperationOptions {} /** * An interface representing optional parameters passed to {@link listRoleAssignments}. */ -export interface ListRoleAssignmentsOptions extends coreHttp.OperationOptions {} +export interface ListRoleAssignmentsOptions extends OperationOptions {} /** * An interface representing optional parameters passed to {@link listRoleDefinitions}. */ -export interface ListRoleDefinitionsOptions extends coreHttp.OperationOptions {} +export interface ListRoleDefinitionsOptions extends OperationOptions {} /** * An interface representing optional parameters passed to {@link getRoleDefinition}. */ -export interface GetRoleDefinitionOptions extends coreHttp.OperationOptions {} +export interface GetRoleDefinitionOptions extends OperationOptions {} /** * An interface representing optional parameters passed to {@link setRoleDefinition}. */ -export interface SetRoleDefinitionOptions extends coreHttp.OperationOptions { +export interface SetRoleDefinitionOptions extends OperationOptions { /** * UUID used as the name of the role definition to create. If it's not provided, a new UUID will be generated. */ @@ -184,7 +252,7 @@ export interface SetRoleDefinitionOptions extends coreHttp.OperationOptions { /** * An interface representing optional parameters passed to {@link deleteRoleDefinition}. */ -export interface DeleteRoleDefinitionOptions extends coreHttp.OperationOptions {} +export interface DeleteRoleDefinitionOptions extends OperationOptions {} /** * Arguments for retrieving the next page of search results. diff --git a/sdk/keyvault/keyvault-admin/src/backupClient.ts b/sdk/keyvault/keyvault-admin/src/backupClient.ts index e997fff43ec0..420d55eb4f95 100644 --- a/sdk/keyvault/keyvault-admin/src/backupClient.ts +++ b/sdk/keyvault/keyvault-admin/src/backupClient.ts @@ -1,16 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { - createPipelineFromOptions, - InternalPipelineOptions, - isTokenCredential, - signingPolicy, - TokenCredential -} from "@azure/core-http"; import { PollerLike } from "@azure/core-lro"; -import { challengeBasedAuthenticationPolicy } from "../../keyvault-common/src"; import { KeyVaultClient } from "./generated/keyVaultClient"; import { KeyVaultBackupClientOptions, @@ -21,7 +13,7 @@ import { KeyVaultRestoreResult, KeyVaultSelectiveKeyRestoreResult } from "./backupClientModels"; -import { LATEST_API_VERSION, SDK_VERSION } from "./constants"; +import { LATEST_API_VERSION, SDK_VERSION, authenticationScopes } from "./constants"; import { logger } from "./log"; import { KeyVaultBackupPoller } from "./lro/backup/poller"; import { KeyVaultRestorePoller } from "./lro/restore/poller"; @@ -30,8 +22,10 @@ import { KeyVaultBackupOperationState } from "./lro/backup/operation"; import { KeyVaultRestoreOperationState } from "./lro/restore/operation"; import { KeyVaultAdminPollOperationState } from "./lro/keyVaultAdminPoller"; import { KeyVaultSelectiveKeyRestoreOperationState } from "./lro/selectiveKeyRestore/operation"; -import { KeyVaultClientOptionalParams } from "./generated/models"; import { mappings } from "./mappings"; +import { TokenCredential } from "@azure/core-auth"; +import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline"; +import { createChallengeCallbacks } from "./challengeAuthenticationCallbacks"; export { KeyVaultBackupOperationState, @@ -93,15 +87,13 @@ export class KeyVaultBackupClient { : libInfo }; - const authPolicy = isTokenCredential(credential) - ? challengeBasedAuthenticationPolicy(credential) - : signingPolicy(credential); + const apiVersion = options.serviceVersion || LATEST_API_VERSION; - const internalPipelineOptions: InternalPipelineOptions = { + const clientOptions = { ...options, loggingOptions: { logger: logger.info, - allowedHeaderNames: [ + additionalAllowedHeaderNames: [ "x-ms-keyvault-region", "x-ms-keyvault-network-info", "x-ms-keyvault-service-version" @@ -109,12 +101,14 @@ export class KeyVaultBackupClient { } }; - const params: KeyVaultClientOptionalParams = createPipelineFromOptions( - internalPipelineOptions, - authPolicy + this.client = new KeyVaultClient(apiVersion, clientOptions); + this.client.pipeline.addPolicy( + bearerTokenAuthenticationPolicy({ + credential, + scopes: authenticationScopes, + challengeCallbacks: createChallengeCallbacks() + }) ); - params.apiVersion = options.serviceVersion || LATEST_API_VERSION; - this.client = new KeyVaultClient(params); } /** diff --git a/sdk/keyvault/keyvault-admin/src/backupClientModels.ts b/sdk/keyvault/keyvault-admin/src/backupClientModels.ts index 8ab3eac1cfe0..dbeaac6a2346 100644 --- a/sdk/keyvault/keyvault-admin/src/backupClientModels.ts +++ b/sdk/keyvault/keyvault-admin/src/backupClientModels.ts @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import * as coreHttp from "@azure/core-http"; +import { CommonClientOptions, OperationOptions } from "@azure/core-client"; import { SUPPORTED_API_VERSIONS } from "./constants"; /** * The optional parameters accepted by the KeyVaultBackupClient */ -export interface KeyVaultBackupClientOptions extends coreHttp.PipelineOptions { +export interface KeyVaultBackupClientOptions extends CommonClientOptions { /** * The accepted versions of the Key Vault's service API. */ @@ -18,7 +18,7 @@ export interface KeyVaultBackupClientOptions extends coreHttp.PipelineOptions { * An interface representing the optional parameters that can be * passed to {@link beginBackup} */ -export interface KeyVaultBackupPollerOptions extends coreHttp.OperationOptions { +export interface KeyVaultBackupPollerOptions extends OperationOptions { /** * Time between each polling */ diff --git a/sdk/keyvault/keyvault-admin/src/challengeAuthenticationCallbacks.ts b/sdk/keyvault/keyvault-admin/src/challengeAuthenticationCallbacks.ts new file mode 100644 index 000000000000..274ea633e571 --- /dev/null +++ b/sdk/keyvault/keyvault-admin/src/challengeAuthenticationCallbacks.ts @@ -0,0 +1,166 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { + AuthorizeRequestOnChallengeOptions, + AuthorizeRequestOptions, + ChallengeCallbacks, + PipelineRequest, + RequestBodyType +} from "@azure/core-rest-pipeline"; +import { GetTokenOptions } from "@azure/core-auth"; + +const validParsedWWWAuthenticateProperties = ["authorization", "resource", "scope"]; + +/** + * @internal + * + * Holds the known WWWAuthenticate keys and their values as a result of + * parsing a WWW-Authenticate header. + */ +type ParsedWWWAuthenticate = { + [Key in "authorization" | "resource" | "scope"]?: string; +}; + +/** + * @internal + * Holds the state of Challenge Auth. + * When making the first request we force Key Vault to begin a challenge + * by clearing out the request body and storing it locally. + * + * Later on, the authorizeRequestOnChallenge callback will process the + * challenge and, if ready to resend the original request, reset the body + * so that it may be sent again. + * + * Once a client has succeeded once, we can start skipping CAE. + */ +type ChallengeState = + | { + status: "none"; + } + | { + status: "started"; + originalBody?: RequestBodyType; + } + | { + status: "complete"; + }; + +/** + * Parses an WWW-Authenticate response. + * This transforms a string value like: + * `Bearer authorization="some_authorization", resource="https://some.url"` + * into an object like: + * `{ authorization: "some_authorization", resource: "https://some.url" }` + * @param wwwAuthenticate - String value in the WWW-Authenticate header + */ +export function parseWWWAuthenticate(wwwAuthenticate: string): ParsedWWWAuthenticate { + const pairDelimiter = /,? +/; + return wwwAuthenticate.split(pairDelimiter).reduce((kvPairs, p) => { + if (p.match(/\w="/)) { + // 'sampleKey="sample_value"' -> [sampleKey, "sample_value"] -> { sampleKey: sample_value } + const [key, value] = p.split("="); + if (validParsedWWWAuthenticateProperties.includes(key)) { + // The values will be wrapped in quotes, which need to be stripped out. + return { ...kvPairs, [key]: value.slice(1, -1) }; + } + } + return kvPairs; + }, {}); +} + +/** + * @internal + * + * Creates challenge callback handlers to manage CAE lifecycle in Azure Key Vault. + * + * Key Vault supports other authentication schemes, but we ensure challenge authentication + * is used by first sending a copy of the request, without authorization or content. + * + * when the challenge is received, it will be authenticated and used to send the original + * request with authorization. + * + * Following the first request of a client, follow-up requests will get the cached token + * if possible. + */ +export function createChallengeCallbacks(): ChallengeCallbacks { + let challengeState: ChallengeState = { status: "none" }; + + function requestToOptions(request: PipelineRequest): GetTokenOptions { + return { + abortSignal: request.abortSignal, + requestOptions: { + timeout: request.timeout + }, + tracingOptions: request.tracingOptions + }; + } + + async function authorizeRequest(options: AuthorizeRequestOptions) { + const { scopes, request } = options; + const requestOptions: GetTokenOptions = requestToOptions(request); + + switch (challengeState.status) { + case "none": + challengeState = { + status: "started", + originalBody: request.body + }; + request.body = null; + break; + case "started": + break; // Retry, we should not overwrite the original body + case "complete": { + const token = await options.getAccessToken(scopes, requestOptions); + if (token) { + request.headers.set("authorization", `Bearer ${token.token}`); + } + break; + } + } + return Promise.resolve(); + } + + async function authorizeRequestOnChallenge( + options: AuthorizeRequestOnChallengeOptions + ): Promise { + const { scopes, request, response } = options; + + if (request.body === null && challengeState.status === "started") { + // Reset the original body before doing anything else. + // Note: If successful status will be "complete", otherwise "none" will + // restart the process. + request.body = challengeState.originalBody; + } + + const getTokenOptions = requestToOptions(request); + + const challenge = response.headers.get("WWW-Authenticate"); + if (!challenge) { + throw new Error("Missing challenge."); + } + const parsedChallenge: ParsedWWWAuthenticate = parseWWWAuthenticate(challenge) || []; + + const accessToken = await options.getAccessToken( + parsedChallenge.scope ? [parsedChallenge.scope] : scopes, + getTokenOptions + ); + + if (!accessToken) { + return false; + } + + options.request.headers.set("Authorization", `Bearer ${accessToken.token}`); + + challengeState = { + status: "complete" + }; + + return true; + } + + return { + authorizeRequest, + authorizeRequestOnChallenge + }; +} diff --git a/sdk/keyvault/keyvault-admin/src/constants.ts b/sdk/keyvault/keyvault-admin/src/constants.ts index 557757871381..a80b776975d3 100644 --- a/sdk/keyvault/keyvault-admin/src/constants.ts +++ b/sdk/keyvault/keyvault-admin/src/constants.ts @@ -15,3 +15,8 @@ export const LATEST_API_VERSION = "7.2"; * Supported API versions */ export type SUPPORTED_API_VERSIONS = "7.2"; + +/** + * Authentication scopes + */ +export const authenticationScopes = ["https://managedhsm.azure.net/.default"]; diff --git a/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts b/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts index 69b2bc474277..b7843fd72d71 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts @@ -6,7 +6,7 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; import { RoleDefinitionsImpl, RoleAssignmentsImpl } from "./operations"; import { RoleDefinitions, RoleAssignments } from "./operationsInterfaces"; import * as Parameters from "./models/parameters"; @@ -14,6 +14,7 @@ import * as Mappers from "./models/mappers"; import { KeyVaultClientContext } from "./keyVaultClientContext"; import { KeyVaultClientOptionalParams, + ApiVersion72, KeyVaultClientFullBackupOptionalParams, KeyVaultClientFullBackupResponse, KeyVaultClientFullBackupStatusOptionalParams, @@ -29,10 +30,14 @@ import { export class KeyVaultClient extends KeyVaultClientContext { /** * Initializes a new instance of the KeyVaultClient class. + * @param apiVersion Api Version * @param options The parameter options */ - constructor(options?: KeyVaultClientOptionalParams) { - super(options); + constructor( + apiVersion: ApiVersion72, + options?: KeyVaultClientOptionalParams + ) { + super(apiVersion, options); this.roleDefinitions = new RoleDefinitionsImpl(this); this.roleAssignments = new RoleAssignmentsImpl(this); } @@ -46,14 +51,10 @@ export class KeyVaultClient extends KeyVaultClientContext { vaultBaseUrl: string, options?: KeyVaultClientFullBackupOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.sendOperationRequest( - operationArguments, + { vaultBaseUrl, options }, fullBackupOperationSpec - ) as Promise; + ); } /** @@ -67,15 +68,10 @@ export class KeyVaultClient extends KeyVaultClientContext { jobId: string, options?: KeyVaultClientFullBackupStatusOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - jobId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.sendOperationRequest( - operationArguments, + { vaultBaseUrl, jobId, options }, fullBackupStatusOperationSpec - ) as Promise; + ); } /** @@ -88,14 +84,10 @@ export class KeyVaultClient extends KeyVaultClientContext { vaultBaseUrl: string, options?: KeyVaultClientFullRestoreOperationOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.sendOperationRequest( - operationArguments, + { vaultBaseUrl, options }, fullRestoreOperationOperationSpec - ) as Promise; + ); } /** @@ -109,15 +101,10 @@ export class KeyVaultClient extends KeyVaultClientContext { jobId: string, options?: KeyVaultClientRestoreStatusOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - jobId, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.sendOperationRequest( - operationArguments, + { vaultBaseUrl, jobId, options }, restoreStatusOperationSpec - ) as Promise; + ); } /** @@ -132,24 +119,19 @@ export class KeyVaultClient extends KeyVaultClientContext { keyName: string, options?: KeyVaultClientSelectiveKeyRestoreOperationOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - keyName, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.sendOperationRequest( - operationArguments, + { vaultBaseUrl, keyName, options }, selectiveKeyRestoreOperationOperationSpec - ) as Promise; + ); } roleDefinitions: RoleDefinitions; roleAssignments: RoleAssignments; } // Operation Specifications -const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); -const fullBackupOperationSpec: coreHttp.OperationSpec = { +const fullBackupOperationSpec: coreClient.OperationSpec = { path: "/backup", httpMethod: "POST", responses: { @@ -168,7 +150,7 @@ const fullBackupOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const fullBackupStatusOperationSpec: coreHttp.OperationSpec = { +const fullBackupStatusOperationSpec: coreClient.OperationSpec = { path: "/backup/{jobId}/pending", httpMethod: "GET", responses: { @@ -184,7 +166,7 @@ const fullBackupStatusOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const fullRestoreOperationOperationSpec: coreHttp.OperationSpec = { +const fullRestoreOperationOperationSpec: coreClient.OperationSpec = { path: "/restore", httpMethod: "PUT", responses: { @@ -203,7 +185,7 @@ const fullRestoreOperationOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const restoreStatusOperationSpec: coreHttp.OperationSpec = { +const restoreStatusOperationSpec: coreClient.OperationSpec = { path: "/restore/{jobId}/pending", httpMethod: "GET", responses: { @@ -219,7 +201,7 @@ const restoreStatusOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const selectiveKeyRestoreOperationOperationSpec: coreHttp.OperationSpec = { +const selectiveKeyRestoreOperationOperationSpec: coreClient.OperationSpec = { path: "/keys/{keyName}/restore", httpMethod: "PUT", responses: { diff --git a/sdk/keyvault/keyvault-admin/src/generated/keyVaultClientContext.ts b/sdk/keyvault/keyvault-admin/src/generated/keyVaultClientContext.ts index 47366d5de20d..164b60fd2535 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/keyVaultClientContext.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/keyVaultClientContext.ts @@ -6,36 +6,51 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; -import { KeyVaultClientOptionalParams } from "./models"; +import * as coreClient from "@azure/core-client"; +import { ApiVersion72, KeyVaultClientOptionalParams } from "./models"; -const packageName = "@azure/keyvault-admin"; export const packageVersion = "4.1.0-beta.1"; -export class KeyVaultClientContext extends coreHttp.ServiceClient { - apiVersion: string; +export class KeyVaultClientContext extends coreClient.ServiceClient { + apiVersion: ApiVersion72; /** * Initializes a new instance of the KeyVaultClientContext class. + * @param apiVersion Api Version * @param options The parameter options */ - constructor(options?: KeyVaultClientOptionalParams) { + constructor( + apiVersion: ApiVersion72, + options?: KeyVaultClientOptionalParams + ) { + if (apiVersion === undefined) { + throw new Error("'apiVersion' cannot be null"); + } + // Initializing default values for options if (!options) { options = {}; } - - if (!options.userAgent) { - const defaultUserAgent = coreHttp.getDefaultUserAgentValue(); - options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`; - } - - super(undefined, options); - - this.requestContentType = "application/json; charset=utf-8"; - this.baseUri = options.endpoint || "{vaultBaseUrl}"; - - // Assigning values to Constant parameters - this.apiVersion = options.apiVersion || "7.2"; + const defaults: KeyVaultClientOptionalParams = { + requestContentType: "application/json; charset=utf-8" + }; + + const packageDetails = `azsdk-js-keyvault-admin/4.1.0-beta.1`; + const userAgentPrefix = + options.userAgentOptions && options.userAgentOptions.userAgentPrefix + ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` + : `${packageDetails}`; + + const optionsWithDefaults = { + ...defaults, + ...options, + userAgentOptions: { + userAgentPrefix + }, + baseUri: options.endpoint || "{vaultBaseUrl}" + }; + super(optionsWithDefaults); + // Parameter assignments + this.apiVersion = apiVersion; } } diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/azureAsyncOperationStrategy.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/azureAsyncOperationStrategy.ts deleted file mode 100644 index ecdc300c1ff5..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/azureAsyncOperationStrategy.ts +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { - LROStrategy, - BaseResult, - LROOperationStep, - LROResponseInfo, - FinalStateVia -} from "./models"; -import { OperationSpec, OperationArguments } from "@azure/core-http"; -import { terminalStates } from "./constants"; -import { SendOperationFn } from "."; - -export function createAzureAsyncOperationStrategy( - initialOperation: LROOperationStep, - sendOperationFn: SendOperationFn, - finalStateVia?: FinalStateVia -): LROStrategy { - const lroData = initialOperation.result._lroData; - if (!lroData) { - throw new Error( - "Expected lroData to be defined for Azure-AsyncOperation strategy" - ); - } - - let currentOperation = initialOperation; - let lastKnownPollingUrl = - lroData.azureAsyncOperation || lroData.operationLocation; - - return { - isTerminal: () => { - const currentResult = currentOperation.result._lroData; - - if (!currentResult) { - throw new Error("Expected lroData to determine terminal status"); - } - - if (currentOperation === initialOperation) { - // Azure-AsyncOperations don't need to check for terminal state - // on originalOperation result, always need to poll - return false; - } - - const { status = "succeeded" } = currentResult; - return terminalStates.includes(status.toLowerCase()); - }, - sendFinalRequest: async () => { - if (!initialOperation.result._lroData) { - throw new Error("Expected lroData to determine terminal status"); - } - - if (!currentOperation.result._lroData) { - throw new Error("Expected lroData to determine terminal status"); - } - - const initialOperationResult = initialOperation.result._lroData; - const currentOperationResult = currentOperation.result._lroData; - - if ( - !shouldPerformFinalGet(initialOperationResult, currentOperationResult) - ) { - return currentOperation; - } - - if (initialOperationResult.requestMethod === "PUT") { - currentOperation = await sendFinalGet( - initialOperation, - sendOperationFn - ); - - return currentOperation; - } - - if (initialOperationResult.location) { - switch (finalStateVia) { - case "original-uri": - currentOperation = await sendFinalGet( - initialOperation, - sendOperationFn - ); - return currentOperation; - - case "azure-async-operation": - return currentOperation; - case "location": - default: - const location = - initialOperationResult.location || - currentOperationResult.location; - - if (!location) { - throw new Error("Couldn't determine final GET URL from location"); - } - - return await sendFinalGet( - initialOperation, - sendOperationFn, - location - ); - } - } - - // All other cases return the last operation - return currentOperation; - }, - poll: async () => { - if (!lastKnownPollingUrl) { - throw new Error("Unable to determine polling url"); - } - - const pollingArgs = currentOperation.args; - // Make sure we don't send any body to the get request - const { requestBody, ...restSpec } = currentOperation.spec; - const pollingSpec: OperationSpec = { - ...restSpec, - httpMethod: "GET", - path: lastKnownPollingUrl - }; - - const result = await sendOperationFn(pollingArgs, pollingSpec); - - // Update latest polling url - lastKnownPollingUrl = - result._lroData?.azureAsyncOperation || - result._lroData?.operationLocation || - lastKnownPollingUrl; - - // Update lastOperation result - currentOperation = { - args: pollingArgs, - spec: pollingSpec, - result - }; - - return currentOperation; - } - }; -} - -function shouldPerformFinalGet( - initialResult: LROResponseInfo, - currentResult: LROResponseInfo -) { - const { status } = currentResult; - const { requestMethod: initialRequestMethod, location } = initialResult; - if (status && status.toLowerCase() !== "succeeded") { - return false; - } - - if (initialRequestMethod === "DELETE") { - return false; - } - - if (initialRequestMethod !== "PUT" && !location) { - return false; - } - - return true; -} - -async function sendFinalGet( - initialOperation: LROOperationStep, - sendOperationFn: SendOperationFn, - path?: string -): Promise> { - // Make sure we don't send any body to the get request - const { requestBody, ...restSpec } = initialOperation.spec; - const finalGetSpec: OperationSpec = { - ...restSpec, - httpMethod: "GET" - }; - - // Send final GET request to the Original URL - const spec = { - ...finalGetSpec, - ...(path && { path }) - }; - - let operationArgs: OperationArguments = initialOperation.args; - if (operationArgs.options) { - operationArgs.options.shouldDeserialize = true; - } - - const finalResult = await sendOperationFn(initialOperation.args, spec); - - return { - args: initialOperation.args, - spec, - result: finalResult - }; -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/bodyPollingStrategy.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/bodyPollingStrategy.ts deleted file mode 100644 index 35cc6bac2a3a..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/bodyPollingStrategy.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { LROStrategy, BaseResult, LROOperationStep } from "./models"; -import { OperationSpec } from "@azure/core-http"; -import { terminalStates } from "./constants"; -import { SendOperationFn } from "./lroPoller"; - -/** - * Creates a polling strategy based on BodyPolling which uses the provisioning state - * from the result to determine the current operation state - */ -export function createBodyPollingStrategy( - initialOperation: LROOperationStep, - sendOperation: SendOperationFn -): LROStrategy { - if (!initialOperation.result._lroData) { - throw new Error("Expected lroData to be defined for BodyPolling strategy"); - } - - let currentOperation = initialOperation; - - return { - isTerminal: () => { - const currentResult = currentOperation.result._lroData; - if (!currentResult) { - throw new Error("Expected lroData to determine terminal status"); - } - - const { provisioningState = "succeeded" } = currentResult; - // If provisioning state is missing, default to Success - - return terminalStates.includes(provisioningState.toLowerCase()); - }, - sendFinalRequest: () => { - // BodyPolling doesn't require a final get so return the lastOperation - return Promise.resolve(currentOperation); - }, - poll: async () => { - // When doing BodyPolling, we need to poll to the original url with a - // GET http method - const { requestBody, ...restSpec } = initialOperation.spec; - const pollingSpec: OperationSpec = { - // Make sure we don't send any body to the get request - ...restSpec, - httpMethod: "GET" - }; - - // Execute the polling operation - initialOperation.result = await sendOperation( - initialOperation.args, - pollingSpec - ); - return initialOperation; - } - }; -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/constants.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/constants.ts deleted file mode 100644 index fa0ee2d9942c..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/constants.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -export const terminalStates = ["succeeded", "failed", "canceled", "cancelled"]; diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/index.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/index.ts deleted file mode 100644 index f605ce7ee356..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -export { shouldDeserializeLRO } from "./requestUtils"; -export { createBodyPollingStrategy } from "./bodyPollingStrategy"; -export { terminalStates } from "./constants"; -export { lroPolicy } from "./lroPolicy"; -export { LROPoller, LROPollerOptions, SendOperationFn } from "./lroPoller"; -export { - LROResponseInfo, - BaseResult, - LROOperationStep, - LROOperationState, - LROStrategy, - LROOperation -} from "./models"; -export { makeOperation } from "./operation"; -export * from "./locationStrategy"; diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/locationStrategy.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/locationStrategy.ts deleted file mode 100644 index 1a5c8d462eac..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/locationStrategy.ts +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { BaseResult, LROOperationStep, LROStrategy } from "./models"; -import { SendOperationFn } from "./lroPoller"; -import { OperationSpec } from "@azure/core-http"; - -export function createLocationStrategy( - initialOperation: LROOperationStep, - sendOperationFn: SendOperationFn -): LROStrategy { - const lroData = initialOperation.result._lroData; - if (!lroData) { - throw new Error( - "Expected lroData to be defined for Azure-AsyncOperation strategy" - ); - } - - let currentOperation = initialOperation; - let lastKnownPollingUrl = lroData.location; - - return { - isTerminal: () => { - const currentResult = currentOperation.result._lroData; - if (!currentResult) { - throw new Error("Expected lroData to determine terminal status"); - } - - if (currentOperation === initialOperation) { - return false; - } - - if (currentResult.statusCode === 202) { - return false; - } - - return true; - }, - sendFinalRequest: () => Promise.resolve(currentOperation), - poll: async () => { - if (!lastKnownPollingUrl) { - throw new Error("Unable to determine polling url"); - } - - const pollingArgs = currentOperation.args; - // Make sure we don't send any body to the get request - const { requestBody, ...restSpec } = currentOperation.spec; - const pollingSpec: OperationSpec = { - ...restSpec, - httpMethod: "GET", - path: lastKnownPollingUrl - }; - - const result = await sendOperationFn(pollingArgs, pollingSpec); - - // Update latest polling url - lastKnownPollingUrl = result._lroData?.location || lastKnownPollingUrl; - - // Update lastOperation result - currentOperation = { - args: pollingArgs, - spec: pollingSpec, - result - }; - - return currentOperation; - } - }; -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/lroPolicy.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/lroPolicy.ts deleted file mode 100644 index 0591f541b30a..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/lroPolicy.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { - RequestPolicy, - RequestPolicyOptions, - BaseRequestPolicy, - HttpOperationResponse, - WebResource -} from "@azure/core-http"; -import { getLROData } from "./requestUtils"; - -export function lroPolicy() { - return { - create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => { - return new LROPolicy(nextPolicy, options); - } - }; -} - -class LROPolicy extends BaseRequestPolicy { - constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions) { - super(nextPolicy, options); - } - - public async sendRequest( - webResource: WebResource - ): Promise { - let result = await this._nextPolicy.sendRequest(webResource); - - if (webResource.shouldDeserialize !== undefined) { - const _lroData = getLROData(result); - result.parsedBody = { ...result.parsedBody, _lroData }; - } - - return result; - } -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/lroPoller.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/lroPoller.ts deleted file mode 100644 index bc2f2aa05a24..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/lroPoller.ts +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { Poller } from "@azure/core-lro"; -import { - OperationSpec, - OperationArguments, - delay, - RestError -} from "@azure/core-http"; -import { - BaseResult, - LROOperationState, - LROOperationStep, - FinalStateVia -} from "./models"; -import { makeOperation } from "./operation"; -import { createBodyPollingStrategy } from "./bodyPollingStrategy"; -import { createAzureAsyncOperationStrategy } from "./azureAsyncOperationStrategy"; -import { createLocationStrategy } from "./locationStrategy"; -import { createPassthroughStrategy } from "./passthroughStrategy"; - -export type SendOperationFn = ( - args: OperationArguments, - spec: OperationSpec -) => Promise; - -export interface LROPollerOptions { - /** - * Defines how much time the poller is going to wait before making a new request to the service. - */ - intervalInMs?: number; - /** - * Arguments used to send the initial operation - */ - initialOperationArguments: OperationArguments; - /** - * Operation spec provided for the initial operation - */ - initialOperationSpec: OperationSpec; - /** - * Result from the initial operation - */ - initialOperationResult: TResult; - /** - * Function to execute an operation based on an operation spec and arguments - */ - sendOperation: SendOperationFn; - /** - * Optional information on where to poll. When not defined it defaults to "Location" - */ - finalStateVia?: FinalStateVia; -} - -export class LROPoller extends Poller< - LROOperationState, - TResult -> { - private intervalInMs: number; - - constructor({ - initialOperationArguments, - initialOperationResult, - initialOperationSpec, - sendOperation, - finalStateVia, - intervalInMs = 2000 - }: LROPollerOptions) { - const initialOperation = { - args: initialOperationArguments, - spec: initialOperationSpec, - result: initialOperationResult - }; - - const pollingStrategy = getPollingStrategy( - initialOperation, - sendOperation, - finalStateVia - ); - - const state: LROOperationState = { - // Initial operation will become the last operation - initialOperation, - lastOperation: initialOperation, - pollingStrategy, - finalStateVia - }; - - const operation = makeOperation(state); - super(operation); - - this.intervalInMs = intervalInMs; - } - - /** - * The method used by the poller to wait before attempting to update its operation. - */ - delay(): Promise { - return delay(this.intervalInMs); - } -} - -/** - * This function determines which strategy to use based on the response from - * the last operation executed, this last operation can be an initial operation - * or a polling operation. The 3 possible strategies are described below: - * - * A) Azure-AsyncOperation or Operation-Location - * B) Location - * C) BodyPolling (provisioningState) - * - This strategy is used when: - * - Response doesn't contain any of the following headers Location, Azure-AsyncOperation or Operation-Location - * - Last operation method is PUT - */ -function getPollingStrategy( - initialOperation: LROOperationStep, - sendOperationFn: SendOperationFn, - finalStateVia?: FinalStateVia -) { - const lroData = initialOperation.result._lroData; - - if (!lroData) { - const error = new RestError( - "Service response doesn't include the required LRO data to continue polling" - ); - error.statusCode = initialOperation.result._response.status; - error.response = initialOperation.result._response; - throw error; - } - - if (lroData.azureAsyncOperation || lroData.operationLocation) { - return createAzureAsyncOperationStrategy( - initialOperation, - sendOperationFn, - finalStateVia - ); - } - - if (lroData.location) { - return createLocationStrategy(initialOperation, sendOperationFn); - } - - if (["PUT", "PATCH"].includes(lroData.requestMethod || "")) { - return createBodyPollingStrategy(initialOperation, sendOperationFn); - } - - // Default strategy is just a passthrough returning the initial operation - return createPassthroughStrategy(initialOperation); -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/models.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/models.ts deleted file mode 100644 index a90afc5b41de..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/models.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { - OperationArguments, - OperationSpec, - RestResponse, - HttpMethods -} from "@azure/core-http"; -import { PollOperationState, PollOperation } from "@azure/core-lro"; - -export type FinalStateVia = - | "azure-async-operation" - | "location" - | "original-uri"; - -export interface LROResponseInfo { - requestMethod: HttpMethods; - statusCode: number; - isInitialRequest?: boolean; - azureAsyncOperation?: string; - operationLocation?: string; - location?: string; - provisioningState?: string; - status?: string; -} - -export interface BaseResult extends RestResponse { - _lroData?: LROResponseInfo; -} - -export interface LROOperationStep { - args: OperationArguments; - spec: OperationSpec; - result: TResult; -} - -export interface LROOperationState - extends PollOperationState { - lastOperation: LROOperationStep; - initialOperation: LROOperationStep; - pollingStrategy: LROStrategy; - finalStateVia?: FinalStateVia; -} - -export interface LROStrategy { - isTerminal: () => boolean; - sendFinalRequest: () => Promise>; - poll: () => Promise>; -} - -export type LROOperation = PollOperation< - LROOperationState, - TResult ->; diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/operation.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/operation.ts deleted file mode 100644 index 9cda560a0212..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/operation.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { BaseResult, LROOperationState, LROOperation } from "./models"; - -/** - * Creates a copy of the operation from a given State - */ -export function makeOperation( - state: LROOperationState -): LROOperation { - return { - state: { ...state }, - update, - cancel, - toString: function(this: LROOperation) { - return JSON.stringify(this.state); - } - }; -} - -/** - * General update function for LROPoller, the general process is as follows - * 1. Check initial operation result to determine the strategy to use - * - Strategies: Location, Azure-AsyncOperation, Original Uri - * 2. Check if the operation result has a terminal state - * - Terminal state will be determined by each strategy - * 2.1 If it is terminal state Check if a final GET request is required, if so - * send final GET request and return result from operation. If no final GET - * is required, just return the result from operation. - * - Determining what to call for final request is responsibility of each strategy - * 2.2 If it is not terminal state, call the polling operation call it and go to step 1 - * - Determining what to call for polling is responsibility of each strategy - * - Strategies will always use the latest URI for polling if provided otherwise - * the last known one - */ -async function update( - this: LROOperation -): Promise> { - const state = { ...this.state }; - - const { sendFinalRequest, poll, isTerminal } = state.pollingStrategy; - const currentResponse = state.lastOperation; - const currentLroData = currentResponse.result._lroData; - - if (!currentLroData) { - throw new Error( - "Expected lroData to be defined for updating LRO operation" - ); - } - - if (state.result) { - state.isCompleted = true; - return makeOperation(state); - } - - // Check if last result is terminal - if (isTerminal()) { - state.lastOperation = await sendFinalRequest(); - state.result = state.lastOperation.result; - } else { - state.lastOperation = await poll(); - } - - // Return operation - return makeOperation(state); -} - -/** - * Swagger doesn't support defining a cancel operation, we'll just mark - * the operation state as cancelled - */ -async function cancel( - this: LROOperation -): Promise> { - return makeOperation({ ...this.state, isCancelled: true }); -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/passthroughStrategy.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/passthroughStrategy.ts deleted file mode 100644 index 23342c2e4ec7..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/passthroughStrategy.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { LROStrategy, BaseResult, LROOperationStep } from "./models"; - -/** - * Creates a polling strategy based on BodyPolling which uses the provisioning state - * from the result to determine the current operation state - */ -export function createPassthroughStrategy( - initialOperation: LROOperationStep -): LROStrategy { - return { - isTerminal: () => { - return true; - }, - sendFinalRequest: () => { - // BodyPolling doesn't require a final get so return the lastOperation - return Promise.resolve(initialOperation); - }, - poll: async () => { - throw new Error("Passthrough strategy should never poll"); - } - }; -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/lro/requestUtils.ts b/sdk/keyvault/keyvault-admin/src/generated/lro/requestUtils.ts deleted file mode 100644 index e9af4cde5e25..000000000000 --- a/sdk/keyvault/keyvault-admin/src/generated/lro/requestUtils.ts +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - * Changes may cause incorrect behavior and will be lost if the code is regenerated. - */ - -import { HttpOperationResponse } from "@azure/core-http"; -import { terminalStates } from "./constants"; -import { LROResponseInfo } from "./models"; - -/** - * We need to selectively deserialize our responses, only deserializing if we - * are in a final LRO response, not deserializing any polling non-terminal responses - */ -export function shouldDeserializeLRO(finalStateVia?: string) { - let initialOperationInfo: LROResponseInfo | undefined; - let isInitialRequest = true; - - return (response: HttpOperationResponse) => { - if (response.status < 200 || response.status >= 300) { - return true; - } - - if (!initialOperationInfo) { - initialOperationInfo = getLROData(response); - } else { - isInitialRequest = false; - } - - if ( - initialOperationInfo.azureAsyncOperation || - initialOperationInfo.operationLocation - ) { - return ( - !isInitialRequest && - isAsyncOperationFinalResponse( - response, - initialOperationInfo, - finalStateVia - ) - ); - } - - if (initialOperationInfo.location) { - return isLocationFinalResponse(response); - } - - if (initialOperationInfo.requestMethod === "PUT") { - return isBodyPollingFinalResponse(response); - } - - return true; - }; -} - -function isAsyncOperationFinalResponse( - response: HttpOperationResponse, - initialOperationInfo: LROResponseInfo, - finalStateVia?: string -): boolean { - const status: string = response.parsedBody?.status || "Succeeded"; - if (!terminalStates.includes(status.toLowerCase())) { - return false; - } - - if (initialOperationInfo.requestMethod === "DELETE") { - return true; - } - - if ( - initialOperationInfo.requestMethod === "PUT" && - finalStateVia && - finalStateVia.toLowerCase() === "azure-asyncoperation" - ) { - return true; - } - - if ( - initialOperationInfo.requestMethod !== "PUT" && - !initialOperationInfo.location - ) { - return true; - } - - return false; -} - -function isLocationFinalResponse(response: HttpOperationResponse): boolean { - return response.status !== 202; -} - -function isBodyPollingFinalResponse(response: HttpOperationResponse): boolean { - const provisioningState: string = - response.parsedBody?.properties?.provisioningState || "Succeeded"; - - if (terminalStates.includes(provisioningState.toLowerCase())) { - return true; - } - - return false; -} - -export function getLROData(result: HttpOperationResponse): LROResponseInfo { - const statusCode = result.status; - const { status, properties } = result.parsedBody || {}; - return { - statusCode, - azureAsyncOperation: result.headers.get("azure-asyncoperation"), - operationLocation: result.headers.get("operation-location"), - location: result.headers.get("location"), - requestMethod: result.request.method, - status, - provisioningState: properties?.provisioningState - }; -} diff --git a/sdk/keyvault/keyvault-admin/src/generated/models/index.ts b/sdk/keyvault/keyvault-admin/src/generated/models/index.ts index 171d758142ae..aed423362463 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/models/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/models/index.ts @@ -6,7 +6,7 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; /** The key vault error exception. */ export interface KeyVaultError { @@ -265,6 +265,21 @@ export interface KeyVaultClientSelectiveKeyRestoreOperationHeaders { azureAsyncOperation?: string; } +/** Known values of {@link ApiVersion72} that the service accepts. */ +export const enum KnownApiVersion72 { + /** Api Version '7.2' */ + Seven2 = "7.2" +} + +/** + * Defines values for ApiVersion72. \ + * {@link KnownApiVersion72} can be used interchangeably with ApiVersion72, + * this enum contains the known values that the service supports. + * ### Known values supported by the service + * **7.2**: Api Version '7.2' + */ +export type ApiVersion72 = string; + /** Known values of {@link RoleType} that the service accepts. */ export const enum KnownRoleType { /** Built in role. */ @@ -277,16 +292,14 @@ export const enum KnownRoleType { * Defines values for RoleType. \ * {@link KnownRoleType} can be used interchangeably with RoleType, * this enum contains the known values that the service supports. - * ### Know values supported by the service + * ### Known values supported by the service * **AKVBuiltInRole**: Built in role. \ * **CustomRole**: Custom role. */ export type RoleType = string; /** Known values of {@link DataAction} that the service accepts. */ -// Note: `const` keyword removed manually while we discuss the generated code -// in https://github.com/Azure/autorest.typescript/issues/1013 -export enum KnownDataAction { +export const enum KnownDataAction { /** Read HSM key metadata. */ ReadHsmKey = "Microsoft.KeyVault/managedHsm/keys/read/action", /** Update an HSM key. */ @@ -351,7 +364,7 @@ export enum KnownDataAction { * Defines values for DataAction. \ * {@link KnownDataAction} can be used interchangeably with DataAction, * this enum contains the known values that the service supports. - * ### Know values supported by the service + * ### Known values supported by the service * **Microsoft.KeyVault\/managedHsm\/keys\/read\/action**: Read HSM key metadata. \ * **Microsoft.KeyVault\/managedHsm\/keys\/write\/action**: Update an HSM key. \ * **Microsoft.KeyVault\/managedHsm\/keys\/deletedKeys\/read\/action**: Read deleted HSM key. \ @@ -385,9 +398,7 @@ export enum KnownDataAction { export type DataAction = string; /** Known values of {@link RoleScope} that the service accepts. */ -// Note: `const` keyword removed manually while we discuss the generated code -// in https://github.com/Azure/autorest.typescript/issues/1013 -export enum KnownRoleScope { +export const enum KnownRoleScope { /** Global scope */ Global = "/", /** Keys scope */ @@ -398,7 +409,7 @@ export enum KnownRoleScope { * Defines values for RoleScope. \ * {@link KnownRoleScope} can be used interchangeably with RoleScope, * this enum contains the known values that the service supports. - * ### Know values supported by the service + * ### Known values supported by the service * **\/**: Global scope \ * **\/keys**: Keys scope */ @@ -413,248 +424,137 @@ export const enum KnownRoleDefinitionType { * Defines values for RoleDefinitionType. \ * {@link KnownRoleDefinitionType} can be used interchangeably with RoleDefinitionType, * this enum contains the known values that the service supports. - * ### Know values supported by the service + * ### Known values supported by the service * **Microsoft.Authorization\/roleDefinitions** */ export type RoleDefinitionType = string; /** Optional parameters. */ -export interface RoleDefinitionsDeleteOptionalParams extends coreHttp.OperationOptions {} +export interface RoleDefinitionsDeleteOptionalParams + extends coreClient.OperationOptions {} /** Optional parameters. */ -export interface RoleDefinitionsCreateOrUpdateOptionalParams extends coreHttp.OperationOptions {} +export interface RoleDefinitionsCreateOrUpdateOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the createOrUpdate operation. */ -export type RoleDefinitionsCreateOrUpdateResponse = RoleDefinition & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleDefinition; - }; -}; +export type RoleDefinitionsCreateOrUpdateResponse = RoleDefinition; /** Optional parameters. */ -export interface RoleDefinitionsGetOptionalParams extends coreHttp.OperationOptions {} +export interface RoleDefinitionsGetOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the get operation. */ -export type RoleDefinitionsGetResponse = RoleDefinition & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleDefinition; - }; -}; +export type RoleDefinitionsGetResponse = RoleDefinition; /** Optional parameters. */ -export interface RoleDefinitionsListOptionalParams extends coreHttp.OperationOptions { +export interface RoleDefinitionsListOptionalParams + extends coreClient.OperationOptions { /** The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as well. */ filter?: string; } /** Contains response data for the list operation. */ -export type RoleDefinitionsListResponse = RoleDefinitionListResult & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleDefinitionListResult; - }; -}; +export type RoleDefinitionsListResponse = RoleDefinitionListResult; /** Optional parameters. */ -export interface RoleDefinitionsListNextOptionalParams extends coreHttp.OperationOptions { +export interface RoleDefinitionsListNextOptionalParams + extends coreClient.OperationOptions { /** The filter to apply on the operation. Use atScopeAndBelow filter to search below the given scope as well. */ filter?: string; } /** Contains response data for the listNext operation. */ -export type RoleDefinitionsListNextResponse = RoleDefinitionListResult & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleDefinitionListResult; - }; -}; +export type RoleDefinitionsListNextResponse = RoleDefinitionListResult; /** Optional parameters. */ -export interface RoleAssignmentsDeleteOptionalParams extends coreHttp.OperationOptions {} +export interface RoleAssignmentsDeleteOptionalParams + extends coreClient.OperationOptions {} /** Optional parameters. */ -export interface RoleAssignmentsCreateOptionalParams extends coreHttp.OperationOptions {} +export interface RoleAssignmentsCreateOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the create operation. */ -export type RoleAssignmentsCreateResponse = RoleAssignment & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleAssignment; - }; -}; +export type RoleAssignmentsCreateResponse = RoleAssignment; /** Optional parameters. */ -export interface RoleAssignmentsGetOptionalParams extends coreHttp.OperationOptions {} +export interface RoleAssignmentsGetOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the get operation. */ -export type RoleAssignmentsGetResponse = RoleAssignment & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleAssignment; - }; -}; +export type RoleAssignmentsGetResponse = RoleAssignment; /** Optional parameters. */ -export interface RoleAssignmentsListForScopeOptionalParams extends coreHttp.OperationOptions { +export interface RoleAssignmentsListForScopeOptionalParams + extends coreClient.OperationOptions { /** The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope for the specified principal. */ filter?: string; } /** Contains response data for the listForScope operation. */ -export type RoleAssignmentsListForScopeResponse = RoleAssignmentListResult & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleAssignmentListResult; - }; -}; +export type RoleAssignmentsListForScopeResponse = RoleAssignmentListResult; /** Optional parameters. */ -export interface RoleAssignmentsListForScopeNextOptionalParams extends coreHttp.OperationOptions { +export interface RoleAssignmentsListForScopeNextOptionalParams + extends coreClient.OperationOptions { /** The filter to apply on the operation. Use $filter=atScope() to return all role assignments at or above the scope. Use $filter=principalId eq {id} to return all role assignments at, above or below the scope for the specified principal. */ filter?: string; } /** Contains response data for the listForScopeNext operation. */ -export type RoleAssignmentsListForScopeNextResponse = RoleAssignmentListResult & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RoleAssignmentListResult; - }; -}; +export type RoleAssignmentsListForScopeNextResponse = RoleAssignmentListResult; /** Optional parameters. */ -export interface KeyVaultClientFullBackupOptionalParams extends coreHttp.OperationOptions { +export interface KeyVaultClientFullBackupOptionalParams + extends coreClient.OperationOptions { /** Azure blob shared access signature token pointing to a valid Azure blob container where full backup needs to be stored. This token needs to be valid for at least next 24 hours from the time of making this call */ azureStorageBlobContainerUri?: SASTokenParameter; } /** Contains response data for the fullBackup operation. */ export type KeyVaultClientFullBackupResponse = KeyVaultClientFullBackupHeaders & - FullBackupOperation & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: FullBackupOperation; - /** The parsed HTTP response headers. */ - parsedHeaders: KeyVaultClientFullBackupHeaders; - }; - }; + FullBackupOperation; /** Optional parameters. */ -export interface KeyVaultClientFullBackupStatusOptionalParams extends coreHttp.OperationOptions {} +export interface KeyVaultClientFullBackupStatusOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the fullBackupStatus operation. */ -export type KeyVaultClientFullBackupStatusResponse = FullBackupOperation & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: FullBackupOperation; - }; -}; +export type KeyVaultClientFullBackupStatusResponse = FullBackupOperation; /** Optional parameters. */ export interface KeyVaultClientFullRestoreOperationOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The Azure blob SAS token pointing to a folder where the previous successful full backup was stored */ restoreBlobDetails?: RestoreOperationParameters; } /** Contains response data for the fullRestoreOperation operation. */ export type KeyVaultClientFullRestoreOperationResponse = KeyVaultClientFullRestoreOperationHeaders & - RestoreOperation & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RestoreOperation; - /** The parsed HTTP response headers. */ - parsedHeaders: KeyVaultClientFullRestoreOperationHeaders; - }; - }; + RestoreOperation; /** Optional parameters. */ -export interface KeyVaultClientRestoreStatusOptionalParams extends coreHttp.OperationOptions {} +export interface KeyVaultClientRestoreStatusOptionalParams + extends coreClient.OperationOptions {} /** Contains response data for the restoreStatus operation. */ -export type KeyVaultClientRestoreStatusResponse = RestoreOperation & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: RestoreOperation; - }; -}; +export type KeyVaultClientRestoreStatusResponse = RestoreOperation; /** Optional parameters. */ export interface KeyVaultClientSelectiveKeyRestoreOperationOptionalParams - extends coreHttp.OperationOptions { + extends coreClient.OperationOptions { /** The Azure blob SAS token pointing to a folder where the previous successful full backup was stored */ restoreBlobDetails?: SelectiveKeyRestoreOperationParameters; } /** Contains response data for the selectiveKeyRestoreOperation operation. */ export type KeyVaultClientSelectiveKeyRestoreOperationResponse = KeyVaultClientSelectiveKeyRestoreOperationHeaders & - SelectiveKeyRestoreOperation & { - /** The underlying HTTP response. */ - _response: coreHttp.HttpResponse & { - /** The response body as text (string format) */ - bodyAsText: string; - - /** The response body as parsed JSON or XML */ - parsedBody: SelectiveKeyRestoreOperation; - /** The parsed HTTP response headers. */ - parsedHeaders: KeyVaultClientSelectiveKeyRestoreOperationHeaders; - }; - }; + SelectiveKeyRestoreOperation; /** Optional parameters. */ -export interface KeyVaultClientOptionalParams extends coreHttp.ServiceClientOptions { - /** Api Version */ - apiVersion?: string; +export interface KeyVaultClientOptionalParams + extends coreClient.ServiceClientOptions { /** Overrides client endpoint. */ endpoint?: string; } diff --git a/sdk/keyvault/keyvault-admin/src/generated/models/mappers.ts b/sdk/keyvault/keyvault-admin/src/generated/models/mappers.ts index daa76065ddef..099d0f44b0d2 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/models/mappers.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/models/mappers.ts @@ -6,9 +6,9 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; -export const KeyVaultError: coreHttp.CompositeMapper = { +export const KeyVaultError: coreClient.CompositeMapper = { type: { name: "Composite", className: "KeyVaultError", @@ -24,7 +24,7 @@ export const KeyVaultError: coreHttp.CompositeMapper = { } }; -export const ErrorModel: coreHttp.CompositeMapper = { +export const ErrorModel: coreClient.CompositeMapper = { type: { name: "Composite", className: "ErrorModel", @@ -54,7 +54,7 @@ export const ErrorModel: coreHttp.CompositeMapper = { } }; -export const RoleDefinitionCreateParameters: coreHttp.CompositeMapper = { +export const RoleDefinitionCreateParameters: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleDefinitionCreateParameters", @@ -70,7 +70,7 @@ export const RoleDefinitionCreateParameters: coreHttp.CompositeMapper = { } }; -export const RoleDefinitionProperties: coreHttp.CompositeMapper = { +export const RoleDefinitionProperties: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleDefinitionProperties", @@ -120,7 +120,7 @@ export const RoleDefinitionProperties: coreHttp.CompositeMapper = { } }; -export const Permission: coreHttp.CompositeMapper = { +export const Permission: coreClient.CompositeMapper = { type: { name: "Composite", className: "Permission", @@ -173,7 +173,7 @@ export const Permission: coreHttp.CompositeMapper = { } }; -export const RoleDefinition: coreHttp.CompositeMapper = { +export const RoleDefinition: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleDefinition", @@ -244,7 +244,7 @@ export const RoleDefinition: coreHttp.CompositeMapper = { } }; -export const RoleDefinitionListResult: coreHttp.CompositeMapper = { +export const RoleDefinitionListResult: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleDefinitionListResult", @@ -271,7 +271,7 @@ export const RoleDefinitionListResult: coreHttp.CompositeMapper = { } }; -export const RoleAssignmentCreateParameters: coreHttp.CompositeMapper = { +export const RoleAssignmentCreateParameters: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleAssignmentCreateParameters", @@ -287,7 +287,7 @@ export const RoleAssignmentCreateParameters: coreHttp.CompositeMapper = { } }; -export const RoleAssignmentProperties: coreHttp.CompositeMapper = { +export const RoleAssignmentProperties: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleAssignmentProperties", @@ -310,7 +310,7 @@ export const RoleAssignmentProperties: coreHttp.CompositeMapper = { } }; -export const RoleAssignment: coreHttp.CompositeMapper = { +export const RoleAssignment: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleAssignment", @@ -347,7 +347,7 @@ export const RoleAssignment: coreHttp.CompositeMapper = { } }; -export const RoleAssignmentPropertiesWithScope: coreHttp.CompositeMapper = { +export const RoleAssignmentPropertiesWithScope: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleAssignmentPropertiesWithScope", @@ -374,7 +374,7 @@ export const RoleAssignmentPropertiesWithScope: coreHttp.CompositeMapper = { } }; -export const RoleAssignmentListResult: coreHttp.CompositeMapper = { +export const RoleAssignmentListResult: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleAssignmentListResult", @@ -401,7 +401,7 @@ export const RoleAssignmentListResult: coreHttp.CompositeMapper = { } }; -export const SASTokenParameter: coreHttp.CompositeMapper = { +export const SASTokenParameter: coreClient.CompositeMapper = { type: { name: "Composite", className: "SASTokenParameter", @@ -424,7 +424,7 @@ export const SASTokenParameter: coreHttp.CompositeMapper = { } }; -export const FullBackupOperation: coreHttp.CompositeMapper = { +export const FullBackupOperation: coreClient.CompositeMapper = { type: { name: "Composite", className: "FullBackupOperation", @@ -477,7 +477,7 @@ export const FullBackupOperation: coreHttp.CompositeMapper = { } }; -export const RestoreOperationParameters: coreHttp.CompositeMapper = { +export const RestoreOperationParameters: coreClient.CompositeMapper = { type: { name: "Composite", className: "RestoreOperationParameters", @@ -500,7 +500,7 @@ export const RestoreOperationParameters: coreHttp.CompositeMapper = { } }; -export const RestoreOperation: coreHttp.CompositeMapper = { +export const RestoreOperation: coreClient.CompositeMapper = { type: { name: "Composite", className: "RestoreOperation", @@ -547,7 +547,7 @@ export const RestoreOperation: coreHttp.CompositeMapper = { } }; -export const SelectiveKeyRestoreOperationParameters: coreHttp.CompositeMapper = { +export const SelectiveKeyRestoreOperationParameters: coreClient.CompositeMapper = { type: { name: "Composite", className: "SelectiveKeyRestoreOperationParameters", @@ -570,7 +570,7 @@ export const SelectiveKeyRestoreOperationParameters: coreHttp.CompositeMapper = } }; -export const SelectiveKeyRestoreOperation: coreHttp.CompositeMapper = { +export const SelectiveKeyRestoreOperation: coreClient.CompositeMapper = { type: { name: "Composite", className: "SelectiveKeyRestoreOperation", @@ -617,7 +617,7 @@ export const SelectiveKeyRestoreOperation: coreHttp.CompositeMapper = { } }; -export const RoleAssignmentFilter: coreHttp.CompositeMapper = { +export const RoleAssignmentFilter: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleAssignmentFilter", @@ -632,7 +632,7 @@ export const RoleAssignmentFilter: coreHttp.CompositeMapper = { } }; -export const RoleDefinitionFilter: coreHttp.CompositeMapper = { +export const RoleDefinitionFilter: coreClient.CompositeMapper = { type: { name: "Composite", className: "RoleDefinitionFilter", @@ -647,7 +647,7 @@ export const RoleDefinitionFilter: coreHttp.CompositeMapper = { } }; -export const KeyVaultClientFullBackupHeaders: coreHttp.CompositeMapper = { +export const KeyVaultClientFullBackupHeaders: coreClient.CompositeMapper = { type: { name: "Composite", className: "KeyVaultClientFullBackupHeaders", @@ -668,7 +668,7 @@ export const KeyVaultClientFullBackupHeaders: coreHttp.CompositeMapper = { } }; -export const KeyVaultClientFullRestoreOperationHeaders: coreHttp.CompositeMapper = { +export const KeyVaultClientFullRestoreOperationHeaders: coreClient.CompositeMapper = { type: { name: "Composite", className: "KeyVaultClientFullRestoreOperationHeaders", @@ -689,7 +689,7 @@ export const KeyVaultClientFullRestoreOperationHeaders: coreHttp.CompositeMapper } }; -export const KeyVaultClientSelectiveKeyRestoreOperationHeaders: coreHttp.CompositeMapper = { +export const KeyVaultClientSelectiveKeyRestoreOperationHeaders: coreClient.CompositeMapper = { type: { name: "Composite", className: "KeyVaultClientSelectiveKeyRestoreOperationHeaders", diff --git a/sdk/keyvault/keyvault-admin/src/generated/models/parameters.ts b/sdk/keyvault/keyvault-admin/src/generated/models/parameters.ts index 8a7e76e13804..c5208248fc46 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/models/parameters.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/models/parameters.ts @@ -10,7 +10,7 @@ import { OperationParameter, OperationURLParameter, OperationQueryParameter -} from "@azure/core-http"; +} from "@azure/core-client"; import { RoleDefinitionCreateParameters as RoleDefinitionCreateParametersMapper, RoleAssignmentCreateParameters as RoleAssignmentCreateParametersMapper, @@ -69,9 +69,8 @@ export const roleDefinitionName: OperationURLParameter = { export const apiVersion: OperationQueryParameter = { parameterPath: "apiVersion", mapper: { - defaultValue: "7.2", - isConstant: true, serializedName: "api-version", + required: true, type: { name: "String" } diff --git a/sdk/keyvault/keyvault-admin/src/generated/operations/roleAssignments.ts b/sdk/keyvault/keyvault-admin/src/generated/operations/roleAssignments.ts index 4472cf352b37..859d36f215e1 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/operations/roleAssignments.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/operations/roleAssignments.ts @@ -7,7 +7,7 @@ */ import { RoleAssignments } from "../operationsInterfaces"; -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { KeyVaultClientContext } from "../keyVaultClientContext"; @@ -48,17 +48,11 @@ export class RoleAssignmentsImpl implements RoleAssignments { scope: string, roleAssignmentName: string, options?: RoleAssignmentsDeleteOptionalParams - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - roleAssignmentName, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, roleAssignmentName, options }, deleteOperationSpec - ) as Promise; + ); } /** @@ -76,17 +70,10 @@ export class RoleAssignmentsImpl implements RoleAssignments { parameters: RoleAssignmentCreateParameters, options?: RoleAssignmentsCreateOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - roleAssignmentName, - parameters, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, roleAssignmentName, parameters, options }, createOperationSpec - ) as Promise; + ); } /** @@ -102,16 +89,10 @@ export class RoleAssignmentsImpl implements RoleAssignments { roleAssignmentName: string, options?: RoleAssignmentsGetOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - roleAssignmentName, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, roleAssignmentName, options }, getOperationSpec - ) as Promise; + ); } /** @@ -125,15 +106,10 @@ export class RoleAssignmentsImpl implements RoleAssignments { scope: string, options?: RoleAssignmentsListForScopeOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, options }, listForScopeOperationSpec - ) as Promise; + ); } /** @@ -149,22 +125,16 @@ export class RoleAssignmentsImpl implements RoleAssignments { nextLink: string, options?: RoleAssignmentsListForScopeNextOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - nextLink, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, nextLink, options }, listForScopeNextOperationSpec - ) as Promise; + ); } } // Operation Specifications -const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); -const deleteOperationSpec: coreHttp.OperationSpec = { +const deleteOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}", httpMethod: "DELETE", @@ -184,7 +154,7 @@ const deleteOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const createOperationSpec: coreHttp.OperationSpec = { +const createOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}", httpMethod: "PUT", @@ -207,7 +177,7 @@ const createOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const getOperationSpec: coreHttp.OperationSpec = { +const getOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}", httpMethod: "GET", @@ -228,7 +198,7 @@ const getOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listForScopeOperationSpec: coreHttp.OperationSpec = { +const listForScopeOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleAssignments", httpMethod: "GET", responses: { @@ -244,7 +214,7 @@ const listForScopeOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listForScopeNextOperationSpec: coreHttp.OperationSpec = { +const listForScopeNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { diff --git a/sdk/keyvault/keyvault-admin/src/generated/operations/roleDefinitions.ts b/sdk/keyvault/keyvault-admin/src/generated/operations/roleDefinitions.ts index e16f7be93510..1addeb10b155 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/operations/roleDefinitions.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/operations/roleDefinitions.ts @@ -7,7 +7,7 @@ */ import { RoleDefinitions } from "../operationsInterfaces"; -import * as coreHttp from "@azure/core-http"; +import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { KeyVaultClientContext } from "../keyVaultClientContext"; @@ -48,17 +48,11 @@ export class RoleDefinitionsImpl implements RoleDefinitions { scope: string, roleDefinitionName: string, options?: RoleDefinitionsDeleteOptionalParams - ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - roleDefinitionName, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; + ): Promise { return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, roleDefinitionName, options }, deleteOperationSpec - ) as Promise; + ); } /** @@ -77,17 +71,10 @@ export class RoleDefinitionsImpl implements RoleDefinitions { parameters: RoleDefinitionCreateParameters, options?: RoleDefinitionsCreateOrUpdateOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - roleDefinitionName, - parameters, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, roleDefinitionName, parameters, options }, createOrUpdateOperationSpec - ) as Promise; + ); } /** @@ -103,16 +90,10 @@ export class RoleDefinitionsImpl implements RoleDefinitions { roleDefinitionName: string, options?: RoleDefinitionsGetOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - roleDefinitionName, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, roleDefinitionName, options }, getOperationSpec - ) as Promise; + ); } /** @@ -126,15 +107,10 @@ export class RoleDefinitionsImpl implements RoleDefinitions { scope: string, options?: RoleDefinitionsListOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, options }, listOperationSpec - ) as Promise; + ); } /** @@ -150,22 +126,16 @@ export class RoleDefinitionsImpl implements RoleDefinitions { nextLink: string, options?: RoleDefinitionsListNextOptionalParams ): Promise { - const operationArguments: coreHttp.OperationArguments = { - vaultBaseUrl, - scope, - nextLink, - options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) - }; return this.client.sendOperationRequest( - operationArguments, + { vaultBaseUrl, scope, nextLink, options }, listNextOperationSpec - ) as Promise; + ); } } // Operation Specifications -const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); +const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); -const deleteOperationSpec: coreHttp.OperationSpec = { +const deleteOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}", httpMethod: "DELETE", @@ -185,7 +155,7 @@ const deleteOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const createOrUpdateOperationSpec: coreHttp.OperationSpec = { +const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}", httpMethod: "PUT", @@ -208,7 +178,7 @@ const createOrUpdateOperationSpec: coreHttp.OperationSpec = { mediaType: "json", serializer }; -const getOperationSpec: coreHttp.OperationSpec = { +const getOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}", httpMethod: "GET", @@ -229,7 +199,7 @@ const getOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listOperationSpec: coreHttp.OperationSpec = { +const listOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Authorization/roleDefinitions", httpMethod: "GET", responses: { @@ -245,7 +215,7 @@ const listOperationSpec: coreHttp.OperationSpec = { headerParameters: [Parameters.accept], serializer }; -const listNextOperationSpec: coreHttp.OperationSpec = { +const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { diff --git a/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleAssignments.ts b/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleAssignments.ts index 157c263f9e2f..64a01edae5f3 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleAssignments.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleAssignments.ts @@ -6,7 +6,6 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; import { RoleAssignmentsDeleteOptionalParams, RoleAssignmentCreateParameters, @@ -34,7 +33,7 @@ export interface RoleAssignments { scope: string, roleAssignmentName: string, options?: RoleAssignmentsDeleteOptionalParams - ): Promise; + ): Promise; /** * Creates a role assignment. * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. diff --git a/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleDefinitions.ts b/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleDefinitions.ts index 5780ec44cfa0..55e150491670 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleDefinitions.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/operationsInterfaces/roleDefinitions.ts @@ -6,7 +6,6 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import * as coreHttp from "@azure/core-http"; import { RoleDefinitionsDeleteOptionalParams, RoleDefinitionCreateParameters, @@ -34,7 +33,7 @@ export interface RoleDefinitions { scope: string, roleDefinitionName: string, options?: RoleDefinitionsDeleteOptionalParams - ): Promise; + ): Promise; /** * Creates or updates a custom role definition. * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net. diff --git a/sdk/keyvault/keyvault-admin/src/index.ts b/sdk/keyvault/keyvault-admin/src/index.ts index 133961b78ca3..853d2ec37e4b 100644 --- a/sdk/keyvault/keyvault-admin/src/index.ts +++ b/sdk/keyvault/keyvault-admin/src/index.ts @@ -7,4 +7,4 @@ export * from "./accessControlModels"; export * from "./backupClient"; export * from "./backupClientModels"; -export * from "./constants"; +export { LATEST_API_VERSION, SDK_VERSION, SUPPORTED_API_VERSIONS } from "./constants"; diff --git a/sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts b/sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts index 585f04f30e9b..171c8a1a6a3b 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts @@ -2,7 +2,6 @@ // Licensed under the MIT license. import { AbortSignalLike } from "@azure/abort-controller"; -import { RequestOptionsBase } from "@azure/core-http"; import { KeyVaultClient } from "../../generated/keyVaultClient"; import { FullBackupOperation, @@ -15,7 +14,7 @@ import { KeyVaultAdminPollOperation, KeyVaultAdminPollOperationState } from "../keyVaultAdminPoller"; -import { createTraceFunction } from "../../../../keyvault-common/src/tracingHelpers"; +import { createTraceFunction } from "../../tracingHelpers"; /** * @internal @@ -53,7 +52,7 @@ export class KeyVaultBackupPollOperation extends KeyVaultAdminPollOperation< public state: KeyVaultBackupPollOperationState, private vaultUrl: string, private client: KeyVaultClient, - private requestOptions: RequestOptionsBase = {} + private requestOptions: KeyVaultBeginBackupOptions = {} ) { super(state, { cancelMessage: "Cancelling a full Key Vault backup is not supported." }); } diff --git a/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts b/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts index 3c0a3013e843..a07e45ce7bf0 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -import { delay, RequestOptionsBase } from "@azure/core-http"; +import { OperationOptions } from "@azure/core-client"; import { Poller, PollOperation, PollOperationState } from "@azure/core-lro"; import { KeyVaultClient } from "../generated/keyVaultClient"; @@ -11,7 +11,7 @@ import { KeyVaultClient } from "../generated/keyVaultClient"; export interface KeyVaultAdminPollerOptions { vaultUrl: string; client: KeyVaultClient; - requestOptions?: RequestOptionsBase; + requestOptions?: OperationOptions; intervalInMs?: number; resumeFrom?: string; } @@ -78,7 +78,7 @@ export abstract class KeyVaultAdminPoller< * The method used by the poller to wait before attempting to update its operation. */ async delay(): Promise { - return delay(this.intervalInMs); + return new Promise((resolve) => setTimeout(resolve, this.intervalInMs)); } /** diff --git a/sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts b/sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts index 2c96a94428d3..f75784b47bb6 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts @@ -2,7 +2,6 @@ // Licensed under the MIT license. import { AbortSignalLike } from "@azure/abort-controller"; -import { OperationOptions, RequestOptionsBase } from "@azure/core-http"; import { KeyVaultClient } from "../../generated/keyVaultClient"; import { KeyVaultClientFullRestoreOperationOptionalParams, @@ -14,8 +13,9 @@ import { KeyVaultAdminPollOperation, KeyVaultAdminPollOperationState } from "../keyVaultAdminPoller"; -import { KeyVaultRestoreResult } from "../../backupClientModels"; -import { createTraceFunction } from "../../../../keyvault-common/src"; +import { KeyVaultBeginRestoreOptions, KeyVaultRestoreResult } from "../../backupClientModels"; +import { createTraceFunction } from "../../tracingHelpers"; +import { OperationOptions } from "@azure/core-client"; /** * @internal @@ -59,7 +59,7 @@ export class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation< public state: KeyVaultRestorePollOperationState, private vaultUrl: string, private client: KeyVaultClient, - private requestOptions: RequestOptionsBase = {} + private requestOptions: KeyVaultBeginRestoreOptions = {} ) { super(state, { cancelMessage: "Cancelling the restoration full Key Vault backup is not supported." diff --git a/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts b/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts index f8f993a0cadd..adf130be22bc 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts @@ -2,7 +2,6 @@ // Licensed under the MIT license. import { AbortSignalLike } from "@azure/abort-controller"; -import { OperationOptions, RequestOptionsBase } from "@azure/core-http"; import { KeyVaultClient } from "../../generated/keyVaultClient"; import { KeyVaultClientRestoreStatusResponse, @@ -14,14 +13,17 @@ import { KeyVaultAdminPollOperation, KeyVaultAdminPollOperationState } from "../keyVaultAdminPoller"; -import { KeyVaultSelectiveKeyRestoreResult } from "../../backupClientModels"; -import { createTraceFunction } from "../../../../keyvault-common/src"; +import { + KeyVaultBeginSelectiveKeyRestoreOptions, + KeyVaultSelectiveKeyRestoreResult +} from "../../backupClientModels"; +import { OperationOptions } from "@azure/core-client"; +import { createTraceFunction } from "../../tracingHelpers"; /** * @internal */ const withTrace = createTraceFunction("Azure.KeyVault.Admin.KeyVaultSelectiveKeyRestorePoller"); - /** * An interface representing the publicly available properties of the state of a restore Key Vault's poll operation. */ @@ -62,7 +64,7 @@ export class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollO public state: KeyVaultSelectiveKeyRestorePollOperationState, private vaultUrl: string, private client: KeyVaultClient, - private requestOptions: RequestOptionsBase = {} + private requestOptions: KeyVaultBeginSelectiveKeyRestoreOptions = {} ) { super(state, { cancelMessage: "Cancelling a selective Key Vault restore is not supported." }); } diff --git a/sdk/keyvault/keyvault-admin/src/tracingHelpers.ts b/sdk/keyvault/keyvault-admin/src/tracingHelpers.ts new file mode 100644 index 000000000000..a20a3f97ce31 --- /dev/null +++ b/sdk/keyvault/keyvault-admin/src/tracingHelpers.ts @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { OperationOptions } from "@azure/core-client"; +import { createSpanFunction, Span, SpanStatusCode } from "@azure/core-tracing"; + +/** + * An interface representing a function that is traced. + * + * A traced function will automatically create and close tracing ' + * spans as needed and will handle setting the status / errors as a + * result of calling the underlying callback. + * + * use {@link createTraceFunction} to add tracing to a block of code. + * + * @internal + */ +export interface TracedFunction { + ( + operationName: string, + options: TOptions, + cb: (options: TOptions, span: Span) => Promise + ): Promise; +} + +/** + * Returns a function that can be used for tracing options. + * + * @param prefix - The prefix to use, likely the name of the class / client. + * + * @example const withTrace = createTraceFunction("Azure.KeyVault.Certificates.CertificateClient") + * + * @internal + */ +export function createTraceFunction(prefix: string): TracedFunction { + const createSpan = createSpanFunction({ + namespace: "Microsoft.KeyVault", + packagePrefix: prefix + }); + + return async function(operationName, options, cb) { + const { updatedOptions, span } = createSpan(operationName, options); + + try { + // NOTE: we really do need to await on this function here so we can handle any exceptions thrown and properly + // close the span. + const result = await cb(updatedOptions, span); + + // otel 0.16+ needs this or else the code ends up being set as UNSET + span.setStatus({ + code: SpanStatusCode.OK + }); + return result; + } catch (err) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: err.message + }); + throw err; + } finally { + span.end(); + } + }; +} diff --git a/sdk/keyvault/keyvault-admin/swagger/README.md b/sdk/keyvault/keyvault-admin/swagger/README.md index 3f63cc06be80..fb6afb8b3fdf 100644 --- a/sdk/keyvault/keyvault-admin/swagger/README.md +++ b/sdk/keyvault/keyvault-admin/swagger/README.md @@ -4,11 +4,9 @@ ```yaml package-name: "@azure/keyvault-admin" -use-extension: - "@autorest/typescript": "6.0.0-alpha.20210527.9" azure-arm: false disable-async-iterators: true -use-core-v2: false +api-version-parameter: choice generate-metadata: false add-credentials: false license-header: MICROSOFT_MIT_NO_VERSION diff --git a/sdk/keyvault/keyvault-admin/test/internal/challengeAuthenticationCallbacks.spec.ts b/sdk/keyvault/keyvault-admin/test/internal/challengeAuthenticationCallbacks.spec.ts new file mode 100644 index 000000000000..d3c45efd043e --- /dev/null +++ b/sdk/keyvault/keyvault-admin/test/internal/challengeAuthenticationCallbacks.spec.ts @@ -0,0 +1,200 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import chai, { assert } from "chai"; +import chaiAsPromised from "chai-as-promised"; +chai.use(chaiAsPromised); +import { + createChallengeCallbacks, + parseWWWAuthenticate +} from "../../src/challengeAuthenticationCallbacks"; +import { + AuthorizeRequestOptions, + ChallengeCallbacks, + createHttpHeaders, + createPipelineRequest, + PipelineRequest +} from "@azure/core-rest-pipeline"; + +describe("Challenge based authentication tests", function() { + let request: PipelineRequest; + let challengeCallbacks: ChallengeCallbacks; + + beforeEach(() => { + request = createPipelineRequest({ url: "https://foo.bar" }); + challengeCallbacks = createChallengeCallbacks(); + }); + + describe("authorizeRequest", () => { + it("always starts the challenge on the first call", async () => { + let getAccessTokenCallCount = 0; + const options: AuthorizeRequestOptions = { + getAccessToken: () => { + getAccessTokenCallCount += 1; + return Promise.resolve({ token: "access_token", expiresOnTimestamp: 1000 }); + }, + request, + scopes: [] + }; + + await challengeCallbacks.authorizeRequest!(options); + + assert.notExists(options.request.headers.get("authorization")); + // We do not call getAccessToken on the first request + assert.equal(getAccessTokenCallCount, 0); + }); + + it("sets the authorization token if it gets one on subsequent calls", async () => { + let getAccessTokenCallCount = 0; + const options: AuthorizeRequestOptions = { + getAccessToken: () => { + getAccessTokenCallCount += 1; + return Promise.resolve({ token: "access_token", expiresOnTimestamp: 1000 }); + }, + request, + scopes: [] + }; + + // Set up the challenge state to complete by calling authorizeRequestOnChallenge first + await challengeCallbacks.authorizeRequestOnChallenge!({ + getAccessToken: () => { + return Promise.resolve({ token: "successful_token", expiresOnTimestamp: 999999999 }); + }, + request, + response: { + headers: createHttpHeaders({ + "WWW-Authenticate": `Bearer scope="cae_scope"` + }), + request, + status: 200 + }, + scopes: [] + }); + + await challengeCallbacks.authorizeRequest!(options); + + assert.equal(1, getAccessTokenCallCount); + assert.equal(options.request.headers.get("authorization"), "Bearer access_token"); + }); + + it("does not modify headers when unable to get access token", async () => { + const options: AuthorizeRequestOptions = { + getAccessToken: () => { + return Promise.resolve(null); + }, + request: createPipelineRequest({ + url: "https://foo.bar", + headers: createHttpHeaders() + }), + scopes: ["any_scope"] + }; + + await challengeCallbacks.authorizeRequest!(options); + + assert.notExists(options.request.headers.get("authorization")); + }); + }); + + describe("authorizeRequestOnChallenge", () => { + it("validates WWW-Authenticate exists", async () => { + await assert.isRejected( + challengeCallbacks.authorizeRequestOnChallenge!({ + getAccessToken: () => Promise.resolve(null), + request, + response: { + headers: createHttpHeaders(), + request, + status: 200 + }, + scopes: [] + }), + "Missing challenge" + ); + }); + + it("passes the correct scopes if provided", async () => { + let getAccessTokenScopes: string[] = []; + await challengeCallbacks.authorizeRequestOnChallenge!({ + getAccessToken: (scopes) => { + getAccessTokenScopes = scopes; + return Promise.resolve(null); + }, + request, + response: { + headers: createHttpHeaders({ + "WWW-Authenticate": `Bearer scope="cae_scope"` + }), + request, + status: 200 + }, + scopes: [] + }); + + assert.sameMembers(getAccessTokenScopes, ["cae_scope"]); + }); + + it("returns true and sets the authorization header if challenge succeeds", async () => { + const result = await challengeCallbacks.authorizeRequestOnChallenge!({ + getAccessToken: () => { + return Promise.resolve({ token: "successful_token", expiresOnTimestamp: 999999999 }); + }, + request, + response: { + headers: createHttpHeaders({ + "WWW-Authenticate": `Bearer scope="cae_scope"` + }), + request, + status: 200 + }, + scopes: [] + }); + assert.isTrue(result); + }); + + it("returns false and does not modify header if challenge fails", async () => { + const result = await challengeCallbacks.authorizeRequestOnChallenge!({ + getAccessToken: () => { + return Promise.resolve(null); + }, + request, + response: { + headers: createHttpHeaders({ + "WWW-Authenticate": `Bearer scope="cae_scope"` + }), + request, + status: 200 + }, + scopes: [] + }); + assert.isFalse(result); + }); + }); + + describe("parseWWWAuthenticate tests", () => { + it("Should work for known shapes of the WWW-Authenticate header", () => { + const wwwAuthenticate1 = `Bearer authorization="some_authorization", resource="https://some.url"`; + const parsed1 = parseWWWAuthenticate(wwwAuthenticate1); + assert.deepEqual(parsed1, { + authorization: "some_authorization", + resource: "https://some.url" + }); + + const wwwAuthenticate2 = `Bearer authorization="some_authorization", scope="https://some.url"`; + const parsed2 = parseWWWAuthenticate(wwwAuthenticate2); + assert.deepEqual(parsed2, { + authorization: "some_authorization", + scope: "https://some.url" + }); + }); + + it("Should ignore unknown values in the WWW-Authenticate header", () => { + const wwwAuthenticate1 = `Bearer authorization="some_authorization", resource="https://some.url" scope="scope", a="a", b="b"`; + const parsed1 = parseWWWAuthenticate(wwwAuthenticate1); + assert.deepEqual(parsed1, { + authorization: "some_authorization", + resource: "https://some.url", + scope: "scope" + }); + }); + }); +}); diff --git a/sdk/keyvault/keyvault-admin/test/internal/challengeBasedAuthenticationPolicy.spec.ts b/sdk/keyvault/keyvault-admin/test/internal/challengeBasedAuthenticationPolicy.spec.ts deleted file mode 100644 index 0b0b19324a58..000000000000 --- a/sdk/keyvault/keyvault-admin/test/internal/challengeBasedAuthenticationPolicy.spec.ts +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -import * as assert from "assert"; -import Sinon, { createSandbox } from "sinon"; -import { env, Recorder } from "@azure/test-utils-recorder"; - -import { - AuthenticationChallengeCache, - AuthenticationChallenge, - parseWWWAuthenticate, - challengeBasedAuthenticationPolicy -} from "../../../keyvault-common/src"; -import { KeyVaultAccessControlClient } from "../../src"; -import { authenticate } from "../utils/authentication"; -import { WebResource } from "@azure/core-http"; -import { ClientSecretCredential } from "@azure/identity"; - -describe("Challenge based authentication tests", function() { - let client: KeyVaultAccessControlClient; - let recorder: Recorder; - let sandbox: Sinon.SinonSandbox; - - beforeEach(async function() { - const authentication = await authenticate(this); - client = authentication.accessControlClient; - recorder = authentication.recorder; - sandbox = createSandbox(); - }); - - afterEach(async function() { - sandbox.restore(); - await recorder.stop(); - }); - - it("Authentication should be idempotent", async function() { - const spy = sandbox.spy(AuthenticationChallengeCache.prototype, "setCachedChallenge"); - const spyEqualTo = sandbox.spy(AuthenticationChallenge.prototype, "equalTo"); - - const promises = [ - client.listRoleAssignments("/").next(), - client.listRoleAssignments("/").next() - ]; - await Promise.all(promises); - - // Even though we had multiple requests, only one authentication should have happened. - - // This is determined by the comparison between the cached challenge and the new receive challenge. - // So, AuthenticationChallenge's equalTo should have returned true at least once. - assert.ok(spyEqualTo.returned(true)); - - // The challenge should have been written to the cache exactly ONCE. - assert.equal(spy.getCalls().length, 1); - }); - - it("Once authenticated, new requests should not authenticate again", async function() { - const spy = sandbox.spy(AuthenticationChallengeCache.prototype, "setCachedChallenge"); - - await client.listRoleAssignments("/").next(); - await client.listRoleAssignments("/").next(); - - assert.equal(spy.getCalls().length, 1); - }); - - describe("parseWWWAuthenticate tests", () => { - it("Should work for known shapes of the WWW-Authenticate header", () => { - const wwwAuthenticate1 = `Bearer authorization="some_authorization", resource="https://some.url"`; - const parsed1 = parseWWWAuthenticate(wwwAuthenticate1); - assert.deepEqual(parsed1, { - authorization: "some_authorization", - resource: "https://some.url" - }); - - const wwwAuthenticate2 = `Bearer authorization="some_authorization", scope="https://some.url"`; - const parsed2 = parseWWWAuthenticate(wwwAuthenticate2); - assert.deepEqual(parsed2, { - authorization: "some_authorization", - scope: "https://some.url" - }); - }); - - it("Should skip unexpected properties on the WWW-Authenticate header", () => { - const wwwAuthenticate1 = `Bearer authorization="some_authorization", a="a", b="b"`; - const parsed1 = parseWWWAuthenticate(wwwAuthenticate1); - assert.deepEqual(parsed1, { - authorization: "some_authorization", - a: "a", - b: "b" - }); - - const wwwAuthenticate2 = `scope="https://some.url", a="a", c="c"`; - const parsed2 = parseWWWAuthenticate(wwwAuthenticate2); - assert.deepEqual(parsed2, { - scope: "https://some.url", - a: "a", - c: "c" - }); - }); - }); -}); - -describe("Local Challenge based authentication tests", () => { - it("should recover gracefully when a downstream policy fails", async () => { - // The simplest possible policy with a _nextPolicy that throws an error. - const credential = new ClientSecretCredential( - env.AZURE_TENANT_ID!, - env.AZURE_CLIENT_ID!, - env.AZURE_CLIENT_SECRET! - ); - - const policy = challengeBasedAuthenticationPolicy(credential).create( - { - sendRequest: () => { - throw new Error("Boom"); - } - }, - { log: () => null, shouldLog: () => false } - ); - - const request = new WebResource("https://portal.azure.com", "GET", "request body"); - - try { - await policy.sendRequest(request); - } catch (err) { - // the next policy throws - } - - assert.equal(request.body, "request body"); - }); -}); diff --git a/sdk/keyvault/keyvault-admin/test/internal/serviceVersionParameter.spec.ts b/sdk/keyvault/keyvault-admin/test/internal/serviceVersionParameter.spec.ts index fa9d7173d741..54111694573b 100644 --- a/sdk/keyvault/keyvault-admin/test/internal/serviceVersionParameter.spec.ts +++ b/sdk/keyvault/keyvault-admin/test/internal/serviceVersionParameter.spec.ts @@ -5,7 +5,12 @@ import * as assert from "assert"; import { createSandbox, SinonSandbox, SinonSpy } from "sinon"; import { KeyVaultAccessControlClient, KeyVaultBackupClient } from "../../src"; import { LATEST_API_VERSION } from "../../src/constants"; -import { HttpClient, WebResourceLike, HttpOperationResponse, HttpHeaders } from "@azure/core-http"; +import { + PipelineRequest, + PipelineResponse, + createHttpHeaders, + HttpClient +} from "@azure/core-rest-pipeline"; import { ClientSecretCredential } from "@azure/identity"; import { env } from "@azure/test-utils-recorder"; import { URL } from "url"; @@ -13,19 +18,21 @@ import { URL } from "url"; // Adding this to the source would change the public API. type ApIVersions = "7.2"; +const baseUrl = "https://managed_hsm.managedhsm.azure.net/"; + describe("The keyvault-admin clients should set the serviceVersion", () => { function makeHTTPMock(path: string, status = 200): HttpClient { return { - async sendRequest(httpRequest: WebResourceLike): Promise { + async sendRequest(request: PipelineRequest): Promise { return { status, - headers: new HttpHeaders(), - request: httpRequest, - parsedBody: { - id: `${env.AZURE_MANAGEDHSM_URI}${path}`, + headers: createHttpHeaders(), + request: request, + bodyAsText: JSON.stringify({ + id: `${baseUrl}${path}`, startTime: new Date(), attributes: {} - } + }) }; } }; @@ -33,7 +40,7 @@ describe("The keyvault-admin clients should set the serviceVersion", () => { let mockHttpClient: HttpClient; let sandbox: SinonSandbox; - let spy: SinonSpy<[WebResourceLike], Promise>; + let spy: SinonSpy<[PipelineRequest], Promise>; let credential: ClientSecretCredential; beforeEach(async () => { @@ -56,7 +63,7 @@ describe("The keyvault-admin clients should set the serviceVersion", () => { }); it("it should default to the latest API version", async function() { - const client = new KeyVaultAccessControlClient(env.AZURE_MANAGEDHSM_URI, credential, { + const client = new KeyVaultAccessControlClient(baseUrl, credential, { httpClient: mockHttpClient }); await client.listRoleDefinitions("/").next(); @@ -69,7 +76,7 @@ describe("The keyvault-admin clients should set the serviceVersion", () => { it("it should allow us to specify an API version from a specific set of versions", async function() { const serviceVersion = "7.2"; - const client = new KeyVaultAccessControlClient(env.AZURE_MANAGEDHSM_URI, credential, { + const client = new KeyVaultAccessControlClient(baseUrl, credential, { serviceVersion: serviceVersion as ApIVersions, httpClient: mockHttpClient }); @@ -89,7 +96,7 @@ describe("The keyvault-admin clients should set the serviceVersion", () => { }); it("it should default to the latest API version", async function() { - const client = new KeyVaultBackupClient(env.AZURE_MANAGEDHSM_URI, credential, { + const client = new KeyVaultBackupClient(baseUrl, credential, { httpClient: mockHttpClient }); await client.beginBackup("secretName", "value"); @@ -102,7 +109,7 @@ describe("The keyvault-admin clients should set the serviceVersion", () => { it("it should allow us to specify an API version from a specific set of versions", async function() { const serviceVersion = "7.2"; - const client = new KeyVaultBackupClient(env.AZURE_MANAGEDHSM_URI, credential, { + const client = new KeyVaultBackupClient(baseUrl, credential, { serviceVersion: serviceVersion as ApIVersions, httpClient: mockHttpClient }); diff --git a/sdk/keyvault/keyvault-admin/test/internal/userAgent.spec.ts b/sdk/keyvault/keyvault-admin/test/internal/userAgent.spec.ts index 5e065f41721d..21c4bae829b1 100644 --- a/sdk/keyvault/keyvault-admin/test/internal/userAgent.spec.ts +++ b/sdk/keyvault/keyvault-admin/test/internal/userAgent.spec.ts @@ -4,7 +4,7 @@ import * as assert from "assert"; import { SDK_VERSION } from "../../src/constants"; import { packageVersion } from "../../src/generated/keyVaultClientContext"; -import { isNode } from "@azure/core-http"; +import { isNode } from "@azure/core-util"; import path from "path"; import fs from "fs"; diff --git a/sdk/keyvault/keyvault-admin/test/public/accessControlClient.spec.ts b/sdk/keyvault/keyvault-admin/test/public/accessControlClient.spec.ts index 7599d4e74fd8..8b2d8ff8d970 100644 --- a/sdk/keyvault/keyvault-admin/test/public/accessControlClient.spec.ts +++ b/sdk/keyvault/keyvault-admin/test/public/accessControlClient.spec.ts @@ -13,7 +13,7 @@ import { KnownKeyVaultDataAction } from "../../src"; import { authenticate } from "../utils/authentication"; -import { supportsTracing } from "../../../keyvault-common/test/utils/supportsTracing"; +import { supportsTracing } from "../utils/supportsTracing"; describe("KeyVaultAccessControlClient", () => { let client: KeyVaultAccessControlClient; diff --git a/sdk/keyvault/keyvault-admin/test/public/backupClient.spec.ts b/sdk/keyvault/keyvault-admin/test/public/backupClient.spec.ts index 65974f340f73..0e0c3bd55c7f 100644 --- a/sdk/keyvault/keyvault-admin/test/public/backupClient.spec.ts +++ b/sdk/keyvault/keyvault-admin/test/public/backupClient.spec.ts @@ -10,7 +10,7 @@ import { KeyVaultBackupClient } from "../../src"; import { authenticate } from "../utils/authentication"; import { testPollerProperties } from "../utils/recorder"; import { getSasToken } from "../utils/common"; -import { delay } from "@azure/core-http"; +import { delay } from "@azure/core-util"; import { assert } from "chai"; import { KeyClient } from "@azure/keyvault-keys"; @@ -68,7 +68,7 @@ describe("KeyVaultBackupClient", () => { "invalid_sas_token", testPollerProperties ); - await assert.isRejected(backupPoller.pollUntilDone(), /SAS token is malformed/); + await assert.isRejected(backupPoller.pollUntilDone(), /SAS token/); }); }); diff --git a/sdk/keyvault/keyvault-admin/test/utils/authentication.ts b/sdk/keyvault/keyvault-admin/test/utils/authentication.ts index 69723ab40af0..283769598593 100644 --- a/sdk/keyvault/keyvault-admin/test/utils/authentication.ts +++ b/sdk/keyvault/keyvault-admin/test/utils/authentication.ts @@ -8,7 +8,6 @@ import { v4 as uuidv4 } from "uuid"; import { KeyVaultAccessControlClient, KeyVaultBackupClient } from "../../src"; import { uniqueString } from "./recorder"; -import { DefaultHttpClient } from "@azure/core-http"; import { getEnvironmentVariable } from "./common"; export async function authenticate(that: any): Promise { @@ -67,11 +66,7 @@ export async function authenticate(that: any): Promise { const keyVaultHsmUrl = getEnvironmentVariable("AZURE_MANAGEDHSM_URI"); - // Passing a separate httpClient for every instance as a workaround - // for a caching issue when creating role assignments - const accessControlClient = new KeyVaultAccessControlClient(keyVaultHsmUrl, credential, { - httpClient: new DefaultHttpClient() - }); + const accessControlClient = new KeyVaultAccessControlClient(keyVaultHsmUrl, credential); const keyClient = new KeyClient(keyVaultHsmUrl, credential); const backupClient = new KeyVaultBackupClient(keyVaultHsmUrl, credential); diff --git a/sdk/keyvault/keyvault-admin/test/utils/recorder.ts b/sdk/keyvault/keyvault-admin/test/utils/recorder.ts index dce9de46df48..01d8abd3a2d4 100644 --- a/sdk/keyvault/keyvault-admin/test/utils/recorder.ts +++ b/sdk/keyvault/keyvault-admin/test/utils/recorder.ts @@ -2,7 +2,7 @@ // Licensed under the MIT license. import { isPlaybackMode } from "@azure/test-utils-recorder"; -import { isNode } from "@azure/core-http"; +import { isNode } from "@azure/core-util"; import * as dotenv from "dotenv"; if (isNode) { diff --git a/sdk/keyvault/keyvault-admin/test/utils/supportsTracing.ts b/sdk/keyvault/keyvault-admin/test/utils/supportsTracing.ts new file mode 100644 index 000000000000..da54ac21a98c --- /dev/null +++ b/sdk/keyvault/keyvault-admin/test/utils/supportsTracing.ts @@ -0,0 +1,44 @@ +import { + TestTracer, + setTracer, + setSpan, + context as otContext, + OperationTracingOptions +} from "@azure/core-tracing"; +import { assert } from "chai"; + +const prefix = "Azure.KeyVault"; + +export async function supportsTracing( + callback: (tracingOptions: OperationTracingOptions) => Promise, + children: string[] +): Promise { + const tracer = new TestTracer(); + setTracer(tracer); + const rootSpan = tracer.startSpan("root"); + const tracingContext = setSpan(otContext.active(), rootSpan); + + try { + await callback({ tracingContext }); + } finally { + rootSpan.end(); + } + + // Ensure any spans created by KeyVault are parented correctly + let rootSpans = tracer + .getRootSpans() + .filter((span) => span.name.startsWith(prefix) || span.name === "root"); + + assert.equal(rootSpans.length, 1, "Should only have one root span."); + assert.strictEqual(rootSpan, rootSpans[0], "The root span should match what was passed in."); + + // Ensure top-level children are created correctly. + // Testing the entire tree structure can be tricky as other packages might create their own spans. + const spanGraph = tracer.getSpanGraph(rootSpan.context().traceId); + const directChildren = spanGraph.roots[0].children.map((child) => child.name); + // LROs might poll N times, so we'll make a unique array and compare that. + assert.sameMembers(Array.from(new Set(directChildren)), children); + + // Ensure all spans are properly closed + assert.equal(tracer.getActiveSpans().length, 0, "All spans should have had end called"); +} diff --git a/sdk/keyvault/keyvault-certificates/package.json b/sdk/keyvault/keyvault-certificates/package.json index ac684a2f05e2..0b8f094eff08 100644 --- a/sdk/keyvault/keyvault-certificates/package.json +++ b/sdk/keyvault/keyvault-certificates/package.json @@ -109,7 +109,7 @@ "dependencies": { "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.12", "@azure/logger": "^1.0.0", diff --git a/sdk/keyvault/keyvault-keys/package.json b/sdk/keyvault/keyvault-keys/package.json index 85cf47732d64..8ab2fdcf4e52 100644 --- a/sdk/keyvault/keyvault-keys/package.json +++ b/sdk/keyvault/keyvault-keys/package.json @@ -105,7 +105,7 @@ "dependencies": { "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.12", "@azure/logger": "^1.0.0", diff --git a/sdk/keyvault/keyvault-secrets/package.json b/sdk/keyvault/keyvault-secrets/package.json index 240a9f8db14b..38938b255935 100644 --- a/sdk/keyvault/keyvault-secrets/package.json +++ b/sdk/keyvault/keyvault-secrets/package.json @@ -105,7 +105,7 @@ "dependencies": { "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.12", "@azure/logger": "^1.0.0", diff --git a/sdk/metricsadvisor/ai-metrics-advisor/package.json b/sdk/metricsadvisor/ai-metrics-advisor/package.json index 4d36a57cb3b8..75715f6e56e3 100644 --- a/sdk/metricsadvisor/ai-metrics-advisor/package.json +++ b/sdk/metricsadvisor/ai-metrics-advisor/package.json @@ -82,7 +82,7 @@ "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", "dependencies": { "@azure/core-auth": "^1.3.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", "@azure/core-tracing": "1.0.0-preview.12", diff --git a/sdk/storage/storage-blob-changefeed/package.json b/sdk/storage/storage-blob-changefeed/package.json index f38f05596497..e48cde45b46e 100644 --- a/sdk/storage/storage-blob-changefeed/package.json +++ b/sdk/storage/storage-blob-changefeed/package.json @@ -97,7 +97,7 @@ "@azure/storage-blob": "^12.6.0-beta.1", "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.12", "@azure/logger": "^1.0.0", diff --git a/sdk/storage/storage-blob/package.json b/sdk/storage/storage-blob/package.json index d37bf39348e7..231a43507320 100644 --- a/sdk/storage/storage-blob/package.json +++ b/sdk/storage/storage-blob/package.json @@ -128,7 +128,7 @@ "dependencies": { "@azure/abort-controller": "^1.0.0", "@azure/core-http": "^1.2.0", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.12", "@azure/logger": "^1.0.0", diff --git a/sdk/synapse/synapse-artifacts/package.json b/sdk/synapse/synapse-artifacts/package.json index 693265ec8586..755b64f50394 100644 --- a/sdk/synapse/synapse-artifacts/package.json +++ b/sdk/synapse/synapse-artifacts/package.json @@ -7,7 +7,7 @@ "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/synapse/synapse-artifacts/README.md", "repository": "github:Azure/azure-sdk-for-js", "dependencies": { - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-http": "^1.2.0", "@azure/core-tracing": "1.0.0-preview.12", diff --git a/sdk/textanalytics/ai-text-analytics/package.json b/sdk/textanalytics/ai-text-analytics/package.json index eea2ced8bc95..8ab2efab712b 100644 --- a/sdk/textanalytics/ai-text-analytics/package.json +++ b/sdk/textanalytics/ai-text-analytics/package.json @@ -94,7 +94,7 @@ "@azure/core-auth": "^1.3.0", "@azure/core-client": "^1.0.0", "@azure/core-rest-pipeline": "^1.0.3", - "@azure/core-lro": "^1.0.2", + "@azure/core-lro": "^1.0.6", "@azure/core-paging": "^1.1.1", "@azure/core-tracing": "1.0.0-preview.11", "@azure/logger": "^1.0.0",