Skip to content

Commit 790a526

Browse files
committed
Cleaning up samples
Adding conditional for removing retention policy
1 parent b351aa5 commit 790a526

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

storage/src/remove_retention_policy.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ function remove_retention_policy($bucketName)
3737
{
3838
$storage = new StorageClient();
3939
$bucket = $storage->bucket($bucketName);
40+
$bucket->reload();
41+
42+
if ($bucket->info()['retentionPolicy']['isLocked']) {
43+
printf('Unable to remove retention period as retention policy is locked.' . PHP_EOL);
44+
return;
45+
}
46+
4047
$bucket->update([
41-
'retentionPolicy' => [
42-
]]);
48+
'retentionPolicy' => []
49+
]);
4350
printf('Removed bucket %s retention policy' . PHP_EOL, $bucketName);
4451
}
4552
# [END storage_remove_retention_policy]

storage/storage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
});
149149

150150

151-
// Create Buckets command
151+
// Set Bucket Lock commands
152152
$application->add(new Command('bucketlock'))
153153
->setDescription('Manage Cloud Storage retention policies')
154154
->setHelp(<<
@@ -160,7 +160,7 @@
160160
)
161161
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
162162
->addArgument('object', InputArgument::OPTIONAL, 'The Cloud Storage object name')
163-
->addArgument('retention-period', InputArgument::OPTIONAL, 'The length of the retention period')
163+
->addArgument('retention-period', InputArgument::OPTIONAL, 'The length of the retention period in seconds')
164164
->addOption('set-retention-policy', null, InputOption::VALUE_NONE, 'Set the retention policy')
165165
->addOption('remove-retention-policy', null, InputOption::VALUE_NONE, 'Remove the retention policy')
166166
->addOption('lock-retention-policy', null, InputOption::VALUE_NONE, 'Lock the retention policy')

storage/test/BucketLockCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testRetentionPolicyNoLock()
8282
);
8383
$this->bucket->reload();
8484

85-
$this->assertNull($this->bucket->info()['retentionPolicy']['isLocked']);
85+
$this->assertFalse($this->bucket->info()['retentionPolicy']['isLocked']);
8686
$this->assertNotNull($this->bucket->info()['retentionPolicy']['effectiveTime']);
8787
$this->assertEquals($this->bucket->info()['retentionPolicy']['retentionPeriod'], $retentionPeriod);
8888

0 commit comments

Comments
 (0)