Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
18 changes: 18 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion samples/getPublicAccessPrevention.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`
Expand Down
49 changes: 49 additions & 0 deletions samples/setPublicAccessPreventionInherited.js
Original file line number Diff line number Diff line change
@@ -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));
14 changes: 7 additions & 7 deletions samples/system-test/buckets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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}`
);
Expand All @@ -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,
Expand All @@ -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
);
});

Expand Down
14 changes: 7 additions & 7 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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());
});
Expand Down Expand Up @@ -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(
Expand Down