Skip to content

Instantly share code, notes, and snippets.

@cmbirk
Created May 25, 2023 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmbirk/36580d20e6ffd0c302289fa0b6734ceb to your computer and use it in GitHub Desktop.
Save cmbirk/36580d20e6ffd0c302289fa0b6734ceb to your computer and use it in GitHub Desktop.
import {SecretManagerServiceClient} from '@google-cloud/secret-manager'
const projectId = 'project-id'
// Instantiates a client
const client = new SecretManagerServiceClient();
export const accessSecretVersion = async (secretName) => {
const [version] = await client.accessSecretVersion({
name: `projects/${projectId}/secrets/${secretName}/versions/latest`,
});
// Extract the payload as a string.
const secretValue = version.payload.data.toString();
return secretValue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment