Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]
}
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]
}
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]
}
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]
}
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();
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]
}
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]
}
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]
}