Skip to content

Instantly share code, notes, and snippets.

@rhyskentish
Created May 18, 2020 16:24
Show Gist options
  • Save rhyskentish/df544d306212dba3763bf79478e8e9c1 to your computer and use it in GitHub Desktop.
Save rhyskentish/df544d306212dba3763bf79478e8e9c1 to your computer and use it in GitHub Desktop.
const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
const secretManagerclient = new SecretManagerServiceClient();
const parent = 'projects/<YourProjectId>';
const tokenId = <YourTokenId>
async function storeAppLevelSecret(appLevelSecretToStore) {
const [secret] = await secretManagerclient.createSecret({
parent: parent,
secretId: tokenId,
secret: {
replication: {
automatic: {},
},
},
});
console.log(`Created ${secret}`);
const payload = Buffer.from(appLevelSecretToStore, 'utf8');
const [version] = await client.addSecretVersion({
parent: secret.name,
payload: {
data: payload,
},
});
console.log(version.name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment