Skip to content

Commit

Permalink
docs(samples): Added sample for creating Secret with UserManaged repl…
Browse files Browse the repository at this point in the history
…ication (#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>
  • Loading branch information
kapishps and gcf-owl-bot[bot] authored Aug 17, 2022
1 parent bb84e05 commit 3796e9b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
57 changes: 57 additions & 0 deletions secret-manager/createUmmrSecret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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(
parent = 'projects/my-project',
secretId = 'my-secret',
...locations
) {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const parent = 'projects/my-project';
// const secretId = 'my-secret';
// const locations = ['us-east1', 'us-east4', 'us-west1'];

// Imports the Secret Manager library
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');

// Instantiates a client
const client = new SecretManagerServiceClient();

async function createSecret() {
const [secret] = await client.createSecret({
parent: parent,
secretId: secretId,
secret: {
replication: {
userManaged: {
replicas: locations.map(x => {
return {location: x};
}),
},
},
},
});

console.log(`Created secret ${secret.name}`);
}

createSecret();
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
17 changes: 17 additions & 0 deletions secret-manager/test/secretmanager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ describe('Secret Manager samples', () => {
throw err;
}
}

try {
await client.deleteSecret({
name: `${secret.name}-3`,
});
} catch (err) {
if (!err.message.includes('NOT_FOUND')) {
throw err;
}
}
});

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

it('creates a secret with userManaged replication', async () => {
const output = execSync(
`node createUmmrSecret.js projects/${projectId} ${secretId}-3 us-east1 us-east4`
);
assert.match(output, new RegExp('Created secret'));
});

it('lists secrets', async () => {
const output = execSync(`node listSecrets.js projects/${projectId}`);
assert.match(output, new RegExp(`${secret.name}`));
Expand Down

0 comments on commit 3796e9b

Please sign in to comment.