Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SecretClient

Package version

The SecretClient provides methods to manage KeyVaultSecret in the Azure Key Vault. The client supports creating, retrieving, updating, deleting, purging, backing up, restoring and listing KeyVaultSecrets. The client also supports listing DeletedSecret for a soft-delete enabled Azure Key Vault.

Hierarchy

  • SecretClient

Index

Constructors

constructor

  • new SecretClient(vaultUrl: string, credential: TokenCredential, pipelineOptions?: PipelineOptions): SecretClient
  • Creates an instance of SecretClient.

    Example usage:

    import { SecretClient } from "@azure/keyvault-secrets";
    import { DefaultAzureCredential } from "@azure/identity";
    
    let vaultUrl = `https://<MY KEYVAULT HERE>.vault.azure.net`;
    let credentials = new DefaultAzureCredential();
    
    let client = new SecretClient(vaultUrl, credentials);
    memberof

    SecretClient

    Parameters

    • vaultUrl: string

      the base URL to the vault.

    • credential: TokenCredential

      An object that implements the TokenCredential interface used to authenticate requests to the service. Use the @azure/identity package to create a credential that suits your needs.

    • Default value pipelineOptions: PipelineOptions = {}

    Returns SecretClient

Properties

vaultUrl

vaultUrl: string

The base URL to the vault

Methods

backupSecret

  • backupSecret(secretName: string, options?: BackupSecretOptions): Promise<Uint8Array | undefined>
  • Requests that a backup of the specified secret be downloaded to the client. All versions of the secret will be downloaded. This operation requires the secrets/backup permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    let backupResult = await client.backupSecret("MySecretName");
    summary

    Backs up the specified secret.

    Parameters

    Returns Promise<Uint8Array | undefined>

beginDeleteSecret

  • Deletes a secret stored in Azure Key Vault. This function returns a Long Running Operation poller that allows you to wait indifinetly until the secret is deleted.

    This operation requires the secrets/delete permission.

    Example usage:

    const client = new SecretClient(url, credentials);
    await client.setSecret("MySecretName", "ABC123");
    
    const deletePoller = await client.beginDeleteSecret("MySecretName");
    
    // Serializing the poller
    const serialized = deletePoller.toString();
    
    // A new poller can be created with:
    // const newPoller = await client.beginDeleteSecret("MySecretName", { resumeFrom: serialized });
    
    // Waiting until it's done
    const deletedSecret = await deletePoller.pollUntilDone();
    console.log(deletedSecret);
    summary

    Deletes a secret from a specified key vault.

    Parameters

    Returns Promise<PollerLike<PollOperationState<DeletedSecret>, DeletedSecret>>

beginRecoverDeletedSecret

  • Recovers the deleted secret in the specified vault. This function returns a Long Running Operation poller that allows you to wait indifinetly until the secret is recovered.

    This operation requires the secrets/recover permission.

    Example usage:

    const client = new SecretClient(url, credentials);
    await client.setSecret("MySecretName", "ABC123");
    
    const deletePoller = await client.beginDeleteSecret("MySecretName");
    await deletePoller.pollUntilDone();
    
    const recoverPoller = await client.recoverDeletedSecret("MySecretName");
    
    // Serializing the poller
    const serialized = recoverPoller.toString();
    
    // A new poller can be created with:
    // const newPoller = await client.beginRecoverDeletedSecret("MySecretName", { resumeFrom: serialized });
    
    // Waiting until it's done
    const deletedSecret = await recoverPoller.pollUntilDone();
    console.log(deletedSecret);
    summary

    Recovers the deleted secret to the latest version.

    Parameters

    Returns Promise<PollerLike<PollOperationState<SecretProperties>, SecretProperties>>

getDeletedSecret

  • The getDeletedSecret method returns the specified deleted secret along with its attributes. This operation requires the secrets/get permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    await client.getDeletedSecret("MyDeletedSecret");
    summary

    Gets the specified deleted secret.

    Parameters

    Returns Promise<DeletedSecret>

