How to use @google-cloud/secret-manager - 8 common examples

To help you get started, we’ve selected a few @google-cloud/secret-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-secret-manager / samples / enableSecretVersion.js View on Github external
async function main(name = 'projects/my-project/secrets/my-secret/versions/1') {
  // [START secretmanager_enable_secret_version]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const name = 'projects/my-project/secrets/my-secret/versions/5';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  async function enableSecretVersion() {
    const [version] = await client.enableSecretVersion({
      name: name,
    });

    console.info(`Enabled ${version.name}`);
  }

  enableSecretVersion();
  // [END secretmanager_enable_secret_version]
}
github googleapis / nodejs-secret-manager / samples / listSecrets.js View on Github external
async function main(parent = 'projects/my-project') {
  // [START secretmanager_list_secrets]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const parent = 'projects/my-project';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  async function listSecrets() {
    const [secrets] = await client.listSecrets({
      parent: parent,
    });

    secrets.forEach(secret => {
      const policy = secret.replication.replication;
      console.log(`${secret.name} (${policy})`);
    });
  }

  listSecrets();
  // [END secretmanager_list_secrets]
}
github googleapis / nodejs-secret-manager / samples / getSecretVersion.js View on Github external
async function main(name = 'projects/my-project/secrets/my-secret/versions/1') {
  // [START secretmanager_get_secret_version]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const name = 'projects/my-project/secrets/my-secret/versions/5';
  // const name = 'projects/my-project/secrets/my-secret/versions/latest';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  async function getSecretVersion() {
    const [version] = await client.getSecretVersion({
      name: name,
    });

    console.info(`Found secret ${version.name} with state ${version.state}`);
  }

  getSecretVersion();
  // [END secretmanager_get_secret_version]
}
github googleapis / nodejs-secret-manager / samples / disableSecretVersion.js View on Github external
async function main(name = 'projects/my-project/secrets/my-secret/versions/1') {
  // [START secretmanager_disable_secret_version]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const name = 'projects/my-project/secrets/my-secret/versions/5';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  async function disableSecretVersion() {
    const [version] = await client.disableSecretVersion({
      name: name,
    });

    console.info(`Disabled ${version.name}`);
  }

  disableSecretVersion();
  // [END secretmanager_disable_secret_version]
}
github googleapis / nodejs-secret-manager / samples / addSecretVersion.js View on Github external
async function main(parent = 'projects/my-project/secrets/my-secret') {
  // [START secretmanager_add_secret_version]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const parent = 'projects/my-project/secrets/my-secret';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  // Payload is the plaintext data to store in the secret
  const payload = Buffer.from('my super secret data', 'utf8');

  async function addSecretVersion() {
    const [version] = await client.addSecretVersion({
      parent: parent,
      payload: {
        data: payload,
      },
    });

    console.log(`Added secret version ${version.name}`);
  }

  addSecretVersion();
github googleapis / nodejs-secret-manager / samples / getSecret.js View on Github external
async function main(name = 'projects/my-project/secrets/my-secret') {
  // [START secretmanager_get_secret]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const name = 'projects/my-project/secrets/my-secret';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  async function getSecret() {
    const [secret] = await client.getSecret({
      name: name,
    });

    const policy = secret.replication.replication;

    console.info(`Found secret ${secret.name} (${policy})`);
  }

  getSecret();
  // [END secretmanager_get_secret]
}
github googleapis / nodejs-secret-manager / samples / listSecretVersions.js View on Github external
async function main(parent = 'projects/my-project/secrets/my-secret') {
  // [START secretmanager_list_secret_versions]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const parent = 'projects/my-project/secrets/my-secret';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  async function listSecretVersions() {
    const [versions] = await client.listSecretVersions({
      parent: parent,
    });

    versions.forEach(version => {
      console.log(`${version.name}: ${version.state}`);
    });
  }

  listSecretVersions();
  // [END secretmanager_list_secret_versions]
}
github googleapis / nodejs-secret-manager / samples / destroySecretVersion.js View on Github external
async function main(name = 'projects/my-project/secrets/my-secret/versions/1') {
  // [START secretmanager_destroy_secret_version]
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const name = 'projects/my-project/secrets/my-secret/versions/5';

  // Imports the Secret Manager library
  const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

  // Instantiates a client
  const client = new SecretManagerServiceClient();

  async function destroySecretVersion() {
    const [version] = await client.destroySecretVersion({
      name: name,
    });

    console.info(`Destroyed ${version.name}`);
  }

  destroySecretVersion();
  // [END secretmanager_destroy_secret_version]
}

@google-cloud/secret-manager

Secrets client for Node.js

Apache-2.0
Latest version published 7 months ago

Package Health Score

96 / 100
Full package analysis

Popular @google-cloud/secret-manager functions