├── .eslintignore ├── .eslintrc.json ├── .gitattributes ├── .github ├── .OwlBot.lock.yaml ├── .OwlBot.yaml ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── documentation_request.yml │ ├── feature_request.yml │ ├── processs_request.md │ ├── questions.md │ └── support_request.md ├── PULL_REQUEST_TEMPLATE.md ├── auto-approve.yml ├── auto-label.yaml ├── generated-files-bot.yml ├── release-please.yml ├── release-trigger.yml ├── scripts │ ├── close-invalid-link.cjs │ ├── close-unresponsive.cjs │ └── remove-response-label.cjs ├── sync-repo-settings.yaml └── workflows │ ├── ci.yaml │ ├── conformance-test.yaml │ ├── issues-no-repro.yaml │ └── response.yaml ├── .gitignore ├── .jsdoc.json ├── .kokoro ├── .gitattributes ├── common.cfg ├── conformance-test.sh ├── continuous │ └── node14 │ │ ├── common.cfg │ │ ├── lint.cfg │ │ ├── samples-test.cfg │ │ ├── system-test.cfg │ │ └── test.cfg ├── docs.sh ├── lint.sh ├── populate-secrets.sh ├── pre-samples-test.sh ├── pre-system-test.sh ├── presubmit │ ├── node14 │ │ ├── common.cfg │ │ ├── samples-test.cfg │ │ ├── system-test.cfg │ │ └── test.cfg │ └── windows │ │ ├── common.cfg │ │ └── test.cfg ├── publish.sh ├── release │ ├── common.cfg │ ├── docs-devsite.cfg │ ├── docs-devsite.sh │ ├── docs.cfg │ ├── docs.sh │ └── publish.cfg ├── samples-test.sh ├── setup-vars.sh ├── system-test.sh ├── test.bat ├── test.sh ├── trampoline.sh └── trampoline_v2.sh ├── .mocharc.cjs ├── .nycrc ├── .prettierignore ├── .prettierrc.cjs ├── .readme-partials.yaml ├── .repo-metadata.json ├── .trampolinerc ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── conformance-test ├── conformanceCommon.ts ├── fixtures │ └── signing-service-account.json ├── globalHooks.ts ├── libraryMethods.ts ├── scenarios │ ├── scenarioFive.ts │ ├── scenarioFour.ts │ ├── scenarioOne.ts │ ├── scenarioSeven.ts │ ├── scenarioSix.ts │ ├── scenarioThree.ts │ └── scenarioTwo.ts ├── test-data │ ├── retryInvocationMap.json │ ├── retryStrategyTestData.json │ └── v4SignedUrl.json ├── testBenchUtil.ts └── v4SignedUrl.ts ├── internal-tooling ├── README.md ├── helpers │ └── package.cjs.json ├── performApplicationPerformanceTest.ts ├── performPerformanceTest.ts ├── performTransferManagerTest.ts ├── performanceTest.ts └── performanceUtils.ts ├── linkinator.config.json ├── owlbot.py ├── package.json ├── renovate.json ├── samples ├── .eslintrc.yml ├── README.md ├── addBucketConditionalBinding.js ├── addBucketDefaultOwnerAcl.js ├── addBucketIamMember.js ├── addBucketLabel.js ├── addBucketOwnerAcl.js ├── addBucketWebsiteConfiguration.js ├── addFileOwnerAcl.js ├── bucketMetadata.js ├── changeDefaultStorageClass.js ├── changeFileCSEKToCMEK.js ├── composeFile.js ├── configureBucketCors.js ├── configureRetries.js ├── copyFile.js ├── copyOldVersionOfFile.js ├── createBucketWithDualRegion.js ├── createBucketWithHierarchicalNamespace.js ├── createBucketWithObjectRetention.js ├── createBucketWithStorageClassAndLocation.js ├── createBucketWithTurboReplication.js ├── createNewBucket.js ├── createNotification.js ├── deleteBucket.js ├── deleteFile.js ├── deleteNotification.js ├── deleteOldVersionOfFile.js ├── disableBucketLifecycleManagement.js ├── disableBucketVersioning.js ├── disableDefaultEventBasedHold.js ├── disableRequesterPays.js ├── disableUniformBucketLevelAccess.js ├── downloadByteRange.js ├── downloadEncryptedFile.js ├── downloadFile.js ├── downloadFileInChunksWithTransferManager.js ├── downloadFileUsingRequesterPays.js ├── downloadFolderWithTransferManager.js ├── downloadIntoMemory.js ├── downloadManyFilesWithTransferManager.js ├── downloadPublicFile.js ├── enableBucketLifecycleManagement.js ├── enableBucketVersioning.js ├── enableDefaultEventBasedHold.js ├── enableDefaultKMSKey.js ├── enableRequesterPays.js ├── enableUniformBucketLevelAccess.js ├── fileChangeStorageClass.js ├── fileSetMetadata.js ├── generateEncryptionKey.js ├── generateSignedUrl.js ├── generateV4ReadSignedUrl.js ├── generateV4SignedPolicy.js ├── generateV4UploadSignedUrl.js ├── getAutoclass.js ├── getDefaultEventBasedHold.js ├── getMetadata.js ├── getMetadataNotifications.js ├── getPublicAccessPrevention.js ├── getRPO.js ├── getRequesterPaysStatus.js ├── getRetentionPolicy.js ├── getServiceAccount.js ├── getSoftDeletedBucket.js ├── getUniformBucketLevelAccess.js ├── hmacKeyActivate.js ├── hmacKeyCreate.js ├── hmacKeyDeactivate.js ├── hmacKeyDelete.js ├── hmacKeyGet.js ├── hmacKeysList.js ├── listBuckets.js ├── listFiles.js ├── listFilesByPrefix.js ├── listFilesPaginate.js ├── listFilesWithOldVersions.js ├── listNotifications.js ├── listSoftDeletedBucket.js ├── lockRetentionPolicy.js ├── makeBucketPublic.js ├── makePublic.js ├── moveFile.js ├── moveFileAtomic.js ├── package.json ├── printBucketAcl.js ├── printBucketAclForUser.js ├── printFileAcl.js ├── printFileAclForUser.js ├── quickstart.js ├── releaseEventBasedHold.js ├── releaseTemporaryHold.js ├── removeBucketConditionalBinding.js ├── removeBucketCors.js ├── removeBucketDefaultOwner.js ├── removeBucketIamMember.js ├── removeBucketLabel.js ├── removeBucketOwnerAcl.js ├── removeDefaultKMSKey.js ├── removeFileOwnerAcl.js ├── removeRetentionPolicy.js ├── renameFile.js ├── resources │ ├── .gitignore │ ├── resourcesSub1 │ │ └── testSub1.txt │ ├── test.txt │ └── test2.txt ├── restoreSoftDeletedBucket.js ├── rotateEncryptionKey.js ├── scripts │ └── cleanup ├── setAutoclass.js ├── setClientEndpoint.js ├── setEventBasedHold.js ├── setObjectRetentionPolicy.js ├── setPublicAccessPreventionEnforced.js ├── setPublicAccessPreventionInherited.js ├── setRPOAsyncTurbo.js ├── setRPODefault.js ├── setRetentionPolicy.js ├── setTemporaryHold.js ├── streamFileDownload.js ├── streamFileUpload.js ├── system-test │ ├── acl.test.js │ ├── bucketLifecycle.test.js │ ├── bucketLock.test.js │ ├── buckets.test.js │ ├── encryption.test.js │ ├── files.test.js │ ├── hmacKey.test.js │ ├── iam.test.js │ ├── notifications.test.js │ ├── quickstart.test.js │ ├── requesterPays.test.js │ ├── storage.test.js │ ├── test_9d800329-00da-4cdd-9a3e-7ac6743d5813.txt │ └── transfer-manager.test.js ├── uploadDirectory.js ├── uploadDirectoryWithTransferManager.js ├── uploadEncryptedFile.js ├── uploadFile.js ├── uploadFileInChunksWithTransferManager.js ├── uploadFileWithKmsKey.js ├── uploadFromMemory.js ├── uploadManyFilesWithTransferManager.js ├── uploadWithoutAuthentication.js ├── uploadWithoutAuthenticationSignedUrl.js └── viewBucketIamMembers.js ├── src ├── acl.ts ├── bucket.ts ├── channel.ts ├── crc32c.ts ├── file.ts ├── hash-stream-validator.ts ├── hmacKey.ts ├── iam.ts ├── index.ts ├── nodejs-common │ ├── index.ts │ ├── service-object.ts │ ├── service.ts │ └── util.ts ├── notification.ts ├── package-json-helper.cjs ├── resumable-upload.ts ├── signer.ts ├── storage.ts ├── transfer-manager.ts └── util.ts ├── system-test ├── common.ts ├── data │ ├── CloudPlatform_128px_Retina.png │ ├── empty-file.txt │ ├── long-html-file.html │ └── three-mb-file.tif ├── fixtures │ ├── index-cjs.js │ └── index-esm.js ├── install.ts ├── kitchen.ts └── storage.ts ├── test ├── acl.ts ├── bucket.ts ├── channel.ts ├── crc32c.ts ├── file.ts ├── fixtures │ └── keys.json ├── headers.ts ├── hmacKey.ts ├── iam.ts ├── index.ts ├── nodejs-common │ ├── index.ts │ ├── service-object.ts │ ├── service.ts │ └── util.ts ├── notification.ts ├── resumable-upload.ts ├── signer.ts ├── testdata │ ├── testfile.json │ └── textfile.txt └── transfer-manager.ts ├── tsconfig.cjs.json └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | **/coverage 3 | test/fixtures 4 | build/ 5 | docs/ 6 | protos/ 7 | samples/generated/ 8 | system-test/**/fixtures 9 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/gts" 3 | } 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ts text eol=lf 2 | *.js text eol=lf 3 | protos/* linguist-generated 4 | **/api-extractor.json linguist-language=JSON-with-Comments 5 | -------------------------------------------------------------------------------- /.github/.OwlBot.lock.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2024 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 | # http://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 | docker: 15 | image: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest 16 | digest: sha256:609822e3c09b7a1bd90b99655904609f162cc15acb4704f1edf778284c36f429 17 | # created: 2024-10-01T19:34:30.797530443Z 18 | -------------------------------------------------------------------------------- /.github/.OwlBot.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | # http://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 | docker: 15 | image: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest 16 | 17 | 18 | begin-after-commit-hash: 674a41e0de2869f44f45eb7b1a605852a5394bba 19 | 20 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Code owners file. 2 | # This file controls who is tagged for review for any given pull request. 3 | # 4 | # For syntax help see: 5 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax 6 | 7 | 8 | # Unless specified, the jsteam is the default owner for nodejs repositories. 9 | * @googleapis/gcs-sdk-team @googleapis/jsteam -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Google Cloud Support 3 | url: https://cloud.google.com/support/ 4 | about: If you have a support contract with Google, please use the Google Cloud Support portal. 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/processs_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Process Request 3 | about: Submit a process request to the library. Process requests are any requests related to library infrastructure, for example CI/CD, publishing, releasing, broken links. 4 | --- 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/questions.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: If you have a question, please use Discussions 4 | 5 | --- 6 | 7 | If you have a general question that goes beyond the library itself, we encourage you to use [Discussions](https://github.com//discussions) 8 | to engage with fellow community members! 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/support_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Support request 3 | about: If you have a support contract with Google, please create an issue in the Google Cloud Support console. 4 | 5 | --- 6 | 7 | **PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. 8 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: 2 | - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-storage/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea 3 | - [ ] Ensure the tests and linter pass 4 | - [ ] Code coverage does not decrease (if any source code was changed) 5 | - [ ] Appropriate docs were updated (if necessary) 6 | 7 | Fixes # 🦕 8 | -------------------------------------------------------------------------------- /.github/auto-approve.yml: -------------------------------------------------------------------------------- 1 | processes: 2 | - "NodeDependency" -------------------------------------------------------------------------------- /.github/auto-label.yaml: -------------------------------------------------------------------------------- 1 | requestsize: 2 | enabled: true 3 | -------------------------------------------------------------------------------- /.github/generated-files-bot.yml: -------------------------------------------------------------------------------- 1 | generatedFiles: 2 | - path: '.kokoro/**' 3 | message: '`.kokoro` files are templated and should be updated in [`synthtool`](https://github.com/googleapis/synthtool)' 4 | - path: '.github/CODEOWNERS' 5 | message: 'CODEOWNERS should instead be modified via the `codeowner_team` property in .repo-metadata.json' 6 | - path: '.github/workflows/ci.yaml' 7 | message: '`.github/workflows/ci.yaml` (GitHub Actions) should be updated in [`synthtool`](https://github.com/googleapis/synthtool)' 8 | - path: '.github/generated-files-bot.+(yml|yaml)' 9 | message: '`.github/generated-files-bot.(yml|yaml)` should be updated in [`synthtool`](https://github.com/googleapis/synthtool)' 10 | - path: 'README.md' 11 | message: '`README.md` is managed by [`synthtool`](https://github.com/googleapis/synthtool). However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/main/.readme-partials.yaml' 12 | - path: 'samples/README.md' 13 | message: '`samples/README.md` is managed by [`synthtool`](https://github.com/googleapis/synthtool). However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/main/.readme-partials.yaml' 14 | ignoreAuthors: 15 | - 'gcf-owl-bot[bot]' 16 | - 'yoshi-automation' 17 | -------------------------------------------------------------------------------- /.github/release-please.yml: -------------------------------------------------------------------------------- 1 | handleGHRelease: true 2 | releaseType: node 3 | branches: 4 | - handleGHRelease: true 5 | releaseType: node 6 | branch: 4.x -------------------------------------------------------------------------------- /.github/release-trigger.yml: -------------------------------------------------------------------------------- 1 | enabled: true 2 | -------------------------------------------------------------------------------- /.github/scripts/remove-response-label.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2024 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 | // http://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 | module.exports = async ({ github, context }) => { 16 | const commenter = context.actor; 17 | const issue = await github.rest.issues.get({ 18 | owner: context.repo.owner, 19 | repo: context.repo.repo, 20 | issue_number: context.issue.number, 21 | }); 22 | const author = issue.data.user.login; 23 | const labels = issue.data.labels.map((e) => e.name); 24 | 25 | if (author === commenter && labels.includes('needs more info')) { 26 | await github.rest.issues.removeLabel({ 27 | owner: context.repo.owner, 28 | repo: context.repo.repo, 29 | issue_number: context.issue.number, 30 | name: 'needs more info', 31 | }); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /.github/sync-repo-settings.yaml: -------------------------------------------------------------------------------- 1 | branchProtectionRules: 2 | - pattern: 4.x 3 | isAdminEnforced: true 4 | requiredApprovingReviewCount: 1 5 | requiresCodeOwnerReviews: true 6 | requiresStrictStatusChecks: false 7 | - pattern: main 8 | isAdminEnforced: true 9 | requiredApprovingReviewCount: 1 10 | requiresCodeOwnerReviews: true 11 | requiresStrictStatusChecks: false 12 | requiredStatusCheckContexts: 13 | - "ci/kokoro: Samples test" 14 | - "ci/kokoro: System test" 15 | - docs 16 | - lint 17 | - test (14) 18 | - test (16) 19 | - test (18) 20 | - cla/google 21 | - windows 22 | - OwlBot Post Processor 23 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | pull_request: 6 | name: ci 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | strategy: 11 | matrix: 12 | node: [14, 16, 18, 20] 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions/setup-node@v3 16 | with: 17 | node-version: ${{ matrix.node }} 18 | - run: node --version 19 | # The first installation step ensures that all of our production 20 | # dependencies work on the given Node.js version, this helps us find 21 | # dependencies that don't match our engines field: 22 | - run: npm install --production --engine-strict --ignore-scripts --no-package-lock 23 | # Clean up the production install, before installing dev/production: 24 | - run: rm -rf node_modules 25 | - run: npm install --engine-strict 26 | - run: npm test 27 | env: 28 | MOCHA_THROW_DEPRECATION: false 29 | windows: 30 | runs-on: windows-latest 31 | steps: 32 | - uses: actions/checkout@v3 33 | - uses: actions/setup-node@v3 34 | with: 35 | node-version: 14 36 | - run: npm install --engine-strict 37 | - run: npm test 38 | env: 39 | MOCHA_THROW_DEPRECATION: false 40 | lint: 41 | runs-on: ubuntu-latest 42 | steps: 43 | - uses: actions/checkout@v3 44 | - uses: actions/setup-node@v3 45 | with: 46 | node-version: 14 47 | - run: npm install 48 | - run: npm run lint 49 | docs: 50 | runs-on: ubuntu-latest 51 | steps: 52 | - uses: actions/checkout@v3 53 | - uses: actions/setup-node@v3 54 | with: 55 | node-version: 14 56 | - run: npm install 57 | - run: npm run docs 58 | - uses: JustinBeckwith/linkinator-action@v1 59 | with: 60 | paths: docs/ 61 | -------------------------------------------------------------------------------- /.github/workflows/conformance-test.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | pull_request: 6 | name: conformance 7 | jobs: 8 | conformance-test: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-node@v4 13 | with: 14 | node-version: 14 15 | - run: node --version 16 | - run: npm install 17 | - run: npm run conformance-test 18 | -------------------------------------------------------------------------------- /.github/workflows/issues-no-repro.yaml: -------------------------------------------------------------------------------- 1 | name: invalid_link 2 | on: 3 | issues: 4 | types: [opened, reopened] 5 | 6 | jobs: 7 | close: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | issues: write 11 | pull-requests: write 12 | steps: 13 | - uses: actions/checkout@v4 14 | - uses: actions/github-script@v7 15 | with: 16 | script: | 17 | const script = require('./.github/scripts/close-invalid-link.cjs') 18 | await script({github, context}) 19 | -------------------------------------------------------------------------------- /.github/workflows/response.yaml: -------------------------------------------------------------------------------- 1 | name: no_response 2 | on: 3 | schedule: 4 | - cron: '30 1 * * *' # Run every day at 01:30 5 | workflow_dispatch: 6 | issue_comment: 7 | 8 | jobs: 9 | close: 10 | if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' 11 | runs-on: ubuntu-latest 12 | permissions: 13 | issues: write 14 | pull-requests: write 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/github-script@v7 18 | with: 19 | script: | 20 | const script = require('./.github/scripts/close-unresponsive.cjs') 21 | await script({github, context}) 22 | 23 | remove_label: 24 | if: github.event_name == 'issue_comment' 25 | runs-on: ubuntu-latest 26 | permissions: 27 | issues: write 28 | pull-requests: write 29 | steps: 30 | - uses: actions/checkout@v4 31 | - uses: actions/github-script@v7 32 | with: 33 | script: | 34 | const script = require('./.github/scripts/remove-response-label.cjs') 35 | await script({github, context}) 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.log 2 | **/node_modules 3 | .coverage 4 | .nyc_output 5 | docs/ 6 | out/ 7 | build/ 8 | system-test/secrets.js 9 | system-test/*key.json 10 | *.lock 11 | .DS_Store 12 | google-cloud-logging-winston-*.tgz 13 | google-cloud-logging-bunyan-*.tgz 14 | .vscode 15 | package-lock.json 16 | __pycache__ 17 | -------------------------------------------------------------------------------- /.jsdoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "opts": { 3 | "readme": "./README.md", 4 | "package": "./package.json", 5 | "template": "./node_modules/jsdoc-fresh", 6 | "recurse": true, 7 | "verbose": true, 8 | "destination": "./docs/" 9 | }, 10 | "plugins": ["plugins/markdown", "jsdoc-region-tag"], 11 | "source": { 12 | "excludePattern": "(^|\\/|\\\\)[._]", 13 | "include": ["build/cjs/src"], 14 | "includePattern": "\\.js$" 15 | }, 16 | "templates": { 17 | "copyright": "Copyright 2019 Google, LLC.", 18 | "includeDate": false, 19 | "sourceFiles": false, 20 | "systemName": "@google-cloud/storage", 21 | "theme": "lumen", 22 | "default": { 23 | "outputSourceFiles": false 24 | } 25 | }, 26 | "markdown": { 27 | "idInHeadings": true 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.kokoro/.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-generated=true 2 | -------------------------------------------------------------------------------- /.kokoro/common.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | 3 | # Build logs will be here 4 | action { 5 | define_artifacts { 6 | regex: "**/*sponge_log.xml" 7 | } 8 | } 9 | 10 | # Download trampoline resources. 11 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 12 | 13 | # Use the trampoline script to run in docker. 14 | build_file: "nodejs-storage/.kokoro/trampoline_v2.sh" 15 | 16 | # Configure the docker image for kokoro-trampoline. 17 | env_vars: { 18 | key: "TRAMPOLINE_IMAGE" 19 | value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" 20 | } 21 | env_vars: { 22 | key: "TRAMPOLINE_BUILD_FILE" 23 | value: "github/nodejs-storage/.kokoro/test.sh" 24 | } 25 | -------------------------------------------------------------------------------- /.kokoro/conformance-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2021 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eo pipefail 18 | export NPM_CONFIG_PREFIX=${HOME}/.npm-global 19 | 20 | cd $(dirname $0)/.. 21 | 22 | npm install 23 | # If tests are running against main branch, configure flakybot 24 | # to open issues on failures: 25 | if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]] || [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"nightly"* ]]; then 26 | export MOCHA_REPORTER_OUTPUT=test_output_sponge_log.xml 27 | export MOCHA_REPORTER=xunit 28 | cleanup() { 29 | chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot 30 | $KOKORO_GFILE_DIR/linux_amd64/flakybot 31 | } 32 | trap cleanup EXIT HUP 33 | fi 34 | 35 | npm run conformance-test 36 | -------------------------------------------------------------------------------- /.kokoro/continuous/node14/common.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | 3 | # Build logs will be here 4 | action { 5 | define_artifacts { 6 | regex: "**/*sponge_log.xml" 7 | } 8 | } 9 | 10 | # Download trampoline resources. 11 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 12 | 13 | # Use the trampoline script to run in docker. 14 | build_file: "nodejs-storage/.kokoro/trampoline_v2.sh" 15 | 16 | # Configure the docker image for kokoro-trampoline. 17 | env_vars: { 18 | key: "TRAMPOLINE_IMAGE" 19 | value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" 20 | } 21 | env_vars: { 22 | key: "TRAMPOLINE_BUILD_FILE" 23 | value: "github/nodejs-storage/.kokoro/test.sh" 24 | } 25 | -------------------------------------------------------------------------------- /.kokoro/continuous/node14/lint.cfg: -------------------------------------------------------------------------------- 1 | env_vars: { 2 | key: "TRAMPOLINE_BUILD_FILE" 3 | value: "github/nodejs-storage/.kokoro/lint.sh" 4 | } 5 | -------------------------------------------------------------------------------- /.kokoro/continuous/node14/samples-test.cfg: -------------------------------------------------------------------------------- 1 | # Download resources for system tests (service account key, etc.) 2 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" 3 | 4 | env_vars: { 5 | key: "TRAMPOLINE_BUILD_FILE" 6 | value: "github/nodejs-storage/.kokoro/samples-test.sh" 7 | } 8 | 9 | env_vars: { 10 | key: "SECRET_MANAGER_KEYS" 11 | value: "long-door-651-kokoro-system-test-service-account" 12 | } -------------------------------------------------------------------------------- /.kokoro/continuous/node14/system-test.cfg: -------------------------------------------------------------------------------- 1 | # Download resources for system tests (service account key, etc.) 2 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" 3 | 4 | env_vars: { 5 | key: "TRAMPOLINE_BUILD_FILE" 6 | value: "github/nodejs-storage/.kokoro/system-test.sh" 7 | } 8 | 9 | env_vars: { 10 | key: "SECRET_MANAGER_KEYS" 11 | value: "long-door-651-kokoro-system-test-service-account,client-library-test-universe-domain-credential" 12 | } -------------------------------------------------------------------------------- /.kokoro/continuous/node14/test.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/nodejs-storage/77070b565bf3a347902d38ed46206b86fbf4ffe8/.kokoro/continuous/node14/test.cfg -------------------------------------------------------------------------------- /.kokoro/docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eo pipefail 18 | 19 | export NPM_CONFIG_PREFIX=${HOME}/.npm-global 20 | 21 | cd $(dirname $0)/.. 22 | 23 | npm install 24 | 25 | npm run docs-test 26 | -------------------------------------------------------------------------------- /.kokoro/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eo pipefail 18 | 19 | export NPM_CONFIG_PREFIX=${HOME}/.npm-global 20 | 21 | cd $(dirname $0)/.. 22 | 23 | npm install 24 | 25 | # Install and link samples 26 | if [ -f samples/package.json ]; then 27 | cd samples/ 28 | npm link ../ 29 | npm install 30 | cd .. 31 | fi 32 | 33 | npm run lint 34 | -------------------------------------------------------------------------------- /.kokoro/pre-samples-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | . .kokoro/setup-vars.sh 18 | -------------------------------------------------------------------------------- /.kokoro/pre-system-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | . .kokoro/setup-vars.sh 18 | 19 | # Lease a second service account for testing listing with multiple service accounts 20 | export HMAC_KEY_TEST_SECOND_SERVICE_ACCOUNT=$(./gimmeproj -project=$HMAC_PROJECT lease 15m) 21 | # Add to the list of leased service account for clean up after tests 22 | export LEASED_SERVICE_ACCOUNTS="$LEASED_SERVICE_ACCOUNTS $HMAC_KEY_TEST_SECOND_SERVICE_ACCOUNT" 23 | -------------------------------------------------------------------------------- /.kokoro/presubmit/node14/common.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | 3 | # Build logs will be here 4 | action { 5 | define_artifacts { 6 | regex: "**/*sponge_log.xml" 7 | } 8 | } 9 | 10 | # Download trampoline resources. 11 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 12 | 13 | # Use the trampoline script to run in docker. 14 | build_file: "nodejs-storage/.kokoro/trampoline_v2.sh" 15 | 16 | # Configure the docker image for kokoro-trampoline. 17 | env_vars: { 18 | key: "TRAMPOLINE_IMAGE" 19 | value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" 20 | } 21 | env_vars: { 22 | key: "TRAMPOLINE_BUILD_FILE" 23 | value: "github/nodejs-storage/.kokoro/test.sh" 24 | } 25 | -------------------------------------------------------------------------------- /.kokoro/presubmit/node14/samples-test.cfg: -------------------------------------------------------------------------------- 1 | # Download resources for system tests (service account key, etc.) 2 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" 3 | 4 | env_vars: { 5 | key: "TRAMPOLINE_BUILD_FILE" 6 | value: "github/nodejs-storage/.kokoro/samples-test.sh" 7 | } 8 | 9 | env_vars: { 10 | key: "SECRET_MANAGER_KEYS" 11 | value: "long-door-651-kokoro-system-test-service-account" 12 | } -------------------------------------------------------------------------------- /.kokoro/presubmit/node14/system-test.cfg: -------------------------------------------------------------------------------- 1 | # Download resources for system tests (service account key, etc.) 2 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" 3 | 4 | env_vars: { 5 | key: "TRAMPOLINE_BUILD_FILE" 6 | value: "github/nodejs-storage/.kokoro/system-test.sh" 7 | } 8 | 9 | env_vars: { 10 | key: "SECRET_MANAGER_KEYS" 11 | value: "long-door-651-kokoro-system-test-service-account,client-library-test-universe-domain-credential" 12 | } -------------------------------------------------------------------------------- /.kokoro/presubmit/node14/test.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/nodejs-storage/77070b565bf3a347902d38ed46206b86fbf4ffe8/.kokoro/presubmit/node14/test.cfg -------------------------------------------------------------------------------- /.kokoro/presubmit/windows/common.cfg: -------------------------------------------------------------------------------- 1 | # Format: //devtools/kokoro/config/proto/build.proto 2 | 3 | -------------------------------------------------------------------------------- /.kokoro/presubmit/windows/test.cfg: -------------------------------------------------------------------------------- 1 | # Use the test file directly 2 | build_file: "nodejs-storage/.kokoro/test.bat" 3 | -------------------------------------------------------------------------------- /.kokoro/publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eo pipefail 18 | 19 | export NPM_CONFIG_PREFIX=${HOME}/.npm-global 20 | 21 | # Start the releasetool reporter 22 | python3 -m releasetool publish-reporter-script > /tmp/publisher-script; source /tmp/publisher-script 23 | 24 | cd $(dirname $0)/.. 25 | 26 | NPM_TOKEN=$(cat $KOKORO_KEYSTORE_DIR/73713_google-cloud-npm-token-1) 27 | echo "//wombat-dressing-room.appspot.com/:_authToken=${NPM_TOKEN}" > ~/.npmrc 28 | 29 | npm install 30 | npm pack . 31 | # npm provides no way to specify, observe, or predict the name of the tarball 32 | # file it generates. We have to look in the current directory for the freshest 33 | # .tgz file. 34 | TARBALL=$(ls -1 -t *.tgz | head -1) 35 | 36 | npm publish --access=public --registry=https://wombat-dressing-room.appspot.com "$TARBALL" 37 | 38 | # Kokoro collects *.tgz and package-lock.json files and stores them in Placer 39 | # so we can generate SBOMs and attestations. 40 | # However, we *don't* want Kokoro to collect package-lock.json and *.tgz files 41 | # that happened to be installed with dependencies. 42 | find node_modules -name package-lock.json -o -name "*.tgz" | xargs rm -f -------------------------------------------------------------------------------- /.kokoro/release/common.cfg: -------------------------------------------------------------------------------- 1 | before_action { 2 | fetch_keystore { 3 | keystore_resource { 4 | keystore_config_id: 73713 5 | keyname: "yoshi-automation-github-key" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.kokoro/release/docs-devsite.cfg: -------------------------------------------------------------------------------- 1 | # service account used to publish up-to-date docs. 2 | before_action { 3 | fetch_keystore { 4 | keystore_resource { 5 | keystore_config_id: 73713 6 | keyname: "docuploader_service_account" 7 | } 8 | } 9 | } 10 | 11 | # doc publications use a Python image. 12 | env_vars: { 13 | key: "TRAMPOLINE_IMAGE" 14 | value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" 15 | } 16 | 17 | # Download trampoline resources. 18 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 19 | 20 | # Use the trampoline script to run in docker. 21 | build_file: "nodejs-storage/.kokoro/trampoline_v2.sh" 22 | 23 | env_vars: { 24 | key: "TRAMPOLINE_BUILD_FILE" 25 | value: "github/nodejs-storage/.kokoro/release/docs-devsite.sh" 26 | } 27 | -------------------------------------------------------------------------------- /.kokoro/release/docs-devsite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2021 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eo pipefail 18 | 19 | if [[ -z "$CREDENTIALS" ]]; then 20 | # if CREDENTIALS are explicitly set, assume we're testing locally 21 | # and don't set NPM_CONFIG_PREFIX. 22 | export NPM_CONFIG_PREFIX=${HOME}/.npm-global 23 | export PATH="$PATH:${NPM_CONFIG_PREFIX}/bin" 24 | cd $(dirname $0)/../.. 25 | fi 26 | 27 | npm install 28 | npm install --no-save @google-cloud/cloud-rad@^0.4.0 29 | # publish docs to devsite 30 | npx @google-cloud/cloud-rad . cloud-rad 31 | -------------------------------------------------------------------------------- /.kokoro/release/docs.cfg: -------------------------------------------------------------------------------- 1 | # service account used to publish up-to-date docs. 2 | before_action { 3 | fetch_keystore { 4 | keystore_resource { 5 | keystore_config_id: 73713 6 | keyname: "docuploader_service_account" 7 | } 8 | } 9 | } 10 | 11 | # doc publications use a Python image. 12 | env_vars: { 13 | key: "TRAMPOLINE_IMAGE" 14 | value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" 15 | } 16 | 17 | # Download trampoline resources. 18 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 19 | 20 | # Use the trampoline script to run in docker. 21 | build_file: "nodejs-storage/.kokoro/trampoline_v2.sh" 22 | 23 | env_vars: { 24 | key: "TRAMPOLINE_BUILD_FILE" 25 | value: "github/nodejs-storage/.kokoro/release/docs.sh" 26 | } 27 | -------------------------------------------------------------------------------- /.kokoro/release/docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eo pipefail 18 | 19 | # build jsdocs (Python is installed on the Node 10 docker image). 20 | if [[ -z "$CREDENTIALS" ]]; then 21 | # if CREDENTIALS are explicitly set, assume we're testing locally 22 | # and don't set NPM_CONFIG_PREFIX. 23 | export NPM_CONFIG_PREFIX=${HOME}/.npm-global 24 | export PATH="$PATH:${NPM_CONFIG_PREFIX}/bin" 25 | cd $(dirname $0)/../.. 26 | fi 27 | npm install 28 | npm run docs 29 | 30 | # create docs.metadata, based on package.json and .repo-metadata.json. 31 | npm i json@9.0.6 -g 32 | python3 -m docuploader create-metadata \ 33 | --name=$(cat .repo-metadata.json | json name) \ 34 | --version=$(cat package.json | json version) \ 35 | --language=$(cat .repo-metadata.json | json language) \ 36 | --distribution-name=$(cat .repo-metadata.json | json distribution_name) \ 37 | --product-page=$(cat .repo-metadata.json | json product_documentation) \ 38 | --github-repository=$(cat .repo-metadata.json | json repo) \ 39 | --issue-tracker=$(cat .repo-metadata.json | json issue_tracker) 40 | cp docs.metadata ./docs/docs.metadata 41 | 42 | # deploy the docs. 43 | if [[ -z "$CREDENTIALS" ]]; then 44 | CREDENTIALS=${KOKORO_KEYSTORE_DIR}/73713_docuploader_service_account 45 | fi 46 | if [[ -z "$BUCKET" ]]; then 47 | BUCKET=docs-staging 48 | fi 49 | python3 -m docuploader upload ./docs --credentials $CREDENTIALS --staging-bucket $BUCKET 50 | -------------------------------------------------------------------------------- /.kokoro/release/publish.cfg: -------------------------------------------------------------------------------- 1 | before_action { 2 | fetch_keystore { 3 | keystore_resource { 4 | keystore_config_id: 73713 5 | keyname: "docuploader_service_account" 6 | } 7 | } 8 | } 9 | 10 | before_action { 11 | fetch_keystore { 12 | keystore_resource { 13 | keystore_config_id: 73713 14 | keyname: "google-cloud-npm-token-1" 15 | } 16 | } 17 | } 18 | 19 | env_vars: { 20 | key: "SECRET_MANAGER_KEYS" 21 | value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,client-library-test-universe-domain-credential" 22 | } 23 | 24 | # Download trampoline resources. 25 | gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" 26 | 27 | # Use the trampoline script to run in docker. 28 | build_file: "nodejs-storage/.kokoro/trampoline_v2.sh" 29 | 30 | # Configure the docker image for kokoro-trampoline. 31 | env_vars: { 32 | key: "TRAMPOLINE_IMAGE" 33 | value: "gcr.io/cloud-devrel-kokoro-resources/node:14-user" 34 | } 35 | 36 | env_vars: { 37 | key: "TRAMPOLINE_BUILD_FILE" 38 | value: "github/nodejs-storage/.kokoro/publish.sh" 39 | } 40 | 41 | # Store the packages we uploaded to npmjs.org and their corresponding 42 | # package-lock.jsons in Placer. That way, we have a record of exactly 43 | # what we published, and which version of which tools we used to publish 44 | # it, which we can use to generate SBOMs and attestations. 45 | action { 46 | define_artifacts { 47 | regex: "github/**/*.tgz" 48 | regex: "github/**/package-lock.json" 49 | strip_prefix: "github" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /.kokoro/setup-vars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # nodejs-storage's system tests require additional project and 18 | # system test key 19 | export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/storage-key.json 20 | export GCN_STORAGE_2ND_PROJECT_ID=gcloud-node-whitelist-ci-tests 21 | export GCN_STORAGE_2ND_PROJECT_KEY=${KOKORO_GFILE_DIR}/no-whitelist-key.json 22 | 23 | export GOOGLE_CLOUD_KMS_KEY_ASIA="projects/long-door-651/locations/asia/keyRings/test-key-asia/cryptoKeys/test-key-asia" 24 | export GOOGLE_CLOUD_KMS_KEY_US="projects/long-door-651/locations/us/keyRings/test-key-us/cryptoKeys/test-key-us" 25 | 26 | # For testing SA HMAC 27 | export HMAC_PROJECT=gimme-acc 28 | curl https://storage.googleapis.com/gimme-proj/linux_amd64/gimmeproj > gimmeproj 29 | chmod +x gimmeproj 30 | ./gimmeproj version 31 | 32 | export HMAC_KEY_TEST_SERVICE_ACCOUNT=$(./gimmeproj -project=$HMAC_PROJECT lease 15m) 33 | echo Leased service account: $HMAC_KEY_TEST_SERVICE_ACCOUNT 34 | export LEASED_SERVICE_ACCOUNTS=$HMAC_KEY_TEST_SERVICE_ACCOUNT 35 | 36 | cleanup_service_accounts () { 37 | for i in $LEASED_SERVICE_ACCOUNTS; do 38 | ./gimmeproj -project=$HMAC_PROJECT "done" $i 39 | done 40 | } 41 | 42 | trap cleanup_service_accounts EXIT 43 | -------------------------------------------------------------------------------- /.kokoro/test.bat: -------------------------------------------------------------------------------- 1 | @rem Copyright 2018 Google LLC. All rights reserved. 2 | @rem 3 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 4 | @rem you may not use this file except in compliance with the License. 5 | @rem You may obtain a copy of the License at 6 | @rem 7 | @rem http://www.apache.org/licenses/LICENSE-2.0 8 | @rem 9 | @rem Unless required by applicable law or agreed to in writing, software 10 | @rem distributed under the License is distributed on an "AS IS" BASIS, 11 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | @rem See the License for the specific language governing permissions and 13 | @rem limitations under the License. 14 | 15 | @echo "Starting Windows build" 16 | 17 | cd /d %~dp0 18 | cd .. 19 | 20 | @rem npm path is not currently set in our image, we should fix this next time 21 | @rem we upgrade Node.js in the image: 22 | SET PATH=%PATH%;/cygdrive/c/Program Files/nodejs/npm 23 | 24 | call nvm use v14.17.3 25 | call which node 26 | 27 | call npm install || goto :error 28 | call npm run test || goto :error 29 | 30 | goto :EOF 31 | 32 | :error 33 | exit /b 1 34 | -------------------------------------------------------------------------------- /.kokoro/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2018 Google LLC 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -eo pipefail 18 | 19 | export NPM_CONFIG_PREFIX=${HOME}/.npm-global 20 | 21 | cd $(dirname $0)/.. 22 | 23 | npm install 24 | # If tests are running against main branch, configure flakybot 25 | # to open issues on failures: 26 | if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]] || [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"nightly"* ]]; then 27 | export MOCHA_REPORTER_OUTPUT=test_output_sponge_log.xml 28 | export MOCHA_REPORTER=xunit 29 | cleanup() { 30 | chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot 31 | $KOKORO_GFILE_DIR/linux_amd64/flakybot 32 | } 33 | trap cleanup EXIT HUP 34 | fi 35 | # Unit tests exercise the entire API surface, which may include 36 | # deprecation warnings: 37 | export MOCHA_THROW_DEPRECATION=false 38 | npm test 39 | 40 | # codecov combines coverage across integration and unit tests. Include 41 | # the logic below for any environment you wish to collect coverage for: 42 | COVERAGE_NODE=14 43 | if npx check-node-version@3.3.0 --silent --node $COVERAGE_NODE; then 44 | NYC_BIN=./node_modules/nyc/bin/nyc.js 45 | if [ -f "$NYC_BIN" ]; then 46 | $NYC_BIN report || true 47 | fi 48 | bash $KOKORO_GFILE_DIR/codecov.sh 49 | else 50 | echo "coverage is only reported for Node $COVERAGE_NODE" 51 | fi 52 | -------------------------------------------------------------------------------- /.kokoro/trampoline.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # This file is not used any more, but we keep this file for making it 17 | # easy to roll back. 18 | # TODO: Remove this file from the template. 19 | 20 | set -eo pipefail 21 | 22 | # Always run the cleanup script, regardless of the success of bouncing into 23 | # the container. 24 | function cleanup() { 25 | chmod +x ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh 26 | ${KOKORO_GFILE_DIR}/trampoline_cleanup.sh 27 | echo "cleanup"; 28 | } 29 | trap cleanup EXIT 30 | 31 | $(dirname $0)/populate-secrets.sh # Secret Manager secrets. 32 | python3 "${KOKORO_GFILE_DIR}/trampoline_v1.py" 33 | -------------------------------------------------------------------------------- /.mocharc.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | const config = { 15 | "enable-source-maps": true, 16 | "throw-deprecation": true, 17 | "timeout": 10000, 18 | "recursive": true 19 | } 20 | if (process.env.MOCHA_THROW_DEPRECATION === 'false') { 21 | delete config['throw-deprecation']; 22 | } 23 | if (process.env.MOCHA_REPORTER) { 24 | config.reporter = process.env.MOCHA_REPORTER; 25 | } 26 | if (process.env.MOCHA_REPORTER_OUTPUT) { 27 | config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; 28 | } 29 | module.exports = config 30 | -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "report-dir": "./.coverage", 3 | "reporter": ["text", "lcov"], 4 | "exclude": [ 5 | "**/*-test", 6 | "**/.coverage", 7 | "**/apis", 8 | "**/benchmark", 9 | "**/conformance", 10 | "**/docs", 11 | "**/samples", 12 | "**/scripts", 13 | "**/protos", 14 | "**/test", 15 | "**/*.d.ts", 16 | ".jsdoc.js", 17 | "**/.jsdoc.js", 18 | "karma.conf.js", 19 | "webpack-tests.config.js", 20 | "webpack.config.js" 21 | ], 22 | "exclude-after-remap": false, 23 | "all": true 24 | } 25 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | **/coverage 3 | test/fixtures 4 | build/ 5 | docs/ 6 | protos/ 7 | -------------------------------------------------------------------------------- /.prettierrc.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | module.exports = { 16 | ...require('gts/.prettierrc.json') 17 | } 18 | -------------------------------------------------------------------------------- /.readme-partials.yaml: -------------------------------------------------------------------------------- 1 | introduction: |- 2 | > Node.js idiomatic client for [Cloud Storage][product-docs]. 3 | 4 | [Cloud Storage](https://cloud.google.com/storage/docs) allows world-wide 5 | storage and retrieval of any amount of data at any time. You can use Google 6 | Cloud Storage for a range of scenarios including serving website content, 7 | storing data for archival and disaster recovery, or distributing large data 8 | objects to users via direct download. 9 | -------------------------------------------------------------------------------- /.repo-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "storage", 3 | "name_pretty": "Google Cloud Storage", 4 | "product_documentation": "https://cloud.google.com/storage", 5 | "client_documentation": "https://cloud.google.com/nodejs/docs/reference/storage/latest", 6 | "issue_tracker": "https://issuetracker.google.com/savedsearches/559782", 7 | "release_level": "stable", 8 | "language": "nodejs", 9 | "repo": "googleapis/nodejs-storage", 10 | "distribution_name": "@google-cloud/storage", 11 | "api_id": "storage-api.googleapis.com", 12 | "requires_billing": true, 13 | "codeowner_team": "@googleapis/gcs-sdk-team", 14 | "api_shortname": "storage", 15 | "library_type": "GAPIC_MANUAL" 16 | } 17 | -------------------------------------------------------------------------------- /.trampolinerc: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | # http://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 | # Template for .trampolinerc 16 | 17 | # Add required env vars here. 18 | required_envvars+=( 19 | ) 20 | 21 | # Add env vars which are passed down into the container here. 22 | pass_down_envvars+=( 23 | "AUTORELEASE_PR" 24 | "VERSION" 25 | ) 26 | 27 | # Prevent unintentional override on the default image. 28 | if [[ "${TRAMPOLINE_IMAGE_UPLOAD:-false}" == "true" ]] && \ 29 | [[ -z "${TRAMPOLINE_IMAGE:-}" ]]; then 30 | echo "Please set TRAMPOLINE_IMAGE if you want to upload the Docker image." 31 | exit 1 32 | fi 33 | 34 | # Define the default value if it makes sense. 35 | if [[ -z "${TRAMPOLINE_IMAGE_UPLOAD:-}" ]]; then 36 | TRAMPOLINE_IMAGE_UPLOAD="" 37 | fi 38 | 39 | if [[ -z "${TRAMPOLINE_IMAGE:-}" ]]; then 40 | TRAMPOLINE_IMAGE="" 41 | fi 42 | 43 | if [[ -z "${TRAMPOLINE_DOCKERFILE:-}" ]]; then 44 | TRAMPOLINE_DOCKERFILE="" 45 | fi 46 | 47 | if [[ -z "${TRAMPOLINE_BUILD_FILE:-}" ]]; then 48 | TRAMPOLINE_BUILD_FILE="" 49 | fi 50 | 51 | # Secret Manager secrets. 52 | source ${PROJECT_ROOT}/.kokoro/populate-secrets.sh 53 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security issue, please use [g.co/vulnz](https://g.co/vulnz). 4 | 5 | The Google Security Team will respond within 5 working days of your report on g.co/vulnz. 6 | 7 | We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue. 8 | -------------------------------------------------------------------------------- /conformance-test/globalHooks.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import { 17 | getTestBenchDockerImage, 18 | runTestBenchDockerImage, 19 | stopTestBenchDockerImage, 20 | } from './testBenchUtil'; 21 | 22 | const TIMEOUT_FOR_DOCKER_OPS = 60000; 23 | const TIME_TO_WAIT_FOR_CONTAINER_READY = 10000; 24 | 25 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 26 | export async function mochaGlobalSetup(this: any) { 27 | // Increase the timeout for this before block so that the docker images have time to download and run. 28 | this.suite._timeout = TIMEOUT_FOR_DOCKER_OPS; 29 | await getTestBenchDockerImage(); 30 | await runTestBenchDockerImage(); 31 | await new Promise(resolve => 32 | setTimeout(resolve, TIME_TO_WAIT_FOR_CONTAINER_READY) 33 | ); 34 | } 35 | 36 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 37 | export async function mochaGlobalTeardown(this: any) { 38 | // Increase the timeout for this block so that docker has time to stop the container. 39 | this.suite._timeout = TIMEOUT_FOR_DOCKER_OPS; 40 | await stopTestBenchDockerImage(); 41 | } 42 | -------------------------------------------------------------------------------- /conformance-test/scenarios/scenarioFive.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import * as testFile from '../test-data/retryStrategyTestData.json'; 17 | import {executeScenario, RetryTestCase} from '../conformanceCommon'; 18 | import assert from 'assert'; 19 | 20 | const SCENARIO_NUMBER_TO_TEST = 5; 21 | const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find( 22 | test => test.id === SCENARIO_NUMBER_TO_TEST 23 | ); 24 | 25 | describe(`Scenario ${SCENARIO_NUMBER_TO_TEST}`, () => { 26 | assert(retryTestCase); 27 | executeScenario(retryTestCase); 28 | }); 29 | -------------------------------------------------------------------------------- /conformance-test/scenarios/scenarioFour.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import * as testFile from '../test-data/retryStrategyTestData.json'; 17 | import {executeScenario, RetryTestCase} from '../conformanceCommon'; 18 | import assert from 'assert'; 19 | 20 | const SCENARIO_NUMBER_TO_TEST = 4; 21 | const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find( 22 | test => test.id === SCENARIO_NUMBER_TO_TEST 23 | ); 24 | 25 | describe(`Scenario ${SCENARIO_NUMBER_TO_TEST}`, () => { 26 | assert(retryTestCase); 27 | executeScenario(retryTestCase); 28 | }); 29 | -------------------------------------------------------------------------------- /conformance-test/scenarios/scenarioOne.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import * as testFile from '../test-data/retryStrategyTestData.json'; 17 | import {executeScenario, RetryTestCase} from '../conformanceCommon'; 18 | import assert from 'assert'; 19 | 20 | const SCENARIO_NUMBER_TO_TEST = 1; 21 | const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find( 22 | test => test.id === SCENARIO_NUMBER_TO_TEST 23 | ); 24 | 25 | describe(`Scenario ${SCENARIO_NUMBER_TO_TEST}`, () => { 26 | assert(retryTestCase); 27 | executeScenario(retryTestCase); 28 | }); 29 | -------------------------------------------------------------------------------- /conformance-test/scenarios/scenarioSeven.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import * as testFile from '../test-data/retryStrategyTestData.json'; 17 | import {executeScenario, RetryTestCase} from '../conformanceCommon'; 18 | import assert from 'assert'; 19 | 20 | const SCENARIO_NUMBER_TO_TEST = 7; 21 | const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find( 22 | test => test.id === SCENARIO_NUMBER_TO_TEST 23 | ); 24 | 25 | describe(`Scenario ${SCENARIO_NUMBER_TO_TEST}`, () => { 26 | assert(retryTestCase); 27 | executeScenario(retryTestCase); 28 | }); 29 | -------------------------------------------------------------------------------- /conformance-test/scenarios/scenarioSix.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import * as testFile from '../test-data/retryStrategyTestData.json'; 17 | import {executeScenario, RetryTestCase} from '../conformanceCommon'; 18 | import assert from 'assert'; 19 | 20 | const SCENARIO_NUMBER_TO_TEST = 6; 21 | const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find( 22 | test => test.id === SCENARIO_NUMBER_TO_TEST 23 | ); 24 | 25 | describe(`Scenario ${SCENARIO_NUMBER_TO_TEST}`, () => { 26 | assert(retryTestCase); 27 | executeScenario(retryTestCase); 28 | }); 29 | -------------------------------------------------------------------------------- /conformance-test/scenarios/scenarioThree.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import * as testFile from '../test-data/retryStrategyTestData.json'; 17 | import {executeScenario, RetryTestCase} from '../conformanceCommon'; 18 | import assert from 'assert'; 19 | 20 | const SCENARIO_NUMBER_TO_TEST = 3; 21 | const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find( 22 | test => test.id === SCENARIO_NUMBER_TO_TEST 23 | ); 24 | 25 | describe(`Scenario ${SCENARIO_NUMBER_TO_TEST}`, () => { 26 | assert(retryTestCase); 27 | executeScenario(retryTestCase); 28 | }); 29 | -------------------------------------------------------------------------------- /conformance-test/scenarios/scenarioTwo.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import * as testFile from '../test-data/retryStrategyTestData.json'; 17 | import {executeScenario, RetryTestCase} from '../conformanceCommon'; 18 | import assert from 'assert'; 19 | 20 | const SCENARIO_NUMBER_TO_TEST = 2; 21 | const retryTestCase: RetryTestCase | undefined = testFile.retryTests.find( 22 | test => test.id === SCENARIO_NUMBER_TO_TEST 23 | ); 24 | 25 | describe(`Scenario ${SCENARIO_NUMBER_TO_TEST}`, () => { 26 | assert(retryTestCase); 27 | executeScenario(retryTestCase); 28 | }); 29 | -------------------------------------------------------------------------------- /conformance-test/testBenchUtil.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2021 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import {execSync} from 'child_process'; 17 | import {unlinkSync, writeFileSync} from 'fs'; 18 | import {URL} from 'url'; 19 | 20 | const HOST = process.env.STORAGE_EMULATOR_HOST || 'http://localhost:9000'; 21 | const PORT = new URL(HOST).port; 22 | const CONTAINER_NAME = 'storage-testbench'; 23 | const DEFAULT_IMAGE_NAME = 24 | 'gcr.io/cloud-devrel-public-resources/storage-testbench'; 25 | const DEFAULT_IMAGE_TAG = 'v0.35.0'; 26 | const DOCKER_IMAGE = `${DEFAULT_IMAGE_NAME}:${DEFAULT_IMAGE_TAG}`; 27 | const PULL_CMD = `docker pull ${DOCKER_IMAGE}`; 28 | const RUN_CMD = `docker run --rm -d -p ${PORT}:${PORT} --name ${CONTAINER_NAME} ${DOCKER_IMAGE} && sleep 1`; 29 | const STOP_CMD = `docker stop ${CONTAINER_NAME};`; 30 | 31 | export async function getTestBenchDockerImage(): Promise { 32 | return execSync(PULL_CMD); 33 | } 34 | 35 | export async function runTestBenchDockerImage(): Promise { 36 | return execSync(RUN_CMD); 37 | } 38 | 39 | export async function stopTestBenchDockerImage(): Promise { 40 | return execSync(STOP_CMD); 41 | } 42 | 43 | export function createTestBuffer(sizeInBytes: number): Buffer { 44 | return Buffer.alloc(sizeInBytes, 'testdata'); 45 | } 46 | 47 | export function createTestFileFromBuffer(sizeInMb: number, path: string): void { 48 | const buf = createTestBuffer(sizeInMb); 49 | writeFileSync(path, buf); 50 | } 51 | 52 | export function deleteTestFile(path: string): void { 53 | unlinkSync(path); 54 | } 55 | -------------------------------------------------------------------------------- /internal-tooling/README.md: -------------------------------------------------------------------------------- 1 | # nodejs-storage benchmarking 2 | 3 | **This is not a supported Google product** 4 | 5 | This benchmarking script intended for use by Storage client library maintainers to benchmark various workloads and collect metrics in order to improve performance of the library. Currently the benchmarking runs a Write-1-Read-3 workload and measures throughput. 6 | 7 | ## Run example: 8 | This runs 10K iterations of Write-1-Read-3 on 5KiB to 2GiB files, and generates output to a CSV file: 9 | ```bash 10 | $ cd nodejs-storage 11 | $ npm install 12 | $ cd build/internal-tooling 13 | $ node performanceTest.js --iterations 10000 14 | ``` 15 | 16 | ## CLI parameters 17 | 18 | | Parameter | Description | Possible values | Default | 19 | | --------- | ----------- | --------------- |:-------:| 20 | | --iterations | number of iterations to run | any positive integer | `100` | 21 | | --numthreads | number of threads to run | any positive integer | `1` | 22 | | --bucket | bucket to upload/download to/from | any string bucket name | `nodejs-perf-metrics` | 23 | | --small | number of bytes for lower bound file size | any positive integer | `5120` | 24 | | --large | number of bytes for upper bound file size | any positive integer | `2.147e9` | 25 | | --projectid | project ID to use | any string project ID | `undefined` | 26 | 27 | 28 | ## Workload definition and CSV headers 29 | 30 | For each invocation of the benchmark, write a new object of random size between `small` and `large` . After the successful write, download the object in full three times. For each of the 4 operations record the following fields: 31 | 32 | | Field | Description | 33 | | ----- | ----------- | 34 | | Op | the name of the operations (WRITE, READ[{0,1,2}]) | 35 | | ObjectSize | the number of bytes of the object | 36 | | LibBufferSize | configured to use the library default of 100 MiB | 37 | | Crc32cEnabled | whether crc32c was computed for the operation | 38 | | MD5Enabled | whether MD5 was computed for the operation | 39 | | ApiName | default to JSON| 40 | | ElapsedTimeUs | the elapsed time in microseconds the operation took | 41 | | Status | completion state of the operation [OK, FAIL] | 42 | | AppBufferSize | N/A | 43 | | CpuTimeUs | N/A | -------------------------------------------------------------------------------- /internal-tooling/helpers/package.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } -------------------------------------------------------------------------------- /linkinator.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "recurse": true, 3 | "skip": [ 4 | "https://codecov.io/gh/googleapis/", 5 | "www.googleapis.com", 6 | "img.shields.io", 7 | "node_modules/", 8 | "CHANGELOG.md" 9 | ], 10 | "silent": true, 11 | "concurrency": 10 12 | } 13 | -------------------------------------------------------------------------------- /owlbot.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | # http://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 | import synthtool as s 16 | import synthtool.gcp as gcp 17 | import synthtool.languages.node as node 18 | import logging 19 | 20 | logging.basicConfig(level=logging.DEBUG) 21 | 22 | common_templates = gcp.CommonTemplates() 23 | templates = common_templates.node_library(source_location='build/src') 24 | s.copy(templates, excludes=['.jsdoc.js', 25 | '.github/release-please.yml', 26 | '.github/sync-repo-settings.yaml', 27 | '.prettierrc.js', 28 | '.mocharc.js', 29 | '.kokoro/continuous/node14/system-test.cfg', 30 | '.kokoro/presubmit/node14/system-test.cfg', 31 | '.kokoro/release/publish.cfg', 32 | '.kokoro/system-test.sh' 33 | ]) 34 | 35 | # Create .config directory under $HOME to get around permissions issues 36 | # with resumable upload. 37 | s.replace( 38 | ".circleci/config.yml", 39 | "command: npm run system-test", 40 | "command: mkdir $HOME/.config && npm run system-test") 41 | node.fix() 42 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base", 4 | "docker:disable", 5 | ":disableDependencyDashboard" 6 | ], 7 | "constraintsFiltering": "strict", 8 | "pinVersions": false, 9 | "rebaseStalePrs": true, 10 | "schedule": [ 11 | "after 9am and before 3pm" 12 | ], 13 | "gitAuthor": null, 14 | "packageRules": [ 15 | { 16 | "extends": "packages:linters", 17 | "groupName": "linters" 18 | } 19 | ], 20 | "ignoreDeps": ["typescript"] 21 | } 22 | -------------------------------------------------------------------------------- /samples/.eslintrc.yml: -------------------------------------------------------------------------------- 1 | --- 2 | rules: 3 | no-console: off 4 | no-undef: off 5 | -------------------------------------------------------------------------------- /samples/addBucketDefaultOwnerAcl.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') { 24 | // [START storage_add_bucket_default_owner] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The email address of the user to add 32 | // const userEmail = 'user-email-to-add'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function addBucketDefaultOwner() { 41 | // Makes the user an owner in the default ACL of the bucket. You can use 42 | // addAllUsers(), addDomain(), addProject(), addGroup(), and 43 | // addAllAuthenticatedUsers() to grant access to different types of entities. 44 | // You can also use "readers" and "writers" to grant different roles. 45 | await storage.bucket(bucketName).acl.default.owners.addUser(userEmail); 46 | 47 | console.log(`Added user ${userEmail} as an owner on bucket ${bucketName}.`); 48 | } 49 | 50 | addBucketDefaultOwner().catch(console.error); 51 | // [END storage_add_bucket_default_owner] 52 | } 53 | main(...process.argv.slice(2)); 54 | -------------------------------------------------------------------------------- /samples/addBucketLabel.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: Storage Add Bucket Label. 19 | // description: Adds bucket label. 20 | // usage: node addBucketLabel.js 21 | 22 | function main( 23 | bucketName = 'my-bucket', 24 | labelKey = 'labelone', 25 | labelValue = 'labelonevalue' 26 | ) { 27 | // [START storage_add_bucket_label] 28 | /** 29 | * TODO(developer): Uncomment the following lines before running the sample. 30 | */ 31 | // The ID of your GCS bucket 32 | // const bucketName = 'your-unique-bucket-name'; 33 | 34 | // The key of the label to add 35 | // const labelKey = 'label-key-to-add'; 36 | 37 | // The value of the label to add 38 | // const labelValue = 'label-value-to-add'; 39 | 40 | // Imports the Google Cloud client library 41 | const {Storage} = require('@google-cloud/storage'); 42 | 43 | // Creates a client 44 | const storage = new Storage(); 45 | 46 | const labels = { 47 | [labelKey]: labelValue, 48 | }; 49 | 50 | async function addBucketLabel() { 51 | await storage.bucket(bucketName).setMetadata({labels}); 52 | console.log(`Added label to bucket ${bucketName}`); 53 | } 54 | 55 | addBucketLabel().catch(console.error); 56 | // [END storage_add_bucket_label] 57 | } 58 | process.on('unhandledRejection', err => { 59 | console.error(err.message); 60 | process.exitCode = 1; 61 | }); 62 | main(...process.argv.slice(2)); 63 | -------------------------------------------------------------------------------- /samples/addBucketOwnerAcl.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') { 24 | // [START storage_add_bucket_owner] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The email address of the user to add 32 | // const userEmail = 'user-email-to-add'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function addBucketOwner() { 41 | // Makes the user an owner of the bucket. You can use addAllUsers(), 42 | // addDomain(), addProject(), addGroup(), and addAllAuthenticatedUsers() 43 | // to grant access to different types of entities. You can also use "readers" 44 | // and "writers" to grant different roles. 45 | await storage.bucket(bucketName).acl.owners.addUser(userEmail); 46 | 47 | console.log(`Added user ${userEmail} as an owner on bucket ${bucketName}.`); 48 | } 49 | 50 | addBucketOwner().catch(console.error); 51 | // [END storage_add_bucket_owner] 52 | } 53 | main(...process.argv.slice(2)); 54 | -------------------------------------------------------------------------------- /samples/addFileOwnerAcl.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main( 24 | bucketName = 'my-bucket', 25 | fileName = 'test.txt', 26 | userEmail = 'jdobry@google.com' 27 | ) { 28 | // [START storage_add_file_owner] 29 | /** 30 | * TODO(developer): Uncomment the following lines before running the sample. 31 | */ 32 | // The ID of your GCS bucket 33 | // const bucketName = 'your-unique-bucket-name'; 34 | 35 | // The name of the file to access 36 | // const fileName = 'file.txt'; 37 | 38 | // The email address of the user to add 39 | // const userEmail = 'user-email-to-add'; 40 | 41 | // Imports the Google Cloud client library 42 | const {Storage} = require('@google-cloud/storage'); 43 | 44 | // Creates a client 45 | const storage = new Storage(); 46 | 47 | async function addFileOwner() { 48 | await storage 49 | .bucket(bucketName) 50 | .file(fileName) 51 | .acl.owners.addUser(userEmail); 52 | 53 | console.log(`Added user ${userEmail} as an owner on file ${fileName}.`); 54 | } 55 | 56 | addFileOwner().catch(console.error); 57 | // [END storage_add_file_owner] 58 | } 59 | main(...process.argv.slice(2)); 60 | -------------------------------------------------------------------------------- /samples/bucketMetadata.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | // sample-metadata: 18 | // title: Storage Get Bucket Metadata. 19 | // description: Get bucket metadata. 20 | // usage: node bucketMetadata.js 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_get_bucket_metadata] 24 | // Imports the Google Cloud client library 25 | const {Storage} = require('@google-cloud/storage'); 26 | 27 | // Creates a client 28 | const storage = new Storage(); 29 | 30 | async function getBucketMetadata() { 31 | /** 32 | * TODO(developer): Uncomment the following lines before running the sample. 33 | */ 34 | // The ID of your GCS bucket 35 | // const bucketName = 'your-unique-bucket-name'; 36 | 37 | // Get Bucket Metadata 38 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 39 | 40 | console.log(JSON.stringify(metadata, null, 2)); 41 | } 42 | // [END storage_get_bucket_metadata] 43 | getBucketMetadata().catch(console.error); 44 | } 45 | 46 | main(...process.argv.slice(2)); 47 | -------------------------------------------------------------------------------- /samples/changeDefaultStorageClass.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: Change Bucket's Default Storage Class. 19 | // description: Change Bucket's Default Storage Class. 20 | // usage: node changeDefaultStorageClass.js 21 | 22 | function main(bucketName = 'my-bucket', storageClass = 'standard') { 23 | // [START storage_change_default_storage_class] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // The name of a storage class 31 | // See the StorageClass documentation for other valid storage classes: 32 | // https://googleapis.dev/java/google-cloud-clients/latest/com/google/cloud/storage/StorageClass.html 33 | // const storageClass = 'coldline'; 34 | 35 | // Imports the Google Cloud client library 36 | const {Storage} = require('@google-cloud/storage'); 37 | 38 | // Creates a client 39 | const storage = new Storage(); 40 | 41 | async function changeDefaultStorageClass() { 42 | await storage.bucket(bucketName).setStorageClass(storageClass); 43 | 44 | console.log(`${bucketName} has been set to ${storageClass}`); 45 | } 46 | 47 | changeDefaultStorageClass().catch(console.error); 48 | // [END storage_change_default_storage_class] 49 | } 50 | process.on('unhandledRejection', err => { 51 | console.error(err.message); 52 | process.exitCode = 1; 53 | }); 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/createNewBucket.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | function main(bucketName = 'my-bucket') { 18 | // [START storage_create_bucket] 19 | /** 20 | * TODO(developer): Uncomment the following lines before running the sample. 21 | */ 22 | // The ID of your GCS bucket 23 | // const bucketName = 'your-unique-bucket-name'; 24 | 25 | // Imports the Google Cloud client library 26 | const {Storage} = require('@google-cloud/storage'); 27 | 28 | // Creates a client 29 | // The bucket in the sample below will be created in the project asscociated with this client. 30 | // For more information, please see https://cloud.google.com/docs/authentication/production or https://googleapis.dev/nodejs/storage/latest/Storage.html 31 | const storage = new Storage(); 32 | 33 | async function createBucket() { 34 | // Creates a new bucket in the Asia region with the coldline default storage 35 | // class. Leave the second argument blank for default settings. 36 | // 37 | // For default values see: https://cloud.google.com/storage/docs/locations and 38 | // https://cloud.google.com/storage/docs/storage-classes 39 | 40 | const [bucket] = await storage.createBucket(bucketName, { 41 | location: 'ASIA', 42 | storageClass: 'COLDLINE', 43 | }); 44 | 45 | console.log(`Bucket ${bucket.name} created.`); 46 | } 47 | 48 | createBucket().catch(console.error); 49 | // [END storage_create_bucket] 50 | } 51 | 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/createNotification.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | const uuid = require('uuid'); 23 | 24 | function main( 25 | bucketName = 'my-bucket', 26 | topic = `nodejs-storage-samples-${uuid.v4()}` 27 | ) { 28 | // [START storage_create_bucket_notifications] 29 | /** 30 | * TODO(developer): Uncomment the following lines before running the sample. 31 | */ 32 | // The ID of your GCS bucket 33 | // const bucketName = 'your-unique-bucket-name'; 34 | 35 | // The name of a topic 36 | // const topic = 'my-topic'; 37 | 38 | // Imports the Google Cloud client library 39 | const {Storage} = require('@google-cloud/storage'); 40 | 41 | // Creates a client 42 | const storage = new Storage(); 43 | 44 | async function createNotification() { 45 | // Creates a notification 46 | await storage.bucket(bucketName).createNotification(topic); 47 | 48 | console.log('Notification subscription created.'); 49 | } 50 | 51 | createNotification().catch(console.error); 52 | // [END storage_create_bucket_notifications] 53 | } 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/deleteBucket.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_delete_bucket] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function deleteBucket() { 38 | await storage.bucket(bucketName).delete(); 39 | console.log(`Bucket ${bucketName} deleted`); 40 | } 41 | 42 | deleteBucket().catch(console.error); 43 | // [END storage_delete_bucket] 44 | } 45 | 46 | main(...process.argv.slice(2)); 47 | -------------------------------------------------------------------------------- /samples/deleteNotification.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', notificationId = '1') { 24 | // [START storage_delete_bucket_notification] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The ID of the notification 32 | // const notificationId = '1'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function deleteNotification() { 41 | // Deletes the notification from the bucket 42 | await storage.bucket(bucketName).notification(notificationId).delete(); 43 | 44 | console.log(`Notification ${notificationId} deleted.`); 45 | } 46 | 47 | deleteNotification().catch(console.error); 48 | // [END storage_delete_bucket_notification] 49 | } 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/deleteOldVersionOfFile.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: Delete Old Version Of File. 19 | // description: Delete Old Version Of File. 20 | // usage: node deleteOldVersionOfFile.js 21 | 22 | function main(bucketName = 'my-bucket', fileName = 'test.txt', generation = 1) { 23 | // [START storage_delete_file_archived_generation] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // The ID of your GCS file 31 | // const fileName = 'your-file-name'; 32 | 33 | // The generation of fileName to delete 34 | // const generation = 1579287380533984; 35 | 36 | // Imports the Google Cloud client library 37 | const {Storage} = require('@google-cloud/storage'); 38 | 39 | // Creates a client 40 | const storage = new Storage(); 41 | 42 | async function deleteOldVersionOfFile() { 43 | // Deletes the file from the bucket with given version 44 | await storage 45 | .bucket(bucketName) 46 | .file(fileName, { 47 | generation, 48 | }) 49 | .delete(); 50 | 51 | console.log( 52 | `Generation ${generation} of file ${fileName} was deleted from ${bucketName}` 53 | ); 54 | } 55 | 56 | deleteOldVersionOfFile().catch(console.error); 57 | // [END storage_delete_file_archived_generation] 58 | } 59 | main(...process.argv.slice(2)); 60 | -------------------------------------------------------------------------------- /samples/disableBucketLifecycleManagement.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to disable Object Lifecycle Management for 17 | * a bucket. 18 | * 19 | * For more information, see the documentation at https://cloud.google.com/storage/docs/lifecycle. 20 | */ 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_disable_bucket_lifecycle_management] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function disableBucketLifecycleManagement() { 37 | await storage.bucket(bucketName).setMetadata({lifecycle: null}); 38 | 39 | console.log(`Lifecycle management is disabled for bucket ${bucketName}`); 40 | } 41 | 42 | disableBucketLifecycleManagement().catch(console.error); 43 | // [END storage_disable_bucket_lifecycle_management] 44 | } 45 | 46 | main(...process.argv.slice(2)); 47 | -------------------------------------------------------------------------------- /samples/disableBucketVersioning.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: Storage Disable Bucket Versioning. 19 | // description: Disables bucket versioning. 20 | // usage: node disableBucketVersioning.js 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_disable_versioning] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function disableBucketVersioning() { 37 | await storage.bucket(bucketName).setMetadata({ 38 | versioning: { 39 | enabled: false, 40 | }, 41 | }); 42 | 43 | console.log(`Versioning is disabled for bucket ${bucketName}`); 44 | } 45 | 46 | disableBucketVersioning().catch(console.error); 47 | // [END storage_disable_versioning] 48 | } 49 | 50 | process.on('unhandledRejection', err => { 51 | console.error(err.message); 52 | process.exitCode = 1; 53 | }); 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/disableDefaultEventBasedHold.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to use Bucket Lock operations on buckets 17 | * and objects using the Google Cloud Storage API. 18 | * 19 | * For more information read the documentation 20 | * at https://cloud.google.com/storage/docs/bucket-lock 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_disable_default_event_based_hold] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function disableDefaultEventBasedHold() { 38 | // Disables a default event-based hold for a bucket. 39 | await storage.bucket(bucketName).setMetadata({ 40 | defaultEventBasedHold: false, 41 | }); 42 | console.log(`Default event-based hold was disabled for ${bucketName}.`); 43 | } 44 | 45 | disableDefaultEventBasedHold().catch(console.error); 46 | // [END storage_disable_default_event_based_hold] 47 | } 48 | main(...process.argv.slice(2)); 49 | -------------------------------------------------------------------------------- /samples/disableRequesterPays.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_disable_requester_pays] 25 | 26 | /** 27 | * TODO(developer): Uncomment the following lines before running the sample. 28 | */ 29 | // The ID of your GCS bucket 30 | // const bucketName = 'your-unique-bucket-name'; 31 | 32 | // Imports the Google Cloud client library 33 | const {Storage} = require('@google-cloud/storage'); 34 | 35 | // Creates a client 36 | const storage = new Storage(); 37 | 38 | async function disableRequesterPays() { 39 | // Disables requester-pays requests 40 | await storage.bucket(bucketName).disableRequesterPays(); 41 | 42 | console.log( 43 | `Requester-pays requests have been disabled for bucket ${bucketName}` 44 | ); 45 | } 46 | 47 | disableRequesterPays().catch(console.error); 48 | // [END storage_disable_requester_pays] 49 | } 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/disableUniformBucketLevelAccess.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_disable_uniform_bucket_level_access] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | async function disableUniformBucketLevelAccess() { 37 | // Disables uniform bucket-level access for the bucket 38 | await storage.bucket(bucketName).setMetadata({ 39 | iamConfiguration: { 40 | uniformBucketLevelAccess: { 41 | enabled: false, 42 | }, 43 | }, 44 | }); 45 | 46 | console.log(`Uniform bucket-level access was disabled for ${bucketName}.`); 47 | } 48 | 49 | disableUniformBucketLevelAccess().catch(console.error); 50 | // [END storage_disable_uniform_bucket_level_access] 51 | } 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/downloadFile.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | const path = require('path'); 23 | const cwd = path.join(__dirname, '..'); 24 | 25 | function main( 26 | bucketName = 'my-bucket', 27 | fileName = 'test.txt', 28 | destFileName = path.join(cwd, 'downloaded.txt') 29 | ) { 30 | // [START storage_download_file] 31 | /** 32 | * TODO(developer): Uncomment the following lines before running the sample. 33 | */ 34 | // The ID of your GCS bucket 35 | // const bucketName = 'your-unique-bucket-name'; 36 | 37 | // The ID of your GCS file 38 | // const fileName = 'your-file-name'; 39 | 40 | // The path to which the file should be downloaded 41 | // const destFileName = '/local/path/to/file.txt'; 42 | 43 | // Imports the Google Cloud client library 44 | const {Storage} = require('@google-cloud/storage'); 45 | 46 | // Creates a client 47 | const storage = new Storage(); 48 | 49 | async function downloadFile() { 50 | const options = { 51 | destination: destFileName, 52 | }; 53 | 54 | // Downloads the file 55 | await storage.bucket(bucketName).file(fileName).download(options); 56 | 57 | console.log( 58 | `gs://${bucketName}/${fileName} downloaded to ${destFileName}.` 59 | ); 60 | } 61 | 62 | downloadFile().catch(console.error); 63 | // [END storage_download_file] 64 | } 65 | main(...process.argv.slice(2)); 66 | -------------------------------------------------------------------------------- /samples/downloadIntoMemory.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', fileName = 'test.txt') { 24 | // [START storage_file_download_into_memory] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The ID of your GCS file 32 | // const fileName = 'your-file-name'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function downloadIntoMemory() { 41 | // Downloads the file into a buffer in memory. 42 | const contents = await storage.bucket(bucketName).file(fileName).download(); 43 | 44 | console.log( 45 | `Contents of gs://${bucketName}/${fileName} are ${contents.toString()}.` 46 | ); 47 | } 48 | 49 | downloadIntoMemory().catch(console.error); 50 | // [END storage_file_download_into_memory] 51 | } 52 | process.on('unhandledRejection', err => { 53 | console.error(err.message); 54 | process.exitCode = 1; 55 | }); 56 | main(...process.argv.slice(2)); 57 | -------------------------------------------------------------------------------- /samples/enableBucketLifecycleManagement.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to enable Object Lifecycle Management for 17 | * a bucket. 18 | * 19 | * For more information, see the documentation at https://cloud.google.com/storage/docs/lifecycle. 20 | */ 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_enable_bucket_lifecycle_management] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function enableBucketLifecycleManagement() { 37 | const [metadata] = await storage.bucket(bucketName).addLifecycleRule({ 38 | action: { 39 | type: 'Delete', 40 | }, 41 | condition: {age: 100}, 42 | }); 43 | 44 | console.log( 45 | `Lifecycle management is enabled for bucket ${bucketName} and the rules are:` 46 | ); 47 | 48 | console.log(metadata.lifecycle.rule); 49 | } 50 | 51 | enableBucketLifecycleManagement().catch(console.error); 52 | // [END storage_enable_bucket_lifecycle_management] 53 | } 54 | 55 | main(...process.argv.slice(2)); 56 | -------------------------------------------------------------------------------- /samples/enableBucketVersioning.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: Storage Enable Bucket Versioning. 19 | // description: Enables bucket versioning. 20 | // usage: node enableBucketVersioning.js 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_enable_versioning] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function enableBucketVersioning() { 37 | await storage.bucket(bucketName).setMetadata({ 38 | versioning: { 39 | enabled: true, 40 | }, 41 | }); 42 | 43 | console.log(`Versioning is enabled for bucket ${bucketName}`); 44 | } 45 | 46 | enableBucketVersioning().catch(console.error); 47 | // [END storage_enable_versioning] 48 | } 49 | 50 | process.on('unhandledRejection', err => { 51 | console.error(err.message); 52 | process.exitCode = 1; 53 | }); 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/enableDefaultEventBasedHold.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to use Bucket Lock operations on buckets 17 | * and objects using the Google Cloud Storage API. 18 | * 19 | * For more information read the documentation 20 | * at https://cloud.google.com/storage/docs/bucket-lock 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_enable_default_event_based_hold] 25 | 26 | /** 27 | * TODO(developer): Uncomment the following lines before running the sample. 28 | */ 29 | // The ID of your GCS bucket 30 | // const bucketName = 'your-unique-bucket-name'; 31 | 32 | // Imports the Google Cloud client library 33 | const {Storage} = require('@google-cloud/storage'); 34 | 35 | // Creates a client 36 | const storage = new Storage(); 37 | 38 | async function enableDefaultEventBasedHold() { 39 | // Enables a default event-based hold for the bucket. 40 | await storage.bucket(bucketName).setMetadata({ 41 | defaultEventBasedHold: true, 42 | }); 43 | 44 | console.log(`Default event-based hold was enabled for ${bucketName}.`); 45 | } 46 | 47 | enableDefaultEventBasedHold().catch(console.error); 48 | // [END storage_enable_default_event_based_hold] 49 | } 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/enableDefaultKMSKey.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main( 24 | bucketName = 'my-bucket', 25 | defaultKmsKeyName = process.env.GOOGLE_CLOUD_KMS_KEY_ASIA 26 | ) { 27 | // [START storage_set_bucket_default_kms_key] 28 | /** 29 | * TODO(developer): Uncomment the following lines before running the sample. 30 | */ 31 | // The ID of your GCS bucket 32 | // const bucketName = 'your-unique-bucket-name'; 33 | 34 | // The name of the KMS-key to use as a default 35 | // const defaultKmsKeyName = 'my-key'; 36 | 37 | // Imports the Google Cloud client library 38 | const {Storage} = require('@google-cloud/storage'); 39 | 40 | // Creates a client 41 | const storage = new Storage(); 42 | 43 | async function enableDefaultKMSKey() { 44 | await storage.bucket(bucketName).setMetadata({ 45 | encryption: { 46 | defaultKmsKeyName, 47 | }, 48 | }); 49 | 50 | console.log( 51 | `Default KMS key for ${bucketName} was set to ${defaultKmsKeyName}.` 52 | ); 53 | } 54 | 55 | enableDefaultKMSKey().catch(console.error); 56 | // [END storage_set_bucket_default_kms_key] 57 | } 58 | 59 | main(...process.argv.slice(2)); 60 | -------------------------------------------------------------------------------- /samples/enableRequesterPays.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_enable_requester_pays] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function enableRequesterPays() { 38 | await storage.bucket(bucketName).enableRequesterPays(); 39 | 40 | console.log( 41 | `Requester-pays requests have been enabled for bucket ${bucketName}` 42 | ); 43 | } 44 | 45 | enableRequesterPays().catch(console.error); 46 | // [END storage_enable_requester_pays] 47 | } 48 | main(...process.argv.slice(2)); 49 | -------------------------------------------------------------------------------- /samples/enableUniformBucketLevelAccess.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_enable_uniform_bucket_level_access] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | // Enables uniform bucket-level access for the bucket 38 | async function enableUniformBucketLevelAccess() { 39 | await storage.bucket(bucketName).setMetadata({ 40 | iamConfiguration: { 41 | uniformBucketLevelAccess: { 42 | enabled: true, 43 | }, 44 | }, 45 | }); 46 | 47 | console.log(`Uniform bucket-level access was enabled for ${bucketName}.`); 48 | } 49 | 50 | enableUniformBucketLevelAccess().catch(console.error); 51 | // [END storage_enable_uniform_bucket_level_access] 52 | } 53 | 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/generateEncryptionKey.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on encrypted 17 | * files with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main() { 24 | // [START storage_generate_encryption_key] 25 | const crypto = require('crypto'); 26 | 27 | function generateEncryptionKey() { 28 | /** 29 | * Generates a 256 bit (32 byte) AES encryption key and prints the base64 30 | * representation. 31 | * 32 | * This is included for demonstration purposes. You should generate your own 33 | * key. Please remember that encryption keys should be handled with a 34 | * comprehensive security policy. 35 | */ 36 | const buffer = crypto.randomBytes(32); 37 | const encodedKey = buffer.toString('base64'); 38 | console.log(`Base 64 encoded encryption key: ${encodedKey}`); 39 | } 40 | generateEncryptionKey(); 41 | // [END storage_generate_encryption_key] 42 | } 43 | main(...process.argv.slice(2)); 44 | -------------------------------------------------------------------------------- /samples/generateSignedUrl.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', fileName = 'test.txt') { 24 | // [START storage_generate_signed_url] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The ID of your GCS file 32 | // const fileName = 'your-file-name'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function generateSignedUrl() { 41 | // These options will allow temporary read access to the file 42 | const options = { 43 | version: 'v2', // defaults to 'v2' if missing. 44 | action: 'read', 45 | expires: Date.now() + 1000 * 60 * 60, // one hour 46 | }; 47 | 48 | // Get a v2 signed URL for the file 49 | const [url] = await storage 50 | .bucket(bucketName) 51 | .file(fileName) 52 | .getSignedUrl(options); 53 | 54 | console.log(`The signed url for ${fileName} is ${url}.`); 55 | } 56 | 57 | generateSignedUrl().catch(console.error); 58 | // [END storage_generate_signed_url] 59 | } 60 | main(...process.argv.slice(2)); 61 | -------------------------------------------------------------------------------- /samples/getAutoclass.js: -------------------------------------------------------------------------------- 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_get_autoclass] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function getAutoclass() { 38 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 39 | console.log( 40 | `Autoclass is ${ 41 | metadata.autoclass.enabled ? 'enabled' : 'disabled' 42 | } for ${metadata.name} at ${metadata.autoclass.toggleTime}. 43 | Autoclass terminal storage class is last updated to ${ 44 | metadata.autoclass.terminalStorageClass 45 | } at ${metadata.autoclass.terminalStorageClassUpdateTime}.` 46 | ); 47 | } 48 | 49 | getAutoclass().catch(console.error); 50 | // [END storage_get_autoclass] 51 | } 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/getDefaultEventBasedHold.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to use Bucket Lock operations on buckets 17 | * and objects using the Google Cloud Storage API. 18 | * 19 | * For more information read the documentation 20 | * at https://cloud.google.com/storage/docs/bucket-lock 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_get_default_event_based_hold] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function getDefaultEventBasedHold() { 38 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 39 | console.log(`Default event-based hold: ${metadata.defaultEventBasedHold}.`); 40 | } 41 | 42 | getDefaultEventBasedHold().catch(console.error); 43 | // [END storage_get_default_event_based_hold] 44 | } 45 | main(...process.argv.slice(2)); 46 | -------------------------------------------------------------------------------- /samples/getPublicAccessPrevention.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_get_public_access_prevention] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The name of your GCS bucket 29 | // const bucketName = 'Name of a bucket, e.g. my-bucket'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function getPublicAccessPrevention() { 38 | // Gets Bucket Metadata and prints publicAccessPrevention value (either 'inherited' or 'enforced'). 39 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 40 | console.log( 41 | `Public access prevention is ${metadata.iamConfiguration.publicAccessPrevention} for ${bucketName}.` 42 | ); 43 | } 44 | 45 | getPublicAccessPrevention(); 46 | 47 | // [END storage_get_public_access_prevention] 48 | } 49 | 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/getRPO.js: -------------------------------------------------------------------------------- 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_get_rpo] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The name of your GCS bucket in a dual-region 29 | // const bucketName = 'Name of a bucket, e.g. my-bucket'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function getRPO() { 38 | // Gets Bucket Metadata and prints RPO value (either 'default' or 'async_turbo'). 39 | // If RPO is undefined, the bucket is a single region bucket 40 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 41 | console.log(`RPO is ${metadata.rpo} for ${bucketName}.`); 42 | } 43 | 44 | getRPO(); 45 | 46 | // [END storage_get_rpo] 47 | } 48 | process.on('unhandledRejection', err => { 49 | console.error(err.message); 50 | process.exitCode = 1; 51 | }); 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/getRequesterPaysStatus.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_get_requester_pays_status] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function getRequesterPaysStatus() { 38 | // Gets the requester-pays status of a bucket 39 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 40 | 41 | let status; 42 | if (metadata && metadata.billing && metadata.billing.requesterPays) { 43 | status = 'enabled'; 44 | } else { 45 | status = 'disabled'; 46 | } 47 | console.log( 48 | `Requester-pays requests are ${status} for bucket ${bucketName}.` 49 | ); 50 | } 51 | 52 | getRequesterPaysStatus().catch(console.error); 53 | // [END storage_get_requester_pays_status] 54 | } 55 | main(...process.argv.slice(2)); 56 | -------------------------------------------------------------------------------- /samples/getRetentionPolicy.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to use Bucket Lock operations on buckets 17 | * and objects using the Google Cloud Storage API. 18 | * 19 | * For more information read the documentation 20 | * at https://cloud.google.com/storage/docs/bucket-lock 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_get_retention_policy] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function getRetentionPolicy() { 38 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 39 | if (metadata.retentionPolicy) { 40 | const retentionPolicy = metadata.retentionPolicy; 41 | console.log('A retention policy exists!'); 42 | console.log(`Period: ${retentionPolicy.retentionPeriod}`); 43 | console.log(`Effective time: ${retentionPolicy.effectiveTime}`); 44 | if (retentionPolicy.isLocked) { 45 | console.log('Policy is locked'); 46 | } else { 47 | console.log('Policy is unlocked'); 48 | } 49 | } 50 | } 51 | 52 | getRetentionPolicy().catch(console.error); 53 | // [END storage_get_retention_policy] 54 | } 55 | main(...process.argv.slice(2)); 56 | -------------------------------------------------------------------------------- /samples/getServiceAccount.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | // sample-metadata: 18 | // title: Storage Get Service Account. 19 | // description: Get Service Account. 20 | // usage: node getServiceAccount.js 21 | 22 | function main(projectId = 'serviceAccountProjectId') { 23 | // [START storage_get_service_account] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCP project 28 | // const projectId = 'your-project-id'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage({ 35 | projectId, 36 | }); 37 | 38 | async function getServiceAccount() { 39 | const [serviceAccount] = await storage.getServiceAccount(); 40 | console.log( 41 | `The GCS service account for project ${projectId} is: ${serviceAccount.emailAddress}` 42 | ); 43 | } 44 | 45 | getServiceAccount().catch(console.error); 46 | // [END storage_get_service_account] 47 | } 48 | process.on('unhandledRejection', err => { 49 | console.error(err.message); 50 | process.exitCode = 1; 51 | }); 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/getSoftDeletedBucket.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | function main(bucketName = 'my-bucket', generation = 123456789) { 18 | // [START storage_get_soft_deleted_bucket] 19 | /** 20 | * TODO(developer): Uncomment the following lines before running the sample. 21 | */ 22 | // The ID of your GCS bucket 23 | // const bucketName = 'your-unique-bucket-name'; 24 | 25 | // The generation of the bucket to restore 26 | // const generation = 123456789; 27 | 28 | // Imports the Google Cloud client library 29 | const {Storage} = require('@google-cloud/storage'); 30 | 31 | // Creates a client 32 | const storage = new Storage(); 33 | 34 | async function getSoftDeletedBucket() { 35 | const options = { 36 | generation: generation, 37 | softDeleted: true, 38 | }; 39 | 40 | const [metadata] = await storage.bucket(bucketName).getMetadata(options); 41 | 42 | console.log(`Bucket: ${metadata.name}`); 43 | console.log(`Generation: ${metadata.generation}`); 44 | console.log(`SoftDeleteTime: ${metadata.softDeleteTime}`); 45 | console.log(`HardDeleteTime: ${metadata.hardDeleteTime}`); 46 | } 47 | 48 | getSoftDeletedBucket().catch(console.error); 49 | // [END storage_get_soft_deleted_bucket] 50 | } 51 | 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/hmacKeyActivate.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | // sample-metadata: 18 | // title: Activate HMAC SA Key. 19 | // description: Activate HMAC SA Key. 20 | // usage: node hmacKeyActivate.js [projectId] 21 | 22 | function main( 23 | hmacKeyAccessId = 'GOOG0234230X00', 24 | projectId = 'serviceAccountProjectId' 25 | ) { 26 | // [START storage_activate_hmac_key] 27 | /** 28 | * TODO(developer): Uncomment the following lines before running the sample. 29 | */ 30 | // The access ID of the HMAC key 31 | // const hmacKeyAccessId = 'GOOG0234230X00'; 32 | 33 | // The ID of the project to which the service account belongs 34 | // const projectId = 'project-id'; 35 | 36 | // Imports the Google Cloud client library 37 | const {Storage} = require('@google-cloud/storage'); 38 | 39 | // Creates a client 40 | const storage = new Storage(); 41 | 42 | // Activate HMAC SA Key 43 | async function activateHmacKey() { 44 | const hmacKey = storage.hmacKey(hmacKeyAccessId, {projectId}); 45 | const [hmacKeyMetadata] = await hmacKey.setMetadata({state: 'ACTIVE'}); 46 | 47 | console.log('The HMAC key is now active.'); 48 | console.log('The HMAC key metadata is:'); 49 | for (const [key, value] of Object.entries(hmacKeyMetadata)) { 50 | console.log(`${key}: ${value}`); 51 | } 52 | } 53 | // [END storage_activate_hmac_key] 54 | activateHmacKey().catch(console.error); 55 | } 56 | 57 | main(...process.argv.slice(2)); 58 | -------------------------------------------------------------------------------- /samples/hmacKeyCreate.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | // sample-metadata: 18 | // title: Create HMAC SA Key. 19 | // description: Create HMAC SA Key. 20 | // usage: node hmacKeyCreate.js [projectId] 21 | 22 | function main( 23 | serviceAccountEmail = 'service-account@example.com', 24 | projectId = 'serviceAccountProjectId' 25 | ) { 26 | // [START storage_create_hmac_key] 27 | /** 28 | * TODO(developer): Uncomment the following lines before running the sample. 29 | */ 30 | // The service account email for which the new HMAC key will be created 31 | // const serviceAccountEmail = 'service-account@iam.gserviceaccount.com'; 32 | 33 | // The ID of the project to which the service account belongs 34 | // const projectId = 'project-id'; 35 | 36 | // Imports the Google Cloud client library 37 | const {Storage} = require('@google-cloud/storage'); 38 | 39 | // Creates a client 40 | const storage = new Storage(); 41 | 42 | // Create HMAC SA Key 43 | async function createHmacKey() { 44 | const [hmacKey, secret] = await storage.createHmacKey(serviceAccountEmail, { 45 | projectId, 46 | }); 47 | 48 | console.log(`The base64 encoded secret is: ${secret}`); 49 | console.log('Do not miss that secret, there is no API to recover it.'); 50 | console.log('The HMAC key metadata is:'); 51 | for (const [key, value] of Object.entries(hmacKey.metadata)) { 52 | console.log(`${key}: ${value}`); 53 | } 54 | } 55 | // [END storage_create_hmac_key] 56 | createHmacKey().catch(console.error); 57 | } 58 | 59 | main(...process.argv.slice(2)); 60 | -------------------------------------------------------------------------------- /samples/hmacKeyDeactivate.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | // sample-metadata: 18 | // title: Deactivate HMAC SA Key. 19 | // description: Deactivate HMAC SA Key. 20 | // usage: node hmacKeyDeactivate.js [projectId] 21 | 22 | function main( 23 | hmacKeyAccessId = 'GOOG0234230X00', 24 | projectId = 'serviceAccountProjectId' 25 | ) { 26 | // [START storage_deactivate_hmac_key] 27 | /** 28 | * TODO(developer): Uncomment the following lines before running the sample. 29 | */ 30 | // The access ID of the HMAC key 31 | // const hmacKeyAccessId = 'GOOG0234230X00'; 32 | 33 | // The ID of the project to which the service account belongs 34 | // const projectId = 'project-id'; 35 | 36 | // Imports the Google Cloud client library 37 | const {Storage} = require('@google-cloud/storage'); 38 | 39 | // Creates a client 40 | const storage = new Storage(); 41 | 42 | // Deactivate HMAC SA Key 43 | async function deactivateHmacKey() { 44 | const hmacKey = storage.hmacKey(hmacKeyAccessId, {projectId}); 45 | const [hmacKeyMetadata] = await hmacKey.setMetadata({state: 'INACTIVE'}); 46 | 47 | console.log('The HMAC key is now inactive.'); 48 | console.log('The HMAC key metadata is:'); 49 | for (const [key, value] of Object.entries(hmacKeyMetadata)) { 50 | console.log(`${key}: ${value}`); 51 | } 52 | } 53 | // [END storage_deactivate_hmac_key] 54 | deactivateHmacKey().catch(console.error); 55 | } 56 | 57 | main(...process.argv.slice(2)); 58 | -------------------------------------------------------------------------------- /samples/hmacKeyDelete.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | // sample-metadata: 18 | // title: Delete HMAC SA Key. 19 | // description: Delete HMAC SA Key. 20 | // usage: node hmacKeyDelete.js [projectId] 21 | 22 | function main( 23 | hmacKeyAccessId = 'GOOG0234230X00', 24 | projectId = 'serviceAccountProjectId' 25 | ) { 26 | // [START storage_delete_hmac_key] 27 | /** 28 | * TODO(developer): Uncomment the following lines before running the sample. 29 | */ 30 | // The access ID of the HMAC key 31 | // const hmacKeyAccessId = 'GOOG0234230X00'; 32 | 33 | // The ID of the project to which the service account belongs 34 | // const projectId = 'project-id'; 35 | 36 | // Imports the Google Cloud client library 37 | const {Storage} = require('@google-cloud/storage'); 38 | 39 | // Creates a client 40 | const storage = new Storage(); 41 | 42 | // Delete HMAC SA Key 43 | async function deleteHmacKey() { 44 | const hmacKey = storage.hmacKey(hmacKeyAccessId, {projectId}); 45 | await hmacKey.delete(); 46 | 47 | console.log( 48 | 'The key is deleted, though it may still appear in getHmacKeys() results.' 49 | ); 50 | } 51 | // [END storage_delete_hmac_key] 52 | deleteHmacKey().catch(console.error); 53 | } 54 | 55 | main(...process.argv.slice(2)); 56 | -------------------------------------------------------------------------------- /samples/hmacKeyGet.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | // sample-metadata: 18 | // title: Get HMAC SA Key Metadata. 19 | // description: Get HMAC SA Key Metadata. 20 | // usage: node hmacKeyGet.js [projectId] 21 | 22 | function main( 23 | hmacKeyAccessId = 'GOOG0234230X00', 24 | projectId = 'serviceAccountProjectId' 25 | ) { 26 | // [START storage_get_hmac_key] 27 | /** 28 | * TODO(developer): Uncomment the following lines before running the sample. 29 | */ 30 | // The access ID of the HMAC key 31 | // const hmacKeyAccessId = 'GOOG0234230X00'; 32 | 33 | // The ID of the project to which the service account belongs 34 | // const projectId = 'project-id'; 35 | 36 | // Imports the Google Cloud client library 37 | const {Storage} = require('@google-cloud/storage'); 38 | 39 | // Creates a client 40 | const storage = new Storage(); 41 | 42 | // Get HMAC SA Key Metadata 43 | async function getHmacKey() { 44 | const hmacKey = storage.hmacKey(hmacKeyAccessId, {projectId}); 45 | 46 | // Populate the hmacKey object with metadata from server. 47 | await hmacKey.getMetadata(); 48 | 49 | console.log('The HMAC key metadata is:'); 50 | for (const [key, value] of Object.entries(hmacKey.metadata)) { 51 | console.log(`${key}: ${value}`); 52 | } 53 | } 54 | // [END storage_get_hmac_key] 55 | getHmacKey().catch(console.error); 56 | } 57 | 58 | main(...process.argv.slice(2)); 59 | -------------------------------------------------------------------------------- /samples/hmacKeysList.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | // sample-metadata: 18 | // title: List HMAC SA Keys Metadata. 19 | // description: List HMAC SA Keys Metadata. 20 | // usage: node hmacKeyList.js [projectId] 21 | 22 | function main(projectId = 'serviceAccountProjectId') { 23 | // [START storage_list_hmac_keys] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of the project to which the service account belongs 28 | // const projectId = 'project-id'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | // List HMAC SA Keys' Metadata 37 | async function listHmacKeys() { 38 | const [hmacKeys] = await storage.getHmacKeys({projectId}); 39 | 40 | // hmacKeys is an array of HmacKey objects. 41 | for (const hmacKey of hmacKeys) { 42 | console.log( 43 | `Service Account Email: ${hmacKey.metadata.serviceAccountEmail}` 44 | ); 45 | console.log(`Access Id: ${hmacKey.metadata.accessId}`); 46 | } 47 | } 48 | // [END storage_list_hmac_keys] 49 | listHmacKeys().catch(console.error); 50 | } 51 | 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/listBuckets.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | function main() { 18 | // [START storage_list_buckets] 19 | // Imports the Google Cloud client library 20 | const {Storage} = require('@google-cloud/storage'); 21 | 22 | // Creates a client 23 | const storage = new Storage(); 24 | 25 | async function listBuckets() { 26 | const [buckets] = await storage.getBuckets(); 27 | 28 | console.log('Buckets:'); 29 | buckets.forEach(bucket => { 30 | console.log(bucket.name); 31 | }); 32 | } 33 | 34 | listBuckets().catch(console.error); 35 | // [END storage_list_buckets] 36 | } 37 | 38 | main(...process.argv.slice(2)); 39 | -------------------------------------------------------------------------------- /samples/listFiles.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_list_files] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function listFiles() { 38 | // Lists files in the bucket 39 | const [files] = await storage.bucket(bucketName).getFiles(); 40 | 41 | console.log('Files:'); 42 | files.forEach(file => { 43 | console.log(file.name); 44 | }); 45 | } 46 | 47 | listFiles().catch(console.error); 48 | // [END storage_list_files] 49 | } 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/listFilesPaginate.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /* eslint-disable no-unused-vars */ 15 | 16 | function main(bucketName = 'my-bucket') { 17 | // [START storage_list_files_paginated] 18 | /** 19 | * TODO(developer): Uncomment the following lines before running the sample. 20 | */ 21 | // The ID of your GCS bucket 22 | // const bucketName = 'your-unique-bucket-name'; 23 | 24 | // Imports the Google Cloud client library 25 | const {Storage} = require('@google-cloud/storage'); 26 | 27 | // Creates a client 28 | const storage = new Storage(); 29 | 30 | async function listFilesPaginated() { 31 | const bucket = storage.bucket(bucketName); 32 | const [files, queryForPage2] = await bucket.getFiles({autoPaginate: false}); 33 | 34 | console.log('Files:'); 35 | files.forEach(file => { 36 | console.log(file.name); 37 | }); 38 | 39 | // Page through the next set of results using "queryForPage2" 40 | if (queryForPage2 !== null) { 41 | const [files, queryForPage3] = await bucket.getFiles(queryForPage2); 42 | 43 | console.log('Files:'); 44 | files.forEach(file => { 45 | console.log(file.name); 46 | }); 47 | 48 | // If necessary, continue cursoring using "queryForPage3" 49 | } 50 | } 51 | 52 | listFilesPaginated().catch(console.error); 53 | // [END storage_list_files_paginated] 54 | } 55 | main(...process.argv.slice(2)); 56 | -------------------------------------------------------------------------------- /samples/listFilesWithOldVersions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: List Files with Old Versions. 19 | // description: List Files with Old Versions. 20 | // usage: node listFilesWithOldVersions.js 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_list_file_archived_generations] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function listFilesWithOldVersions() { 37 | const [files] = await storage.bucket(bucketName).getFiles({ 38 | versions: true, 39 | }); 40 | 41 | console.log('Files:'); 42 | files.forEach(file => { 43 | console.log(file.name, file.generation); 44 | }); 45 | } 46 | 47 | listFilesWithOldVersions().catch(console.error); 48 | // [END storage_list_file_archived_generations] 49 | } 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/listNotifications.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_list_bucket_notifications] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function listNotifications() { 38 | // Lists notifications in the bucket 39 | const [notifications] = await storage.bucket(bucketName).getNotifications(); 40 | 41 | console.log('Notifications:'); 42 | notifications.forEach(notification => { 43 | console.log(notification.id); 44 | }); 45 | } 46 | 47 | listNotifications().catch(console.error); 48 | // [END storage_list_bucket_notifications] 49 | } 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/listSoftDeletedBucket.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | function main() { 18 | // [START storage_list_soft_deleted_buckets] 19 | // Imports the Google Cloud client library 20 | const {Storage} = require('@google-cloud/storage'); 21 | 22 | // Creates a client 23 | const storage = new Storage(); 24 | 25 | async function listSoftDeletedBuckets() { 26 | const options = { 27 | softDeleted: true, 28 | }; 29 | 30 | const [buckets] = await storage.getBuckets(options); 31 | 32 | console.log('Buckets:'); 33 | buckets.forEach(bucket => { 34 | console.log(bucket.name); 35 | }); 36 | } 37 | 38 | listSoftDeletedBuckets().catch(console.error); 39 | // [END storage_list_soft_deleted_buckets] 40 | } 41 | 42 | main(...process.argv.slice(2)); 43 | -------------------------------------------------------------------------------- /samples/makeBucketPublic.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | // sample-metadata: 18 | // title: Storage Make Bucket Public. 19 | // description: Storage Make Bucket Public. 20 | // usage: node makeBucketPublic.js 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_set_bucket_public_iam] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function makeBucketPublic() { 37 | await storage.bucket(bucketName).makePublic(); 38 | 39 | console.log(`Bucket ${bucketName} is now publicly readable`); 40 | } 41 | 42 | makeBucketPublic().catch(console.error); 43 | // [END storage_set_bucket_public_iam] 44 | } 45 | process.on('unhandledRejection', err => { 46 | console.error(err.message); 47 | process.exitCode = 1; 48 | }); 49 | main(...process.argv.slice(2)); 50 | -------------------------------------------------------------------------------- /samples/makePublic.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', fileName = 'test.txt') { 24 | // [START storage_make_public] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The ID of your GCS file 32 | // const fileName = 'your-file-name'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function makePublic() { 41 | await storage.bucket(bucketName).file(fileName).makePublic(); 42 | 43 | console.log(`gs://${bucketName}/${fileName} is now public.`); 44 | } 45 | 46 | makePublic().catch(console.error); 47 | // [END storage_make_public] 48 | } 49 | main(...process.argv.slice(2)); 50 | -------------------------------------------------------------------------------- /samples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@google-cloud/storage-samples", 3 | "description": "Samples for the Cloud Storage Client Library for Node.js.", 4 | "license": "Apache-2.0", 5 | "author": "Google Inc.", 6 | "engines": { 7 | "node": ">=12" 8 | }, 9 | "repository": "googleapis/nodejs-storage", 10 | "private": true, 11 | "files": [ 12 | "*.js" 13 | ], 14 | "scripts": { 15 | "cleanup": "node scripts/cleanup", 16 | "test": "mocha system-test/*.js --timeout 600000" 17 | }, 18 | "dependencies": { 19 | "@google-cloud/pubsub": "^4.0.0", 20 | "@google-cloud/storage": "^7.16.0", 21 | "node-fetch": "^2.6.7", 22 | "uuid": "^8.0.0", 23 | "yargs": "^16.0.0" 24 | }, 25 | "devDependencies": { 26 | "chai": "^4.2.0", 27 | "mocha": "^8.0.0", 28 | "p-limit": "^3.1.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /samples/printBucketAcl.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_print_bucket_acl] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function printBucketAcl() { 38 | // Gets the ACL for the bucket 39 | const [acls] = await storage.bucket(bucketName).acl.get(); 40 | 41 | acls.forEach(acl => { 42 | console.log(`${acl.role}: ${acl.entity}`); 43 | }); 44 | } 45 | printBucketAcl().catch(console.error); 46 | // [END storage_print_bucket_acl] 47 | } 48 | 49 | main(...process.argv.slice(2)); 50 | -------------------------------------------------------------------------------- /samples/printBucketAclForUser.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') { 24 | // [START storage_print_bucket_acl_for_user] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The email address of the user to check 32 | // const userEmail = 'user-email-to-check'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function printBucketAclForUser() { 41 | const options = { 42 | // Specify the user 43 | entity: `user-${userEmail}`, 44 | }; 45 | 46 | // Gets the user's ACL for the bucket 47 | const [aclObject] = await storage.bucket(bucketName).acl.get(options); 48 | 49 | console.log(`${aclObject.role}: ${aclObject.entity}`); 50 | } 51 | 52 | printBucketAclForUser().catch(console.error); 53 | // [END storage_print_bucket_acl_for_user] 54 | } 55 | 56 | main(...process.argv.slice(2)); 57 | -------------------------------------------------------------------------------- /samples/printFileAcl.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', fileName = 'test.txt') { 24 | // [START storage_print_file_acl] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The ID of your GCS file 32 | // const fileName = 'your-file-name'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function printFileAcl() { 41 | // Gets the ACL for the file 42 | const [acls] = await storage.bucket(bucketName).file(fileName).acl.get(); 43 | 44 | acls.forEach(acl => { 45 | console.log(`${acl.role}: ${acl.entity}`); 46 | }); 47 | } 48 | 49 | printFileAcl().catch(console.error); 50 | // [END storage_print_file_acl] 51 | } 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/quickstart.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | function main(bucketName = 'my-new-bucket') { 18 | // [START storage_quickstart] 19 | // Imports the Google Cloud client library 20 | const {Storage} = require('@google-cloud/storage'); 21 | 22 | // For more information on ways to initialize Storage, please see 23 | // https://googleapis.dev/nodejs/storage/latest/Storage.html 24 | 25 | // Creates a client using Application Default Credentials 26 | const storage = new Storage(); 27 | 28 | // Creates a client from a Google service account key 29 | // const storage = new Storage({keyFilename: 'key.json'}); 30 | 31 | /** 32 | * TODO(developer): Uncomment these variables before running the sample. 33 | */ 34 | // The ID of your GCS bucket 35 | // const bucketName = 'your-unique-bucket-name'; 36 | 37 | async function createBucket() { 38 | // Creates the new bucket 39 | await storage.createBucket(bucketName); 40 | console.log(`Bucket ${bucketName} created.`); 41 | } 42 | 43 | createBucket().catch(console.error); 44 | // [END storage_quickstart] 45 | } 46 | 47 | main(...process.argv.slice(2)); 48 | -------------------------------------------------------------------------------- /samples/removeBucketCors.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: Storage Remove Bucket Cors Configuration. 19 | // description: Removes bucket cors configuration. 20 | // usage: node removeBucketCors.js 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_remove_cors_configuration] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function removeBucketCors() { 37 | await storage.bucket(bucketName).setCorsConfiguration([]); 38 | 39 | console.log(`Removed CORS configuration from bucket ${bucketName}`); 40 | } 41 | 42 | removeBucketCors().catch(console.error); 43 | // [END storage_remove_cors_configuration] 44 | } 45 | 46 | process.on('unhandledRejection', err => { 47 | console.error(err.message); 48 | process.exitCode = 1; 49 | }); 50 | main(...process.argv.slice(2)); 51 | -------------------------------------------------------------------------------- /samples/removeBucketDefaultOwner.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') { 24 | // [START storage_remove_bucket_default_owner] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The email address of the user to remove 32 | // const userEmail = 'user-email-to-remove'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function removeBucketDefaultOwner() { 41 | // Removes the user from the access control list of the bucket. You can use 42 | // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and 43 | // deleteAllAuthenticatedUsers() to remove access for different types of entities. 44 | await storage.bucket(bucketName).acl.default.owners.deleteUser(userEmail); 45 | 46 | console.log(`Removed user ${userEmail} from bucket ${bucketName}.`); 47 | } 48 | 49 | removeBucketDefaultOwner().catch(console.error); 50 | // [END storage_remove_bucket_default_owner] 51 | } 52 | 53 | main(...process.argv.slice(2)); 54 | -------------------------------------------------------------------------------- /samples/removeBucketLabel.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | // sample-metadata: 18 | // title: Storage Remove Bucket Label. 19 | // description: Removes bucket label. 20 | // usage: node removeBucketLabel.js labelone) 21 | 22 | function main(bucketName = 'my-bucket', labelKey = 'labelone') { 23 | // [START storage_remove_bucket_label] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // The key of the label to remove from the bucket 31 | // const labelKey = 'label-key-to-remove'; 32 | 33 | // Imports the Google Cloud client library 34 | const {Storage} = require('@google-cloud/storage'); 35 | 36 | // Creates a client 37 | const storage = new Storage(); 38 | 39 | async function removeBucketLabel() { 40 | const labels = {}; 41 | // To remove a label set the value of the key to null. 42 | labels[labelKey] = null; 43 | await storage.bucket(bucketName).setMetadata({labels}); 44 | console.log(`Removed labels from bucket ${bucketName}`); 45 | } 46 | 47 | removeBucketLabel().catch(console.error); 48 | // [END storage_remove_bucket_label] 49 | } 50 | process.on('unhandledRejection', err => { 51 | console.error(err.message); 52 | process.exitCode = 1; 53 | }); 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/removeBucketOwnerAcl.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on bucket and 17 | * file Access Control Lists with the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', userEmail = 'jdobry@google.com') { 24 | // [START storage_remove_bucket_owner] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The email address of the user to remove 32 | // const userEmail = 'user-email-to-remove'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function removeBucketOwner() { 41 | // Removes the user from the access control list of the bucket. You can use 42 | // deleteAllUsers(), deleteDomain(), deleteProject(), deleteGroup(), and 43 | // deleteAllAuthenticatedUsers() to remove access for different types of entities. 44 | await storage.bucket(bucketName).acl.owners.deleteUser(userEmail); 45 | 46 | console.log(`Removed user ${userEmail} from bucket ${bucketName}.`); 47 | } 48 | 49 | removeBucketOwner().catch(console.error); 50 | 51 | // [END storage_remove_bucket_owner] 52 | } 53 | 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/removeDefaultKMSKey.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | // sample-metadata: 18 | // title: Remove Default KMS Key. 19 | // description: Remove Default KMS Key. 20 | // usage: node removeDefaultKMSKey.js 21 | 22 | function main(bucketName = 'my-bucket') { 23 | // [START storage_bucket_delete_default_kms_key] 24 | /** 25 | * TODO(developer): Uncomment the following lines before running the sample. 26 | */ 27 | // The ID of your GCS bucket 28 | // const bucketName = 'your-unique-bucket-name'; 29 | 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | 36 | async function removeDefaultKMSKey() { 37 | await storage.bucket(bucketName).setMetadata({ 38 | encryption: { 39 | defaultKmsKeyName: null, 40 | }, 41 | }); 42 | 43 | console.log(`Default KMS key was removed from ${bucketName}`); 44 | } 45 | 46 | removeDefaultKMSKey().catch(console.error); 47 | // [END storage_bucket_delete_default_kms_key] 48 | } 49 | 50 | process.on('unhandledRejection', err => { 51 | console.error(err.message); 52 | process.exitCode = 1; 53 | }); 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/removeRetentionPolicy.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to use Bucket Lock operations on buckets 17 | * and objects using the Google Cloud Storage API. 18 | * 19 | * For more information read the documentation 20 | * at https://cloud.google.com/storage/docs/bucket-lock 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_remove_retention_policy] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | async function removeRetentionPolicy() { 38 | const [metadata] = await storage.bucket(bucketName).getMetadata(); 39 | if (metadata.retentionPolicy && metadata.retentionPolicy.isLocked) { 40 | console.log( 41 | 'Unable to remove retention period as retention policy is locked.' 42 | ); 43 | return null; 44 | } else { 45 | const results = await storage.bucket(bucketName).removeRetentionPeriod(); 46 | console.log(`Removed bucket ${bucketName} retention policy.`); 47 | return results; 48 | } 49 | } 50 | 51 | removeRetentionPolicy().catch(console.error); 52 | // [END storage_remove_retention_policy] 53 | } 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/renameFile.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on files with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main( 24 | srcBucketName = 'my-bucket', 25 | srcFileName = 'test2.txt', 26 | destFileName = 'test4.txt' 27 | ) { 28 | // [START storage_rename_file] 29 | /** 30 | * TODO(developer): Uncomment the following lines before running the sample. 31 | */ 32 | // The ID of the bucket the original file is in 33 | // const srcBucketName = 'your-source-bucket'; 34 | 35 | // The ID of the GCS file to rename 36 | // const srcFilename = 'your-file-name'; 37 | 38 | // The new ID of the GCS file 39 | // const destFileName = 'target-file-name'; 40 | 41 | // Imports the Google Cloud client library 42 | const {Storage} = require('@google-cloud/storage'); 43 | 44 | // Creates a client 45 | const storage = new Storage(); 46 | 47 | async function renameFile() { 48 | // renames the file 49 | await storage.bucket(srcBucketName).file(srcFileName).rename(destFileName); 50 | 51 | console.log( 52 | `gs://${srcBucketName}/${srcFileName} renamed to gs://${srcBucketName}/${destFileName}.` 53 | ); 54 | } 55 | 56 | renameFile().catch(console.error); 57 | // [END storage_rename_file] 58 | } 59 | main(...process.argv.slice(2)); 60 | -------------------------------------------------------------------------------- /samples/resources/.gitignore: -------------------------------------------------------------------------------- 1 | downloaded.txt 2 | -------------------------------------------------------------------------------- /samples/resources/resourcesSub1/testSub1.txt: -------------------------------------------------------------------------------- 1 | Sub1 2 | Hello World! -------------------------------------------------------------------------------- /samples/resources/test.txt: -------------------------------------------------------------------------------- 1 | Hello World! -------------------------------------------------------------------------------- /samples/resources/test2.txt: -------------------------------------------------------------------------------- 1 | Hello World 2! -------------------------------------------------------------------------------- /samples/restoreSoftDeletedBucket.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2024 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | function main(bucketName = 'my-bucket', generation = 123456789) { 18 | // [START storage_restore_soft_deleted_bucket] 19 | /** 20 | * TODO(developer): Uncomment the following lines before running the sample. 21 | */ 22 | // The ID of your GCS bucket 23 | // const bucketName = 'your-unique-bucket-name'; 24 | 25 | // The generation of the bucket to restore 26 | // const generation = 123456789; 27 | 28 | // Imports the Google Cloud client library 29 | const {Storage} = require('@google-cloud/storage'); 30 | 31 | // Creates a client 32 | const storage = new Storage(); 33 | 34 | async function restoreSoftDeletedBucket() { 35 | const options = { 36 | generation: generation, 37 | }; 38 | 39 | await storage.bucket(bucketName).restore(options); 40 | 41 | console.log(`Soft deleted bucket ${bucketName} was restored.`); 42 | } 43 | 44 | restoreSoftDeletedBucket().catch(console.error); 45 | // [END storage_restore_soft_deleted_bucket] 46 | } 47 | 48 | main(...process.argv.slice(2)); 49 | -------------------------------------------------------------------------------- /samples/scripts/cleanup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // Copyright 2019 Google LLC 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | 17 | 'use strict'; 18 | 19 | const {Storage} = require('@google-cloud/storage'); 20 | const storage = new Storage(); 21 | const NAME_REG_EXP = /^nodejs-storage-samples-[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/; 22 | 23 | storage 24 | .getBuckets() 25 | .then(([buckets]) => { 26 | let promise = Promise.resolve(); 27 | 28 | buckets 29 | .filter((bucket) => NAME_REG_EXP.test(bucket.name)) 30 | .forEach((bucket) => { 31 | promise = promise.then(() => { 32 | return bucket.deleteFiles() 33 | .then(() => bucket.deleteFiles(), console.error) 34 | .then(() => { 35 | console.log(`Deleting ${bucket.name}`); 36 | return bucket.delete(); 37 | }, console.error) 38 | .catch(console.error); 39 | }); 40 | }); 41 | }) 42 | .catch((err) => { 43 | console.error('ERROR:', err); 44 | }); 45 | -------------------------------------------------------------------------------- /samples/setAutoclass.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | function main( 18 | bucketName = 'my-bucket', 19 | toggle = true, 20 | terminalStorageClass = 'ARCHIVE' 21 | ) { 22 | // [START storage_set_autoclass] 23 | /** 24 | * TODO(developer): Uncomment the following lines before running the sample. 25 | */ 26 | // The ID of your GCS bucket 27 | // const bucketName = 'your-unique-bucket-name'; 28 | 29 | // The terminal storage class to be set on your GCS bucket. Valid values are NEARLINE and ARCHIVE. 30 | // const terminalStorageClass = 'NEARLINE'; 31 | 32 | // Imports the Google Cloud client library 33 | const {Storage} = require('@google-cloud/storage'); 34 | 35 | // Creates a client 36 | const storage = new Storage(); 37 | 38 | async function setAutoclass() { 39 | // Configure the Autoclass setting for a bucket. 40 | // terminalStorageClass field is optional and defaults to NEARLINE if not otherwise specified. 41 | // Valid terminalStorageClass values are NEARLINE and ARCHIVE. 42 | const [metadata] = await storage.bucket(bucketName).setMetadata({ 43 | autoclass: { 44 | enabled: toggle, 45 | terminalStorageClass, 46 | }, 47 | }); 48 | 49 | console.log( 50 | `Autoclass terminal storage class is ${metadata.autoclass.terminalStorageClass}.` 51 | ); 52 | } 53 | 54 | setAutoclass().catch(console.error); 55 | // [END storage_set_autoclass] 56 | } 57 | 58 | main(...process.argv.slice(2)); 59 | -------------------------------------------------------------------------------- /samples/setClientEndpoint.js: -------------------------------------------------------------------------------- 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 | // http://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 | /** 16 | * This application demonstrates set a custom endpoint with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(apiEndpoint = 'https://storage.googleapis.com') { 24 | // [START storage_set_client_endpoint] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The custom endpoint to which requests should be made 29 | // const apiEndpoint = 'https://yourcustomendpoint.com'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage({ 36 | apiEndpoint: apiEndpoint, 37 | useAuthWithCustomEndpoint: true, 38 | }); 39 | 40 | console.log(`Client initiated with endpoint: ${storage.apiEndpoint}.`); 41 | 42 | // [END storage_set_client_endpoint] 43 | } 44 | process.on('unhandledRejection', err => { 45 | console.error(err.message); 46 | process.exitCode = 1; 47 | }); 48 | main(...process.argv.slice(2)); 49 | -------------------------------------------------------------------------------- /samples/setPublicAccessPreventionEnforced.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_set_public_access_prevention_enforced] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The name of your GCS bucket 29 | // const bucketName = 'Name of a bucket, e.g. my-bucket'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | // Enforces public access prevention for the bucket 38 | async function setPublicAccessPreventionEnforced() { 39 | await storage.bucket(bucketName).setMetadata({ 40 | iamConfiguration: { 41 | publicAccessPrevention: 'enforced', 42 | }, 43 | }); 44 | 45 | console.log( 46 | `Public access prevention is set to enforced for ${bucketName}.` 47 | ); 48 | } 49 | 50 | setPublicAccessPreventionEnforced(); 51 | // [END storage_set_public_access_prevention_enforced] 52 | } 53 | 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /samples/setPublicAccessPreventionInherited.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_set_public_access_prevention_inherited] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The name of your GCS bucket 29 | // const bucketName = 'Name of a bucket, e.g. my-bucket'; 30 | // Imports the Google Cloud client library 31 | const {Storage} = require('@google-cloud/storage'); 32 | 33 | // Creates a client 34 | const storage = new Storage(); 35 | async function setPublicAccessPreventionInherited() { 36 | // Sets public access prevention to 'inherited' for the bucket 37 | await storage.bucket(bucketName).setMetadata({ 38 | iamConfiguration: { 39 | publicAccessPrevention: 'inherited', 40 | }, 41 | }); 42 | 43 | console.log(`Public access prevention is 'inherited' for ${bucketName}.`); 44 | } 45 | 46 | setPublicAccessPreventionInherited(); 47 | // [END storage_set_public_access_prevention_inherited] 48 | } 49 | main(...process.argv.slice(2)); 50 | -------------------------------------------------------------------------------- /samples/setRPOAsyncTurbo.js: -------------------------------------------------------------------------------- 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_set_rpo_async_turbo] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The name of your GCS bucket in a dual-region 29 | // const bucketName = 'Name of a bucket, e.g. my-bucket'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | // Enable turbo replication for the bucket by setting rpo to ASYNC_TURBO. 38 | // The bucket must be a dual-region bucket. 39 | async function setRPOAsyncTurbo() { 40 | await storage.bucket(bucketName).setMetadata({ 41 | rpo: 'ASYNC_TURBO', 42 | }); 43 | 44 | console.log(`Turbo replication enabled for ${bucketName}.`); 45 | } 46 | 47 | setRPOAsyncTurbo(); 48 | // [END storage_set_rpo_async_turbo] 49 | } 50 | 51 | process.on('unhandledRejection', err => { 52 | console.error(err.message); 53 | process.exitCode = 1; 54 | }); 55 | main(...process.argv.slice(2)); 56 | -------------------------------------------------------------------------------- /samples/setRPODefault.js: -------------------------------------------------------------------------------- 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 | // http://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 | /** 16 | * This application demonstrates how to perform basic operations on buckets with 17 | * the Google Cloud Storage API. 18 | * 19 | * For more information, see the README.md under /storage and the documentation 20 | * at https://cloud.google.com/storage/docs. 21 | */ 22 | 23 | function main(bucketName = 'my-bucket') { 24 | // [START storage_set_rpo_default] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The name of your GCS bucket in a dual-region 29 | // const bucketName = 'Name of a bucket, e.g. my-bucket'; 30 | 31 | // Imports the Google Cloud client library 32 | const {Storage} = require('@google-cloud/storage'); 33 | 34 | // Creates a client 35 | const storage = new Storage(); 36 | 37 | // Disable turbo replication for the bucket by setting RPO to default. 38 | // The bucket must be a dual-region bucket. 39 | async function setRPODefault() { 40 | await storage.bucket(bucketName).setMetadata({ 41 | rpo: 'DEFAULT', 42 | }); 43 | 44 | console.log(`Turbo replication disabled for ${bucketName}.`); 45 | } 46 | 47 | setRPODefault(); 48 | // [END storage_set_rpo_default] 49 | } 50 | 51 | process.on('unhandledRejection', err => { 52 | console.error(err.message); 53 | process.exitCode = 1; 54 | }); 55 | main(...process.argv.slice(2)); 56 | -------------------------------------------------------------------------------- /samples/setRetentionPolicy.js: -------------------------------------------------------------------------------- 1 | // Copyright 2020 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 | // http://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 | /** 16 | * This application demonstrates how to use Bucket Lock operations on buckets 17 | * and objects using the Google Cloud Storage API. 18 | * 19 | * For more information read the documentation 20 | * at https://cloud.google.com/storage/docs/bucket-lock 21 | */ 22 | 23 | function main(bucketName = 'my-bucket', retentionPeriod = 5) { 24 | // [START storage_set_retention_policy] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The retention period for objects in bucket 32 | // const retentionPeriod = 3600; // 1 hour in seconds 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | async function setRetentionPolicy() { 41 | const [metadata] = await storage 42 | .bucket(bucketName) 43 | .setRetentionPeriod(retentionPeriod); 44 | console.log( 45 | `Bucket ${bucketName} retention period set for ${metadata.retentionPolicy.retentionPeriod} seconds.` 46 | ); 47 | } 48 | 49 | setRetentionPolicy().catch(console.error); 50 | // [END storage_set_retention_policy] 51 | } 52 | main(...process.argv.slice(2)); 53 | -------------------------------------------------------------------------------- /samples/system-test/quickstart.test.js: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | // http://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 | const {assert} = require('chai'); 18 | const {after, it} = require('mocha'); 19 | const cp = require('child_process'); 20 | const uuid = require('uuid'); 21 | const {Storage} = require('@google-cloud/storage'); 22 | 23 | const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); 24 | 25 | const storage = new Storage(); 26 | const bucketName = `nodejs-storage-samples-${uuid.v4()}`; 27 | 28 | after(async () => { 29 | const bucket = storage.bucket(bucketName); 30 | await bucket.delete().catch(console.error); 31 | }); 32 | 33 | it('should run the quickstart', async () => { 34 | const stdout = execSync(`node quickstart ${bucketName}`); 35 | assert.match(stdout, /Bucket .* created./); 36 | }); 37 | -------------------------------------------------------------------------------- /samples/system-test/storage.test.js: -------------------------------------------------------------------------------- 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 | // http://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 | const {assert} = require('chai'); 18 | const {it} = require('mocha'); 19 | const cp = require('child_process'); 20 | 21 | const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); 22 | 23 | it('should intialize storage with a custom api endpoint', async () => { 24 | const apiEndpoint = 'https://storage.googleapis.com'; 25 | const output = execSync(`node setClientEndpoint.js ${apiEndpoint}`); 26 | assert.match( 27 | output, 28 | new RegExp(`Client initiated with endpoint: ${apiEndpoint}.`) 29 | ); 30 | }); 31 | -------------------------------------------------------------------------------- /samples/system-test/test_9d800329-00da-4cdd-9a3e-7ac6743d5813.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/nodejs-storage/77070b565bf3a347902d38ed46206b86fbf4ffe8/samples/system-test/test_9d800329-00da-4cdd-9a3e-7ac6743d5813.txt -------------------------------------------------------------------------------- /samples/uploadDirectoryWithTransferManager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | // sample-metadata: 19 | // title: Upload Directory With Transfer Manager 20 | // description: Uploads a directory in parallel utilizing transfer manager. 21 | // usage: node uploadFolderWithTransferManager.js 22 | 23 | function main(bucketName = 'my-bucket', directoryName = 'my-directory') { 24 | // [START storage_transfer_manager_upload_directory] 25 | /** 26 | * TODO(developer): Uncomment the following lines before running the sample. 27 | */ 28 | // The ID of your GCS bucket 29 | // const bucketName = 'your-unique-bucket-name'; 30 | 31 | // The local directory to upload 32 | // const directoryName = 'your-directory'; 33 | 34 | // Imports the Google Cloud client library 35 | const {Storage, TransferManager} = require('@google-cloud/storage'); 36 | 37 | // Creates a client 38 | const storage = new Storage(); 39 | 40 | // Creates a transfer manager client 41 | const transferManager = new TransferManager(storage.bucket(bucketName)); 42 | 43 | async function uploadDirectoryWithTransferManager() { 44 | // Uploads the directory 45 | await transferManager.uploadManyFiles(directoryName); 46 | 47 | console.log(`${directoryName} uploaded to ${bucketName}.`); 48 | } 49 | 50 | uploadDirectoryWithTransferManager().catch(console.error); 51 | // [END storage_transfer_manager_upload_directory] 52 | } 53 | 54 | process.on('unhandledRejection', err => { 55 | console.error(err.message); 56 | process.exitCode = 1; 57 | }); 58 | main(...process.argv.slice(2)); 59 | -------------------------------------------------------------------------------- /samples/uploadFromMemory.js: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // http://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 | function main( 16 | bucketName = 'my-bucket', 17 | contents = 'these are my file contents', 18 | destFileName = 'file.txt' 19 | ) { 20 | // [START storage_file_upload_from_memory] 21 | /** 22 | * TODO(developer): Uncomment the following lines before running the sample. 23 | */ 24 | // The ID of your GCS bucket 25 | // const bucketName = 'your-unique-bucket-name'; 26 | 27 | // The contents that you want to upload 28 | // const contents = 'these are my contents'; 29 | 30 | // The new ID for your GCS file 31 | // const destFileName = 'your-new-file-name'; 32 | 33 | // Imports the Google Cloud Node.js client library 34 | const {Storage} = require('@google-cloud/storage'); 35 | 36 | // Creates a client 37 | const storage = new Storage(); 38 | 39 | async function uploadFromMemory() { 40 | await storage.bucket(bucketName).file(destFileName).save(contents); 41 | 42 | console.log( 43 | `${destFileName} with contents ${contents} uploaded to ${bucketName}.` 44 | ); 45 | } 46 | 47 | uploadFromMemory().catch(console.error); 48 | // [END storage_file_upload_from_memory] 49 | } 50 | process.on('unhandledRejection', err => { 51 | console.error(err.message); 52 | process.exitCode = 1; 53 | }); 54 | main(...process.argv.slice(2)); 55 | -------------------------------------------------------------------------------- /src/nodejs-common/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | export {GoogleAuthOptions} from 'google-auth-library'; 17 | 18 | export { 19 | Service, 20 | ServiceConfig, 21 | ServiceOptions, 22 | StreamRequestOptions, 23 | } from './service.js'; 24 | 25 | export { 26 | BaseMetadata, 27 | DeleteCallback, 28 | ExistsCallback, 29 | GetConfig, 30 | InstanceResponseCallback, 31 | Interceptor, 32 | MetadataCallback, 33 | MetadataResponse, 34 | Methods, 35 | ResponseCallback, 36 | ServiceObject, 37 | ServiceObjectConfig, 38 | ServiceObjectParent, 39 | SetMetadataResponse, 40 | } from './service-object.js'; 41 | 42 | export { 43 | Abortable, 44 | AbortableDuplex, 45 | ApiError, 46 | BodyResponseCallback, 47 | DecorateRequestOptions, 48 | ResponseBody, 49 | util, 50 | } from './util.js'; 51 | -------------------------------------------------------------------------------- /src/package-json-helper.cjs: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 | // http://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 | /* eslint-disable node/no-missing-require */ 16 | 17 | function getPackageJSON() { 18 | return require('../../../package.json'); 19 | } 20 | 21 | exports.getPackageJSON = getPackageJSON; 22 | -------------------------------------------------------------------------------- /system-test/data/CloudPlatform_128px_Retina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/nodejs-storage/77070b565bf3a347902d38ed46206b86fbf4ffe8/system-test/data/CloudPlatform_128px_Retina.png -------------------------------------------------------------------------------- /system-test/data/empty-file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/nodejs-storage/77070b565bf3a347902d38ed46206b86fbf4ffe8/system-test/data/empty-file.txt -------------------------------------------------------------------------------- /system-test/data/three-mb-file.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/nodejs-storage/77070b565bf3a347902d38ed46206b86fbf4ffe8/system-test/data/three-mb-file.tif -------------------------------------------------------------------------------- /system-test/fixtures/index-cjs.js: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 | /* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ 16 | const {Storage} = require('@google-cloud/storage'); 17 | 18 | function main() { 19 | const storage = new Storage(); 20 | } 21 | 22 | main(); 23 | -------------------------------------------------------------------------------- /system-test/fixtures/index-esm.js: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 | /* eslint-disable node/no-missing-import, no-unused-vars */ 16 | import {Storage} from '@google-cloud/storage'; 17 | 18 | function main() { 19 | const storage = new Storage(); 20 | } 21 | 22 | main(); 23 | -------------------------------------------------------------------------------- /system-test/install.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2023 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 | import {packNTest} from 'pack-n-play'; 16 | import {readFileSync} from 'fs'; 17 | import {describe, it} from 'mocha'; 18 | 19 | describe('pack-n-play tests', () => { 20 | it('ESM module', async () => { 21 | await packNTest({ 22 | sample: { 23 | description: 'Should be able to import the storage library in ESM', 24 | esm: readFileSync('./system-test/fixtures/index-esm.js').toString(), 25 | }, 26 | }); 27 | }); 28 | 29 | it('CJS module', async () => { 30 | await packNTest({ 31 | sample: { 32 | description: 'Should be able to import the storage library in CJS', 33 | cjs: readFileSync('./system-test/fixtures/index-cjs.js').toString(), 34 | }, 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /test/fixtures/keys.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "service_account", 3 | "project_id": "project-id", 4 | "private_key_id": "12345", 5 | "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC5z21IhrvlHBj7\nifRhobA9ibn25Od7DpE5OauGmqy7B+A9LQOsk1ZujAFdHItnBPcjihSVHpiYxf1a\nLpFbM8z/hRvDvYS3Hs1pyRejmpGiznoOjCyUf6Wv3T1xKelbgn0twHHjqD1o0xzW\njyUILl7yuCbsAf8QlsV6ewS3IqO3i5A9RNHfKjeap8e6A7U3s9QBtR58RrxaMQpM\nz72gw7yOdJRfElkerQfyZTbtu/EBfE6CcskOyoMoRN3YgkjQqLMr1yVdL5/phEcQ\n5hpbDN5lrafGHN7FUtsrMge2iIuIYFfWQUTqu7HtnNXVmwj1LJNq5WeI1iInWaGz\nb7c1rUT9AgMBAAECggEAEB0FicqVX3L7qk9LsBkeItgKFnfB/eaaKsTuM7K/fqCv\njjPpzlIgprQ20g+i+dYbuytC9Fjo5tFp/SNuBji3Ha7kuil56Yoe9NOJh0M6P0zP\nQj+0W1Rj1p0bB5tDhLoLh6eEDjgNde+zioUeCFhCck4MogmHnbVVfspNnba/99oD\nl36heAioqj/KODdkbQ83+ByiH+3BzqblqJ4TR/3y0wOUXtlQvCHko1qximJFIM0z\n3TNoPiit74hTiFFOYfJyHpmRsiEJ5FUUImkmCJz2gk4fbpafKrgxxOMo1m7GqlsE\nE+ybHxyAq61HYbZOoUOO8B4md1/52QXP7DgPvV7JyQKBgQD+JS5nsR4TXRl61c9G\nNxoPW9yCMCoarIjkpyPmhh0uJ7y68cj9wHFgX6ATi1QuTnG9BzJ4z27PMgvv70N+\nAK6k74sdIT2ts8wYsD8H0UyuxDxeKiAnb2JW2f5GTcXNmELQi6rKkMNMoS8jv00d\ngzLCV7UbCbdf+ng9uRPs+Fvk9wKBgQC7KpNaeYFf5dmIYRWQhlZWBRoftdm1ROH/\n5GJsURkzlEjUH1g1y9eAigBn5I+Z9hylX2q1vHLpUHqONWwDz8oQ1L1o2iLz+tkp\nkNoaLSAb9uCl6t8tpqCG2dqUrxOmy1+xj3G8KI8XuYb+IwVSy6KK2df8fWN4d+i0\ng+TBb75MqwKBgEezwcXriKq554hqblJHFYkjx7DLWfWwm+a26UAOsojlGTA9KxG8\ni8A++nDJLHTsGNbWAv1muMKoQgntnUMdeih6lOshB7/MLFcC0qWn/VSJdOa0R+IY\nYMxUMJMxOg9pV+BypzsDYLZr+1rAjEc5TsbZ6/S25w+jIO15HBANeg+9AoGAZulz\nGkVDCLq2UJGpLM1gvW2Svqrb6RrV9UDbiVlSNRUssk4Fz5akiM3YiUeYWfyEJb4A\nS6sxt+4DZRwkpzfikDyZZQTEQUjFjWBTPB9hz16AiVpKmqxLCbrRv/1AHe8nT9di\nnyXiABaIDkatT6geWKCNbQx43C16a382EdJiXX8CgYEAqyAS2xuDi2+uoljRm1Bp\naz7Q2UBtBbcBr/CQmagEacWPXsSyCL6EySOH0e985k7ABZiW+AzWlOwKS5WMWAIb\nkncmxP0SU6WQDWl8xGbXAQ8Dw+HTu5G1n0vrl1rRO5FPwRs3pbV94ML+d5eoai6D\njHs1asOGIpdQ3OGpBpNRub0=\n-----END PRIVATE KEY-----\n", 6 | "client_email": "some-email@example.com", 7 | "client_id": "12345", 8 | "auth_uri": "https://accounts.google.com/o/oauth2/auth", 9 | "token_uri": "https://accounts.google.com/o/oauth2/token", 10 | "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", 11 | "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/el-gato%40el-gato.iam.gserviceaccount.com" 12 | } 13 | -------------------------------------------------------------------------------- /test/nodejs-common/index.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright 2022 Google LLC. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import assert from 'assert'; 17 | import {describe, it} from 'mocha'; 18 | import {Service, ServiceObject, util} from '../../src/nodejs-common/index.js'; 19 | 20 | describe('common', () => { 21 | it('should correctly export the common modules', () => { 22 | assert(Service); 23 | assert(ServiceObject); 24 | assert(util); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /test/testdata/testfile.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/nodejs-storage/77070b565bf3a347902d38ed46206b86fbf4ffe8/test/testdata/testfile.json -------------------------------------------------------------------------------- /test/testdata/textfile.txt: -------------------------------------------------------------------------------- 1 | This is a test file! 2 | -------------------------------------------------------------------------------- /tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/gts/tsconfig-google.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "outDir": "build/cjs", 6 | "resolveJsonModule": true, 7 | "sourceMap": false, 8 | "esModuleInterop": true, 9 | }, 10 | "include": [ 11 | "src/*.ts", 12 | "src/*.cjs", 13 | "test/**/*.ts", 14 | "system-test/*.ts", 15 | "conformance-test/*.ts", 16 | "conformance-test/scenarios/*.ts", 17 | "internal-tooling/*.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/gts/tsconfig-google.json", 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "outDir": "build/esm", 6 | "resolveJsonModule": true, 7 | "module": "es2020", 8 | "moduleResolution": "node", 9 | "lib": ["ES2020"], 10 | "sourceMap": false, 11 | "esModuleInterop": true, 12 | }, 13 | "include": [ 14 | "src/*.ts", 15 | "src/*.cjs", 16 | "internal-tooling/*.ts", 17 | "system-test/*.ts" 18 | ] 19 | } --------------------------------------------------------------------------------