From d8629faceab873049d771a4db1c836da8b3e255f Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Wed, 4 Sep 2024 11:54:11 +0000 Subject: [PATCH 1/9] feat(secretmanager): add samples for secret annotations --- secret-manager/createSecretWithAnnotations.js | 55 +++++++++++++++++ secret-manager/editSecretAnnotations.js | 61 +++++++++++++++++++ secret-manager/test/secretmanager.test.js | 36 +++++++++++ secret-manager/viewSecretAnnotations.js | 45 ++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 secret-manager/createSecretWithAnnotations.js create mode 100644 secret-manager/editSecretAnnotations.js create mode 100644 secret-manager/viewSecretAnnotations.js diff --git a/secret-manager/createSecretWithAnnotations.js b/secret-manager/createSecretWithAnnotations.js new file mode 100644 index 0000000000..696e8278bd --- /dev/null +++ b/secret-manager/createSecretWithAnnotations.js @@ -0,0 +1,55 @@ +// Copyright 2024 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, secretId, annotationKey, annotationValue) { + // [START secretmanager_create_secret_with_annotations] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const parent = 'projects/my-project'; + // const secretId = 'my-secret'; + // const annotationKey = 'exampleannotationkey'; + // const annotationValue = 'exampleannotationvalue'; + + // Imports the Secret Manager library + const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); + + // Instantiates a client + const client = new SecretManagerServiceClient(); + + async function createSecretWithAnnotations() { + const [secret] = await client.createSecret({ + parent: parent, + secretId: secretId, + secret: { + replication: { + automatic: {}, + }, + annotations: { + [annotationKey]: annotationValue, + }, + }, + }); + + console.log(`Created secret ${secret.name}`); + } + + createSecretWithAnnotations(); + // [END secretmanager_create_secret_with_annotations] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); diff --git a/secret-manager/editSecretAnnotations.js b/secret-manager/editSecretAnnotations.js new file mode 100644 index 0000000000..32ca61ad19 --- /dev/null +++ b/secret-manager/editSecretAnnotations.js @@ -0,0 +1,61 @@ +// Copyright 2024 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, annotationKey, annotationValue) { + // [START secretmanager_edit_secret_annotations] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const name = 'projects/my-project/secrets/my-secret'; + // const annotationKey = 'updatedannotationkey'; + // const annotationValue = 'updatedannotationvalue'; + + // Imports the Secret Manager library + const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); + + // Instantiates a client + const client = new SecretManagerServiceClient(); + + async function getSecret() { + const [secret] = await client.getSecret({ + name: name, + }); + + return secret; + } + + async function editSecretAnnotations() { + const oldSecret = await getSecret(); + oldSecret.annotations[annotationKey] = annotationValue; + const [secret] = await client.updateSecret({ + secret: { + name: name, + annotations: oldSecret.annotations, + }, + updateMask: { + paths: ['annotations'], + }, + }); + + console.info(`Updated secret ${secret.name}`); + } + + editSecretAnnotations(); + // [END secretmanager_edit_secret_annotations] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index a34852b1ae..f02b38597e 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -30,6 +30,10 @@ const labelKey = 'secretmanager'; const labelValue = 'rocks'; const labelKeyUpdated = 'gcp'; const labelValueUpdated = 'rock'; +const annotationKey = 'annotationkey'; +const annotationValue = 'annotationvalue'; +const annotationKeyUpdated = 'updatedannotationekey'; +const annotationValueUpdated = 'updatedannotationvalue'; let secret; let regionalSecret; @@ -58,6 +62,9 @@ describe('Secret Manager samples', () => { labels: { [labelKey]: labelValue, }, + annotations: { + [annotationKey]: annotationValue, + } }, }); @@ -170,6 +177,16 @@ describe('Secret Manager samples', () => { throw err; } } + + try { + await client.deleteSecret({ + name: `${secret.name}-5`, + }); + } catch (err) { + if (!err.message.includes('NOT_FOUND')) { + throw err; + } + } }); it('runs the quickstart', async () => { @@ -218,6 +235,13 @@ describe('Secret Manager samples', () => { assert.match(output, new RegExp('Created secret')); }); + it('creates a secret with annotations', async () => { + const output = execSync( + `node createSecretWithAnnotations.js projects/${projectId} ${secretId}-5 ${annotationKey} ${annotationValue}` + ); + 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}`)); @@ -240,6 +264,11 @@ describe('Secret Manager samples', () => { assert.match(output, new RegExp(`${labelKey}`)); }); + it('view a secret annotations', async () => { + const output = execSync(`node viewSecretAnnotations.js ${secret.name}`); + assert.match(output, new RegExp(`${annotationKey}`)); + }); + it('gets a regional secret', async () => { const output = execSync( `node regional_samples/getRegionalSecret.js ${projectId} ${locationId} ${secretId}` @@ -271,6 +300,13 @@ describe('Secret Manager samples', () => { assert.match(output, new RegExp(`Updated secret ${secret.name}`)); }); + it('edits a secret annotation', async () => { + const output = execSync( + `node editSecretAnnotations.js ${secret.name} ${annotationKeyUpdated} ${annotationValueUpdated}` + ); + assert.match(output, new RegExp(`Updated secret ${secret.name}`)); + }); + it('updates a regional secret with an alias', async () => { const output = execSync( `node regional_samples/updateRegionalSecretWithAlias.js ${projectId} ${locationId} ${secretId}` diff --git a/secret-manager/viewSecretAnnotations.js b/secret-manager/viewSecretAnnotations.js new file mode 100644 index 0000000000..1c59d6b008 --- /dev/null +++ b/secret-manager/viewSecretAnnotations.js @@ -0,0 +1,45 @@ +// Copyright 2024 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) { + // [START secretmanager_view_secret_annotations] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const parent = '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 getSecretAnnotations() { + const [secret] = await client.getSecret({ + name: name, + }); + + for (const key in secret.annotations) { + console.log(`${key} : ${secret.annotations[key]}`); + } + } + + getSecretAnnotations(); + // [END secretmanager_view_secret_annotations] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); From 222169eaf243966853961335f18cd9d437bbe4bf Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Wed, 9 Oct 2024 08:01:11 +0000 Subject: [PATCH 2/9] feat: create samples for labels, regional SM --- .../createRegionalSecretWithLabels.js | 58 ++++++++++++++++ .../createUpdateRegionalSecretLabel.js | 68 +++++++++++++++++++ .../deleteRegionalSecretLabel.js | 67 ++++++++++++++++++ .../viewRegionalSecretLabels.js | 52 ++++++++++++++ secret-manager/test/secretmanager.test.js | 45 +++++++++++- 5 files changed, 289 insertions(+), 1 deletion(-) create mode 100644 secret-manager/regional_samples/createRegionalSecretWithLabels.js create mode 100644 secret-manager/regional_samples/createUpdateRegionalSecretLabel.js create mode 100644 secret-manager/regional_samples/deleteRegionalSecretLabel.js create mode 100644 secret-manager/regional_samples/viewRegionalSecretLabels.js diff --git a/secret-manager/regional_samples/createRegionalSecretWithLabels.js b/secret-manager/regional_samples/createRegionalSecretWithLabels.js new file mode 100644 index 0000000000..19cf6f04d4 --- /dev/null +++ b/secret-manager/regional_samples/createRegionalSecretWithLabels.js @@ -0,0 +1,58 @@ +// Copyright 2024 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(projectId, locationId, secretId, labelKey, labelValue) { + // [START secretmanager_create_regional_secret_with_labels] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const project = 'my-project'; + // const locationId = 'my-location'; + // const secretId = 'my-secret'; + // const labelKey = 'secretmanager'; + // const labelValue = 'rocks'; + const parent = `projects/${projectId}/locations/${locationId}`; + + // Imports the Secret Manager library + const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); + + // Adding the endpoint to call the regional secret manager sever + const options = {}; + options.apiEndpoint = `secretmanager.${locationId}.rep.googleapis.com`; + + // Instantiates a client + const client = new SecretManagerServiceClient(options); + + async function createRegionalSecretWithLabels() { + const [secret] = await client.createSecret({ + parent: parent, + secretId: secretId, + secret: { + labels: { + [labelKey]: labelValue, + }, + }, + }); + + console.log(`Created secret ${secret.name}`); + } + + createRegionalSecretWithLabels(); + // [END secretmanager_create_regional_secret_with_labels] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); diff --git a/secret-manager/regional_samples/createUpdateRegionalSecretLabel.js b/secret-manager/regional_samples/createUpdateRegionalSecretLabel.js new file mode 100644 index 0000000000..883f8f1906 --- /dev/null +++ b/secret-manager/regional_samples/createUpdateRegionalSecretLabel.js @@ -0,0 +1,68 @@ +// Copyright 2024 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(projectId, locationId, secretId, labelKey, labelValue) { + // [START secretmanager_create_regional_update_secret_label] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'my-project' + // const locationId = 'locationId'; + // const secretId = 'my-secret'; + // const labelKey = 'gcp'; + // const labelValue = 'rocks'; + const name = `projects/${projectId}/locations/${locationId}/secrets/${secretId}`; + + // Imports the Secret Manager library + const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); + + // Adding the endpoint to call the regional secret manager sever + const options = {}; + options.apiEndpoint = `secretmanager.${locationId}.rep.googleapis.com`; + + // Instantiates a client + const client = new SecretManagerServiceClient(options); + + async function getSecret() { + const [secret] = await client.getSecret({ + name: name, + }); + + return secret; + } + + async function createUpdateRegionalSecretLabel() { + const oldSecret = await getSecret(); + oldSecret.labels[labelKey] = labelValue; + const [secret] = await client.updateSecret({ + secret: { + name: name, + labels: oldSecret.labels, + }, + updateMask: { + paths: ['labels'], + }, + }); + + console.info(`Updated secret ${secret.name}`); + } + + createUpdateRegionalSecretLabel(); + // [END secretmanager_create_regional_update_secret_label] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); diff --git a/secret-manager/regional_samples/deleteRegionalSecretLabel.js b/secret-manager/regional_samples/deleteRegionalSecretLabel.js new file mode 100644 index 0000000000..68e72274d9 --- /dev/null +++ b/secret-manager/regional_samples/deleteRegionalSecretLabel.js @@ -0,0 +1,67 @@ +// Copyright 2024 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(projectId, locationId, secretId, labelKey) { + // [START secretmanager_delete_regional_secret_label] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'my-project' + // const locationId = 'locationId'; + // const secretId = 'my-secret'; + // const labelKey = 'secretmanager'; + const name = `projects/${projectId}/locations/${locationId}/secrets/${secretId}`; + + // Imports the Secret Manager library + const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); + + // Adding the endpoint to call the regional secret manager sever + const options = {}; + options.apiEndpoint = `secretmanager.${locationId}.rep.googleapis.com`; + + // Instantiates a client + const client = new SecretManagerServiceClient(options); + + async function getSecret() { + const [secret] = await client.getSecret({ + name: name, + }); + + return secret; + } + + async function deleteRegionalSecretLabel() { + const oldSecret = await getSecret(); + delete oldSecret.labels[labelKey]; + const [secret] = await client.updateSecret({ + secret: { + name: name, + labels: oldSecret.labels, + }, + updateMask: { + paths: ['labels'], + }, + }); + + console.info(`Updated secret ${secret.name}`); + } + + deleteRegionalSecretLabel(); + // [END secretmanager_delete_regional_secret_label] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); diff --git a/secret-manager/regional_samples/viewRegionalSecretLabels.js b/secret-manager/regional_samples/viewRegionalSecretLabels.js new file mode 100644 index 0000000000..97e99c2459 --- /dev/null +++ b/secret-manager/regional_samples/viewRegionalSecretLabels.js @@ -0,0 +1,52 @@ +// Copyright 2024 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(projectId, locationId, secretId) { + // [START secretmanager_view_regional_secret_labels] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'my-project' + // const locationId = 'locationId'; + // const secretId = 'my-secret'; + const name = `projects/${projectId}/locations/${locationId}/secrets/${secretId}`; + + // Imports the Secret Manager library + const {SecretManagerServiceClient} = require('@google-cloud/secret-manager'); + + // Adding the endpoint to call the regional secret manager sever + const options = {}; + options.apiEndpoint = `secretmanager.${locationId}.rep.googleapis.com`; + + // Instantiates a client + const client = new SecretManagerServiceClient(options); + + async function getRegionalSecretLabels() { + const [secret] = await client.getSecret({ + name: name, + }); + + for (const key in secret.labels) { + console.log(`${key} : ${secret.labels[key]}`); + } + } + + getRegionalSecretLabels(); + // [END secretmanager_view_regional_secret_labels] +} + +const args = process.argv.slice(2); +main(...args).catch(console.error); diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index f02b38597e..480fcaf832 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -71,6 +71,11 @@ describe('Secret Manager samples', () => { [regionalSecret] = await regionalClient.createSecret({ parent: `projects/${projectId}/locations/${locationId}`, secretId: secretId, + secret: { + labels: { + [labelKey]: labelValue, + }, + } }); [version] = await client.addSecretVersion({ @@ -187,6 +192,16 @@ describe('Secret Manager samples', () => { throw err; } } + + try { + await client.deleteSecret({ + name: `${secret.name}-6`, + }); + } catch (err) { + if (!err.message.includes('NOT_FOUND')) { + throw err; + } + } }); it('runs the quickstart', async () => { @@ -235,9 +250,16 @@ describe('Secret Manager samples', () => { assert.match(output, new RegExp('Created secret')); }); + it('creates a regional secret with labels', async () => { + const output = execSync( + `node regional_samples/createRegionalSecretWithLabels.js ${projectId} ${locationId} ${secretId}-5 ${labelKey} ${labelValue}` + ); + assert.match(output, new RegExp('Created secret')); + }); + it('creates a secret with annotations', async () => { const output = execSync( - `node createSecretWithAnnotations.js projects/${projectId} ${secretId}-5 ${annotationKey} ${annotationValue}` + `node createSecretWithAnnotations.js projects/${projectId} ${secretId}-6 ${annotationKey} ${annotationValue}` ); assert.match(output, new RegExp('Created secret')); }); @@ -264,6 +286,13 @@ describe('Secret Manager samples', () => { assert.match(output, new RegExp(`${labelKey}`)); }); + it('view a regional secret labels', async () => { + const output = execSync( + `node regional_samples/viewRegionalSecretLabels.js ${projectId} ${locationId} ${secretId} + `); + assert.match(output, new RegExp(`${labelKey}`)); + }); + it('view a secret annotations', async () => { const output = execSync(`node viewSecretAnnotations.js ${secret.name}`); assert.match(output, new RegExp(`${annotationKey}`)); @@ -300,6 +329,13 @@ describe('Secret Manager samples', () => { assert.match(output, new RegExp(`Updated secret ${secret.name}`)); }); + it('create or updates a regional secret labels', async () => { + const output = execSync( + `node regional_samples/createUpdateRegionalSecretLabel.js ${projectId} ${locationId} ${secretId} ${labelKeyUpdated} ${labelValueUpdated}` + ); + assert.match(output, new RegExp(`Updated secret ${regionalSecret.name}`)); + }); + it('edits a secret annotation', async () => { const output = execSync( `node editSecretAnnotations.js ${secret.name} ${annotationKeyUpdated} ${annotationValueUpdated}` @@ -328,6 +364,13 @@ describe('Secret Manager samples', () => { assert.match(output, new RegExp(`Updated secret ${secret.name}`)); }); + it('deletes a regional secret label', async () => { + const output = execSync( + `node regional_samples/deleteRegionalSecretLabel.js ${projectId} ${locationId} ${secretId} ${labelKey}` + ); + assert.match(output, new RegExp(`Updated secret ${regionalSecret.name}`)); + }); + it('deletes a regional secret', async () => { const output = execSync( `node regional_samples/deleteRegionalSecret.js ${projectId} ${locationId} ${secretId}-3` From 4b447745a0308f055834f130ddb2aa66af31e704 Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Wed, 9 Oct 2024 08:15:35 +0000 Subject: [PATCH 3/9] fix: fix linting issue --- secret-manager/test/secretmanager.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index 480fcaf832..97fb695bf6 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -64,7 +64,7 @@ describe('Secret Manager samples', () => { }, annotations: { [annotationKey]: annotationValue, - } + }, }, }); @@ -75,7 +75,7 @@ describe('Secret Manager samples', () => { labels: { [labelKey]: labelValue, }, - } + }, }); [version] = await client.addSecretVersion({ @@ -290,6 +290,7 @@ describe('Secret Manager samples', () => { const output = execSync( `node regional_samples/viewRegionalSecretLabels.js ${projectId} ${locationId} ${secretId} `); + assert.match(output, new RegExp(`${labelKey}`)); }); From a5087e8cd5cf8452be44279862496263fb65bc82 Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Wed, 9 Oct 2024 08:19:58 +0000 Subject: [PATCH 4/9] fix: lint fix --- secret-manager/test/secretmanager.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index 97fb695bf6..1f1aab0c16 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -288,9 +288,9 @@ describe('Secret Manager samples', () => { it('view a regional secret labels', async () => { const output = execSync( - `node regional_samples/viewRegionalSecretLabels.js ${projectId} ${locationId} ${secretId} - `); - + `node regional_samples/viewRegionalSecretLabels.js ${projectId} ${locationId} ${secretId}` + ); + assert.match(output, new RegExp(`${labelKey}`)); }); From 72000a7f07cd411dccdef6b1f23b2924516bb9aa Mon Sep 17 00:00:00 2001 From: vipul7499 <45483005+vipul7499@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:54:08 +0530 Subject: [PATCH 5/9] Update viewSecretAnnotations.js --- secret-manager/viewSecretAnnotations.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/secret-manager/viewSecretAnnotations.js b/secret-manager/viewSecretAnnotations.js index 1c59d6b008..c323ed6420 100644 --- a/secret-manager/viewSecretAnnotations.js +++ b/secret-manager/viewSecretAnnotations.js @@ -27,7 +27,7 @@ async function main(name) { // Instantiates a client const client = new SecretManagerServiceClient(); - async function getSecretAnnotations() { + async function viewSecretAnnotations() { const [secret] = await client.getSecret({ name: name, }); @@ -37,7 +37,7 @@ async function main(name) { } } - getSecretAnnotations(); + viewSecretAnnotations(); // [END secretmanager_view_secret_annotations] } From 2e12325408eb7670078367a3f7f8aaebd130afac Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Mon, 14 Oct 2024 16:12:57 +0000 Subject: [PATCH 6/9] fix: changed filename --- ...pdateRegionalSecretLabel.js => editRegionalSecretLabel.js} | 4 ++-- secret-manager/test/secretmanager.test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename secret-manager/regional_samples/{createUpdateRegionalSecretLabel.js => editRegionalSecretLabel.js} (94%) diff --git a/secret-manager/regional_samples/createUpdateRegionalSecretLabel.js b/secret-manager/regional_samples/editRegionalSecretLabel.js similarity index 94% rename from secret-manager/regional_samples/createUpdateRegionalSecretLabel.js rename to secret-manager/regional_samples/editRegionalSecretLabel.js index 883f8f1906..329888ba01 100644 --- a/secret-manager/regional_samples/createUpdateRegionalSecretLabel.js +++ b/secret-manager/regional_samples/editRegionalSecretLabel.js @@ -15,7 +15,7 @@ 'use strict'; async function main(projectId, locationId, secretId, labelKey, labelValue) { - // [START secretmanager_create_regional_update_secret_label] + // [START secretmanager_edit_regional_secret_label] /** * TODO(developer): Uncomment these variables before running the sample. */ @@ -61,7 +61,7 @@ async function main(projectId, locationId, secretId, labelKey, labelValue) { } createUpdateRegionalSecretLabel(); - // [END secretmanager_create_regional_update_secret_label] + // [END secretmanager_edit_regional_secret_label] } const args = process.argv.slice(2); diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index 1f1aab0c16..48aaf405d2 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -332,7 +332,7 @@ describe('Secret Manager samples', () => { it('create or updates a regional secret labels', async () => { const output = execSync( - `node regional_samples/createUpdateRegionalSecretLabel.js ${projectId} ${locationId} ${secretId} ${labelKeyUpdated} ${labelValueUpdated}` + `node regional_samples/editRegionalSecretLabel.js ${projectId} ${locationId} ${secretId} ${labelKeyUpdated} ${labelValueUpdated}` ); assert.match(output, new RegExp(`Updated secret ${regionalSecret.name}`)); }); From df63e864d03770004e0d18d5d927719d08a9e73c Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Wed, 23 Oct 2024 05:22:22 +0000 Subject: [PATCH 7/9] fix: fixed tests --- secret-manager/test/secretmanager.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index b661663ed9..b4df75e733 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -74,6 +74,7 @@ describe('Secret Manager samples', () => { secret: { labels: { [labelKey]: labelValue, + }, annotations: { [annotationKey]: annotationValue, }, From f8d305ae79665bb9840393d40878b21622ba7398 Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Wed, 23 Oct 2024 05:35:43 +0000 Subject: [PATCH 8/9] fix: fixed tests --- secret-manager/test/secretmanager.test.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index b4df75e733..e9d2e1d218 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -188,7 +188,7 @@ describe('Secret Manager samples', () => { try { await client.deleteSecret({ - name: `${secret.name}-5`, + name: `${secret.name}-6`, }); } catch (err) { if (!err.message.includes('NOT_FOUND')) { @@ -196,19 +196,30 @@ describe('Secret Manager samples', () => { } } + try { - await client.deleteSecret({ - name: `${secret.name}-6`, + await regionalClient.deleteSecret({ + name: `${regionalSecret.name}-4`, }); } catch (err) { if (!err.message.includes('NOT_FOUND')) { throw err; } } - + try { await regionalClient.deleteSecret({ - name: `${regionalSecret.name}-4`, + name: `${regionalSecret.name}-5`, + }); + } catch (err) { + if (!err.message.includes('NOT_FOUND')) { + throw err; + } + } + + try { + await regionalClient.deleteSecret({ + name: `${regionalSecret.name}-6`, }); } catch (err) { if (!err.message.includes('NOT_FOUND')) { @@ -279,7 +290,7 @@ describe('Secret Manager samples', () => { it('creates a regional secret with annotations', async () => { const output = execSync( - `node regional_samples/createRegionalSecretWithAnnotations.js ${projectId} ${locationId} ${secretId}-5 ${annotationKey} ${annotationValue}` + `node regional_samples/createRegionalSecretWithAnnotations.js ${projectId} ${locationId} ${secretId}-6 ${annotationKey} ${annotationValue}` ); assert.match(output, new RegExp('Created secret')); }); From 80e68b9b61bca6219009e4415932651d10b1e6b0 Mon Sep 17 00:00:00 2001 From: Vipul Mittal Date: Wed, 23 Oct 2024 05:40:15 +0000 Subject: [PATCH 9/9] fix: fixed linting --- secret-manager/test/secretmanager.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/secret-manager/test/secretmanager.test.js b/secret-manager/test/secretmanager.test.js index e9d2e1d218..d9416ebca4 100644 --- a/secret-manager/test/secretmanager.test.js +++ b/secret-manager/test/secretmanager.test.js @@ -196,7 +196,6 @@ describe('Secret Manager samples', () => { } } - try { await regionalClient.deleteSecret({ name: `${regionalSecret.name}-4`, @@ -284,10 +283,10 @@ describe('Secret Manager samples', () => { it('creates a secret with annotations', async () => { const output = execSync( `node createSecretWithAnnotations.js projects/${projectId} ${secretId}-6 ${annotationKey} ${annotationValue}` - ); + ); assert.match(output, new RegExp('Created secret')); }); - + it('creates a regional secret with annotations', async () => { const output = execSync( `node regional_samples/createRegionalSecretWithAnnotations.js ${projectId} ${locationId} ${secretId}-6 ${annotationKey} ${annotationValue}`