Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions secret-manager/bindTagsToSecret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2025 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, secretId, tagValue) {
// [START secretmanager_bind_tags_to_secret]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const secretId = 'my-secret';
// const tagValue = 'tagValues/281476592621530';
const parent = `projects/${projectId}`;

// Imports the library
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
const {TagBindingsClient} = require('@google-cloud/resource-manager').v3;

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

async function bindTagsToSecret() {
const [secret] = await client.createSecret({
parent: parent,
secretId: secretId,
secret: {
replication: {
automatic: {},
},
},
});

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

const [operation] = await resourcemanagerClient.createTagBinding({
tagBinding: {
parent: `//secretmanager.googleapis.com/${secret.name}`,
tagValue: tagValue,
},
});
const [response] = await operation.promise();
console.log('Created Tag Binding', response.name);
}

bindTagsToSecret();
// [END secretmanager_bind_tags_to_secret]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
56 changes: 56 additions & 0 deletions secret-manager/createSecretWithTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2025 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, secretId, tagKey, tagValue) {
// [START secretmanager_create_secret_with_tags]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const secretId = 'my-secret';
// const tagKey = 'tagKeys/281475012216835';
// const tagValue = 'tagValues/281476592621530';
const parent = `projects/${projectId}`;

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

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

async function createSecretWithTags() {
const [secret] = await client.createSecret({
parent: parent,
secretId: secretId,
secret: {
replication: {
automatic: {},
},
tags: {
[tagKey]: tagValue,
},
},
});

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

createSecretWithTags();
// [END secretmanager_create_secret_with_tags]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
3 changes: 2 additions & 1 deletion secret-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"test": "c8 mocha -p -j 2 --recursive test/ --timeout=800000"
},
"dependencies": {
"@google-cloud/secret-manager": "^5.6.0"
"@google-cloud/secret-manager": "^6.1.0",
"@google-cloud/resource-manager": "^6.2.0"
},
"devDependencies": {
"c8": "^10.0.0",
Expand Down
65 changes: 65 additions & 0 deletions secret-manager/regional_samples/bindTagsToRegionalSecret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2025 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, tagValue) {
// [START secretmanager_bind_tags_to_regional_secret]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const locationId = 'my-location';
// const secretId = 'my-secret';
// const tagValue = 'tagValues/281476592621530';
const parent = `projects/${projectId}/locations/${locationId}`;

// Imports the library
const {SecretManagerServiceClient} = require('@google-cloud/secret-manager');
const {TagBindingsClient} = require('@google-cloud/resource-manager').v3;

// Adding the endpoint to call the regional
const options = {};
const bindingOptions = {};
options.apiEndpoint = `secretmanager.${locationId}.rep.googleapis.com`;
bindingOptions.apiEndpoint = `${locationId}-cloudresourcemanager.googleapis.com`;

// Instantiates a client
const client = new SecretManagerServiceClient(options);
const resourcemanagerClient = new TagBindingsClient(bindingOptions);

async function bindTagsToRegionalSecret() {
const [secret] = await client.createSecret({
parent: parent,
secretId: secretId,
});

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

const [operation] = await resourcemanagerClient.createTagBinding({
tagBinding: {
parent: `//secretmanager.googleapis.com/${secret.name}`,
tagValue: tagValue,
},
});
const [response] = await operation.promise();
console.log('Created Tag Binding', response.name);
}

bindTagsToRegionalSecret();
// [END secretmanager_bind_tags_to_regional_secret]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
58 changes: 58 additions & 0 deletions secret-manager/regional_samples/createRegionalSecretWithTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2025 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, tagKey, tagValue) {
// [START secretmanager_create_regional_secret_with_tags]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'my-project';
// const locationId = 'my-location';
// const secretId = 'my-secret';
// const tagKey = 'tagKeys/281475012216835';
// const tagValue = 'tagValues/281476592621530';
const parent = `projects/${projectId}/locations/${locationId}`;

// Imports the 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 createRegionalSecretWithTags() {
const [secret] = await client.createSecret({
parent: parent,
secretId: secretId,
secret: {
tags: {
[tagKey]: tagValue,
},
},
});

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

createRegionalSecretWithTags();
// [END secretmanager_create_regional_secret_with_tags]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
Loading
Loading