Skip to content

migrate code from googleapis/nodejs-secret-manager #2874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 62 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
3003630
feat!: initial generation of library (#1)
bcoe Dec 18, 2019
ee175d7
feat: add secretmanager samples (#8)
sethvargo Dec 20, 2019
b3b3b0e
fix: rename comment samples (#10)
sethvargo Dec 20, 2019
6a1bcc1
chore: release 1.0.0 (#6)
release-please[bot] Dec 20, 2019
9240b76
chore(deps): update dependency c8 to v7 (#12)
renovate-bot Dec 23, 2019
5d0b2ed
chore: release 1.0.1 (#14)
release-please[bot] Dec 23, 2019
119aa54
chore: release 1.1.0 (#18)
release-please[bot] Dec 23, 2019
aa29fa9
chore(deps): update dependency mocha to v7 (#21)
renovate-bot Jan 6, 2020
75346f5
chore: release 1.1.1 (#23)
release-please[bot] Jan 9, 2020
d3071a2
chore: release 1.1.2 (#25)
release-please[bot] Jan 14, 2020
1d97e26
docs: remove misleading header (#28)
sethvargo Jan 16, 2020
4a15284
feat: add IAM samples (#34)
sethvargo Jan 30, 2020
9ab11aa
chore: release 1.2.0 (#38)
release-please[bot] Jan 30, 2020
9458838
chore: release 1.2.1 (#50)
release-please[bot] Feb 12, 2020
e63d673
chore: release 2.0.0 (#63)
release-please[bot] Feb 28, 2020
4923709
chore: release 2.0.1 (#68)
release-please[bot] Mar 2, 2020
22bd938
chore: release 2.1.0 (#70)
release-please[bot] Mar 9, 2020
92982a7
feat!: drop node8 support, support for async iterators (#85)
alexander-fenster Mar 31, 2020
4b1912b
chore: release 3.0.0 (#86)
release-please[bot] Apr 10, 2020
790bc8b
chore: update uuid (#114)
bcoe May 4, 2020
abf66f9
fix(samples): correct usage of toString() (#117)
anchor-crockagile May 19, 2020
20cb501
chore(deps): update dependency mocha to v8 (#126)
renovate-bot Jun 11, 2020
cbefa28
chore: release 3.1.0 (#113)
release-please[bot] Jun 26, 2020
be60a8c
chore: release 3.2.0 (#166)
release-please[bot] Sep 15, 2020
66b1c9d
chore: release 3.2.1 (#185)
release-please[bot] Nov 5, 2020
d588d27
chore: release 3.2.2 (#188)
release-please[bot] Nov 11, 2020
ce8506b
chore: release 3.2.3 (#192)
release-please[bot] Dec 2, 2020
f0d61a8
chore: release 3.3.0 (#200)
release-please[bot] Jan 12, 2021
c6e84b6
chore: release 3.4.0 (#203)
release-please[bot] Jan 21, 2021
8f373d0
docs: update samples for correct types (#205)
sofisl Feb 4, 2021
a94b4f1
chore: release 3.5.0 (#208)
release-please[bot] Mar 3, 2021
8b769f2
chore: release 3.6.0 (#229)
release-please[bot] Apr 1, 2021
da90ab5
chore: release 3.6.1 (#248)
release-please[bot] May 13, 2021
3cb5064
chore: release 3.7.0 (#256)
release-please[bot] May 25, 2021
483e819
chore: release 3.7.1 (#259)
release-please[bot] May 25, 2021
cc4b9a3
chore: release 3.7.2 (#270)
release-please[bot] Jun 24, 2021
405a6a8
chore: release 3.7.3 (#275)
release-please[bot] Jun 30, 2021
3ecf3d4
chore: release 3.8.0 (#277)
release-please[bot] Jul 13, 2021
db4ad1c
chore: release 3.8.1 (#280)
release-please[bot] Jul 16, 2021
52bbb59
chore: release 3.9.0 (#285)
release-please[bot] Jul 30, 2021
6388952
chore: release 3.9.1 (#290)
release-please[bot] Aug 17, 2021
04cd30d
chore: release 3.10.0 (#292)
release-please[bot] Aug 24, 2021
1dac2dd
chore: release 3.10.1 (#296)
release-please[bot] Sep 10, 2021
0bfc9d7
docs(samples): add example tags to generated samples (#312)
gcf-owl-bot[bot] Nov 10, 2021
305e836
samples: update getSecret sample to include version (#311)
OskarDamkjaer Nov 17, 2021
3635d98
Revert "samples: update getSecret sample to include version (#311)" (…
bcoe Nov 17, 2021
ca5dada
chore(main): release 3.11.0 (#336)
release-please[bot] Feb 8, 2022
6be8257
chore(main): release 3.12.0 (#357)
release-please[bot] Apr 11, 2022
0b8d87d
build!: update library to use Node 12 (#371)
sofisl May 20, 2022
edbdfb7
chore(main): release 4.0.0 (#372)
release-please[bot] Jun 6, 2022
14f948c
chore(main): release 4.0.1 (#381)
release-please[bot] Jun 30, 2022
bb84e05
feat: add code samples for secret manager access by alias (#373)
nataliesalvati Aug 9, 2022
3796e9b
docs(samples): Added sample for creating Secret with UserManaged repl…
kapishps Aug 17, 2022
f327590
chore(main): release 4.1.0 (#389)
release-please[bot] Aug 23, 2022
100f137
chore(main): release 4.1.1 (#397)
release-please[bot] Aug 26, 2022
d9432da
chore(main): release 4.1.2 (#400)
release-please[bot] Sep 7, 2022
336dd79
chore(deps): update dependency uuid to v9 (#401)
renovate-bot Sep 9, 2022
dbc2527
chore(main): release 4.1.3 (#404)
release-please[bot] Sep 22, 2022
ab4721c
chore(main): release 4.1.4 (#415)
release-please[bot] Nov 11, 2022
7af29cd
Merge remote-tracking branch 'migration/main' into nodejs-secret-mana…
Nov 18, 2022
0634195
Adds workflow config for secret-manager/
Nov 18, 2022
3574078
Merge branch 'main' into nodejs-secret-manager-migration
ahrarmonsur Nov 18, 2022
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
68 changes: 68 additions & 0 deletions .github/workflows/secret-manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: secret-manager
on:
push:
branches:
- main
paths:
- 'secret-manager/**'
pull_request:
paths:
- 'secret-manager/**'
pull_request_target:
types: [labeled]
paths:
- 'secret-manager/**'
schedule:
- cron: '0 0 * * 0'
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: 'write'
pull-requests: 'write'
id-token: 'write'
steps:
- uses: actions/[email protected]
with:
ref: ${{github.event.pull_request.head.sha}}
- uses: 'google-github-actions/[email protected]'
with:
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
service_account: '[email protected]'
create_credentials_file: 'true'
access_token_lifetime: 600s
- uses: actions/[email protected]
with:
node-version: 16
- run: npm install
working-directory: secret-manager
- run: npm test
working-directory: secret-manager
env:
MOCHA_REPORTER_SUITENAME: secret_manager
MOCHA_REPORTER_OUTPUT: secret_manager_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule'}}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"datastore/functions",
"service-directory/snippets",
"scheduler",
"secret-manager",
"speech",
"talent",
"texttospeech",
Expand Down
49 changes: 49 additions & 0 deletions secret-manager/accessSecretVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019 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 = 'projects/my-project/secrets/my-secret/versions/1') {
// [START secretmanager_access_secret_version]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const name = 'projects/my-project/secrets/my-secret/versions/5';
// const name = 'projects/my-project/secrets/my-secret/versions/latest';

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

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

async function accessSecretVersion() {
const [version] = await client.accessSecretVersion({
name: name,
});

// Extract the payload as a string.
const payload = version.payload.data.toString();

// WARNING: Do not print the secret in a production environment - this
// snippet is showing how to access the secret material.
console.info(`Payload: ${payload}`);
}

accessSecretVersion();
// [END secretmanager_access_secret_version]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
49 changes: 49 additions & 0 deletions secret-manager/addSecretVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2019 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/secrets/my-secret') {
// [START secretmanager_add_secret_version]
/**
* 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();

// Payload is the plaintext data to store in the secret
const payload = Buffer.from('my super secret data', 'utf8');

async function addSecretVersion() {
const [version] = await client.addSecretVersion({
parent: parent,
payload: {
data: payload,
},
});

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

addSecretVersion();
// [END secretmanager_add_secret_version]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
50 changes: 50 additions & 0 deletions secret-manager/createSecret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2019 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') {
// [START secretmanager_create_secret]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const parent = 'projects/my-project';
// const secretId = 'my-secret';

// 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: {
automatic: {},
},
},
});

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

createSecret();
// [END secretmanager_create_secret]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
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);
43 changes: 43 additions & 0 deletions secret-manager/deleteSecret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2019 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 = 'projects/my-project/secrets/my-secret') {
// [START secretmanager_delete_secret]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const name = '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 deleteSecret() {
await client.deleteSecret({
name: name,
});

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

deleteSecret();
// [END secretmanager_delete_secret]
}

const args = process.argv.slice(2);
main(...args).catch(console.error);
43 changes: 43 additions & 0 deletions secret-manager/destroySecretVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2019 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 = 'projects/my-project/secrets/my-secret/versions/1') {
// [START secretmanager_destroy_secret_version]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const name = 'projects/my-project/secrets/my-secret/versions/5';

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

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

async function destroySecretVersion() {
const [version] = await client.destroySecretVersion({
name: name,
});

console.info(`Destroyed ${version.name}`);
}

destroySecretVersion();
// [END secretmanager_destroy_secret_version]
}

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