MySQL Shell 9.4  /  Getting Started with MySQL Shell  /  Generic Secret Storage

4.5 Generic Secret Storage

This section describes MySQL Shell's secret storage.

Secret Management Functions

You can use the following functions to manage your secrets:

  • shell.storeSecret(key, value): Stores a secret with the given key.

  • shell.readSecret(key): Reads a secret with the given key.

  • shell.deleteSecret(key): Deletes a secret with the given key.

  • shell.deleteAllSecrets(): Deletes all secrets

  • shell.listSecrets(): Lists keys of all secrets

Note

Secrets stored with this API are not accessible to the credential methods listed here: Section 4.4.2, “Working with Credentials”, nor can this API access credentials managed by that API.

Storing Secrets

To store a secret, use the shell.storeSecret(key, value) function. This function takes two parameters: key and value. key is a string that uniquely identifies the secret, while the value parameter is an optional string that specifies the value of the secret.

  • key: String that uniquely identifies the secret.

  • value: (optional) String that specifies the value of the secret.

    If you do not provide a value, you will be prompted to enter it in a masked prompt. If a secret with the given key already exists in storage, its value will be overwritten.

For example:

shell.storeSecret("my_secret", "my_secret_value")

Alternatively, to enter your secret in a masked prompt, omit the value and enter when prompted:

shell.storeSecret("my_secret")
Please provide the secret to store: *****************

Reading Secrets

To read a secret, use the shell.readSecret(key) function.

  • key: String identifying the key of the secret to read.

For example:

shell.readSecret("my_secret")

Listing Secrets

To list all secrets' keys stored by your current Secret Store Helper, use the shell.listSecrets() function. This function returns a list of strings containing all keys in storage.

In the following example, three secrets are defined in the current credential store and are returned as an array:

shell.listSecrets()
     [
    "my_secret2",
    "my_secret1",
    "my_secret"
    ]

Deleting Secrets

To delete a secret, use the shell.deleteSecret(key) function.

  • key: String identifying the key of the secret to delete.

For example:

shell.deleteSecret("my_secret")

Deleting All Secrets

To delete all secrets stored by your current Secret Store Helper, use the shell.deleteAllSecrets() function.

For example:

shell.deleteAllSecrets()