Skip to content

Commit 62f55c2

Browse files
Storage: Changed references from 'unspecified' to 'inherited' (GoogleCloudPlatform#1535)
* Storage: Changed references from 'unspecified' to 'inherited'
1 parent 104005b commit 62f55c2

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
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+
* 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+
18+
/**
19+
* For instructions on how to run the full sample:
20+
*
21+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/storage/README.md
22+
*/
23+
24+
namespace Google\Cloud\Samples\Storage;
25+
26+
# [START storage_set_public_access_prevention_inherited]
27+
use Google\Cloud\Storage\StorageClient;
28+
29+
/**
30+
* Set the bucket Public Access Prevention to inherited.
31+
*
32+
* @param string $bucketName the name of your Cloud Storage bucket.
33+
*/
34+
function set_public_access_prevention_inherited($bucketName)
35+
{
36+
// $bucketName = 'my-bucket';
37+
38+
$storage = new StorageClient();
39+
$bucket = $storage->bucket($bucketName);
40+
41+
$bucket->update([
42+
'iamConfiguration' => [
43+
'publicAccessPrevention' => 'inherited'
44+
]
45+
]);
46+
47+
printf(
48+
'Public Access Prevention has been set to inherited for %s.' . PHP_EOL,
49+
$bucketName
50+
);
51+
}
52+
# [END storage_set_public_access_prevention_inherited]
53+
54+
// The following 2 lines are only needed to run the samples
55+
require_once __DIR__ . '/../../testing/sample_helpers.php';
56+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

storage/test/PublicAccessPreventionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public function testSetPublicAccessPreventionToEnforced()
6565
}
6666

6767
/** @depends testSetPublicAccessPreventionToEnforced */
68-
public function testSetPublicAccessPreventionToUnspecified()
68+
public function testSetPublicAccessPreventionToInherited()
6969
{
70-
$output = self::runFunctionSnippet('set_public_access_prevention_unspecified', [
70+
$output = self::runFunctionSnippet('set_public_access_prevention_inherited', [
7171
self::$bucket->name(),
7272
]);
7373

7474
$this->assertStringContainsString(
7575
sprintf(
76-
"Public Access Prevention has been set to unspecified for %s.",
76+
"Public Access Prevention has been set to inherited for %s.",
7777
self::$bucket->name()
7878
),
7979
$output
@@ -82,10 +82,10 @@ public function testSetPublicAccessPreventionToUnspecified()
8282
self::$bucket->reload();
8383
$bucketInformation = self::$bucket->info();
8484
$pap = $bucketInformation['iamConfiguration']['publicAccessPrevention'];
85-
$this->assertEquals('unspecified', $pap);
85+
$this->assertEquals('inherited', $pap);
8686
}
8787

88-
/** @depends testSetPublicAccessPreventionToUnspecified */
88+
/** @depends testSetPublicAccessPreventionToInherited */
8989
public function testGetPublicAccessPrevention()
9090
{
9191
$output = self::runFunctionSnippet('get_public_access_prevention', [
@@ -94,7 +94,7 @@ public function testGetPublicAccessPrevention()
9494

9595
$this->assertStringContainsString(
9696
sprintf(
97-
"The bucket public access prevention is unspecified for %s.",
97+
"The bucket public access prevention is inherited for %s.",
9898
self::$bucket->name()
9999
),
100100
$output
@@ -103,6 +103,6 @@ public function testGetPublicAccessPrevention()
103103
self::$bucket->reload();
104104
$bucketInformation = self::$bucket->info();
105105
$pap = $bucketInformation['iamConfiguration']['publicAccessPrevention'];
106-
$this->assertEquals('unspecified', $pap);
106+
$this->assertEquals('inherited', $pap);
107107
}
108108
}

0 commit comments

Comments
 (0)