Skip to content
Navigation Menu
{{ message }}
forked from GoogleCloudPlatform/php-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.php
More file actions
666 lines (592 loc) · 30.6 KB
/
Copy pathstorage.php
File metadata and controls
666 lines (592 loc) · 30.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
<?php
/**
* Copyright 2016 Google Inc.
*
* 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.
*/
namespace Google\Cloud\Samples\Storage;
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use InvalidArgumentException;
$application = new Application();
// Create Bucket ACL command
$application->add(new Command('bucket-acl'))
->setDescription('Manage the ACL for Cloud Storage buckets.')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage ACL.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addOption('entity', null, InputOption::VALUE_REQUIRED, 'Add or filter by a user')
->addOption('role', null, InputOption::VALUE_REQUIRED, 'One of OWNER, READER, or WRITER', 'READER')
->addOption('create', null, InputOption::VALUE_NONE, 'Create an ACL for the supplied user')
->addOption('delete', null, InputOption::VALUE_NONE, 'Remove a user from the ACL')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$entity = $input->getOption('entity');
$role = $input->getOption('role');
if ($entity) {
if ($input->getOption('create')) {
add_bucket_acl($bucketName, $entity, $role);
} elseif ($input->getOption('delete')) {
delete_bucket_acl($bucketName, $entity);
} else {
get_bucket_acl_for_entity($bucketName, $entity);
}
} else {
get_bucket_acl($bucketName);
}
});
// Create Bucket Default ACL command
$application->add(new Command('bucket-default-acl'))
->setDescription('Manage the default ACL for Cloud Storage buckets.')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage ACL.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addOption('entity', null, InputOption::VALUE_REQUIRED, 'Add or filter by a user')
->addOption('role', null, InputOption::VALUE_REQUIRED, 'One of OWNER, READER, or WRITER', 'READER')
->addOption('create', null, InputOption::VALUE_NONE, 'Create an ACL for the supplied user')
->addOption('delete', null, InputOption::VALUE_NONE, 'Remove a user from the ACL')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$entity = $input->getOption('entity');
$role = $input->getOption('role');
if ($entity) {
if ($input->getOption('create')) {
add_bucket_default_acl($bucketName, $entity, $role);
} elseif ($input->getOption('delete')) {
delete_bucket_default_acl($bucketName, $entity);
} else {
get_bucket_default_acl_for_entity($bucketName, $entity);
}
} else {
get_bucket_default_acl($bucketName);
}
});
// Create Bucket Labels command
$application->add(new Command('bucket-labels'))
->setDescription('Manage Cloud Storage bucket labels')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage Bucket labels.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('label', InputArgument::OPTIONAL, 'The Cloud Storage label')
->addOption('value', null, InputOption::VALUE_REQUIRED, 'Set the value of the label')
->addOption('remove', null, InputOption::VALUE_NONE, 'Remove the buckets label')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
if ($label = $input->getArgument('label')) {
if ($value = $input->getOption('value')) {
add_bucket_label($bucketName, $label, $value);
} elseif ($input->getOption('remove')) {
remove_bucket_label($bucketName, $label);
} else {
throw new \Exception('You must provide --value or --remove '
. 'when including a label name.');
}
} else {
get_bucket_labels($bucketName);
}
});
// Create Buckets command
$application->add(new Command('buckets'))
->setDescription('Manage Cloud Storage buckets')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages buckets.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::OPTIONAL, 'The Cloud Storage bucket name')
->addOption('create', null, InputOption::VALUE_NONE, 'Create the bucket')
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete the bucket')
->addOption('metadata', null, InputOption::VALUE_NONE, 'Get the bucket metadata')
->setCode(function ($input, $output) {
if ($bucketName = $input->getArgument('bucket')) {
if ($input->getOption('create')) {
create_bucket($bucketName);
} elseif ($input->getOption('delete')) {
delete_bucket($bucketName);
} elseif ($input->getOption('metadata')) {
get_bucket_metadata($bucketName);
} else {
throw new \Exception('Supply --create or --delete with bucket name');
}
} else {
list_buckets();
}
});
// Set Bucket Lock commands
$application->add(new Command('bucket-lock'))
->setDescription('Manage Cloud Storage retention policies')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage retention policies.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::OPTIONAL, 'The Cloud Storage object name')
->addArgument('retention-period', InputArgument::OPTIONAL, 'The length of the retention period in seconds')
->addOption('set-retention-policy', null, InputOption::VALUE_NONE, 'Set the retention policy')
->addOption('remove-retention-policy', null, InputOption::VALUE_NONE, 'Remove the retention policy')
->addOption('lock-retention-policy', null, InputOption::VALUE_NONE, 'Lock the retention policy')
->addOption('get-retention-policy', null, InputOption::VALUE_NONE, 'Gets the retention policy')
->addOption('set-event-based-hold', null, InputOption::VALUE_NONE, 'Set an event-based hold')
->addOption('release-event-based-hold', null, InputOption::VALUE_NONE, 'Release an event-based hold')
->addOption('enable-default-event-based-hold', null, InputOption::VALUE_NONE, 'Enable default event-based hold')
->addOption('disable-default-event-based-hold', null, InputOption::VALUE_NONE, 'Disable default event-based hold')
->addOption('get-default-event-based-hold', null, InputOption::VALUE_NONE, 'Gets default event-based hold')
->addOption('set-temporary-hold', null, InputOption::VALUE_NONE, 'Set a temporary hold')
->addOption('release-temporary-hold', null, InputOption::VALUE_NONE, 'Release a temporary hold')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
if ($bucketName) {
if ($input->getOption('remove-retention-policy')) {
remove_retention_policy($bucketName);
} elseif ($input->getOption('lock-retention-policy')) {
lock_retention_policy($bucketName);
} elseif ($input->getOption('get-retention-policy')) {
get_retention_policy($bucketName);
} elseif ($input->getOption('enable-default-event-based-hold')) {
enable_default_event_based_hold($bucketName);
} elseif ($input->getOption('disable-default-event-based-hold')) {
disable_default_event_based_hold($bucketName);
} elseif ($input->getOption('get-default-event-based-hold')) {
get_default_event_based_hold($bucketName);
} elseif ($input->getOption('set-retention-policy')) {
if ($retentionPeriod = $input->getArgument('retention-period')) {
set_retention_policy($bucketName, $retentionPeriod);
} else {
throw new \Exception('Supply a retention period');
}
} elseif ($objectName = $input->getArgument('object')) {
if ($input->getOption('set-event-based-hold')) {
set_event_based_hold($bucketName, $objectName);
} elseif ($input->getOption('release-event-based-hold')) {
release_event_based_hold($bucketName, $objectName);
} elseif ($input->getOption('set-temporary-hold')) {
set_temporary_hold($bucketName, $objectName);
} elseif ($input->getOption('release-temporary-hold')) {
release_temporary_hold($bucketName, $objectName);
}
} else {
throw new \Exception('Supply an object name');
}
} else {
throw new \Exception('Supply a bucket name');
}
});
// Create Encryption command
$application->add(new Command('encryption'))
->setDescription('Upload and download Cloud Storage objects with encryption')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage ACL.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::OPTIONAL, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::OPTIONAL, 'The Cloud Storage object name')
->addOption('upload-from', null, InputOption::VALUE_REQUIRED, 'Path to the file to upload')
->addOption('download-to', null, InputOption::VALUE_REQUIRED, 'Path to store the dowloaded file')
->addOption('key', null, InputOption::VALUE_REQUIRED, 'Supply your encryption key')
->addOption('rotate-key', null, InputOption::VALUE_REQUIRED, 'Supply a new encryption key')
->addOption('generate-key', null, InputOption::VALUE_NONE, 'Generates an encryption key')
->setCode(function ($input, $output) {
if ($input->getOption('generate-key')) {
generate_encryption_key();
} else {
$bucketName = $input->getArgument('bucket');
$objectName = $input->getArgument('object');
$encryptionKey = $input->getOption('key');
if ($bucketName && $objectName) {
if ($source = $input->getOption('upload-from')) {
upload_encrypted_object($bucketName, $objectName, $source, $encryptionKey);
} elseif ($destination = $input->getOption('download-to')) {
download_encrypted_object($bucketName, $objectName, $destination, $encryptionKey);
} elseif ($rotateKey = $input->getOption('rotate-key')) {
if (is_null($encryptionKey)) {
throw new \Exception('--key is required when using --rotate-key');
}
rotate_encryption_key($bucketName, $objectName, $encryptionKey, $rotateKey);
} else {
throw new \Exception('Supply --rotate-key, --upload-from or --download-to');
}
} else {
throw new \Exception('Supply a bucket and object OR --generate-key');
}
}
});
$application->add(new Command('iam'))
->setDescription('Manage IAM for Storage')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Storage IAM policies.
<info>php %command.full_name% my-bucket</info>
<info>php %command.full_name% my-bucket --role my-role --add-member user:test1@email.com --add-member user:test2@email.com</info>
<info>php %command.full_name% my-bucket --role my-role --remove-member user:test@email.com</info>
<info>php %command.full_name% my-bucket --role my-role --remove-binding --title cond-title --description cond-description --expression cond-expression</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The bucket that you want to change IAM for. ')
->addOption('role', null, InputOption::VALUE_REQUIRED, 'The new role to add to a bucket. ')
->addOption('add-member', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, "The new member(s) to add with the new role to the bucket. ")
->addOption('remove-member', null, InputOption::VALUE_REQUIRED, 'The member to remove from a role for a bucket. ')
->addOption('remove-binding', null, InputOption::VALUE_NONE, 'Remove conditional policy')
->addOption('title', null, InputOption::VALUE_REQUIRED, 'Optional. A title for the condition, if --expression is used. ')
->addOption('description', null, InputOption::VALUE_REQUIRED, 'Optional. A description for the condition, if --expression is used. ')
->addOption('expression', null, InputOption::VALUE_REQUIRED, 'Add the role/members pair with an IAM condition expression. ')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$role = $input->getOption('role');
$members = $input->getOption('add-member');
$removeMember = $input->getOption('remove-member');
$removeBinding = $input->getOption('remove-binding');
$expression = $input->getOption('expression');
$title = $input->getOption('title');
$description = $input->getOption('description');
if ($members) {
if (!$role) {
throw new InvalidArgumentException('Must provide role as an option.');
}
if ($expression) {
add_bucket_conditional_iam_binding($bucketName, $role, $members, $title, $description, $expression);
} else {
add_bucket_iam_member($bucketName, $role, $members);
}
} elseif ($removeMember) {
if (!$role) {
throw new InvalidArgumentException('Must provide role as an option.');
}
remove_bucket_iam_member($bucketName, $role, $removeMember);
} elseif ($removeBinding) {
if (!$role) {
throw new InvalidArgumentException('Must provide role as an option.');
}
if (!$title) {
throw new InvalidArgumentException('Must provide title as an option.');
}
if (!$description) {
throw new InvalidArgumentException('Must provide description as an option.');
}
if (!$expression) {
throw new InvalidArgumentException('Must provide expression as an option.');
}
remove_bucket_conditional_iam_binding($bucketName, $role, $title, $description, $expression);
} else {
view_bucket_iam_members($bucketName);
}
});
$application->add(new Command('object-acl'))
->setDescription('Manage the ACL for Cloud Storage objects')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage ACL.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::REQUIRED, 'The Cloud Storage object name')
->addOption('entity', null, InputOption::VALUE_REQUIRED, 'Add or filter by a user')
->addOption('role', null, InputOption::VALUE_REQUIRED, 'One of OWNER, READER, or WRITER', 'READER')
->addOption('create', null, InputOption::VALUE_NONE, 'Create an ACL for the supplied user')
->addOption('delete', null, InputOption::VALUE_NONE, 'Remove a user from the ACL')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$entity = $input->getOption('entity');
$role = $input->getOption('role');
$objectName = $input->getArgument('object');
if ($entity) {
if ($input->getOption('create')) {
add_object_acl($bucketName, $objectName, $entity, $role);
} elseif ($input->getOption('delete')) {
delete_object_acl($bucketName, $objectName, $entity);
} else {
get_object_acl_for_entity($bucketName, $objectName, $entity);
}
} else {
get_object_acl($bucketName, $objectName);
}
});
$application->add(new Command('objects'))
->setDescription('Manage Cloud Storage objects')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage objects.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::OPTIONAL, 'The Cloud Storage object name')
->addOption('upload-from', null, InputOption::VALUE_REQUIRED, 'Path to the file to upload')
->addOption('download-to', null, InputOption::VALUE_REQUIRED, 'Path to store the dowloaded file')
->addOption('move-to', null, InputOption::VALUE_REQUIRED, 'new name for the object')
->addOption('copy-to', null, InputOption::VALUE_REQUIRED, 'copy path for the object')
->addOption('make-public', null, InputOption::VALUE_NONE, 'makes the supplied object public')
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete the bucket')
->addOption('prefix', null, InputOption::VALUE_REQUIRED, 'List objects matching a prefix')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
if ($objectName = $input->getArgument('object')) {
if ($source = $input->getOption('upload-from')) {
upload_object($bucketName, $objectName, $source);
} elseif ($destination = $input->getOption('download-to')) {
download_object($bucketName, $objectName, $destination);
} elseif ($newObjectName = $input->getOption('move-to')) {
move_object($bucketName, $objectName, $bucketName, $newObjectName);
} elseif ($newObjectName = $input->getOption('copy-to')) {
copy_object($bucketName, $objectName, $bucketName, $newObjectName);
} elseif ($input->getOption('make-public')) {
make_public($bucketName, $objectName);
} elseif ($input->getOption('delete')) {
delete_object($bucketName, $objectName);
} else {
object_metadata($bucketName, $objectName);
}
} else {
if ($prefix = $input->getOption('prefix')) {
list_objects_with_prefix($bucketName, $prefix);
} else {
list_objects($bucketName);
}
}
});
$application->add(new Command('requester-pays'))
->setDescription('Manage Cloud Storage requester pays buckets.')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage requester pays buckets.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('project', InputArgument::REQUIRED, 'Your billable Google Cloud Project ID')
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage requester pays bucket name')
->addArgument('object', InputArgument::OPTIONAL, 'The Cloud Storage requester pays object name')
->addArgument('download-to', null, InputArgument::OPTIONAL, 'Path to store the dowloaded file')
->addOption('enable', null, InputOption::VALUE_NONE, 'Enable requester pays on a Cloud Storage bucket')
->addOption('disable', null, InputOption::VALUE_NONE, 'Disable requester pays on a Cloud Storage bucket')
->addOption('check-status', null, InputOption::VALUE_NONE, 'Check requester pays status on a Cloud Storage bucekt')
->setCode(function ($input, $output) {
$projectId = $input->getArgument('project');
$bucketName = $input->getArgument('bucket');
if ($objectName = $input->getArgument('object')) {
if ($destination = $input->getArgument('download-to')) {
download_file_requester_pays($projectId, $bucketName, $objectName, $destination);
}
} elseif ($input->getOption('enable')) {
enable_requester_pays($projectId, $bucketName);
} elseif ($input->getOption('disable')) {
disable_requester_pays($projectId, $bucketName);
} elseif ($input->getOption('check-status')) {
get_requester_pays_status($projectId, $bucketName);
}
});
$application->add(new Command('uniform-bucket-level-access'))
->setDescription('Manage Cloud Storage uniform bucket-level access buckets.')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage uniform bucket-level access buckets.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage uniform bucket-level access bucket name')
->addOption('enable', null, InputOption::VALUE_NONE, 'Enable uniform bucket-level access on a Cloud Storage bucket')
->addOption('disable', null, InputOption::VALUE_NONE, 'Disable uniform bucket-level access on a Cloud Storage bucket')
->addOption('get', null, InputOption::VALUE_NONE, 'Get uniform bucket-level access on a Cloud Storage bucekt')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
if ($input->getOption('enable')) {
enable_uniform_bucket_level_access($bucketName);
} elseif ($input->getOption('disable')) {
disable_uniform_bucket_level_access($bucketName);
} elseif ($input->getOption('get')) {
get_uniform_bucket_level_access($bucketName);
} else {
throw new \Exception('You must provide --enable, --disable, or --get with a bucket name.');
}
});
$application->add(new Command('hmac-sa-list'))
->setDescription('List Cloud Storage HMAC Keys.')
->setHelp(<<<EOF
The <info>%command.name%</info> command lists Cloud Storage HMAC Keys.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('projectId', InputArgument::REQUIRED, 'The Cloud Project ID with HMAC Keys to list')
->setCode(function ($input, $output) {
$projectId = $input->getArgument('projectId');
list_hmac_keys($projectId);
});
$application->add(new Command('hmac-sa-create'))
->setDescription('Create a Cloud Storage HMAC Key.')
->setHelp(<<<EOF
The <info>%command.name%</info> command creates Cloud Storage HMAC Keys.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('projectId', InputArgument::REQUIRED, 'The Cloud Project ID associated with the service account email')
->addArgument('serviceAccountEmail', InputArgument::REQUIRED, 'The service account to associate with the new HMAC Key')
->setCode(function ($input, $output) {
$projectId = $input->getArgument('projectId');
$serviceAccountEmail = $input->getArgument('serviceAccountEmail');
create_hmac_key($serviceAccountEmail, $projectId);
});
$application->add(new Command('hmac-sa-manage'))
->setDescription('Manage Cloud Storage HMAC Keys.')
->setHelp(<<<EOF
The <info>%command.name%</info> command manages Cloud Storage HMAC Keys.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('projectId', InputArgument::REQUIRED, 'The Cloud Project ID associated with the HMAC Key')
->addArgument('accessId', InputArgument::REQUIRED, 'The Cloud Storage HMAC Key access ID')
->addOption('activate', null, InputOption::VALUE_NONE, 'Activate an HMAC Key')
->addOption('deactivate', null, InputOption::VALUE_NONE, 'Deactivate an HMAC Key')
->addOption('get', null, InputOption::VALUE_NONE, 'Get an HMAC Key\'s metadata')
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete an HMAC Key')
->setCode(function ($input, $output) {
$projectId = $input->getArgument('projectId');
$accessId = $input->getArgument('accessId');
if ($input->getOption('activate')) {
activate_hmac_key($accessId, $projectId);
} elseif ($input->getOption('deactivate')) {
deactivate_hmac_key($accessId, $projectId);
} elseif ($input->getOption('get')) {
get_hmac_key($accessId, $projectId);
} elseif ($input->getOption('delete')) {
delete_hmac_key($accessId, $projectId);
} else {
throw new \Exception(
'You must provide --activate, --deactivate, --get, or --delete with an HMAC key accessId.'
);
}
});
$application->add(new Command('enable-default-kms-key'))
->setDescription('Enable default KMS encryption for a bucket.')
->setHelp(<<<EOF
The <info>%command.name%</info> command enables default KMS encryption for bucket.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('project', InputArgument::REQUIRED, 'Your billable Google Cloud Project ID')
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('kms-key-name', InputArgument::REQUIRED, 'KMS key ID to use as the default KMS key.')
->setCode(function ($input, $output) {
$projectId = $input->getArgument('project');
$bucketName = $input->getArgument('bucket');
$kmsKeyName = $input->getArgument('kms-key-name');
enable_default_kms_key($projectId, $bucketName, $kmsKeyName);
});
$application->add(new Command('upload-with-kms-key'))
->setDescription('Upload a file using KMS encryption.')
->setHelp(<<<EOF
The <info>%command.name%</info> command uploads a file using KMS encryption.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('project', InputArgument::REQUIRED, 'Your billable Google Cloud Project ID')
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::REQUIRED, 'The Cloud Storage object name')
->addArgument('upload-from', InputArgument::REQUIRED, 'Path to the file to upload')
->addArgument('kms-key-name', InputArgument::REQUIRED, 'KMS key ID used to encrypt objects server side.')
->setCode(function ($input, $output) {
$projectId = $input->getArgument('project');
$bucketName = $input->getArgument('bucket');
$objectName = $input->getArgument('object');
$uploadFrom = $input->getArgument('upload-from');
$kmsKeyName = $input->getArgument('kms-key-name');
upload_with_kms_key($projectId, $bucketName, $objectName, $uploadFrom, $kmsKeyName);
});
$application->add(new Command('get-object-v2-signed-url'))
->setDescription('Generate a v2 signed URL for downloading an object.')
->setHelp(<<<EOF
The <info>%command.name%</info> command generates a v2 signed URL for downloading an object.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::REQUIRED, 'The Cloud Storage object name')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$objectName = $input->getArgument('object');
get_object_v2_signed_url($bucketName, $objectName);
});
$application->add(new Command('get-object-v4-signed-url'))
->setDescription('Generate a v4 signed URL for downloading an object.')
->setHelp(<<<EOF
The <info>%command.name%</info> command generates a v4 signed URL for downloading an object.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::REQUIRED, 'The Cloud Storage object name')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$objectName = $input->getArgument('object');
get_object_v4_signed_url($bucketName, $objectName);
});
$application->add(new Command('get-object-v4-upload-signed-url'))
->setDescription('Generate a v4 signed URL for uploading an object.')
->setHelp(<<<EOF
The <info>%command.name%</info> command generates a v4 signed URL for uploading an object.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::REQUIRED, 'The Cloud Storage object name')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$objectName = $input->getArgument('object');
upload_object_v4_signed_url($bucketName, $objectName);
});
$application->add(new Command('generate-v4-post-policy'))
->setDescription('Generate a v4 post policy form for uploading an object.')
->setHelp(<<<EOF
The <info>%command.name%</info> command generates a v4 post policy form for uploading an object.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addArgument('object', InputArgument::REQUIRED, 'The Cloud Storage object name')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
$objectName = $input->getArgument('object');
generate_v4_post_policy($bucketName, $objectName);
});
$application->add(new Command('bucket-lifecycle-management'))
->setDescription('Manages lifecycle rules for a bucket.')
->setHelp(<<<EOF
The <info>%command.name%</info> command enables or disables lifecycles rules for a bucket.
<info>php %command.full_name% --help</info>
EOF
)
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage bucket name')
->addOption('enable', null, InputOption::VALUE_NONE, 'Enable lifecycle management on a Cloud Storage bucket')
->addOption('disable', null, InputOption::VALUE_NONE, 'Disable lifecycle management on a Cloud Storage bucket')
->setCode(function ($input, $output) {
$bucketName = $input->getArgument('bucket');
if ($input->getOption('enable')) {
enable_bucket_lifecycle_management($bucketName);
} elseif ($input->getOption('disable')) {
disable_bucket_lifecycle_management($bucketName);
} else {
throw new \Exception('You must provide --enable or --disable with a bucket name.');
}
});
// for testing
if (getenv('PHPUNIT_TESTS') === '1') {
return $application;
}
$application->run();
You can’t perform that action at this time.