getSecret

  • The getSecret method is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    let secret = await client.getSecret("MySecretName");
    summary

    Get a specified secret from a given key vault.

    Parameters

    • secretName: string

      The name of the secret.

    • Default value options: GetSecretOptions = {}

    Returns Promise<KeyVaultSecret>

listDeletedSecrets

  • Iterates the deleted secrets in the vault. The full secret identifier and attributes are provided in the response. No values are returned for the secrets. This operations requires the secrets/list permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    for await (const deletedSecret of client.listDeletedSecrets()) {
      const deletedSecret = await client.getSecret(deletedSecret.name);
      console.log("deleted secret: ", deletedSecret);
    }
    summary

    List all secrets in the vault.

    Parameters

    Returns PagedAsyncIterableIterator<DeletedSecret, DeletedSecret[]>

listPropertiesOfSecretVersions

  • Iterates all versions of the given secret in the vault. The full secret identifier and attributes are provided in the response. No values are returned for the secrets. This operations requires the secrets/list permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    for await (const secretProperties of client.listPropertiesOfSecretVersions("MySecretName")) {
      const secret = await client.getSecret(secretProperties.name);
      console.log("secret version: ", secret);
    }

    Parameters

    Returns PagedAsyncIterableIterator<SecretProperties, SecretProperties[]>

listPropertiesOfSecrets

  • Iterates the latest version of all secrets in the vault. The full secret identifier and attributes are provided in the response. No values are returned for the secrets. This operations requires the secrets/list permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    for await (const secretProperties of client.listPropertiesOfSecrets()) {
      const secret = await client.getSecret(secretProperties.name);
      console.log("secret: ", secret);
    }
    summary

    List all secrets in the vault.

    Parameters

    Returns PagedAsyncIterableIterator<SecretProperties, SecretProperties[]>

purgeDeletedSecret

  • The purge deleted secret operation removes the secret permanently, without the possibility of recovery. This operation can only be enabled on a soft-delete enabled vault. This operation requires the secrets/purge permission.

    Example usage:

    const client = new SecretClient(url, credentials);
    const deletePoller = await client.beginDeleteSecret("MySecretName");
    await deletePoller.pollUntilDone();
    await client.purgeDeletedSecret("MySecretName");
    summary

    Permanently deletes the specified secret.

    Parameters

    Returns Promise<void>

restoreSecretBackup

  • Restores a backed up secret, and all its versions, to a vault. This operation requires the secrets/restore permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    let mySecretBundle = await client.backupSecret("MySecretName");
    // ...
    await client.restoreSecretBackup(mySecretBundle);
    summary

    Restores a backed up secret to a vault.

    Parameters

    • secretBundleBackup: Uint8Array

      The backup blob associated with a secret bundle.

    • Default value options: RestoreSecretBackupOptions = {}

    Returns Promise<SecretProperties>

setSecret

  • The setSecret method adds a secret or secret version to the Azure Key Vault. If the named secret already exists, Azure Key Vault creates a new version of that secret. This operation requires the secrets/set permission.

    Example usage:

    let client = new SecretClient(url, credentials);
    await client.setSecret("MySecretName", "ABC123");
    summary

    Adds a secret in a specified key vault.

    Parameters

    • secretName: string

      The name of the secret.

    • value: string

      The value of the secret.

    • Default value options: SetSecretOptions = {}

    Returns Promise<KeyVaultSecret>

updateSecretProperties

  • The updateSecret method changes specified attributes of an existing stored secret. Properties that are not specified in the request are left unchanged. The value of a secret itself cannot be changed. This operation requires the secrets/set permission.

    Example usage:

    let secretName = "MySecretName";
    let client = new SecretClient(url, credentials);
    let secret = await client.getSecret(secretName);
    await client.updateSecret(secretName, secret.version, { enabled: false });
    summary

    Updates the attributes associated with a specified secret in a given key vault.

    Parameters

    • secretName: string

      The name of the secret.

    • secretVersion: string

      The version of the secret.

    • Default value options: UpdateSecretPropertiesOptions = {}

    Returns Promise<SecretProperties>

Generated using TypeDoc