diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0c2874f9b..1e6af2bd4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -50,4 +50,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 14 + - run: npm install + - run: npm run docs - uses: JustinBeckwith/linkinator-action@v1 + with: + paths: docs/ \ No newline at end of file diff --git a/README.md b/README.md index ad542cb7e..28a5358c7 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-storage/tre | Rotate Encryption Key | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/rotateEncryptionKey.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/rotateEncryptionKey.js,samples/README.md) | | Set Event Based Hold | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setEventBasedHold.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setEventBasedHold.js,samples/README.md) | | Set Public Access Prevention Enforced | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionEnforced.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionEnforced.js,samples/README.md) | +| Set Public Access Prevention Inherited | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionInherited.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionInherited.js,samples/README.md) | | Set Public Access Prevention Unspecified | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionUnspecified.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionUnspecified.js,samples/README.md) | | Set Retention Policy | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setRetentionPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setRetentionPolicy.js,samples/README.md) | | Set Temporary Hold | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setTemporaryHold.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setTemporaryHold.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index 6296a57ca..c63fe47fd 100644 --- a/samples/README.md +++ b/samples/README.md @@ -106,6 +106,7 @@ objects to users via direct download. * [Rotate Encryption Key](#rotate-encryption-key) * [Set Event Based Hold](#set-event-based-hold) * [Set Public Access Prevention Enforced](#set-public-access-prevention-enforced) + * [Set Public Access Prevention Inherited](#set-public-access-prevention-inherited) * [Set Public Access Prevention Unspecified](#set-public-access-prevention-unspecified) * [Set Retention Policy](#set-retention-policy) * [Set Temporary Hold](#set-temporary-hold) @@ -1682,6 +1683,23 @@ __Usage:__ +### Set Public Access Prevention Inherited + +View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionInherited.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionInherited.js,samples/README.md) + +__Usage:__ + + +`node samples/setPublicAccessPreventionInherited.js` + + +----- + + + + ### Set Public Access Prevention Unspecified View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionUnspecified.js). diff --git a/samples/getPublicAccessPrevention.js b/samples/getPublicAccessPrevention.js index e85bdea01..7a53f7ff2 100644 --- a/samples/getPublicAccessPrevention.js +++ b/samples/getPublicAccessPrevention.js @@ -35,7 +35,7 @@ function main(bucketName = 'my-bucket') { const storage = new Storage(); async function getPublicAccessPrevention() { - // Gets Bucket Metadata and prints publicAccessPrevention value (either 'unspecified' or 'enforced'). + // Gets Bucket Metadata and prints publicAccessPrevention value (either 'inherited' or 'enforced'). const [metadata] = await storage.bucket(bucketName).getMetadata(); console.log( `Public access prevention is ${metadata.iamConfiguration.publicAccessPrevention} for ${bucketName}.` diff --git a/samples/setPublicAccessPreventionInherited.js b/samples/setPublicAccessPreventionInherited.js new file mode 100644 index 000000000..14f61e0cd --- /dev/null +++ b/samples/setPublicAccessPreventionInherited.js @@ -0,0 +1,49 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on buckets with + * the Google Cloud Storage API. + * + * For more information, see the README.md under /storage and the documentation + * at https://cloud.google.com/storage/docs. + */ + +function main(bucketName = 'my-bucket') { + // [START storage_set_public_access_prevention_inherited] + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // The name of your GCS bucket + // const bucketName = 'Name of a bucket, e.g. my-bucket'; + // Imports the Google Cloud client library + const {Storage} = require('@google-cloud/storage'); + + // Creates a client + const storage = new Storage(); + async function setPublicAccessPreventionInherited() { + // Sets public access prevention to 'inherited' for the bucket + await storage.bucket(bucketName).setMetadata({ + iamConfiguration: { + publicAccessPrevention: 'inherited', + }, + }); + + console.log(`Public access prevention is 'inherited' for ${bucketName}.`); + } + + setPublicAccessPreventionInherited(); + // [END storage_set_public_access_prevention_inherited] +} +main(...process.argv.slice(2)); diff --git a/samples/system-test/buckets.test.js b/samples/system-test/buckets.test.js index 4bae0ade4..a46339d8d 100644 --- a/samples/system-test/buckets.test.js +++ b/samples/system-test/buckets.test.js @@ -31,7 +31,7 @@ const bucketWithClassAndLocation = storage.bucket( bucketNameWithClassAndLocation ); -const PUBLIC_ACCESS_PREVENTION_UNSPECIFIED = 'unspecified'; +const PUBLIC_ACCESS_PREVENTION_INHERITED = 'inherited'; const PUBLIC_ACCESS_PREVENTION_ENFORCED = 'enforced'; after(async () => { @@ -150,7 +150,7 @@ it('should remove a bucket cors configuration', async () => { assert.ok(!bucket.metadata.cors); }); -it.skip('should set public access prevention to enforced', async () => { +it('should set public access prevention to enforced', async () => { const output = execSync( `node setPublicAccessPreventionEnforced.js ${bucketName}` ); @@ -166,7 +166,7 @@ it.skip('should set public access prevention to enforced', async () => { ); }); -it.skip("should get a bucket's public access prevention metadata", async () => { +it("should get a bucket's public access prevention metadata", async () => { await storage.bucket(bucketName).setMetadata({ iamConfiguration: { publicAccessPrevention: PUBLIC_ACCESS_PREVENTION_ENFORCED, @@ -184,19 +184,19 @@ it.skip("should get a bucket's public access prevention metadata", async () => { assert.ok(metadata.iamConfiguration.publicAccessPrevention); }); -it.skip('should set public access prevention to unspecified', async () => { +it('should set public access prevention to inherited', async () => { const output = execSync( - `node setPublicAccessPreventionUnspecified.js ${bucketName}` + `node setPublicAccessPreventionInherited.js ${bucketName}` ); assert.match( output, - new RegExp(`Public access prevention is 'unspecified' for ${bucketName}.`) + new RegExp(`Public access prevention is 'inherited' for ${bucketName}.`) ); const metadata = await bucket.getMetadata(); assert.strictEqual( metadata[0].iamConfiguration.publicAccessPrevention, - PUBLIC_ACCESS_PREVENTION_UNSPECIFIED + PUBLIC_ACCESS_PREVENTION_INHERITED ); }); diff --git a/system-test/storage.ts b/system-test/storage.ts index 538886fb2..27edc9622 100644 --- a/system-test/storage.ts +++ b/system-test/storage.ts @@ -794,7 +794,7 @@ describe('storage', () => { describe('public access prevention', () => { let bucket: Bucket; - const PUBLIC_ACCESS_PREVENTION_UNSPECIFIED = 'unspecified'; + const PUBLIC_ACCESS_PREVENTION_INHERITED = 'inherited'; const PUBLIC_ACCESS_PREVENTION_ENFORCED = 'enforced'; const createBucket = () => { @@ -878,24 +878,24 @@ describe('storage', () => { }); }); - it.skip('inserts a bucket with unspecified public access prevention', async () => { + it('inserts a bucket with inherited public access prevention', async () => { await setPublicAccessPrevention( bucket, - PUBLIC_ACCESS_PREVENTION_UNSPECIFIED + PUBLIC_ACCESS_PREVENTION_INHERITED ); const [bucketMetadata] = await bucket.getMetadata(); const publicAccessPreventionStatus = bucketMetadata.iamConfiguration.publicAccessPrevention; return assert.strictEqual( publicAccessPreventionStatus, - PUBLIC_ACCESS_PREVENTION_UNSPECIFIED + PUBLIC_ACCESS_PREVENTION_INHERITED ); }); - it('makes public a bucket with unspecified public access prevention', async () => { + it('makes public a bucket with inherited public access prevention', async () => { await setPublicAccessPrevention( bucket, - PUBLIC_ACCESS_PREVENTION_UNSPECIFIED + PUBLIC_ACCESS_PREVENTION_INHERITED ); return assert.ok(() => bucket.makePublic()); }); @@ -938,7 +938,7 @@ describe('storage', () => { bucketMetadata.iamConfiguration.uniformBucketLevelAccess.enabled; await setPublicAccessPrevention( bucket, - PUBLIC_ACCESS_PREVENTION_UNSPECIFIED + PUBLIC_ACCESS_PREVENTION_INHERITED ); const [updatedBucketMetadata] = await bucket.getMetadata(); return assert.strictEqual(