diff --git a/sdk/keyvault/keyvault-admin/src/backupClient.ts b/sdk/keyvault/keyvault-admin/src/backupClient.ts index b92562f6eef0..2976af15e768 100644 --- a/sdk/keyvault/keyvault-admin/src/backupClient.ts +++ b/sdk/keyvault/keyvault-admin/src/backupClient.ts @@ -11,20 +11,21 @@ import { KeyVaultSelectiveKeyRestoreResult, } from "./backupClientModels.js"; // import { KeyVaultAdminPollOperationState } from "./lro/keyVaultAdminPoller.js"; -import { KeyVaultBackupOperationState } from "./lro/backup/operation.js"; +import { KeyVaultBackupOperationState, KeyVaultBackupPoller } from "./lro/backup/poller.js"; // import { KeyVaultBackupPoller } from "./lro/backup/poller.js"; import { KeyVaultClient } from "./generated/keyVaultClient.js"; -import { KeyVaultRestoreOperationState } from "./lro/restore/operation.js"; // import { KeyVaultRestorePoller } from "./lro/restore/poller.js"; -import { KeyVaultSelectiveKeyRestoreOperationState } from "./lro/selectiveKeyRestore/operation.js"; // import { KeyVaultSelectiveKeyRestorePoller } from "./lro/selectiveKeyRestore/poller.js"; import { LATEST_API_VERSION } from "./constants.js"; -import { PollerLike } from "@azure/core-lro"; import { TokenCredential } from "@azure/core-auth"; import { keyVaultAuthenticationPolicy } from "@azure/keyvault-common"; import { logger } from "./log.js"; import { bearerTokenAuthenticationPolicyName } from "@azure/core-rest-pipeline"; import { mappings } from "./mappings.js"; +import { PollerLike } from "./lro/keyVaultAdminPoller.js"; +import { KeyVaultRestoreOperationState, KeyVaultRestorePoller } from "./lro/restore/poller.js"; +import { SimplePollerLike, wrapPoller } from "./lro/shim.js"; +import { KeyVaultSelectiveKeyRestoreOperationState, selectiveKeyRestoreOperation } from "./lro/selectiveKeyRestore/operation.js"; // TODO: discuss no longer exporting the state at the top level as a bugfix // export { @@ -182,18 +183,15 @@ export class KeyVaultBackupClient { const options = typeof sasTokenOrOptions === "string" ? optionsWhenSasTokenSpecified : sasTokenOrOptions; - const poller = this.client.fullBackup( - { - storageResourceUri: blobStorageUri, - token: sasToken, - useManagedIdentity: sasToken === undefined, - }, - options, - ); - - await poller.submitted(); - - // @ts-expect-error TODO: Poller's type assumes no result, but we need a KeyVaultBackupResult + const poller = new KeyVaultBackupPoller({ + blobStorageUri, + sasToken, + client: this.client, + operationOptions: options, + resumeFrom: options.resumeFrom, + intervalInMs: options.intervalInMs, + }); + await poller.poll(); return poller; } @@ -282,21 +280,15 @@ export class KeyVaultBackupClient { typeof sasTokenOrOptions === "string" ? optionsWhenSasTokenSpecified : sasTokenOrOptions; const folderParts = mappings.folderUriParts(folderUri); - const poller = this.client.fullRestoreOperation( - { - folderToRestore: folderParts.folderName, - sasTokenParameters: { - storageResourceUri: folderParts.folderUri, - token: sasToken, - useManagedIdentity: sasToken === undefined, - }, - }, - options, - ); - - await poller.submitted(); - - // @ts-expect-error TODO: startTime should be required in the spec + const poller = new KeyVaultRestorePoller({ + ...folderParts, + sasToken, + client: this.client, + operationOptions: options, + resumeFrom: options.resumeFrom, + intervalInMs: options.intervalInMs, + }); + await poller.poll(); return poller; } @@ -339,7 +331,7 @@ export class KeyVaultBackupClient { sasToken: string, options?: KeyVaultBeginSelectiveKeyRestoreOptions, ): Promise< - PollerLike + SimplePollerLike, KeyVaultSelectiveKeyRestoreResult> >; /** @@ -380,7 +372,7 @@ export class KeyVaultBackupClient { folderUri: string, options?: KeyVaultBeginSelectiveKeyRestoreOptions, ): Promise< - PollerLike + SimplePollerLike, KeyVaultSelectiveKeyRestoreResult> >; public async beginSelectiveKeyRestore( @@ -389,27 +381,27 @@ export class KeyVaultBackupClient { sasTokenOrOptions: string | KeyVaultBeginSelectiveKeyRestoreOptions = {}, optionsWhenSasTokenSpecified: KeyVaultBeginSelectiveKeyRestoreOptions = {}, ): Promise< - PollerLike + SimplePollerLike, KeyVaultSelectiveKeyRestoreResult> > { const sasToken = typeof sasTokenOrOptions === "string" ? sasTokenOrOptions : undefined; const options = typeof sasTokenOrOptions === "string" ? optionsWhenSasTokenSpecified : sasTokenOrOptions; - - const folderParts = mappings.folderUriParts(folderUri); - const poller = this.client.selectiveKeyRestoreOperation( - keyName, - { - folder: folderParts.folderName, - sasTokenParameters: { - storageResourceUri: folderParts.folderUri, - token: sasToken, - useManagedIdentity: sasToken === undefined, + const folderUriParts = mappings.folderUriParts(folderUri); + const poller = await wrapPoller( + selectiveKeyRestoreOperation(this.client["_client"], keyName, { + ...options, + restoreBlobDetails: { + folder: folderUriParts.folderName, + sasTokenParameters: { + storageResourceUri: folderUri, + token: sasToken, + useManagedIdentity: !sasToken, + }, }, }, - options, + ), ); - await poller.submitted(); - // @ts-expect-error TODO: startTime should be required in the spec + await poller.poll(); return poller; } } diff --git a/sdk/keyvault/keyvault-admin/src/backupClientModels.ts b/sdk/keyvault/keyvault-admin/src/backupClientModels.ts index b693eebffe52..eecdc509a42f 100644 --- a/sdk/keyvault/keyvault-admin/src/backupClientModels.ts +++ b/sdk/keyvault/keyvault-admin/src/backupClientModels.ts @@ -39,19 +39,19 @@ export interface KeyVaultBackupPollerOptions extends OperationOptions { * An interface representing the optional parameters that can be * passed to {@link beginBackup} */ -export interface KeyVaultBeginBackupOptions extends KeyVaultBackupPollerOptions {} +export interface KeyVaultBeginBackupOptions extends KeyVaultBackupPollerOptions { } /** * An interface representing the optional parameters that can be * passed to {@link beginRestore} */ -export interface KeyVaultBeginRestoreOptions extends KeyVaultBackupPollerOptions {} +export interface KeyVaultBeginRestoreOptions extends KeyVaultBackupPollerOptions { } /** * An interface representing the optional parameters that can be * passed to {@link beginSelectiveKeyRestore} */ -export interface KeyVaultBeginSelectiveKeyRestoreOptions extends KeyVaultBackupPollerOptions {} +export interface KeyVaultBeginSelectiveKeyRestoreOptions extends KeyVaultBackupPollerOptions { } /** * An interface representing the result of a backup operation. @@ -95,10 +95,10 @@ export interface KeyVaultSelectiveKeyRestoreResult { /** * The start time of the selective key restore operation. */ - startTime: Date; + startTime: string; /** * The end time of the selective key restore operation. */ - endTime?: Date; + endTime?: string; } diff --git a/sdk/keyvault/keyvault-admin/src/generated/api/index.ts b/sdk/keyvault/keyvault-admin/src/generated/api/index.ts index f0c929111301..0d95c0b897d9 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/api/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/api/index.ts @@ -18,3 +18,23 @@ export { getSetting, getSettings, } from "./operations.js"; +export { + FullBackupStatusOptionalParams, + FullBackupOptionalParams, + PreFullBackupOptionalParams, + RestoreStatusOptionalParams, + PreFullRestoreOperationOptionalParams, + FullRestoreOperationOptionalParams, + SelectiveKeyRestoreOperationOptionalParams, + UpdateSettingOptionalParams, + GetSettingOptionalParams, + GetSettingsOptionalParams, + RoleDefinitionsDeleteOptionalParams, + RoleDefinitionsCreateOrUpdateOptionalParams, + RoleDefinitionsGetOptionalParams, + RoleDefinitionsListOptionalParams, + RoleAssignmentsDeleteOptionalParams, + RoleAssignmentsCreateOptionalParams, + RoleAssignmentsGetOptionalParams, + RoleAssignmentsListForScopeOptionalParams, +} from "./options.js"; diff --git a/sdk/keyvault/keyvault-admin/src/generated/api/keyVaultContext.ts b/sdk/keyvault/keyvault-admin/src/generated/api/keyVaultContext.ts index 7f7f06b689c6..2313e1d6e4fa 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/api/keyVaultContext.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/api/keyVaultContext.ts @@ -1,10 +1,14 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { TokenCredential } from "@azure/core-auth"; -import { ClientOptions, Client, getClient } from "@azure-rest/core-client"; import { logger } from "../logger.js"; +import { Client, ClientOptions, getClient } from "@azure-rest/core-client"; +import { TokenCredential } from "@azure/core-auth"; +/** + * The key vault client performs cryptographic key operations and vault operations + * against the Key Vault service. + */ export interface KeyVaultContext extends Client {} /** Optional parameters for the client. */ @@ -23,11 +27,11 @@ export function createKeyVault( options: KeyVaultClientOptionalParams = {}, ): KeyVaultContext { const endpointUrl = options.endpoint ?? options.baseUrl ?? `${vaultBaseUrl}`; - const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; + const userAgentInfo = `azsdk-js-security-keyvault-administration/1.0.0-beta.1`; const userAgentPrefix = prefixFromOptions - ? `${prefixFromOptions} azsdk-js-api` - : "azsdk-js-api"; + ? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}` + : `azsdk-js-api ${userAgentInfo}`; const { apiVersion: _, ...updatedOptions } = { ...options, userAgentOptions: { userAgentPrefix }, diff --git a/sdk/keyvault/keyvault-admin/src/generated/api/operations.ts b/sdk/keyvault/keyvault-admin/src/generated/api/operations.ts index 7c6273b10237..9c96964bf066 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/api/operations.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/api/operations.ts @@ -2,40 +2,45 @@ // Licensed under the MIT License. import { - sASTokenParameterSerializer, + KeyVaultContext as Client, + FullBackupOptionalParams, + FullBackupStatusOptionalParams, + FullRestoreOperationOptionalParams, + GetSettingOptionalParams, + GetSettingsOptionalParams, + PreFullBackupOptionalParams, + PreFullRestoreOperationOptionalParams, + RestoreStatusOptionalParams, + SelectiveKeyRestoreOperationOptionalParams, + UpdateSettingOptionalParams, +} from "./index.js"; +import { FullBackupOperation, - SASTokenParameter, - PreBackupOperationParameters, + fullBackupOperationDeserializer, + sASTokenParameterSerializer, + preBackupOperationParametersSerializer, RestoreOperation, + restoreOperationDeserializer, PreRestoreOperationParameters, + preRestoreOperationParametersSerializer, RestoreOperationParameters, - SelectiveKeyRestoreOperationParameters, - SelectiveKeyRestoreOperation, + restoreOperationParametersSerializer, + selectiveKeyRestoreOperationParametersSerializer, UpdateSettingRequest, + updateSettingRequestSerializer, Setting, + settingDeserializer, SettingsListResult, + settingsListResultDeserializer, } from "../models/models.js"; -import { KeyVaultContext as Client } from "./index.js"; +import { getLongRunningPoller } from "../static-helpers/pollingHelpers.js"; import { StreamableMethod, - operationOptionsToRequestParameters, PathUncheckedResponse, createRestError, + operationOptionsToRequestParameters, } from "@azure-rest/core-client"; -import { getLongRunningPoller } from "../static-helpers/pollingHelpers.js"; import { PollerLike, OperationState } from "@azure/core-lro"; -import { - FullBackupStatusOptionalParams, - FullBackupOptionalParams, - PreFullBackupOptionalParams, - RestoreStatusOptionalParams, - PreFullRestoreOperationOptionalParams, - FullRestoreOperationOptionalParams, - SelectiveKeyRestoreOperationOptionalParams, - UpdateSettingOptionalParams, - GetSettingOptionalParams, - GetSettingsOptionalParams, -} from "../models/options.js"; export function _fullBackupStatusSend( context: Client, @@ -55,29 +60,7 @@ export async function _fullBackupStatusDeserialize( throw createRestError(result); } - return { - status: result.body["status"], - statusDetails: result.body["statusDetails"], - error: !result.body.error - ? undefined - : { - code: result.body.error?.["code"], - message: result.body.error?.["message"], - innerError: !result.body.error?.innererror - ? undefined - : result.body.error?.innererror, - }, - startTime: - result.body["startTime"] !== undefined - ? new Date(result.body["startTime"]) - : undefined, - endTime: - result.body["endTime"] !== undefined - ? new Date(result.body["endTime"]) - : undefined, - jobId: result.body["jobId"], - azureStorageBlobContainerUri: result.body["azureStorageBlobContainerUri"], - }; + return fullBackupOperationDeserializer(result.body); } /** Returns the status of full backup operation */ @@ -92,35 +75,27 @@ export async function fullBackupStatus( export function _fullBackupSend( context: Client, - azureStorageBlobContainerUri?: SASTokenParameter, options: FullBackupOptionalParams = { requestOptions: {} }, ): StreamableMethod { return context .path("/backup") .post({ ...operationOptionsToRequestParameters(options), - body: - azureStorageBlobContainerUri === undefined - ? azureStorageBlobContainerUri - : { - storageResourceUri: - azureStorageBlobContainerUri["storageResourceUri"], - token: azureStorageBlobContainerUri["token"], - useManagedIdentity: - azureStorageBlobContainerUri["useManagedIdentity"], - }, + body: !options["azureStorageBlobContainerUri"] + ? options["azureStorageBlobContainerUri"] + : sASTokenParameterSerializer(options["azureStorageBlobContainerUri"]), }); } export async function _fullBackupDeserialize( result: PathUncheckedResponse, -): Promise { +): Promise { const expectedStatuses = ["202", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); } - return; + return fullBackupOperationDeserializer(result.body); } /** @@ -129,48 +104,41 @@ export async function _fullBackupDeserialize( */ export function fullBackup( context: Client, - azureStorageBlobContainerUri?: SASTokenParameter, options: FullBackupOptionalParams = { requestOptions: {} }, -): PollerLike, void> { +): PollerLike, FullBackupOperation> { return getLongRunningPoller(context, _fullBackupDeserialize, ["202", "200"], { updateIntervalInMs: options?.updateIntervalInMs, abortSignal: options?.abortSignal, - getInitialResponse: () => - _fullBackupSend(context, azureStorageBlobContainerUri, options), - }) as PollerLike, void>; + getInitialResponse: () => _fullBackupSend(context, options), + resourceLocationConfig: "azure-async-operation", + }) as PollerLike, FullBackupOperation>; } export function _preFullBackupSend( context: Client, - preBackupOperationParameters?: PreBackupOperationParameters, options: PreFullBackupOptionalParams = { requestOptions: {} }, ): StreamableMethod { return context .path("/prebackup") .post({ ...operationOptionsToRequestParameters(options), - body: - preBackupOperationParameters === undefined - ? preBackupOperationParameters - : { - storageResourceUri: - preBackupOperationParameters["storageResourceUri"], - token: preBackupOperationParameters["token"], - useManagedIdentity: - preBackupOperationParameters["useManagedIdentity"], - }, + body: !options["preBackupOperationParameters"] + ? options["preBackupOperationParameters"] + : preBackupOperationParametersSerializer( + options["preBackupOperationParameters"], + ), }); } export async function _preFullBackupDeserialize( result: PathUncheckedResponse, -): Promise { +): Promise { const expectedStatuses = ["202", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); } - return; + return fullBackupOperationDeserializer(result.body); } /** @@ -179,9 +147,8 @@ export async function _preFullBackupDeserialize( */ export function preFullBackup( context: Client, - preBackupOperationParameters?: PreBackupOperationParameters, options: PreFullBackupOptionalParams = { requestOptions: {} }, -): PollerLike, void> { +): PollerLike, FullBackupOperation> { return getLongRunningPoller( context, _preFullBackupDeserialize, @@ -189,10 +156,10 @@ export function preFullBackup( { updateIntervalInMs: options?.updateIntervalInMs, abortSignal: options?.abortSignal, - getInitialResponse: () => - _preFullBackupSend(context, preBackupOperationParameters, options), + getInitialResponse: () => _preFullBackupSend(context, options), + resourceLocationConfig: "azure-async-operation", }, - ) as PollerLike, void>; + ) as PollerLike, FullBackupOperation>; } export function _restoreStatusSend( @@ -213,28 +180,7 @@ export async function _restoreStatusDeserialize( throw createRestError(result); } - return { - status: result.body["status"], - statusDetails: result.body["statusDetails"], - error: !result.body.error - ? undefined - : { - code: result.body.error?.["code"], - message: result.body.error?.["message"], - innerError: !result.body.error?.innererror - ? undefined - : result.body.error?.innererror, - }, - jobId: result.body["jobId"], - startTime: - result.body["startTime"] !== undefined - ? new Date(result.body["startTime"]) - : undefined, - endTime: - result.body["endTime"] !== undefined - ? new Date(result.body["endTime"]) - : undefined, - }; + return restoreOperationDeserializer(result.body); } /** Returns the status of restore operation */ @@ -256,14 +202,9 @@ export function _preFullRestoreOperationSend( .path("/prerestore") .put({ ...operationOptionsToRequestParameters(options), - body: { - sasTokenParameters: !preRestoreOperationParameters.sasTokenParameters - ? preRestoreOperationParameters.sasTokenParameters - : sASTokenParameterSerializer( - preRestoreOperationParameters.sasTokenParameters, - ), - folderToRestore: preRestoreOperationParameters["folderToRestore"], - }, + body: preRestoreOperationParametersSerializer( + preRestoreOperationParameters, + ), }); } @@ -275,28 +216,7 @@ export async function _preFullRestoreOperationDeserialize( throw createRestError(result); } - return { - status: result.body["status"], - statusDetails: result.body["statusDetails"], - error: !result.body.error - ? undefined - : { - code: result.body.error?.["code"], - message: result.body.error?.["message"], - innerError: !result.body.error?.innererror - ? undefined - : result.body.error?.innererror, - }, - jobId: result.body["jobId"], - startTime: - result.body["startTime"] !== undefined - ? new Date(result.body["startTime"]) - : undefined, - endTime: - result.body["endTime"] !== undefined - ? new Date(result.body["endTime"]) - : undefined, - }; + return restoreOperationDeserializer(result.body); } /** @@ -321,6 +241,7 @@ export function preFullRestoreOperation( preRestoreOperationParameters, options, ), + resourceLocationConfig: "azure-async-operation", }, ) as PollerLike, RestoreOperation>; } @@ -334,12 +255,7 @@ export function _fullRestoreOperationSend( .path("/restore") .put({ ...operationOptionsToRequestParameters(options), - body: { - sasTokenParameters: sASTokenParameterSerializer( - restoreBlobDetails.sasTokenParameters, - ), - folderToRestore: restoreBlobDetails["folderToRestore"], - }, + body: restoreOperationParametersSerializer(restoreBlobDetails), }); } @@ -351,28 +267,7 @@ export async function _fullRestoreOperationDeserialize( throw createRestError(result); } - return { - status: result.body["status"], - statusDetails: result.body["statusDetails"], - error: !result.body.error - ? undefined - : { - code: result.body.error?.["code"], - message: result.body.error?.["message"], - innerError: !result.body.error?.innererror - ? undefined - : result.body.error?.innererror, - }, - jobId: result.body["jobId"], - startTime: - result.body["startTime"] !== undefined - ? new Date(result.body["startTime"]) - : undefined, - endTime: - result.body["endTime"] !== undefined - ? new Date(result.body["endTime"]) - : undefined, - }; + return restoreOperationDeserializer(result.body); } /** @@ -393,6 +288,7 @@ export function fullRestoreOperation( abortSignal: options?.abortSignal, getInitialResponse: () => _fullRestoreOperationSend(context, restoreBlobDetails, options), + resourceLocationConfig: "azure-async-operation", }, ) as PollerLike, RestoreOperation>; } @@ -400,55 +296,29 @@ export function fullRestoreOperation( export function _selectiveKeyRestoreOperationSend( context: Client, keyName: string, - restoreBlobDetails?: SelectiveKeyRestoreOperationParameters, options: SelectiveKeyRestoreOperationOptionalParams = { requestOptions: {} }, ): StreamableMethod { return context .path("/keys/{keyName}/restore", keyName) .put({ ...operationOptionsToRequestParameters(options), - body: - restoreBlobDetails === undefined - ? restoreBlobDetails - : { - sasTokenParameters: sASTokenParameterSerializer( - restoreBlobDetails.sasTokenParameters, - ), - folder: restoreBlobDetails["folder"], - }, + body: !options["restoreBlobDetails"] + ? options["restoreBlobDetails"] + : selectiveKeyRestoreOperationParametersSerializer( + options["restoreBlobDetails"], + ), }); } export async function _selectiveKeyRestoreOperationDeserialize( result: PathUncheckedResponse, -): Promise { +): Promise { const expectedStatuses = ["202", "200"]; if (!expectedStatuses.includes(result.status)) { throw createRestError(result); } - return { - status: result.body["status"], - statusDetails: result.body["statusDetails"], - error: !result.body.error - ? undefined - : { - code: result.body.error?.["code"], - message: result.body.error?.["message"], - innerError: !result.body.error?.innererror - ? undefined - : result.body.error?.innererror, - }, - jobId: result.body["jobId"], - startTime: - result.body["startTime"] !== undefined - ? new Date(result.body["startTime"]) - : undefined, - endTime: - result.body["endTime"] !== undefined - ? new Date(result.body["endTime"]) - : undefined, - }; + return restoreOperationDeserializer(result.body); } /** @@ -458,12 +328,8 @@ export async function _selectiveKeyRestoreOperationDeserialize( export function selectiveKeyRestoreOperation( context: Client, keyName: string, - restoreBlobDetails?: SelectiveKeyRestoreOperationParameters, options: SelectiveKeyRestoreOperationOptionalParams = { requestOptions: {} }, -): PollerLike< - OperationState, - SelectiveKeyRestoreOperation -> { +): PollerLike, RestoreOperation> { return getLongRunningPoller( context, _selectiveKeyRestoreOperationDeserialize, @@ -472,17 +338,10 @@ export function selectiveKeyRestoreOperation( updateIntervalInMs: options?.updateIntervalInMs, abortSignal: options?.abortSignal, getInitialResponse: () => - _selectiveKeyRestoreOperationSend( - context, - keyName, - restoreBlobDetails, - options, - ), + _selectiveKeyRestoreOperationSend(context, keyName, options), + resourceLocationConfig: "azure-async-operation", }, - ) as PollerLike< - OperationState, - SelectiveKeyRestoreOperation - >; + ) as PollerLike, RestoreOperation>; } export function _updateSettingSend( @@ -492,10 +351,10 @@ export function _updateSettingSend( options: UpdateSettingOptionalParams = { requestOptions: {} }, ): StreamableMethod { return context - .path("/settings/{setting-name}", settingName) + .path("/settings/{settingName}", settingName) .patch({ ...operationOptionsToRequestParameters(options), - body: { value: parameters["value"] }, + body: updateSettingRequestSerializer(parameters), }); } @@ -507,11 +366,7 @@ export async function _updateSettingDeserialize( throw createRestError(result); } - return { - name: result.body["name"], - value: result.body["value"], - type: result.body["type"], - }; + return settingDeserializer(result.body); } /** Description of the pool setting to be updated */ @@ -536,7 +391,7 @@ export function _getSettingSend( options: GetSettingOptionalParams = { requestOptions: {} }, ): StreamableMethod { return context - .path("/settings/{setting-name}", settingName) + .path("/settings/{settingName}", settingName) .get({ ...operationOptionsToRequestParameters(options) }); } @@ -548,11 +403,7 @@ export async function _getSettingDeserialize( throw createRestError(result); } - return { - name: result.body["name"], - value: result.body["value"], - type: result.body["type"], - }; + return settingDeserializer(result.body); } /** Retrieves the setting object of a specified setting name. */ @@ -582,14 +433,7 @@ export async function _getSettingsDeserialize( throw createRestError(result); } - return { - settings: - result.body["settings"] === undefined - ? result.body["settings"] - : result.body["settings"].map((p: any) => { - return { name: p["name"], value: p["value"], type: p["type"] }; - }), - }; + return settingsListResultDeserializer(result.body); } /** Retrieves a list of all the available account settings that can be configured. */ diff --git a/sdk/keyvault/keyvault-admin/src/generated/models/options.ts b/sdk/keyvault/keyvault-admin/src/generated/api/options.ts similarity index 79% rename from sdk/keyvault/keyvault-admin/src/generated/models/options.ts rename to sdk/keyvault/keyvault-admin/src/generated/api/options.ts index 546a64b10d76..4801c32a9f87 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/models/options.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/api/options.ts @@ -2,6 +2,11 @@ // Licensed under the MIT License. import { OperationOptions } from "@azure-rest/core-client"; +import { + SASTokenParameter, + PreBackupOperationParameters, + SelectiveKeyRestoreOperationParameters, +} from "../models/models.js"; /** Optional parameters. */ export interface FullBackupStatusOptionalParams extends OperationOptions {} @@ -10,12 +15,19 @@ export interface FullBackupStatusOptionalParams extends OperationOptions {} export interface FullBackupOptionalParams extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; + /** + * 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; } /** Optional parameters. */ export interface PreFullBackupOptionalParams extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; + /** Optional parameters to validate prior to performing a full backup operation. */ + preBackupOperationParameters?: PreBackupOperationParameters; } /** Optional parameters. */ @@ -39,6 +51,11 @@ export interface SelectiveKeyRestoreOperationOptionalParams extends OperationOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; + /** + * The Azure blob SAS token pointing to a folder where the previous successful + * full backup was stored + */ + restoreBlobDetails?: SelectiveKeyRestoreOperationParameters; } /** Optional parameters. */ diff --git a/sdk/keyvault/keyvault-admin/src/generated/api/roleAssignments/index.ts b/sdk/keyvault/keyvault-admin/src/generated/api/roleAssignments/index.ts index 84fb866c93d6..8d0fa622b71a 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/api/roleAssignments/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/api/roleAssignments/index.ts @@ -2,28 +2,30 @@ // Licensed under the MIT License. import { - roleAssignmentPropertiesSerializer, + KeyVaultContext as Client, + RoleAssignmentsCreateOptionalParams, + RoleAssignmentsDeleteOptionalParams, + RoleAssignmentsGetOptionalParams, + RoleAssignmentsListForScopeOptionalParams, +} from "../index.js"; +import { RoleAssignment, + roleAssignmentDeserializer, RoleAssignmentCreateParameters, + roleAssignmentCreateParametersSerializer, _RoleAssignmentListResult, + _roleAssignmentListResultDeserializer, } from "../../models/models.js"; -import { KeyVaultContext as Client } from "../index.js"; -import { - StreamableMethod, - operationOptionsToRequestParameters, - PathUncheckedResponse, - createRestError, -} from "@azure-rest/core-client"; import { PagedAsyncIterableIterator, buildPagedAsyncIterator, } from "../../static-helpers/pagingHelpers.js"; import { - RoleAssignmentsDeleteOptionalParams, - RoleAssignmentsCreateOptionalParams, - RoleAssignmentsGetOptionalParams, - RoleAssignmentsListForScopeOptionalParams, -} from "../../models/options.js"; + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; export function _$deleteSend( context: Client, @@ -34,7 +36,7 @@ export function _$deleteSend( return context .path( "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}", - scope, + { value: scope, allowReserved: true }, roleAssignmentName, ) .delete({ ...operationOptionsToRequestParameters(options) }); @@ -48,18 +50,7 @@ export async function _$deleteDeserialize( throw createRestError(result); } - return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - properties: !result.body.properties - ? undefined - : { - scope: result.body.properties?.["scope"], - roleDefinitionId: result.body.properties?.["roleDefinitionId"], - principalId: result.body.properties?.["principalId"], - }, - }; + return roleAssignmentDeserializer(result.body); } /** Deletes a role assignment. */ @@ -93,14 +84,12 @@ export function _createSend( return context .path( "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}", - scope, + { value: scope, allowReserved: true }, roleAssignmentName, ) .put({ ...operationOptionsToRequestParameters(options), - body: { - properties: roleAssignmentPropertiesSerializer(parameters.properties), - }, + body: roleAssignmentCreateParametersSerializer(parameters), }); } @@ -112,18 +101,7 @@ export async function _createDeserialize( throw createRestError(result); } - return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - properties: !result.body.properties - ? undefined - : { - scope: result.body.properties?.["scope"], - roleDefinitionId: result.body.properties?.["roleDefinitionId"], - principalId: result.body.properties?.["principalId"], - }, - }; + return roleAssignmentDeserializer(result.body); } /** Creates a role assignment. */ @@ -153,7 +131,7 @@ export function _getSend( return context .path( "/{scope}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentName}", - scope, + { value: scope, allowReserved: true }, roleAssignmentName, ) .get({ ...operationOptionsToRequestParameters(options) }); @@ -167,18 +145,7 @@ export async function _getDeserialize( throw createRestError(result); } - return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - properties: !result.body.properties - ? undefined - : { - scope: result.body.properties?.["scope"], - roleDefinitionId: result.body.properties?.["roleDefinitionId"], - principalId: result.body.properties?.["principalId"], - }, - }; + return roleAssignmentDeserializer(result.body); } /** Get the specified role assignment. */ @@ -198,7 +165,10 @@ export function _listForScopeSend( options: RoleAssignmentsListForScopeOptionalParams = { requestOptions: {} }, ): StreamableMethod { return context - .path("/{scope}/providers/Microsoft.Authorization/roleAssignments", scope) + .path("/{scope}/providers/Microsoft.Authorization/roleAssignments", { + value: scope, + allowReserved: true, + }) .get({ ...operationOptionsToRequestParameters(options), queryParameters: { $filter: options?.$filter }, @@ -213,23 +183,7 @@ export async function _listForScopeDeserialize( throw createRestError(result); } - return { - value: result.body["value"].map((p: any) => { - return { - id: p["id"], - name: p["name"], - type: p["type"], - properties: !p.properties - ? undefined - : { - scope: p.properties?.["scope"], - roleDefinitionId: p.properties?.["roleDefinitionId"], - principalId: p.properties?.["principalId"], - }, - }; - }), - nextLink: result.body["nextLink"], - }; + return _roleAssignmentListResultDeserializer(result.body); } /** Gets role assignments for a scope. */ diff --git a/sdk/keyvault/keyvault-admin/src/generated/api/roleDefinitions/index.ts b/sdk/keyvault/keyvault-admin/src/generated/api/roleDefinitions/index.ts index 6e304ba924df..beeb4dcd6523 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/api/roleDefinitions/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/api/roleDefinitions/index.ts @@ -2,28 +2,30 @@ // Licensed under the MIT License. import { - roleDefinitionPropertiesSerializer, + KeyVaultContext as Client, + RoleDefinitionsCreateOrUpdateOptionalParams, + RoleDefinitionsDeleteOptionalParams, + RoleDefinitionsGetOptionalParams, + RoleDefinitionsListOptionalParams, +} from "../index.js"; +import { RoleDefinition, + roleDefinitionDeserializer, RoleDefinitionCreateParameters, + roleDefinitionCreateParametersSerializer, _RoleDefinitionListResult, + _roleDefinitionListResultDeserializer, } from "../../models/models.js"; -import { KeyVaultContext as Client } from "../index.js"; -import { - StreamableMethod, - operationOptionsToRequestParameters, - PathUncheckedResponse, - createRestError, -} from "@azure-rest/core-client"; import { PagedAsyncIterableIterator, buildPagedAsyncIterator, } from "../../static-helpers/pagingHelpers.js"; import { - RoleDefinitionsDeleteOptionalParams, - RoleDefinitionsCreateOrUpdateOptionalParams, - RoleDefinitionsGetOptionalParams, - RoleDefinitionsListOptionalParams, -} from "../../models/options.js"; + StreamableMethod, + PathUncheckedResponse, + createRestError, + operationOptionsToRequestParameters, +} from "@azure-rest/core-client"; export function _$deleteSend( context: Client, @@ -34,7 +36,7 @@ export function _$deleteSend( return context .path( "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}", - scope, + { value: scope, allowReserved: true }, roleDefinitionName, ) .delete({ ...operationOptionsToRequestParameters(options) }); @@ -48,30 +50,7 @@ export async function _$deleteDeserialize( throw createRestError(result); } - return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - properties: !result.body.properties - ? undefined - : { - roleName: result.body.properties?.["roleName"], - description: result.body.properties?.["description"], - roleType: result.body.properties?.["type"], - permissions: - result.body.properties?.["permissions"] === undefined - ? result.body.properties?.["permissions"] - : result.body.properties?.["permissions"].map((p: any) => { - return { - actions: p["actions"], - notActions: p["notActions"], - dataActions: p["dataActions"], - notDataActions: p["notDataActions"], - }; - }), - assignableScopes: result.body.properties?.["assignableScopes"], - }, - }; + return roleDefinitionDeserializer(result.body); } /** Deletes a custom role definition. */ @@ -105,14 +84,12 @@ export function _createOrUpdateSend( return context .path( "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}", - scope, + { value: scope, allowReserved: true }, roleDefinitionName, ) .put({ ...operationOptionsToRequestParameters(options), - body: { - properties: roleDefinitionPropertiesSerializer(parameters.properties), - }, + body: roleDefinitionCreateParametersSerializer(parameters), }); } @@ -124,30 +101,7 @@ export async function _createOrUpdateDeserialize( throw createRestError(result); } - return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - properties: !result.body.properties - ? undefined - : { - roleName: result.body.properties?.["roleName"], - description: result.body.properties?.["description"], - roleType: result.body.properties?.["type"], - permissions: - result.body.properties?.["permissions"] === undefined - ? result.body.properties?.["permissions"] - : result.body.properties?.["permissions"].map((p: any) => { - return { - actions: p["actions"], - notActions: p["notActions"], - dataActions: p["dataActions"], - notDataActions: p["notDataActions"], - }; - }), - assignableScopes: result.body.properties?.["assignableScopes"], - }, - }; + return roleDefinitionDeserializer(result.body); } /** Creates or updates a custom role definition. */ @@ -177,7 +131,7 @@ export function _getSend( return context .path( "/{scope}/providers/Microsoft.Authorization/roleDefinitions/{roleDefinitionName}", - scope, + { value: scope, allowReserved: true }, roleDefinitionName, ) .get({ ...operationOptionsToRequestParameters(options) }); @@ -191,30 +145,7 @@ export async function _getDeserialize( throw createRestError(result); } - return { - id: result.body["id"], - name: result.body["name"], - type: result.body["type"], - properties: !result.body.properties - ? undefined - : { - roleName: result.body.properties?.["roleName"], - description: result.body.properties?.["description"], - roleType: result.body.properties?.["type"], - permissions: - result.body.properties?.["permissions"] === undefined - ? result.body.properties?.["permissions"] - : result.body.properties?.["permissions"].map((p: any) => { - return { - actions: p["actions"], - notActions: p["notActions"], - dataActions: p["dataActions"], - notDataActions: p["notDataActions"], - }; - }), - assignableScopes: result.body.properties?.["assignableScopes"], - }, - }; + return roleDefinitionDeserializer(result.body); } /** Get the specified role definition. */ @@ -234,7 +165,10 @@ export function _listSend( options: RoleDefinitionsListOptionalParams = { requestOptions: {} }, ): StreamableMethod { return context - .path("/{scope}/providers/Microsoft.Authorization/roleDefinitions", scope) + .path("/{scope}/providers/Microsoft.Authorization/roleDefinitions", { + value: scope, + allowReserved: true, + }) .get({ ...operationOptionsToRequestParameters(options), queryParameters: { $filter: options?.$filter }, @@ -249,35 +183,7 @@ export async function _listDeserialize( throw createRestError(result); } - return { - value: result.body["value"].map((p: any) => { - return { - id: p["id"], - name: p["name"], - type: p["type"], - properties: !p.properties - ? undefined - : { - roleName: p.properties?.["roleName"], - description: p.properties?.["description"], - roleType: p.properties?.["type"], - permissions: - p.properties?.["permissions"] === undefined - ? p.properties?.["permissions"] - : p.properties?.["permissions"].map((p: any) => { - return { - actions: p["actions"], - notActions: p["notActions"], - dataActions: p["dataActions"], - notDataActions: p["notDataActions"], - }; - }), - assignableScopes: p.properties?.["assignableScopes"], - }, - }; - }), - nextLink: result.body["nextLink"], - }; + return _roleDefinitionListResultDeserializer(result.body); } /** Get all role definitions that are applicable at scope and above. */ diff --git a/sdk/keyvault/keyvault-admin/src/generated/classic/roleAssignments/index.ts b/sdk/keyvault/keyvault-admin/src/generated/classic/roleAssignments/index.ts index 0064973c970e..705db5b65af2 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/classic/roleAssignments/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/classic/roleAssignments/index.ts @@ -3,22 +3,22 @@ import { KeyVaultContext } from "../../api/keyVaultContext.js"; import { - RoleAssignment, - RoleAssignmentCreateParameters, -} from "../../models/models.js"; + RoleAssignmentsDeleteOptionalParams, + RoleAssignmentsCreateOptionalParams, + RoleAssignmentsGetOptionalParams, + RoleAssignmentsListForScopeOptionalParams, +} from "../../api/options.js"; import { $delete, create, get, listForScope, } from "../../api/roleAssignments/index.js"; -import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; import { - RoleAssignmentsDeleteOptionalParams, - RoleAssignmentsCreateOptionalParams, - RoleAssignmentsGetOptionalParams, - RoleAssignmentsListForScopeOptionalParams, -} from "../../models/options.js"; + RoleAssignment, + RoleAssignmentCreateParameters, +} from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; /** Interface representing a RoleAssignments operations. */ export interface RoleAssignmentsOperations { diff --git a/sdk/keyvault/keyvault-admin/src/generated/classic/roleDefinitions/index.ts b/sdk/keyvault/keyvault-admin/src/generated/classic/roleDefinitions/index.ts index 244eb313f91a..7effac9a8422 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/classic/roleDefinitions/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/classic/roleDefinitions/index.ts @@ -3,22 +3,22 @@ import { KeyVaultContext } from "../../api/keyVaultContext.js"; import { - RoleDefinition, - RoleDefinitionCreateParameters, -} from "../../models/models.js"; + RoleDefinitionsDeleteOptionalParams, + RoleDefinitionsCreateOrUpdateOptionalParams, + RoleDefinitionsGetOptionalParams, + RoleDefinitionsListOptionalParams, +} from "../../api/options.js"; import { $delete, createOrUpdate, get, list, } from "../../api/roleDefinitions/index.js"; -import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; import { - RoleDefinitionsDeleteOptionalParams, - RoleDefinitionsCreateOrUpdateOptionalParams, - RoleDefinitionsGetOptionalParams, - RoleDefinitionsListOptionalParams, -} from "../../models/options.js"; + RoleDefinition, + RoleDefinitionCreateParameters, +} from "../../models/models.js"; +import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; /** Interface representing a RoleDefinitions operations. */ export interface RoleDefinitionsOperations { diff --git a/sdk/keyvault/keyvault-admin/src/generated/index.ts b/sdk/keyvault/keyvault-admin/src/generated/index.ts index e297705a7d8b..1b9d7ae52780 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/index.ts @@ -7,10 +7,7 @@ import { PagedAsyncIterableIterator, } from "./static-helpers/pagingHelpers.js"; -export { - KeyVaultClient, - KeyVaultClientOptionalParams, -} from "./keyVaultClient.js"; +export { KeyVaultClient } from "./keyVaultClient.js"; export { restorePoller, RestorePollerOptions } from "./restorePollerHelpers.js"; export { FullBackupOperation, @@ -45,8 +42,9 @@ export { KnownDataAction, DataAction, RoleDefinitionCreateParameters, - Versions, - KeyVaultError, +} from "./models/index.js"; +export { + KeyVaultClientOptionalParams, FullBackupStatusOptionalParams, FullBackupOptionalParams, PreFullBackupOptionalParams, @@ -65,7 +63,7 @@ export { RoleAssignmentsCreateOptionalParams, RoleAssignmentsGetOptionalParams, RoleAssignmentsListForScopeOptionalParams, -} from "./models/index.js"; +} from "./api/index.js"; export { RoleAssignmentsOperations, RoleDefinitionsOperations, diff --git a/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts b/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts index 81b7edc963f0..613c38eee325 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/keyVaultClient.ts @@ -1,33 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { TokenCredential } from "@azure/core-auth"; -import { Pipeline } from "@azure/core-rest-pipeline"; -import { - FullBackupOperation, - SASTokenParameter, - PreBackupOperationParameters, - RestoreOperation, - PreRestoreOperationParameters, - RestoreOperationParameters, - SelectiveKeyRestoreOperationParameters, - SelectiveKeyRestoreOperation, - UpdateSettingRequest, - Setting, - SettingsListResult, -} from "./models/models.js"; -import { - FullBackupStatusOptionalParams, - FullBackupOptionalParams, - PreFullBackupOptionalParams, - RestoreStatusOptionalParams, - PreFullRestoreOperationOptionalParams, - FullRestoreOperationOptionalParams, - SelectiveKeyRestoreOperationOptionalParams, - UpdateSettingOptionalParams, - GetSettingOptionalParams, - GetSettingsOptionalParams, -} from "./models/options.js"; import { getRoleDefinitionsOperations, RoleDefinitionsOperations, @@ -50,7 +23,28 @@ import { updateSetting, getSetting, getSettings, + FullBackupStatusOptionalParams, + FullBackupOptionalParams, + PreFullBackupOptionalParams, + RestoreStatusOptionalParams, + PreFullRestoreOperationOptionalParams, + FullRestoreOperationOptionalParams, + SelectiveKeyRestoreOperationOptionalParams, + UpdateSettingOptionalParams, + GetSettingOptionalParams, + GetSettingsOptionalParams, } from "./api/index.js"; +import { + FullBackupOperation, + RestoreOperation, + PreRestoreOperationParameters, + RestoreOperationParameters, + UpdateSettingRequest, + Setting, + SettingsListResult, +} from "./models/models.js"; +import { Pipeline } from "@azure/core-rest-pipeline"; +import { TokenCredential } from "@azure/core-auth"; import { PollerLike, OperationState } from "@azure/core-lro"; export { KeyVaultClientOptionalParams } from "./api/keyVaultContext.js"; @@ -72,7 +66,7 @@ export class KeyVaultClient { const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; const userAgentPrefix = prefixFromOptions ? `${prefixFromOptions} azsdk-js-client` - : "azsdk-js-client"; + : `azsdk-js-client`; this._client = createKeyVault(vaultBaseUrl, credential, { ...options, userAgentOptions: { userAgentPrefix }, @@ -95,10 +89,9 @@ export class KeyVaultClient { * container. */ fullBackup( - azureStorageBlobContainerUri?: SASTokenParameter, options: FullBackupOptionalParams = { requestOptions: {} }, - ): PollerLike, void> { - return fullBackup(this._client, azureStorageBlobContainerUri, options); + ): PollerLike, FullBackupOperation> { + return fullBackup(this._client, options); } /** @@ -106,10 +99,9 @@ export class KeyVaultClient { * backup operation. */ preFullBackup( - preBackupOperationParameters?: PreBackupOperationParameters, options: PreFullBackupOptionalParams = { requestOptions: {} }, - ): PollerLike, void> { - return preFullBackup(this._client, preBackupOperationParameters, options); + ): PollerLike, FullBackupOperation> { + return preFullBackup(this._client, options); } /** Returns the status of restore operation */ @@ -152,20 +144,11 @@ export class KeyVaultClient { */ selectiveKeyRestoreOperation( keyName: string, - restoreBlobDetails?: SelectiveKeyRestoreOperationParameters, options: SelectiveKeyRestoreOperationOptionalParams = { requestOptions: {}, }, - ): PollerLike< - OperationState, - SelectiveKeyRestoreOperation - > { - return selectiveKeyRestoreOperation( - this._client, - keyName, - restoreBlobDetails, - options, - ); + ): PollerLike, RestoreOperation> { + return selectiveKeyRestoreOperation(this._client, keyName, options); } /** Description of the pool setting to be updated */ diff --git a/sdk/keyvault/keyvault-admin/src/generated/logger.ts b/sdk/keyvault/keyvault-admin/src/generated/logger.ts index 24ae3e9aa089..7e3c688e7b0d 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/logger.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/logger.ts @@ -2,4 +2,4 @@ // Licensed under the MIT License. import { createClientLogger } from "@azure/logger"; -export const logger = createClientLogger("keyvault-admin"); +export const logger = createClientLogger("security-keyvault-administration"); diff --git a/sdk/keyvault/keyvault-admin/src/generated/models/index.ts b/sdk/keyvault/keyvault-admin/src/generated/models/index.ts index 308ce3490f42..d734f3c14cf3 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/models/index.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/models/index.ts @@ -34,26 +34,4 @@ export { KnownDataAction, DataAction, RoleDefinitionCreateParameters, - Versions, - KeyVaultError, } from "./models.js"; -export { - FullBackupStatusOptionalParams, - FullBackupOptionalParams, - PreFullBackupOptionalParams, - RestoreStatusOptionalParams, - PreFullRestoreOperationOptionalParams, - FullRestoreOperationOptionalParams, - SelectiveKeyRestoreOperationOptionalParams, - UpdateSettingOptionalParams, - GetSettingOptionalParams, - GetSettingsOptionalParams, - RoleDefinitionsDeleteOptionalParams, - RoleDefinitionsCreateOrUpdateOptionalParams, - RoleDefinitionsGetOptionalParams, - RoleDefinitionsListOptionalParams, - RoleAssignmentsDeleteOptionalParams, - RoleAssignmentsCreateOptionalParams, - RoleAssignmentsGetOptionalParams, - RoleAssignmentsListForScopeOptionalParams, -} from "./options.js"; diff --git a/sdk/keyvault/keyvault-admin/src/generated/models/models.ts b/sdk/keyvault/keyvault-admin/src/generated/models/models.ts index ce17d9fbd1d9..686a4f4b446a 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/models/models.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/models/models.ts @@ -19,15 +19,31 @@ export interface FullBackupOperation { azureStorageBlobContainerUri?: string; } -/** Known values of {@link OperationStatus} that the service accepts. */ +export function fullBackupOperationDeserializer( + item: any, +): FullBackupOperation { + return { + status: item["status"], + statusDetails: item["statusDetails"], + error: !item["error"] ? item["error"] : errorDeserializer(item["error"]), + startTime: !item["startTime"] + ? item["startTime"] + : new Date(item["startTime"]), + endTime: !item["endTime"] ? item["endTime"] : new Date(item["endTime"]), + jobId: item["jobId"], + azureStorageBlobContainerUri: item["azureStorageBlobContainerUri"], + }; +} + +/** The status of a long-running operation. */ export enum KnownOperationStatus { - /** InProgress */ + /** The operation is in progress. */ InProgress = "InProgress", - /** Succeeded */ + /** The operation successfully completed. */ Succeeded = "Succeeded", - /** Canceled */ + /** The operation was canceled. */ Canceled = "Canceled", - /** Failed */ + /** The operation failed. */ Failed = "Failed", } @@ -36,10 +52,10 @@ export enum KnownOperationStatus { * {@link KnownOperationStatus} can be used interchangeably with OperationStatus, * this enum contains the known values that the service supports. * ### Known values supported by the service - * **InProgress** \ - * **Succeeded** \ - * **Canceled** \ - * **Failed** + * **InProgress**: The operation is in progress. \ + * **Succeeded**: The operation successfully completed. \ + * **Canceled**: The operation was canceled. \ + * **Failed**: The operation failed. */ export type OperationStatus = string; @@ -53,6 +69,16 @@ export interface ErrorModel { readonly innerError?: ErrorModel; } +export function errorDeserializer(item: any): ErrorModel { + return { + code: item["code"], + message: item["message"], + innerError: !item["innererror"] + ? item["innererror"] + : errorDeserializer(item["innererror"]), + }; +} + /** An authentication method and location for the operation. */ export interface SASTokenParameter { /** Azure Blob storage container Uri */ @@ -67,9 +93,7 @@ export interface SASTokenParameter { useManagedIdentity?: boolean; } -export function sASTokenParameterSerializer( - item: SASTokenParameter, -): Record { +export function sASTokenParameterSerializer(item: SASTokenParameter): any { return { storageResourceUri: item["storageResourceUri"], token: item["token"], @@ -93,7 +117,7 @@ export interface PreBackupOperationParameters { export function preBackupOperationParametersSerializer( item: PreBackupOperationParameters, -): Record { +): any { return { storageResourceUri: item["storageResourceUri"], token: item["token"], @@ -117,6 +141,19 @@ export interface RestoreOperation { endTime?: Date; } +export function restoreOperationDeserializer(item: any): RestoreOperation { + return { + status: item["status"], + statusDetails: item["statusDetails"], + error: !item["error"] ? item["error"] : errorDeserializer(item["error"]), + jobId: item["jobId"], + startTime: !item["startTime"] + ? item["startTime"] + : new Date(item["startTime"]), + endTime: !item["endTime"] ? item["endTime"] : new Date(item["endTime"]), + }; +} + /** The authentication method and location for the restore operation. */ export interface PreRestoreOperationParameters { /** A user-provided SAS token to an Azure blob storage container. */ @@ -127,11 +164,11 @@ export interface PreRestoreOperationParameters { export function preRestoreOperationParametersSerializer( item: PreRestoreOperationParameters, -): Record { +): any { return { - sasTokenParameters: !item.sasTokenParameters - ? item.sasTokenParameters - : sASTokenParameterSerializer(item.sasTokenParameters), + sasTokenParameters: !item["sasTokenParameters"] + ? item["sasTokenParameters"] + : sASTokenParameterSerializer(item["sasTokenParameters"]), folderToRestore: item["folderToRestore"], }; } @@ -146,9 +183,9 @@ export interface RestoreOperationParameters { export function restoreOperationParametersSerializer( item: RestoreOperationParameters, -): Record { +): any { return { - sasTokenParameters: sASTokenParameterSerializer(item.sasTokenParameters), + sasTokenParameters: sASTokenParameterSerializer(item["sasTokenParameters"]), folderToRestore: item["folderToRestore"], }; } @@ -163,9 +200,9 @@ export interface SelectiveKeyRestoreOperationParameters { export function selectiveKeyRestoreOperationParametersSerializer( item: SelectiveKeyRestoreOperationParameters, -): Record { +): any { return { - sasTokenParameters: sASTokenParameterSerializer(item.sasTokenParameters), + sasTokenParameters: sASTokenParameterSerializer(item["sasTokenParameters"]), folder: item["folder"], }; } @@ -186,6 +223,21 @@ export interface SelectiveKeyRestoreOperation { endTime?: Date; } +export function selectiveKeyRestoreOperationDeserializer( + item: any, +): SelectiveKeyRestoreOperation { + return { + status: item["status"], + statusDetails: item["statusDetails"], + error: !item["error"] ? item["error"] : errorDeserializer(item["error"]), + jobId: item["jobId"], + startTime: !item["startTime"] + ? item["startTime"] + : new Date(item["startTime"]), + endTime: !item["endTime"] ? item["endTime"] : new Date(item["endTime"]), + }; +} + /** The update settings request object. */ export interface UpdateSettingRequest { /** The value of the pool setting. */ @@ -194,10 +246,8 @@ export interface UpdateSettingRequest { export function updateSettingRequestSerializer( item: UpdateSettingRequest, -): Record { - return { - value: item["value"], - }; +): any { + return { value: item["value"] }; } /** A Key Vault account setting. */ @@ -210,9 +260,17 @@ export interface Setting { type?: SettingTypeEnum; } -/** Known values of {@link SettingTypeEnum} that the service accepts. */ +export function settingDeserializer(item: any): Setting { + return { + name: item["name"], + value: item["value"], + type: item["type"], + }; +} + +/** The type specifier of the value. */ export enum KnownSettingTypeEnum { - /** boolean */ + /** A boolean setting value. */ boolean = "boolean", } @@ -221,7 +279,7 @@ export enum KnownSettingTypeEnum { * {@link KnownSettingTypeEnum} can be used interchangeably with SettingTypeEnum, * this enum contains the known values that the service supports. * ### Known values supported by the service - * **boolean** + * **boolean**: A boolean setting value. */ export type SettingTypeEnum = string; @@ -234,6 +292,20 @@ export interface SettingsListResult { readonly settings?: Setting[]; } +export function settingsListResultDeserializer(item: any): SettingsListResult { + return { + settings: !item["settings"] + ? item["settings"] + : settingArrayDeserializer(item["settings"]), + }; +} + +export function settingArrayDeserializer(result: Array): any[] { + return result.map((item) => { + return settingDeserializer(item); + }); +} + /** Role Assignments */ export interface RoleAssignment { /** The role assignment ID. */ @@ -246,6 +318,17 @@ export interface RoleAssignment { properties?: RoleAssignmentPropertiesWithScope; } +export function roleAssignmentDeserializer(item: any): RoleAssignment { + return { + id: item["id"], + name: item["name"], + type: item["type"], + properties: !item["properties"] + ? item["properties"] + : roleAssignmentPropertiesWithScopeDeserializer(item["properties"]), + }; +} + /** Role assignment properties with scope. */ export interface RoleAssignmentPropertiesWithScope { /** The role scope. */ @@ -256,11 +339,21 @@ export interface RoleAssignmentPropertiesWithScope { principalId?: string; } -/** Known values of {@link RoleScope} that the service accepts. */ +export function roleAssignmentPropertiesWithScopeDeserializer( + item: any, +): RoleAssignmentPropertiesWithScope { + return { + scope: item["scope"], + roleDefinitionId: item["roleDefinitionId"], + principalId: item["principalId"], + }; +} + +/** The role scope. */ export enum KnownRoleScope { - /** Global */ + /** Global scope */ Global = "/", - /** Keys */ + /** Keys scope */ Keys = "/keys", } @@ -269,8 +362,8 @@ export enum KnownRoleScope { * {@link KnownRoleScope} can be used interchangeably with RoleScope, * this enum contains the known values that the service supports. * ### Known values supported by the service - * **\/** \ - * **\/keys** + * **\/**: Global scope \ + * **\/keys**: Keys scope */ export type RoleScope = string; @@ -282,10 +375,8 @@ export interface RoleAssignmentCreateParameters { export function roleAssignmentCreateParametersSerializer( item: RoleAssignmentCreateParameters, -): Record { - return { - properties: roleAssignmentPropertiesSerializer(item.properties), - }; +): any { + return { properties: roleAssignmentPropertiesSerializer(item["properties"]) }; } /** Role assignment properties. */ @@ -301,7 +392,7 @@ export interface RoleAssignmentProperties { export function roleAssignmentPropertiesSerializer( item: RoleAssignmentProperties, -): Record { +): any { return { roleDefinitionId: item["roleDefinitionId"], principalId: item["principalId"], @@ -316,6 +407,23 @@ export interface _RoleAssignmentListResult { nextLink?: string; } +export function _roleAssignmentListResultDeserializer( + item: any, +): _RoleAssignmentListResult { + return { + value: roleAssignmentArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} + +export function roleAssignmentArrayDeserializer( + result: Array, +): any[] { + return result.map((item) => { + return roleAssignmentDeserializer(item); + }); +} + /** Role definition. */ export interface RoleDefinition { /** The role definition ID. */ @@ -328,9 +436,20 @@ export interface RoleDefinition { properties?: RoleDefinitionProperties; } -/** Known values of {@link RoleDefinitionType} that the service accepts. */ +export function roleDefinitionDeserializer(item: any): RoleDefinition { + return { + id: item["id"], + name: item["name"], + type: item["type"], + properties: !item["properties"] + ? item["properties"] + : roleDefinitionPropertiesDeserializer(item["properties"]), + }; +} + +/** The role definition type. */ export enum KnownRoleDefinitionType { - /** Microsoft.Authorization/roleDefinitions */ + /** Microsoft-defined role definitions. */ "Microsoft.Authorization/roleDefinitions" = "Microsoft.Authorization/roleDefinitions", } @@ -339,7 +458,7 @@ export enum KnownRoleDefinitionType { * {@link KnownRoleDefinitionType} can be used interchangeably with RoleDefinitionType, * this enum contains the known values that the service supports. * ### Known values supported by the service - * **Microsoft.Authorization\/roleDefinitions** + * **Microsoft.Authorization\/roleDefinitions**: Microsoft-defined role definitions. */ export type RoleDefinitionType = string; @@ -359,24 +478,45 @@ export interface RoleDefinitionProperties { export function roleDefinitionPropertiesSerializer( item: RoleDefinitionProperties, -): Record { +): any { return { roleName: item["roleName"], description: item["description"], type: item["roleType"], - permissions: - item["permissions"] === undefined - ? item["permissions"] - : item["permissions"].map(permissionSerializer), - assignableScopes: item["assignableScopes"], + permissions: !item["permissions"] + ? item["permissions"] + : permissionArraySerializer(item["permissions"]), + assignableScopes: !item["assignableScopes"] + ? item["assignableScopes"] + : item["assignableScopes"].map((p: any) => { + return p; + }), + }; +} + +export function roleDefinitionPropertiesDeserializer( + item: any, +): RoleDefinitionProperties { + return { + roleName: item["roleName"], + description: item["description"], + roleType: item["type"], + permissions: !item["permissions"] + ? item["permissions"] + : permissionArrayDeserializer(item["permissions"]), + assignableScopes: !item["assignableScopes"] + ? item["assignableScopes"] + : item["assignableScopes"].map((p: any) => { + return p; + }), }; } -/** Known values of {@link RoleType} that the service accepts. */ +/** The role type. */ export enum KnownRoleType { - /** BuiltInRole */ + /** Built in role. */ BuiltInRole = "AKVBuiltInRole", - /** CustomRole */ + /** Custom role. */ CustomRole = "CustomRole", } @@ -385,8 +525,8 @@ export enum KnownRoleType { * {@link KnownRoleType} can be used interchangeably with RoleType, * this enum contains the known values that the service supports. * ### Known values supported by the service - * **AKVBuiltInRole** \ - * **CustomRole** + * **AKVBuiltInRole**: Built in role. \ + * **CustomRole**: Custom role. */ export type RoleType = string; @@ -408,86 +548,125 @@ export interface Permission { notDataActions?: DataAction[]; } -export function permissionSerializer( - item: Permission, -): Record { +export function permissionSerializer(item: Permission): any { return { - actions: item["actions"], - notActions: item["notActions"], - dataActions: item["dataActions"], - notDataActions: item["notDataActions"], + actions: !item["actions"] + ? item["actions"] + : item["actions"].map((p: any) => { + return p; + }), + notActions: !item["notActions"] + ? item["notActions"] + : item["notActions"].map((p: any) => { + return p; + }), + dataActions: !item["dataActions"] + ? item["dataActions"] + : item["dataActions"].map((p: any) => { + return p; + }), + notDataActions: !item["notDataActions"] + ? item["notDataActions"] + : item["notDataActions"].map((p: any) => { + return p; + }), }; } -/** Known values of {@link DataAction} that the service accepts. */ +export function permissionDeserializer(item: any): Permission { + return { + actions: !item["actions"] + ? item["actions"] + : item["actions"].map((p: any) => { + return p; + }), + notActions: !item["notActions"] + ? item["notActions"] + : item["notActions"].map((p: any) => { + return p; + }), + dataActions: !item["dataActions"] + ? item["dataActions"] + : item["dataActions"].map((p: any) => { + return p; + }), + notDataActions: !item["notDataActions"] + ? item["notDataActions"] + : item["notDataActions"].map((p: any) => { + return p; + }), + }; +} + +/** Supported permissions for data actions. */ export enum KnownDataAction { - /** ReadHsmKey */ + /** Read HSM key metadata. */ ReadHsmKey = "Microsoft.KeyVault/managedHsm/keys/read/action", - /** WriteHsmKey */ + /** Update an HSM key. */ WriteHsmKey = "Microsoft.KeyVault/managedHsm/keys/write/action", - /** ReadDeletedHsmKey */ + /** Read deleted HSM key. */ ReadDeletedHsmKey = "Microsoft.KeyVault/managedHsm/keys/deletedKeys/read/action", - /** RecoverDeletedHsmKey */ + /** Recover deleted HSM key. */ RecoverDeletedHsmKey = "Microsoft.KeyVault/managedHsm/keys/deletedKeys/recover/action", - /** BackupHsmKeys */ + /** Backup HSM keys. */ BackupHsmKeys = "Microsoft.KeyVault/managedHsm/keys/backup/action", - /** RestoreHsmKeys */ + /** Restore HSM keys. */ RestoreHsmKeys = "Microsoft.KeyVault/managedHsm/keys/restore/action", - /** DeleteRoleAssignment */ + /** Delete role assignment. */ DeleteRoleAssignment = "Microsoft.KeyVault/managedHsm/roleAssignments/delete/action", - /** GetRoleAssignment */ + /** Get role assignment. */ GetRoleAssignment = "Microsoft.KeyVault/managedHsm/roleAssignments/read/action", - /** WriteRoleAssignment */ + /** Create or update role assignment. */ WriteRoleAssignment = "Microsoft.KeyVault/managedHsm/roleAssignments/write/action", - /** ReadRoleDefinition */ + /** Get role definition. */ ReadRoleDefinition = "Microsoft.KeyVault/managedHsm/roleDefinitions/read/action", - /** WriteRoleDefinition */ + /** Create or update role definition. */ WriteRoleDefinition = "Microsoft.KeyVault/managedHsm/roleDefinitions/write/action", - /** DeleteRoleDefinition */ + /** Delete role definition. */ DeleteRoleDefinition = "Microsoft.KeyVault/managedHsm/roleDefinitions/delete/action", - /** EncryptHsmKey */ + /** Encrypt using an HSM key. */ EncryptHsmKey = "Microsoft.KeyVault/managedHsm/keys/encrypt/action", - /** DecryptHsmKey */ + /** Decrypt using an HSM key. */ DecryptHsmKey = "Microsoft.KeyVault/managedHsm/keys/decrypt/action", - /** WrapHsmKey */ + /** Wrap using an HSM key. */ WrapHsmKey = "Microsoft.KeyVault/managedHsm/keys/wrap/action", - /** UnwrapHsmKey */ + /** Unwrap using an HSM key. */ UnwrapHsmKey = "Microsoft.KeyVault/managedHsm/keys/unwrap/action", - /** SignHsmKey */ + /** Sign using an HSM key. */ SignHsmKey = "Microsoft.KeyVault/managedHsm/keys/sign/action", - /** VerifyHsmKey */ + /** Verify using an HSM key. */ VerifyHsmKey = "Microsoft.KeyVault/managedHsm/keys/verify/action", - /** CreateHsmKey */ + /** Create an HSM key. */ CreateHsmKey = "Microsoft.KeyVault/managedHsm/keys/create", - /** DeleteHsmKey */ + /** Delete an HSM key. */ DeleteHsmKey = "Microsoft.KeyVault/managedHsm/keys/delete", - /** ExportHsmKey */ + /** Export an HSM key. */ ExportHsmKey = "Microsoft.KeyVault/managedHsm/keys/export/action", - /** ReleaseKey */ + /** Release an HSM key using Secure Key Release. */ ReleaseKey = "Microsoft.KeyVault/managedHsm/keys/release/action", - /** ImportHsmKey */ + /** Import an HSM key. */ ImportHsmKey = "Microsoft.KeyVault/managedHsm/keys/import/action", - /** PurgeDeletedHsmKey */ + /** Purge a deleted HSM key. */ PurgeDeletedHsmKey = "Microsoft.KeyVault/managedHsm/keys/deletedKeys/delete", - /** DownloadHsmSecurityDomain */ + /** Download an HSM security domain. */ DownloadHsmSecurityDomain = "Microsoft.KeyVault/managedHsm/securitydomain/download/action", - /** DownloadHsmSecurityDomainStatus */ + /** Check status of HSM security domain download. */ DownloadHsmSecurityDomainStatus = "Microsoft.KeyVault/managedHsm/securitydomain/download/read", - /** UploadHsmSecurityDomain */ + /** Upload an HSM security domain. */ UploadHsmSecurityDomain = "Microsoft.KeyVault/managedHsm/securitydomain/upload/action", - /** ReadHsmSecurityDomainStatus */ + /** Check the status of the HSM security domain exchange file. */ ReadHsmSecurityDomainStatus = "Microsoft.KeyVault/managedHsm/securitydomain/upload/read", - /** ReadHsmSecurityDomainTransferKey */ + /** Download an HSM security domain transfer key. */ ReadHsmSecurityDomainTransferKey = "Microsoft.KeyVault/managedHsm/securitydomain/transferkey/read", - /** StartHsmBackup */ + /** Start an HSM backup. */ StartHsmBackup = "Microsoft.KeyVault/managedHsm/backup/start/action", - /** StartHsmRestore */ + /** Start an HSM restore. */ StartHsmRestore = "Microsoft.KeyVault/managedHsm/restore/start/action", - /** ReadHsmBackupStatus */ + /** Read an HSM backup status. */ ReadHsmBackupStatus = "Microsoft.KeyVault/managedHsm/backup/status/action", - /** ReadHsmRestoreStatus */ + /** Read an HSM restore status. */ ReadHsmRestoreStatus = "Microsoft.KeyVault/managedHsm/restore/status/action", - /** RandomNumbersGenerate */ + /** Generate random numbers. */ RandomNumbersGenerate = "Microsoft.KeyVault/managedHsm/rng/action", } @@ -496,43 +675,55 @@ export enum KnownDataAction { * {@link KnownDataAction} can be used interchangeably with DataAction, * this enum contains the known values that the service supports. * ### Known values supported by the service - * **Microsoft.KeyVault\/managedHsm\/keys\/read\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/write\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/deletedKeys\/read\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/deletedKeys\/recover\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/backup\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/restore\/action** \ - * **Microsoft.KeyVault\/managedHsm\/roleAssignments\/delete\/action** \ - * **Microsoft.KeyVault\/managedHsm\/roleAssignments\/read\/action** \ - * **Microsoft.KeyVault\/managedHsm\/roleAssignments\/write\/action** \ - * **Microsoft.KeyVault\/managedHsm\/roleDefinitions\/read\/action** \ - * **Microsoft.KeyVault\/managedHsm\/roleDefinitions\/write\/action** \ - * **Microsoft.KeyVault\/managedHsm\/roleDefinitions\/delete\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/encrypt\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/decrypt\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/wrap\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/unwrap\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/sign\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/verify\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/create** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/delete** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/export\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/release\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/import\/action** \ - * **Microsoft.KeyVault\/managedHsm\/keys\/deletedKeys\/delete** \ - * **Microsoft.KeyVault\/managedHsm\/securitydomain\/download\/action** \ - * **Microsoft.KeyVault\/managedHsm\/securitydomain\/download\/read** \ - * **Microsoft.KeyVault\/managedHsm\/securitydomain\/upload\/action** \ - * **Microsoft.KeyVault\/managedHsm\/securitydomain\/upload\/read** \ - * **Microsoft.KeyVault\/managedHsm\/securitydomain\/transferkey\/read** \ - * **Microsoft.KeyVault\/managedHsm\/backup\/start\/action** \ - * **Microsoft.KeyVault\/managedHsm\/restore\/start\/action** \ - * **Microsoft.KeyVault\/managedHsm\/backup\/status\/action** \ - * **Microsoft.KeyVault\/managedHsm\/restore\/status\/action** \ - * **Microsoft.KeyVault\/managedHsm\/rng\/action** + * **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. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/deletedKeys\/recover\/action**: Recover deleted HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/backup\/action**: Backup HSM keys. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/restore\/action**: Restore HSM keys. \ + * **Microsoft.KeyVault\/managedHsm\/roleAssignments\/delete\/action**: Delete role assignment. \ + * **Microsoft.KeyVault\/managedHsm\/roleAssignments\/read\/action**: Get role assignment. \ + * **Microsoft.KeyVault\/managedHsm\/roleAssignments\/write\/action**: Create or update role assignment. \ + * **Microsoft.KeyVault\/managedHsm\/roleDefinitions\/read\/action**: Get role definition. \ + * **Microsoft.KeyVault\/managedHsm\/roleDefinitions\/write\/action**: Create or update role definition. \ + * **Microsoft.KeyVault\/managedHsm\/roleDefinitions\/delete\/action**: Delete role definition. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/encrypt\/action**: Encrypt using an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/decrypt\/action**: Decrypt using an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/wrap\/action**: Wrap using an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/unwrap\/action**: Unwrap using an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/sign\/action**: Sign using an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/verify\/action**: Verify using an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/create**: Create an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/delete**: Delete an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/export\/action**: Export an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/release\/action**: Release an HSM key using Secure Key Release. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/import\/action**: Import an HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/keys\/deletedKeys\/delete**: Purge a deleted HSM key. \ + * **Microsoft.KeyVault\/managedHsm\/securitydomain\/download\/action**: Download an HSM security domain. \ + * **Microsoft.KeyVault\/managedHsm\/securitydomain\/download\/read**: Check status of HSM security domain download. \ + * **Microsoft.KeyVault\/managedHsm\/securitydomain\/upload\/action**: Upload an HSM security domain. \ + * **Microsoft.KeyVault\/managedHsm\/securitydomain\/upload\/read**: Check the status of the HSM security domain exchange file. \ + * **Microsoft.KeyVault\/managedHsm\/securitydomain\/transferkey\/read**: Download an HSM security domain transfer key. \ + * **Microsoft.KeyVault\/managedHsm\/backup\/start\/action**: Start an HSM backup. \ + * **Microsoft.KeyVault\/managedHsm\/restore\/start\/action**: Start an HSM restore. \ + * **Microsoft.KeyVault\/managedHsm\/backup\/status\/action**: Read an HSM backup status. \ + * **Microsoft.KeyVault\/managedHsm\/restore\/status\/action**: Read an HSM restore status. \ + * **Microsoft.KeyVault\/managedHsm\/rng\/action**: Generate random numbers. */ export type DataAction = string; +export function permissionArraySerializer(result: Array): any[] { + return result.map((item) => { + return permissionSerializer(item); + }); +} + +export function permissionArrayDeserializer(result: Array): any[] { + return result.map((item) => { + return permissionDeserializer(item); + }); +} + /** Role definition create parameters. */ export interface RoleDefinitionCreateParameters { /** Role definition properties. */ @@ -541,10 +732,8 @@ export interface RoleDefinitionCreateParameters { export function roleDefinitionCreateParametersSerializer( item: RoleDefinitionCreateParameters, -): Record { - return { - properties: roleDefinitionPropertiesSerializer(item.properties), - }; +): any { + return { properties: roleDefinitionPropertiesSerializer(item["properties"]) }; } /** Role definition list operation result. */ @@ -555,11 +744,19 @@ export interface _RoleDefinitionListResult { nextLink?: string; } -/** The available API versions. */ -export type Versions = "7.5" | "7.6-preview.1"; +export function _roleDefinitionListResultDeserializer( + item: any, +): _RoleDefinitionListResult { + return { + value: roleDefinitionArrayDeserializer(item["value"]), + nextLink: item["nextLink"], + }; +} -/** The key vault error exception. */ -export interface KeyVaultError { - /** The key vault server error. */ - readonly error?: ErrorModel; +export function roleDefinitionArrayDeserializer( + result: Array, +): any[] { + return result.map((item) => { + return roleDefinitionDeserializer(item); + }); } diff --git a/sdk/keyvault/keyvault-admin/src/generated/static-helpers/pollingHelpers.ts b/sdk/keyvault/keyvault-admin/src/generated/static-helpers/pollingHelpers.ts index 87a63b1fc5d1..231ce3acce89 100644 --- a/sdk/keyvault/keyvault-admin/src/generated/static-helpers/pollingHelpers.ts +++ b/sdk/keyvault/keyvault-admin/src/generated/static-helpers/pollingHelpers.ts @@ -20,7 +20,7 @@ import { } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; -export interface GetLongRunningPollerOptions { +export interface GetLongRunningPollerOptions { /** Delay to wait until next poll, in milliseconds. */ updateIntervalInMs?: number; /** @@ -44,6 +44,11 @@ export interface GetLongRunningPollerOptions { * The function to get the initial response */ getInitialResponse?: () => PromiseLike; + + /** + * A function to process the state of the LRO. + */ + updateState?: (state: TState, response: OperationResponse) => void; } export function getLongRunningPoller< TResponse extends PathUncheckedResponse, @@ -52,7 +57,7 @@ export function getLongRunningPoller< client: Client, processResponseBody: (result: TResponse) => Promise, expectedStatuses: string[], - options: GetLongRunningPollerOptions, + options: GetLongRunningPollerOptions, TResponse>, ): PollerLike, TResult> { const { restoreFrom, getInitialResponse } = options; if (!restoreFrom && !getInitialResponse) { @@ -113,6 +118,7 @@ export function getLongRunningPoller< processResult: (result: unknown) => { return processResponseBody(result as TResponse); }, + updateState: options?.updateState }); } /** diff --git a/sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts b/sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts deleted file mode 100644 index 816cbcf91970..000000000000 --- a/sdk/keyvault/keyvault-admin/src/lro/backup/operation.ts +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// import { -// FullBackupOperation, -// FullBackupOptionalParams, -// FullBackupResponse, -// FullBackupStatusResponse, -// } from "../../generated/models/index.js"; -import { KeyVaultAdminPollOperationState } from "../keyVaultAdminPoller.js"; -import { KeyVaultBackupResult } from "../../backupClientModels.js"; -// import { AbortSignalLike } from "@azure/abort-controller"; -// import { KeyVaultClient } from "../../generated/keyVaultClient.js"; -// import { tracingClient } from "../../tracing.js"; - -/** - * An interface representing the publicly available properties of the state of a backup Key Vault's poll operation. - */ -export type KeyVaultBackupOperationState = KeyVaultAdminPollOperationState; - -// /** -// * An internal interface representing the state of a backup Key Vault's poll operation. -// */ -// export interface KeyVaultBackupPollOperationState -// extends KeyVaultAdminPollOperationState { -// /** -// * The URI of the blob storage account. -// */ -// blobStorageUri: string; -// /** -// * The SAS token. -// */ -// sasToken?: string; -// } - -// /** -// * The backup Key Vault's poll operation. -// */ -// export class KeyVaultBackupPollOperation extends KeyVaultAdminPollOperation< -// KeyVaultBackupPollOperationState, -// string -// > { -// constructor( -// public state: KeyVaultBackupPollOperationState, -// private vaultUrl: string, -// private client: KeyVaultClient, -// private requestOptions: KeyVaultBeginBackupOptions = {}, -// ) { -// super(state, { cancelMessage: "Cancelling a full Key Vault backup is not supported." }); -// } - -// /** -// * Tracing the fullBackup operation -// */ -// private fullBackup(options: FullBackupOptionalParams): Promise { -// return tracingClient.withSpan("KeyVaultBackupPoller.fullBackup", options, (updatedOptions) => -// this.client.fullBackup(this.vaultUrl, updatedOptions), -// ); -// } - -// /** -// * Tracing the fullBackupStatus operation -// */ -// private fullBackupStatus( -// jobId: string, -// options: KeyVaultBeginBackupOptions, -// ): Promise { -// return tracingClient.withSpan( -// "KeyVaultBackupPoller.fullBackupStatus", -// options, -// (updatedOptions) => this.client.fullBackupStatus(this.vaultUrl, jobId, updatedOptions), -// ); -// } - -// /** -// * Reaches to the service and updates the backup's poll operation. -// */ -// async update( -// options: { -// abortSignal?: AbortSignalLike; -// fireProgress?: (state: KeyVaultBackupPollOperationState) => void; -// } = {}, -// ): Promise { -// const state = this.state; -// const { blobStorageUri, sasToken } = state; - -// if (options.abortSignal) { -// this.requestOptions.abortSignal = options.abortSignal; -// } - -// if (!state.isStarted) { -// const serviceOperation = await this.fullBackup({ -// ...this.requestOptions, -// azureStorageBlobContainerUri: { -// storageResourceUri: blobStorageUri!, -// token: sasToken, -// useManagedIdentity: sasToken === undefined, -// }, -// }); - -// this.mapState(serviceOperation); -// } else if (!state.isCompleted) { -// if (!state.jobId) { -// throw new Error(`Missing "jobId" from the full backup operation.`); -// } -// const serviceOperation = await this.fullBackupStatus(state.jobId, this.requestOptions); -// this.mapState(serviceOperation); -// } - -// return this; -// } - -// private mapState(serviceOperation: FullBackupOperation): void { -// const state = this.state; -// const { -// startTime, -// jobId, -// azureStorageBlobContainerUri, -// endTime, -// error, -// status, -// statusDetails, -// } = serviceOperation; -// if (!startTime) { -// throw new Error( -// `Missing "startTime" from the full backup operation. Full backup did not start successfully.`, -// ); -// } - -// state.isStarted = true; -// state.jobId = jobId; -// state.endTime = endTime; -// state.startTime = startTime; -// state.status = status; -// state.statusDetails = statusDetails; -// state.isCompleted = !!endTime; - -// if (state.isCompleted && error?.code) { -// throw new Error(error?.message || statusDetails); -// } - -// if (state.isCompleted) { -// state.result = { -// folderUri: azureStorageBlobContainerUri, -// startTime, -// endTime, -// }; -// } -// } -// } diff --git a/sdk/keyvault/keyvault-admin/src/lro/backup/poller.ts b/sdk/keyvault/keyvault-admin/src/lro/backup/poller.ts index 4c2edec88118..39b02bab1c60 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/backup/poller.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/backup/poller.ts @@ -1,56 +1,126 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -// import { KeyVaultAdminPoller, KeyVaultAdminPollerOptions } from "../keyVaultAdminPoller.js"; -// import { -// KeyVaultBackupOperationState, -// KeyVaultBackupPollOperation, -// KeyVaultBackupPollOperationState, -// } from "./operation.js"; -// import { KeyVaultBackupResult } from "../../backupClientModels.js"; - -// export interface KeyVaultBackupPollerOptions extends KeyVaultAdminPollerOptions { -// blobStorageUri: string; -// sasToken?: string; -// } - -// /** -// * Class that creates a poller that waits until the backup of a Key Vault ends up being generated. -// */ -// export class KeyVaultBackupPoller extends KeyVaultAdminPoller< -// KeyVaultBackupOperationState, -// KeyVaultBackupResult -// > { -// constructor(options: KeyVaultBackupPollerOptions) { -// const { -// client, -// vaultUrl, -// blobStorageUri, -// sasToken, -// requestOptions, -// intervalInMs = 2000, -// resumeFrom, -// } = options; - -// let state: KeyVaultBackupPollOperationState | undefined; - -// if (resumeFrom) { -// state = JSON.parse(resumeFrom).state; -// } - -// const operation = new KeyVaultBackupPollOperation( -// { -// ...state, -// blobStorageUri, -// sasToken, -// }, -// vaultUrl, -// client, -// requestOptions, -// ); - -// super(operation); - -// this.intervalInMs = intervalInMs; -// } -// } +import { OperationResponse } from "@azure/core-lro"; +import { KeyVaultBackupResult } from "../../backupClientModels.js"; +import { + FullBackupOperation, + FullBackupOptionalParams, + FullBackupStatusOptionalParams, +} from "../../generated/index.js"; +import { + KeyVaultAdminPollerOptions, + KeyVaultAdminPoller, + KeyVaultAdminPollOperationState, +} from "../keyVaultAdminPoller.js"; +import { FullOperationResponse } from "@azure-rest/core-client"; +import { _fullBackupDeserialize, _fullBackupSend } from "../../generated/api/operations.js"; + +/** + * An interface representing the publicly available properties of the state of a backup Key Vault's poll operation. + */ +export type KeyVaultBackupOperationState = KeyVaultAdminPollOperationState; + +export interface KeyVaultKeyBackupPollerOptions extends KeyVaultAdminPollerOptions { + /** + * The URI of the blob storage account. + */ + blobStorageUri: string; + /** + * The SAS token. + */ + sasToken?: string; +} + +export class KeyVaultBackupPoller extends KeyVaultAdminPoller< + KeyVaultBackupOperationState, + KeyVaultBackupResult +> { + protected options: KeyVaultKeyBackupPollerOptions; + private initialResponseBody?: FullBackupOperation; + constructor(options: KeyVaultKeyBackupPollerOptions) { + super(options); + this.options = options; + } + + // Need to re-write the fullBackup because we want to override the default LRO behavior + private async fullBackup(option?: FullBackupOptionalParams): Promise { + const res = await _fullBackupSend(this.options.client["_client"], { + ...option, + azureStorageBlobContainerUri: { + storageResourceUri: this.options.blobStorageUri!, + token: this.options.sasToken, + useManagedIdentity: this.options.sasToken === undefined, + }, + }); + return _fullBackupDeserialize(res); + } + + /** + * Tracing the fullBackupStatus operation + */ + private fullBackupStatus(options?: FullBackupStatusOptionalParams): Promise { + if (!this.httpPoller.operationState?.jobId) { + throw new Error(`Missing "jobId" from the full backup operation.`); + } + return this.options.client.fullBackupStatus(this.httpPoller.operationState.jobId, options); + } + + async sendInitialRequest(): Promise> { + let response: FullOperationResponse; + this.initialResponseBody = await this.fullBackup({ + ...this.options.operationOptions, + onResponse: (rawResponse) => { + response = rawResponse; + }, + }); + return this.getLroResponse(response! as any); + } + + async poll(_options?: {}): Promise { + await this.httpPoller.submitted(); + if (!this.httpPoller.operationState?.isStarted && this.initialResponseBody) { + this.mapState(this.initialResponseBody); + } + if (!this.httpPoller.operationState?.isCompleted) { + const serviceOperation = await this.fullBackupStatus(this.options.operationOptions); + this.mapState(serviceOperation); + } + } + + private mapState(serviceOperation: FullBackupOperation): void { + if (this.httpPoller.operationState === undefined) { + (this.httpPoller as any)["operationState"] = {}; + } + const state = this.httpPoller.operationState!; + const { startTime, jobId, azureStorageBlobContainerUri, endTime, error, statusDetails } = + serviceOperation; + if (!startTime) { + throw new Error( + `Missing "startTime" from the full backup operation. Full backup did not start successfully.`, + ); + } + + state.isStarted = true; + state.jobId = jobId; + state.endTime = endTime; + state.startTime = startTime; + state.statusDetails = statusDetails; + state.isCompleted = !!endTime; + // TODO: transform the status to the one expected by the poller + state.status = state.isCompleted ? "succeeded" : "running"; + + if (state.isCompleted && error?.code) { + state.status = "failed"; + throw new Error(error?.message || statusDetails); + } + + if (state.isCompleted) { + state.result = { + folderUri: azureStorageBlobContainerUri, + startTime, + endTime, + }; + } + } +} diff --git a/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts b/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts index d035dda5cb96..1d3e424347f6 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/keyVaultAdminPoller.ts @@ -1,27 +1,29 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { OperationState } from "@azure/core-lro"; +import { HttpResponse, OperationOptions } from "@azure-rest/core-client"; +import { AbortSignalLike } from "@azure/abort-controller"; +import { + CancelOnProgress, + OperationResponse, + OperationState, + createHttpPoller, + PollerLike as CorePollerLike, +} from "@azure/core-lro"; +import { KeyVaultClient } from "../generated/keyVaultClient.js"; -// import { PollOperation, PollOperationState, Poller } from "@azure/core-lro"; -// import { KeyVaultClient } from "../generated/keyVaultClient.js"; -// import { OperationOptions } from "@azure-rest/core-client"; - -// /** -// * Common parameters to a Key Vault Admin Poller. -// */ -// export interface KeyVaultAdminPollerOptions { -// vaultUrl: string; -// client: KeyVaultClient; -// requestOptions?: OperationOptions; -// intervalInMs?: number; -// resumeFrom?: string; -// } +export interface PollOperationState extends OperationState { + /** + * True if the operation has started. + */ + isStarted?: boolean; + isCompleted?: boolean; +} /** * An interface representing the state of a Key Vault Admin Poller's operation. */ -export interface KeyVaultAdminPollOperationState extends OperationState { +export interface KeyVaultAdminPollOperationState extends PollOperationState { /** * Identifier for the full restore operation. */ @@ -40,97 +42,118 @@ export interface KeyVaultAdminPollOperationState extends OperationState endTime?: Date; } -// /** -// * Generates a version of the state with only public properties. At least those common for all of the Key Vault Admin pollers. -// */ -// export function cleanState, TResult>( -// state: TState, -// ): KeyVaultAdminPollOperationState { -// return { -// jobId: state.jobId, -// status: state.status, -// statusDetails: state.statusDetails, -// startTime: state.startTime, -// endTime: state.endTime, -// isStarted: state.isStarted, -// isCancelled: state.isCancelled, -// isCompleted: state.isCompleted, -// error: state.error, -// result: state.result, -// }; -// } - -// /** -// * Common properties and methods of the Key Vault Admin Pollers. -// */ -// export abstract class KeyVaultAdminPoller< -// TState extends KeyVaultAdminPollOperationState, -// TResult, -// > extends Poller { -// /** -// * Defines how much time the poller is going to wait before making a new request to the service. -// */ -// public intervalInMs: number = 2000; - -// /** -// * The method used by the poller to wait before attempting to update its operation. -// */ -// async delay(): Promise { -// return new Promise((resolve) => setTimeout(resolve, this.intervalInMs)); -// } - -// /** -// * Gets the public state of the polling operation -// */ -// public getOperationState(): TState { -// return cleanState(this.operation.state) as TState; -// } -// } - -// /** -// * Optional parameters to the KeyVaultAdminPollOperation -// */ -// export interface KeyVaultAdminPollOperationOptions { -// cancelMessage: string; -// } - -// /** -// * Common properties and methods of the Key Vault Admin Poller operations. -// */ -// export class KeyVaultAdminPollOperation< -// TState extends KeyVaultAdminPollOperationState, -// TResult, -// > implements PollOperation -// { -// private cancelMessage: string; +/** + * Abstract representation of a poller, intended to expose just the minimal API that the user needs to work with. + */ +export interface PollerLike, TResult> { + /** + * Returns a promise that will resolve once a single polling request finishes. + * It does this by calling the update method of the Poller's operation. + */ + poll(options?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Returns a promise that will resolve once the underlying operation is completed. + */ + pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Returns the state of the operation. + * The TState defined in PollerLike can be a subset of the TState defined in + * the Poller implementation. + */ + getOperationState(): TState; + /** + * Returns the result value of the operation, + * regardless of the state of the poller. + * It can return undefined or an incomplete form of the final TResult value + * depending on the implementation. + */ + getResult(): TResult | undefined; + /** + * Returns a serialized version of the poller's operation + * by invoking the operation's toString method. + */ + toString(): string; +} -// constructor( -// public state: TState, -// options: KeyVaultAdminPollOperationOptions, -// ) { -// this.cancelMessage = options.cancelMessage; -// } +/** + * Common parameters to a Key Vault Key Poller. + */ +export interface KeyVaultAdminPollerOptions { + client: KeyVaultClient; + operationOptions?: OperationOptions; + intervalInMs?: number; + resumeFrom?: string; +} +export class KeyVaultAdminPoller, TResult> + implements PollerLike +{ + protected httpPoller: CorePollerLike; + protected options: KeyVaultAdminPollerOptions; + constructor(options: KeyVaultAdminPollerOptions) { + this.options = options; + this.httpPoller = createHttpPoller( + { + sendInitialRequest: this.sendInitialRequest.bind(this), + sendPollRequest: (_path: string) => { + throw new Error("No need to pass poll request."); + }, + }, + { + restoreFrom: options.resumeFrom, + }, + ); + } + getOperationState(): TState { + if (!this.httpPoller.operationState) { + throw new Error("Operation state is not available."); + } + return this.httpPoller.operationState; + } -// /** -// * Meant to reach to the service and update the Poller operation. -// */ -// public async update(): Promise> { -// throw new Error("Operation not supported."); -// } + async sendInitialRequest(): Promise> { + throw new Error("Method not implemented."); + } -// /** -// * Meant to reach to the service and cancel the Poller operation. -// */ -// public async cancel(): Promise> { -// throw new Error(this.cancelMessage); -// } + async poll(_options?: { abortSignal?: AbortSignalLike }): Promise { + throw new Error("Method not implemented."); + } + pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise { + return this.httpPoller.pollUntilDone(pollOptions); + } + onProgress(callback: (state: any) => void): CancelOnProgress { + return this.httpPoller.onProgress(callback); + } + stopPolling(): void { + throw new Error("Method not implemented."); + } + isStopped(): boolean { + throw new Error("Method not implemented."); + } + cancelOperation(_options?: { abortSignal?: AbortSignalLike }): Promise { + throw new Error("Method not implemented."); + } + getResult(): any { + return this.httpPoller.result; + } + toString(): string { + if (!this.httpPoller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return JSON.stringify({ + state: this.httpPoller.operationState, + }); + } -// /** -// * Serializes the Poller operation. -// */ -// public toString(): string { -// return JSON.stringify({ -// state: cleanState(this.state), -// }); -// } -// } + getLroResponse(raw: HttpResponse): OperationResponse { + return { + flatResponse: raw, + rawResponse: { + ...raw, + statusCode: Number(raw.status), + body: raw.body, + }, + }; + } +} diff --git a/sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts b/sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts deleted file mode 100644 index d19e3ab70b7a..000000000000 --- a/sdk/keyvault/keyvault-admin/src/lro/restore/operation.ts +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// import { -// FullRestoreOperationOptionalParams, -// FullRestoreOperationResponse, -// RestoreOperation, -// RestoreStatusResponse, -// } from "../../generated/models/index.js"; -import { KeyVaultAdminPollOperationState } from "../keyVaultAdminPoller.js"; -import { KeyVaultRestoreResult } from "../../backupClientModels.js"; - -// import { AbortSignalLike } from "@azure/abort-controller"; -// import { KeyVaultClient } from "../../generated/keyVaultClient.js"; -// import { OperationOptions } from "@azure-rest/core-client"; -// import { tracingClient } from "../../tracing.js"; - -/** - * An interface representing the publicly available properties of the state of a restore Key Vault's poll operation. - */ -export interface KeyVaultRestoreOperationState - extends KeyVaultAdminPollOperationState {} - -// /** -// * An internal interface representing the state of a restore Key Vault's poll operation. -// * @internal -// */ -// export interface KeyVaultRestorePollOperationState -// extends KeyVaultAdminPollOperationState { -// /** -// * The URI of the blob storage account. -// */ -// folderUri: string; -// /** -// * The SAS token. -// */ -// sasToken?: string; -// /** -// * The Folder name of the blob where the previous successful full backup was stored -// */ -// folderName: string; -// } - -// /** -// * An interface representing a restore Key Vault's poll operation. -// */ -// export class KeyVaultRestorePollOperation extends KeyVaultAdminPollOperation< -// KeyVaultRestorePollOperationState, -// KeyVaultRestoreResult -// > { -// constructor( -// public state: KeyVaultRestorePollOperationState, -// private vaultUrl: string, -// private client: KeyVaultClient, -// private requestOptions: KeyVaultBeginRestoreOptions = {}, -// ) { -// super(state, { -// cancelMessage: "Cancelling the restoration full Key Vault backup is not supported.", -// }); -// } - -// /** -// * Tracing the fullRestore operation -// */ -// private fullRestore( -// options: FullRestoreOperationOptionalParams, -// ): Promise { -// return tracingClient.withSpan("KeyVaultRestorePoller.fullRestore", options, (updatedOptions) => -// this.client.fullRestoreOperation(this.vaultUrl, updatedOptions), -// ); -// } - -// /** -// * Tracing the restoreStatus operation. -// */ -// private async restoreStatus( -// jobId: string, -// options: OperationOptions, -// ): Promise { -// return tracingClient.withSpan( -// "KeyVaultRestorePoller.restoreStatus", -// options, -// (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions), -// ); -// } - -// /** -// * Reaches to the service and updates the restore poll operation. -// */ -// async update( -// options: { -// abortSignal?: AbortSignalLike; -// fireProgress?: (state: KeyVaultRestorePollOperationState) => void; -// } = {}, -// ): Promise { -// const state = this.state; -// const { folderUri, sasToken, folderName } = state; - -// if (options.abortSignal) { -// this.requestOptions.abortSignal = options.abortSignal; -// } - -// if (!state.isStarted) { -// const serviceOperation = await this.fullRestore({ -// ...this.requestOptions, -// restoreBlobDetails: { -// folderToRestore: folderName, -// sasTokenParameters: { -// storageResourceUri: folderUri, -// token: sasToken, -// useManagedIdentity: sasToken === undefined, -// }, -// }, -// }); - -// this.mapState(serviceOperation); -// } else if (!state.isCompleted) { -// if (!state.jobId) { -// throw new Error(`Missing "jobId" from the full restore operation.`); -// } -// const serviceOperation = await this.restoreStatus(state.jobId, this.requestOptions); -// this.mapState(serviceOperation); -// } - -// return this; -// } - -// private mapState(serviceOperation: RestoreOperation): void { -// const state = this.state; -// const { startTime, jobId, endTime, error, status, statusDetails } = serviceOperation; - -// if (!startTime) { -// throw new Error( -// `Missing "startTime" from the full restore operation. Restore did not start successfully.`, -// ); -// } - -// state.isStarted = true; -// state.jobId = jobId; -// state.endTime = endTime; -// state.startTime = startTime; -// state.status = status; -// state.statusDetails = statusDetails; - -// state.isCompleted = !!endTime; - -// if (state.isCompleted && error?.code) { -// throw new Error(error?.message || statusDetails); -// } - -// if (state.isCompleted) { -// state.result = { -// startTime, -// endTime, -// }; -// } -// } -// } diff --git a/sdk/keyvault/keyvault-admin/src/lro/restore/poller.ts b/sdk/keyvault/keyvault-admin/src/lro/restore/poller.ts index 51aa7f9b53af..7e88b15ad1fe 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/restore/poller.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/restore/poller.ts @@ -1,59 +1,127 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -// import { KeyVaultAdminPoller, KeyVaultAdminPollerOptions } from "../keyVaultAdminPoller.js"; -// import { -// KeyVaultRestoreOperationState, -// KeyVaultRestorePollOperation, -// KeyVaultRestorePollOperationState, -// } from "./operation.js"; -// import { KeyVaultRestoreResult } from "../../backupClientModels.js"; - -// export interface KeyVaultRestorePollerOptions extends KeyVaultAdminPollerOptions { -// folderUri: string; -// sasToken?: string; -// folderName: string; -// } - -// /** -// * Class that creates a poller that waits until a Key Vault ends up being restored. -// */ -// export class KeyVaultRestorePoller extends KeyVaultAdminPoller< -// KeyVaultRestoreOperationState, -// KeyVaultRestoreResult -// > { -// constructor(options: KeyVaultRestorePollerOptions) { -// const { -// client, -// vaultUrl, -// folderUri, -// sasToken, -// folderName, -// requestOptions, -// intervalInMs = 2000, -// resumeFrom, -// } = options; - -// let state: KeyVaultRestorePollOperationState | undefined; - -// if (resumeFrom) { -// state = JSON.parse(resumeFrom).state; -// } - -// const operation = new KeyVaultRestorePollOperation( -// { -// ...state, -// folderUri, -// sasToken, -// folderName, -// }, -// vaultUrl, -// client, -// requestOptions, -// ); - -// super(operation); - -// this.intervalInMs = intervalInMs; -// } -// } +import { FullOperationResponse } from "@azure-rest/core-client"; +import { + _fullRestoreOperationDeserialize, + _fullRestoreOperationSend, +} from "../../generated/api/operations.js"; +import { + FullRestoreOperationOptionalParams, + RestoreOperation, + RestoreStatusOptionalParams, +} from "../../generated/index.js"; +import { + KeyVaultAdminPoller, + KeyVaultAdminPollerOptions, + KeyVaultAdminPollOperationState, +} from "../keyVaultAdminPoller.js"; +import { OperationResponse } from "@azure/core-lro"; +import { KeyVaultRestoreResult } from "../../backupClientModels.js"; + +export interface KeyVaultRestoreOperationState + extends KeyVaultAdminPollOperationState {} + +export interface KeyVaultRestorePollerOptions extends KeyVaultAdminPollerOptions { + folderUri: string; + sasToken?: string; + folderName: string; +} + +export class KeyVaultRestorePoller extends KeyVaultAdminPoller< + KeyVaultRestoreOperationState, + KeyVaultRestoreResult +> { + protected options: KeyVaultRestorePollerOptions; + private initialResponseBody?: RestoreOperation; + constructor(options: KeyVaultRestorePollerOptions) { + super(options); + this.options = options; + } + + /** + * Tracing the fullRestore operation + */ + private async fullRestore( + options?: FullRestoreOperationOptionalParams, + ): Promise { + const res = await _fullRestoreOperationSend( + this.options.client["_client"], + { + folderToRestore: this.options.folderName, + sasTokenParameters: { + storageResourceUri: this.options.folderUri, + token: this.options.sasToken, + useManagedIdentity: this.options.sasToken === undefined, + }, + }, + options, + ); + return _fullRestoreOperationDeserialize(res); + } + + /** + * Tracing the restoreStatus operation. + */ + private async restoreStatus(options?: RestoreStatusOptionalParams): Promise { + if (!this.httpPoller.operationState?.jobId) { + throw new Error(`Missing "jobId" from the full restore operation.`); + } + return this.options.client.restoreStatus(this.httpPoller.operationState.jobId, options); + } + + async sendInitialRequest(): Promise> { + let response: FullOperationResponse; + this.initialResponseBody = await this.fullRestore({ + ...this.options.operationOptions, + onResponse: (rawResponse) => { + response = rawResponse; + }, + }); + return this.getLroResponse(response! as any); + } + + async poll(_options?: {}): Promise { + await this.httpPoller.submitted(); + if (!this.httpPoller.operationState?.isStarted && this.initialResponseBody) { + this.mapState(this.initialResponseBody); + } + if (!this.httpPoller.operationState?.isCompleted) { + const serviceOperation = await this.restoreStatus(this.options.operationOptions); + this.mapState(serviceOperation); + } + } + + private mapState(serviceOperation: RestoreOperation): void { + if (this.httpPoller.operationState === undefined) { + (this.httpPoller as any)["operationState"] = {}; + } + const state = this.httpPoller.operationState!; + const { startTime, jobId, endTime, error, statusDetails } = serviceOperation; + if (!startTime) { + throw new Error( + `Missing "startTime" from the full restore operation. Restore did not start successfully.`, + ); + } + state.isStarted = true; + state.jobId = jobId; + state.endTime = endTime; + state.startTime = startTime; + state.statusDetails = statusDetails; + state.isCompleted = !!endTime; + // TODO: transform the status to the one expected by the poller + state.status = state.isCompleted ? "succeeded" : "running"; + + if (state.isCompleted && error?.code) { + state.status = "failed"; + throw new Error(error?.message || statusDetails); + } + + if (state.isCompleted) { + state.result = { + startTime, + endTime, + }; + } + } +} diff --git a/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts b/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts index bd8b7ebb2f46..3192083c112a 100644 --- a/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts +++ b/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/operation.ts @@ -1,155 +1,89 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { KeyVaultAdminPollOperationState } from "../keyVaultAdminPoller.js"; import { KeyVaultSelectiveKeyRestoreResult } from "../../backupClientModels.js"; -// import { -// RestoreOperation, -// RestoreStatusResponse, -// SelectiveKeyRestoreOperationOptionalParams, -// SelectiveKeyRestoreOperationResponse, -// } from "../../generated/models/index.js"; -// import { AbortSignalLike } from "@azure/abort-controller"; -// import { KeyVaultClient } from "../../generated/keyVaultClient.js"; -// import { OperationOptions } from "@azure-rest/core-client"; -// import { tracingClient } from "../../tracing.js"; +import { Client, PathUncheckedResponse } from "@azure-rest/core-client"; +import { SelectiveKeyRestoreOperationOptionalParams } from "../../generated/index.js"; +import { OperationResponse, OperationState, PollerLike } from "@azure/core-lro"; +import { getLongRunningPoller } from "../../generated/static-helpers/pollingHelpers.js"; +import { _selectiveKeyRestoreOperationSend } from "../../generated/api/operations.js"; -// /** -// * An interface representing the publicly available properties of the state of a restore Key Vault's poll operation. -// */ -export interface KeyVaultSelectiveKeyRestoreOperationState - extends KeyVaultAdminPollOperationState {} +export interface KeyVaultSelectiveKeyRestoreOperationState + extends OperationState { + /** +* Identifier for the full restore operation. +*/ + jobId?: string; + /** + * The status details of restore operation. + */ + statusDetails?: string; + /** + * The start time of the restore operation in UTC + */ + startTime?: Date; + /** + * The end time of the restore operation in UTC + */ + endTime?: Date; + isStarted?: boolean; + isCompleted?: boolean; +} -// /** -// * An internal interface representing the state of a restore Key Vault's poll operation. -// */ -// export interface KeyVaultSelectiveKeyRestorePollOperationState -// extends KeyVaultAdminPollOperationState { -// /** -// * The name of a Key Vault Key. -// */ -// keyName: string; -// /** -// * The Folder name of the blob where the previous successful full backup was stored -// */ -// folderName: string; -// /** -// * The URI of the blob storage account where the previous successful full backup was stored. -// */ -// folderUri: string; -// /** -// * The SAS token. -// */ -// sasToken?: string; -// } -// /** -// * The selective restore Key Vault's poll operation. -// */ -// export class KeyVaultSelectiveKeyRestorePollOperation extends KeyVaultAdminPollOperation< -// KeyVaultSelectiveKeyRestorePollOperationState, -// string -// > { -// constructor( -// public state: KeyVaultSelectiveKeyRestorePollOperationState, -// private vaultUrl: string, -// private client: KeyVaultClient, -// private requestOptions: KeyVaultBeginSelectiveKeyRestoreOptions = {}, -// ) { -// super(state, { cancelMessage: "Cancelling a selective Key Vault restore is not supported." }); -// } +function processFinalResult(result: PathUncheckedResponse): Promise { + // please note this raw body would be one on the wire + const serviceOperation = result.body as any; + const { startTime, endTime, error, statusDetails } = serviceOperation; + if (serviceOperation.error?.code) { + throw new Error(error?.message || statusDetails); + } + return Promise.resolve({ + startTime: startTime!, // TODO: Please note this startTime would be string on the wire + endTime, + }); +} -// /** -// * Tracing the selectiveRestore operation -// */ -// private selectiveRestore( -// keyName: string, -// options: SelectiveKeyRestoreOperationOptionalParams, -// ): Promise { -// return tracingClient.withSpan( -// "KeyVaultSelectiveKeyRestorePoller.selectiveRestore", -// options, -// (updatedOptions) => -// this.client.selectiveKeyRestoreOperation(this.vaultUrl, keyName, updatedOptions), -// ); -// } +function updateRestoreState(state: KeyVaultSelectiveKeyRestoreOperationState, response: OperationResponse): void { + // please note this raw body would be one on the wire + const serviceOperation = (response as OperationResponse).flatResponse.body as any; + const { startTime, jobId, endTime, error, statusDetails } = serviceOperation; + if (!startTime) { + throw new Error( + `Missing "startTime" from the full restore operation. Restore did not start successfully.`, + ); + } + state.isStarted = true; + state.jobId = jobId; + state.endTime = endTime; + state.startTime = startTime; + state.isCompleted = !!endTime; + // TODO: transform the status to the one expected by the poller + state.status = state.isCompleted ? "succeeded" : "running"; + state.statusDetails = statusDetails; + if (serviceOperation.error?.code) { + state.status = "failed"; + throw new Error(error?.message || statusDetails); + } +} -// /** -// * Tracing the restoreStatus operation. -// */ -// private restoreStatus(jobId: string, options: OperationOptions): Promise { -// return tracingClient.withSpan( -// "KeyVaultSelectiveKeyRestorePoller.restoreStatus", -// options, -// (updatedOptions) => this.client.restoreStatus(this.vaultUrl, jobId, updatedOptions), -// ); -// } -// /** -// * Reaches to the service and updates the selective restore poll operation. -// */ -// async update( -// options: { -// abortSignal?: AbortSignalLike; -// fireProgress?: (state: KeyVaultSelectiveKeyRestorePollOperationState) => void; -// } = {}, -// ): Promise { -// const state = this.state; -// const { keyName, folderUri, sasToken, folderName } = state; - -// if (options.abortSignal) { -// this.requestOptions.abortSignal = options.abortSignal; -// } - -// if (!state.isStarted) { -// const selectiveRestoreOperation = await this.selectiveRestore(keyName, { -// ...this.requestOptions, -// restoreBlobDetails: { -// folder: folderName, -// sasTokenParameters: { -// storageResourceUri: folderUri, -// token: sasToken, -// useManagedIdentity: sasToken === undefined, -// }, -// }, -// }); -// this.mapState(selectiveRestoreOperation); -// } else if (!state.isCompleted) { -// if (!state.jobId) { -// throw new Error(`Missing "jobId" from the full restore operation.`); -// } -// const serviceOperation = await this.restoreStatus(state.jobId, this.requestOptions); -// this.mapState(serviceOperation); -// } - -// return this; -// } - -// private mapState(serviceOperation: RestoreOperation): void { -// const state = this.state; -// const { startTime, jobId, endTime, error, status, statusDetails } = serviceOperation; - -// if (!startTime) { -// throw new Error(`Missing "startTime" from the selective restore operation.`); -// } - -// state.isStarted = true; -// state.jobId = jobId; -// state.endTime = endTime; -// state.startTime = startTime; -// state.status = status; -// state.statusDetails = statusDetails; -// state.isCompleted = !!endTime; - -// if (state.isCompleted && error?.code) { -// throw new Error(error?.message || statusDetails); -// } - -// if (state.isCompleted) { -// state.result = { -// startTime, -// endTime, -// }; -// } -// } -// } +export function selectiveKeyRestoreOperation( + context: Client, + keyName: string, + options: SelectiveKeyRestoreOperationOptionalParams = { requestOptions: {} }, +): PollerLike, KeyVaultSelectiveKeyRestoreResult> { + return getLongRunningPoller( + context, + processFinalResult, // TODO: this function to update result + ["202", "200"], + { + updateIntervalInMs: options?.updateIntervalInMs, + abortSignal: options?.abortSignal, + getInitialResponse: () => + _selectiveKeyRestoreOperationSend(context, keyName, options), + resourceLocationConfig: "azure-async-operation", + updateState: updateRestoreState // TODO: this function to update state + }, + ); +} diff --git a/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/poller.ts b/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/poller.ts deleted file mode 100644 index 965e1f3bf410..000000000000 --- a/sdk/keyvault/keyvault-admin/src/lro/selectiveKeyRestore/poller.ts +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -// import { KeyVaultAdminPoller, KeyVaultAdminPollerOptions } from "../keyVaultAdminPoller.js"; -// import { -// KeyVaultSelectiveKeyRestoreOperationState, -// KeyVaultSelectiveKeyRestorePollOperation, -// KeyVaultSelectiveKeyRestorePollOperationState, -// } from "./operation.js"; -// import { KeyVaultSelectiveKeyRestoreResult } from "../../backupClientModels.js"; - -// export interface KeyVaultSelectiveKeyRestorePollerOptions extends KeyVaultAdminPollerOptions { -// keyName: string; -// folderUri: string; -// sasToken?: string; -// folderName: string; -// } - -// /** -// * Class that creates a poller that waits until a key of a Key Vault backup ends up being restored. -// */ -// export class KeyVaultSelectiveKeyRestorePoller extends KeyVaultAdminPoller< -// KeyVaultSelectiveKeyRestoreOperationState, -// KeyVaultSelectiveKeyRestoreResult -// > { -// constructor(options: KeyVaultSelectiveKeyRestorePollerOptions) { -// const { -// client, -// vaultUrl, -// keyName, -// folderUri, -// sasToken, -// folderName, -// requestOptions, -// intervalInMs = 2000, -// resumeFrom, -// } = options; - -// let state: KeyVaultSelectiveKeyRestorePollOperationState | undefined; - -// if (resumeFrom) { -// state = JSON.parse(resumeFrom).state; -// } - -// const operation = new KeyVaultSelectiveKeyRestorePollOperation( -// { -// ...state, -// keyName, -// folderUri: folderUri, -// sasToken, -// folderName, -// }, -// vaultUrl, -// client, -// requestOptions, -// ); - -// super(operation); - -// this.intervalInMs = intervalInMs; -// } -// } diff --git a/sdk/keyvault/keyvault-admin/src/lro/shim.ts b/sdk/keyvault/keyvault-admin/src/lro/shim.ts new file mode 100644 index 000000000000..40397c4efd95 --- /dev/null +++ b/sdk/keyvault/keyvault-admin/src/lro/shim.ts @@ -0,0 +1,130 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { AbortSignalLike } from "@azure/abort-controller"; +import { + CancelOnProgress, + OperationState, + PollerLike, +} from "@azure/core-lro"; + +/** + * A simple poller that can be used to poll a long running operation. + */ +export interface SimplePollerLike, TResult> { + /** + * Returns true if the poller has finished polling. + */ + isDone(): boolean; + /** + * Returns true if the poller is stopped. + */ + isStopped(): boolean; + /** + * Returns the state of the operation. + */ + getOperationState(): TState; + /** + * Returns the result value of the operation, + * regardless of the state of the poller. + * It can return undefined or an incomplete form of the final TResult value + * depending on the implementation. + */ + getResult(): TResult | undefined; + /** + * Returns a promise that will resolve once a single polling request finishes. + * It does this by calling the update method of the Poller's operation. + */ + poll(options?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Returns a promise that will resolve once the underlying operation is completed. + */ + pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Invokes the provided callback after each polling is completed, + * sending the current state of the poller's operation. + * + * It returns a method that can be used to stop receiving updates on the given callback function. + */ + onProgress(callback: (state: TState) => void): CancelOnProgress; + + /** + * Wait the poller to be submitted. + */ + submitted(): Promise; + + /** + * Returns a string representation of the poller's operation. Similar to serialize but returns a string. + */ + toString(): string; + + /** + * Stops the poller from continuing to poll. Please note this will only stop the client-side polling + */ + stopPolling(): void; +} + + +export async function wrapPoller, TResult>( + httpPoller: PollerLike +): Promise> { + const abortController = new AbortController(); + const simplePoller: SimplePollerLike = { + isDone() { + return httpPoller.isDone; + }, + isStopped() { + return abortController.signal.aborted; + }, + getOperationState() { + if (!httpPoller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return httpPoller.operationState; + }, + getResult() { + return this.getOperationState().result; + }, + toString() { + if (!httpPoller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return JSON.stringify({ + state: httpPoller.operationState, + }); + }, + stopPolling() { + abortController.abort(); + }, + onProgress(callback: (state: TargetState) => void): CancelOnProgress { + // we could simple castcade here if they are both OperationState + return httpPoller.onProgress(callback as unknown as (state: SourceState) => void) + }, + async poll() { + await httpPoller.poll(); + }, + async pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }) { + function abortListener(): void { + abortController.abort(); + } + const inputAbortSignal = pollOptions?.abortSignal; + const abortSignal = abortController.signal; + if (inputAbortSignal?.aborted) { + abortController.abort(); + } else if (!abortSignal.aborted) { + inputAbortSignal?.addEventListener("abort", abortListener, { + once: true, + }); + } + await httpPoller.pollUntilDone({ abortSignal: abortController.signal }); + return this.getOperationState().result!; + }, + submitted: httpPoller.submitted, + }; + await httpPoller.submitted(); + return simplePoller; +}