UNPKG

@azure/keyvault-secrets

Version:
81 lines 3.22 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { KeyVaultSecretPollOperation } from "../keyVaultSecretPoller.js"; import { getSecretFromSecretBundle } from "../../transformations.js"; import { tracingClient } from "../../tracing.js"; /** * An interface representing a delete secret's poll operation */ export class RecoverDeletedSecretPollOperation extends KeyVaultSecretPollOperation { state; client; options; constructor(state, client, options = {}) { super(state, { cancelMessage: "Canceling the recovery of a deleted secret is not supported." }); this.state = state; this.client = client; this.options = options; } /** * The getSecret method returns the specified secret along with its properties. * This operation requires the secrets/get permission. */ getSecret(name, options = {}) { return tracingClient.withSpan("RecoverDeletedSecretPoller.getSecret", options, async (updatedOptions) => { const response = await this.client.getSecret(name, options && options.version ? options.version : "", updatedOptions); return getSecretFromSecretBundle(response); }); } /** * The recoverDeletedSecret method recovers the specified deleted secret along with its properties. * This operation requires the secrets/recover permission. */ recoverDeletedSecret(name, options = {}) { return tracingClient.withSpan("RecoverDeletedSecretPoller.recoverDeletedSecret", options, async (updatedOptions) => { const response = await this.client.recoverDeletedSecret(name, updatedOptions); return getSecretFromSecretBundle(response); }); } /** * Reaches to the service and updates the delete secret's poll operation. */ async update(options = {}) { const state = this.state; const { name } = state; if (options.abortSignal) { this.options.abortSignal = options.abortSignal; } if (!state.isStarted) { try { state.result = (await this.getSecret(name, this.options)).properties; state.isCompleted = true; } catch { // Nothing to do here. } if (!state.isCompleted) { state.result = (await this.recoverDeletedSecret(name, this.options)).properties; state.isStarted = true; } } if (!state.isCompleted) { try { state.result = (await this.getSecret(name, this.options)).properties; state.isCompleted = true; } catch (error) { if (error.statusCode === 403) { // At this point, the resource exists but the user doesn't have access to it. state.isCompleted = true; } else if (error.statusCode !== 404) { state.error = error; state.isCompleted = true; throw error; } } } return this; } } //# sourceMappingURL=operation.js.map