Skip to content

Commit

Permalink
feat: add code samples for secret manager access by alias (#373)
Browse files Browse the repository at this point in the history
* feat: add code samples for secret manager access by alias

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Benjamin E. Coe <[email protected]>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 9, 2022
1 parent 14f948c commit bb84e05
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions secret-manager/test/secretmanager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ describe('Secret Manager samples', () => {
assert.match(output, new RegExp(`Updated secret ${secret.name}`));
});

it('updates a secret with an alias', async () => {
const output = execSync(`node updateSecretWithAlias.js ${secret.name}`);
assert.match(output, new RegExp(`Updated secret ${secret.name}`));
});

it('deletes a secret', async () => {
const output = execSync(
`node deleteSecret.js projects/${projectId}/secrets/${secretId}-2`
Expand Down
51 changes: 51 additions & 0 deletions secret-manager/updateSecretWithAlias.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

async function main(name = 'projects/my-project/secrets/my-secret') {
// [START secretmanager_update_secret_with_alias]
/**
* 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 updateSecret() {
const [secret] = await client.updateSecret({
secret: {
name: name,
versionAliases: {
test: 1,
},
},
updateMask: {
paths: ['version_aliases'],
},
});

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

updateSecret();
// [END secretmanager_update_secret_with_alias]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);

0 comments on commit bb84e05

Please sign in to comment.