|
| 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); |
0 commit comments