Skip to content

Commit 3796e9b

Browse files
docs(samples): Added sample for creating Secret with UserManaged replication (#388)
* added create ummr secret sample * added test for create ummr secret * fix dependency version * lint changes * updated copyright * updated comment * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent bb84e05 commit 3796e9b

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

secret-manager/createUmmrSecret.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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(
18+
parent = 'projects/my-project',
19+
secretId = 'my-secret',
20+
...locations
21+
) {
22+
/**
23+
* TODO(developer): Uncomment these variables before running the sample.
24+
*/
25+
// const parent = 'projects/my-project';
26+
// const secretId = 'my-secret';
27+
// const locations = ['us-east1', 'us-east4', 'us-west1'];
28+
29+
// Imports the Secret Manager library
30+
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
31+
32+
// Instantiates a client
33+
const client = new SecretManagerServiceClient();
34+
35+
async function createSecret() {
36+
const [secret] = await client.createSecret({
37+
parent: parent,
38+
secretId: secretId,
39+
secret: {
40+
replication: {
41+
userManaged: {
42+
replicas: locations.map(x => {
43+
return {location: x};
44+
}),
45+
},
46+
},
47+
},
48+
});
49+
50+
console.log(`Created secret ${secret.name}`);
51+
}
52+
53+
createSecret();
54+
}
55+
56+
const args = process.argv.slice(2);
57+
main(...args).catch(console.error);

secret-manager/test/secretmanager.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ describe('Secret Manager samples', () => {
8181
throw err;
8282
}
8383
}
84+
85+
try {
86+
await client.deleteSecret({
87+
name: `${secret.name}-3`,
88+
});
89+
} catch (err) {
90+
if (!err.message.includes('NOT_FOUND')) {
91+
throw err;
92+
}
93+
}
8494
});
8595

8696
it('runs the quickstart', async () => {
@@ -99,6 +109,13 @@ describe('Secret Manager samples', () => {
99109
assert.match(output, new RegExp('Created secret'));
100110
});
101111

112+
it('creates a secret with userManaged replication', async () => {
113+
const output = execSync(
114+
`node createUmmrSecret.js projects/${projectId} ${secretId}-3 us-east1 us-east4`
115+
);
116+
assert.match(output, new RegExp('Created secret'));
117+
});
118+
102119
it('lists secrets', async () => {
103120
const output = execSync(`node listSecrets.js projects/${projectId}`);
104121
assert.match(output, new RegExp(`${secret.name}`));

0 commit comments

Comments
 (0)