Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit afe8dbe

Browse files
nataliesalvatiBenjamin E. Coegcf-owl-bot[bot]
authored
feat: add code samples for secret manager access by alias (#373)
* 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>
1 parent b0bbc97 commit afe8dbe

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-secret-mana
128128
| List Secrets | [source code](https://github.com/googleapis/nodejs-secret-manager/blob/main/samples/listSecrets.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-secret-manager&page=editor&open_in_editor=samples/listSecrets.js,samples/README.md) |
129129
| Quickstart | [source code](https://github.com/googleapis/nodejs-secret-manager/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-secret-manager&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
130130
| Update Secret | [source code](https://github.com/googleapis/nodejs-secret-manager/blob/main/samples/updateSecret.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-secret-manager&page=editor&open_in_editor=samples/updateSecret.js,samples/README.md) |
131+
| Update Secret With Alias | [source code](https://github.com/googleapis/nodejs-secret-manager/blob/main/samples/updateSecretWithAlias.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-secret-manager&page=editor&open_in_editor=samples/updateSecretWithAlias.js,samples/README.md) |
131132

132133

133134

samples/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* [List Secrets](#list-secrets)
2828
* [Quickstart](#quickstart)
2929
* [Update Secret](#update-secret)
30+
* [Update Secret With Alias](#update-secret-with-alias)
3031

3132
## Before you begin
3233

@@ -293,6 +294,23 @@ __Usage:__
293294
`node samples/updateSecret.js`
294295

295296

297+
-----
298+
299+
300+
301+
302+
### Update Secret With Alias
303+
304+
View the [source code](https://github.com/googleapis/nodejs-secret-manager/blob/main/samples/updateSecretWithAlias.js).
305+
306+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-secret-manager&page=editor&open_in_editor=samples/updateSecretWithAlias.js,samples/README.md)
307+
308+
__Usage:__
309+
310+
311+
`node samples/updateSecretWithAlias.js`
312+
313+
296314

297315

298316

samples/test/secretmanager.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ describe('Secret Manager samples', () => {
114114
assert.match(output, new RegExp(`Updated secret ${secret.name}`));
115115
});
116116

117+
it('updates a secret with an alias', async () => {
118+
const output = execSync(`node updateSecretWithAlias.js ${secret.name}`);
119+
assert.match(output, new RegExp(`Updated secret ${secret.name}`));
120+
});
121+
117122
it('deletes a secret', async () => {
118123
const output = execSync(
119124
`node deleteSecret.js projects/${projectId}/secrets/${secretId}-2`

samples/updateSecretWithAlias.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function main(name = 'projects/my-project/secrets/my-secret') {
18+
// [START secretmanager_update_secret_with_alias]
19+
/**
20+
* TODO(developer): Uncomment these variables before running the sample.
21+
*/
22+
// const name = 'projects/my-project/secrets/my-secret';
23+
24+
// Imports the Secret Manager library
25+
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
26+
27+
// Instantiates a client
28+
const client = new SecretManagerServiceClient();
29+
30+
async function updateSecret() {
31+
const [secret] = await client.updateSecret({
32+
secret: {
33+
name: name,
34+
versionAliases: {
35+
test: 1,
36+
},
37+
},
38+
updateMask: {
39+
paths: ['version_aliases'],
40+
},
41+
});
42+
43+
console.info(`Updated secret ${secret.name}`);
44+
}
45+
46+
updateSecret();
47+
// [END secretmanager_update_secret_with_alias]
48+
}
49+
50+
const args = process.argv.slice(2);
51+
main(...args).catch(console.error);

0 commit comments

Comments
 (0)