Main Content

setSecretMetadata

Set metadata of secret in MATLAB vault

Since R2024a

Description

setSecretMetadata(secretname,secretMetadata) adds the metadata in the dictionary secretMetadata to the specified secret in your MATLAB® vault. Your MATLAB vault is accessible only from the exact combination of your operating system account and local machine.

example

setSecretMetadata(secretname,secretMetadata,WriteMode=mode) specifies whether to add, merge, or replace existing secret metadata.

example

Examples

collapse all

Create a dictionary that contains metadata for an existing secret. Specify dictionary keys as strings, and specify dictionary values as cells.

m = dictionary(["Description","TeamMembers", ... 
    "Phone","CreationDate"], ...
    [{"This is an example of metadata"}, ...
    {"Maria Silva, Akane Saito"}, ...
    {"123-456-7890"},{datetime("now")}])
m =

  dictionary (string ⟼ cell) with 4 entries:

    "Description"  ⟼ {["This is an example of metadata"]}
    "TeamMembers"  ⟼ {["Maria Silva, Akane Saito"]}
    "Phone"        ⟼ {["123-456-7890"]}
    "CreationDate" ⟼ {[01-Nov-2023 12:34:06]}

Add the metadata to an existing secret in your vault.

setSecretMetadata("SFTPpassword",m);

Add additional elements to your metadata using additional dictionaries. View your updated metadata.

version = dictionary(["version"],[{"5.1"}]);
setSecretMetadata("SFTPpassword",version);
getSecretMetadata("SFTPpassword")
  dictionary (string ⟼ cell) with 5 entries:

    "CreationDate" ⟼ {[01-Nov-2023 12:34:06]}
    "Description"  ⟼ {["This is an example of metadata"]}
    "Phone"        ⟼ {["123-456-7890"]}
    "TeamMembers"  ⟼ {["Maria Silva, Akane Saito"]}
    "version"      ⟼ {["5.1"]}

Add metadata to an existing secret in your vault.

m = dictionary(["Description","TeamMembers", ... 
    "Phone","CreationDate"], ...
    [{"This is an example of metadata"}, ...
    {"Maria Silva, Akane Saito"}, ...
    {"123-456-7890"},{datetime("now")}]);
setSecretMetadata("SFTPpassword",m);

Overwrite the value of TeamMembers by merging a new dictionary with the existing metadata dictionary. Then view the updated metadata of the secret.

m2 = dictionary(["TeamMembers"],[{"John Doe, Omar Ali"}]);
setSecretMetadata("SFTPpassword",m2,WriteMode="merge");
getSecretMetadata("SFTPpassword")
  dictionary (string ⟼ cell) with 4 entries:

    "CreationDate" ⟼ {[01-Nov-2023 12:41:12]}
    "Description"  ⟼ {["This is an example of metadata"]}
    "Phone"        ⟼ {["123-456-7890"]}
    "TeamMembers"  ⟼ {["John Doe, Omar Ali"]}

Add metadata to an existing secret in your vault.

m = dictionary(["Description","TeamMembers", ... 
    "Phone","CreationDate"], ...
    [{"This is an example of metadata"}, ...
    {"Maria Silva, Akane Saito"}, ...
    {"123-456-7890"},{datetime("now")}]);
setSecretMetadata("SFTPpassword",m);

Replace the existing metadata dictionary of the secret with a new dictionary. Then view the updated metadata.

m2 = dictionary(["Description","CreationDate"], ...
    [{"Another example of metadata"},{datetime("now")}]);
setSecretMetadata("SFTPpassword",m2,WriteMode="replace");
getSecretMetadata("SFTPpassword")
  dictionary (string ⟼ cell) with 2 entries:

    "CreationDate" ⟼ {[01-Nov-2023 12:51:17]}
    "Description"  ⟼ {["Another example of metadata"]}

Add metadata to an existing secret in your vault.

m = dictionary(["Description","TeamMembers", ... 
    "Phone","CreationDate"], ...
    [{"This is an example of metadata"}, ...
    {"Maria Silva, Akane Saito"}, ...
    {"123-456-7890"},{datetime("now")}]);
setSecretMetadata("SFTPpassword",m);

Clear the metadata of the secret by replacing it with an empty dictionary. Then view the cleared metadata.

m2 = configureDictionary("string","cell");
setSecretMetadata("SFTPpassword",m2,WriteMode="replace");
getSecretMetadata("SFTPpassword")
  dictionary (string ⟼ cell) with no entries.

Input Arguments

collapse all

Unique case-sensitive text identifier for the secret, specified as a string scalar or character vector. You can use a secret to hold sensitive information, such as passwords, certificates, credentials, OAuth tokens, and other configuration data for:

  • SFTP and FTP servers

  • Password-protected files, such as PDFs

  • Password-protected archives, such as zip files

  • Cloud providers, such as Amazon S3™ and Windows Azure® Blob Storage

  • API keys, SSH keys, and encryption keys

  • Databases and applications

The forward slash character (/) is not supported in secretname.

Metadata for the secret, specified as a dictionary whose keys are strings and values are cells. For more information on dictionaries, see dictionary. You can use metadata to store information, such as:

  • Description

  • Creation time

  • URL

  • Geolocation

  • Email address

  • Phone number

Mode for modifying secret metadata dictionary, specified as one of these values:

  • "add" – Add elements to the metadata dictionary of a secret. Existing metadata is not modified and matching keys cause an error.

  • "merge" – Merge a new metadata dictionary with the existing metadata dictionary of a secret. If any keys match existing keys, the new values overwrite the existing values.

  • "replace" – Replace the entire metadata dictionary. Use this mode with an empty dictionary to clear the metadata.

For more information on dictionaries, see dictionary.

Data Types: string | char

More About

collapse all

MATLAB Vault

Your secrets are stored in your MATLAB vault, which is accessible only from the exact combination of your operating system account and local machine. Your vault and secrets, which do not leave your local machine, persist across MATLAB sessions. Each secret consists of a name, value, and optional metadata.

  • Secret name – A unique case-sensitive text identifier for the secret. The secret name is stored unencrypted in your vault as a string scalar.

  • Secret value – A text value associated with the secret. The Secret Prompt dialog box, where you enter the secret value, supports copy-paste functionality. The secret value is stored encrypted in your vault using industry standard AES-256 encryption. The secret value is returned as a string scalar.

  • Secret metadata – A dictionary containing additional information associated with the secret. The optional secret metadata is stored unencrypted in your vault.

To set a secret, use setSecret.

Version History

Introduced in R2024a