Skip to content

Commit f72586d

Browse files
author
Frank Natividad
committed
Add projectId as a clear parameter
1 parent 335981e commit f72586d

File tree

7 files changed

+23
-20
lines changed

7 files changed

+23
-20
lines changed

storage/src/activate_hmac_key.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030
* Activate HMAC key.
3131
*
3232
* @param string $accessId access ID for an inactive HMAC key.
33+
* @param string $projectId Google Cloud Project ID.
3334
*
3435
*/
35-
function activate_hmac_key($accessId)
36+
function activate_hmac_key($accessId, $projectId)
3637
{
3738
$storage = new StorageClient();
3839
// By default hmacKey will use the projectId used by StorageClient().
39-
$hmacKey = $storage->hmacKey($accessId);
40+
$hmacKey = $storage->hmacKey($accessId, $projectId);
4041

41-
$hmacKey = $hmacKey->update('ACTIVE');
42+
$hmacKey->update('ACTIVE');
4243

4344
print("The HMAC key is now active.");
4445
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info()));

storage/src/create_hmac_key.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
* Create a new HMAC key.
3131
*
3232
* @param string $serviceAccountEmail service account email to associate with new HMAC key.
33-
* @param string $options options for the new HMAC key such as projectId.
33+
* @param string $projectId Google Cloud Project ID.
3434
*
3535
*/
36-
function create_hmac_key($serviceAccountEmail, $options = ['projectId' => 'your-project-id'])
36+
function create_hmac_key($serviceAccountEmail, $projectId)
3737
{
3838
$storage = new StorageClient();
3939
// By default createHmacKey will use the projectId used by StorageClient().
40-
$hmacKeyCreated = $storage->createHmacKey($serviceAccountEmail, $options);
40+
$hmacKeyCreated = $storage->createHmacKey($serviceAccountEmail, ['projectId' => $projectId]);
4141

4242
printf("The base64 encoded secret is: %s", $hmacKeyCreated->secret());
4343
print("Do not miss that secret, there is no API to recover it.");

storage/src/deactivate_hmac_key.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030
* Deactivate HMAC key.
3131
*
3232
* @param string $accessId access ID for an inactive HMAC key.
33+
* @param string $projectId Google Cloud Project ID.
3334
*
3435
*/
35-
function deactivate_hmac_key($accessId)
36+
function deactivate_hmac_key($accessId, $projectId)
3637
{
3738
$storage = new StorageClient();
3839
// By default hmacKey will use the projectId used by StorageClient().
39-
$hmacKey = $storage->hmacKey($accessId);
40+
$hmacKey = $storage->hmacKey($accessId, $projectId);
4041

41-
$hmacKey = $hmacKey->update('INACTIVE');
42+
$hmacKey->update('INACTIVE');
4243

4344
print("The HMAC key is now inactive.");
4445
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info()));

storage/src/delete_hmac_key.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
* Delete HMAC key.
3131
*
3232
* @param string $accessId access ID for an inactive HMAC key.
33+
* @param string $projectId Google Cloud Project ID.
3334
*
3435
*/
35-
function delete_hmac_key($accessId)
36+
function delete_hmac_key($accessId, $projectId)
3637
{
3738
$storage = new StorageClient();
3839
// By default hmacKey will use the projectId used by StorageClient().
39-
$hmacKey = $storage->hmacKey($accessId);
40+
$hmacKey = $storage->hmacKey($accessId, $projectId);
4041

4142
$hmacKey->delete();
4243
print("The key is deleted, though it may still appear in StorageClient.hmacKeys() results.");

storage/src/get_hmac_key.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* Get HMAC key.
3131
*
3232
* @param string $accessId access ID for HMAC key.
33-
* @param string $projectId Google Cloud Project Id.
33+
* @param string $projectId Google Cloud Project ID.
3434
*
3535
*/
3636
function get_hmac_key($accessId, $projectId)

storage/src/list_hmac_keys.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
/**
3030
* List HMAC keys.
3131
*
32-
* @param string $options options for the new HMAC key.
32+
* @param string $projectId Google Cloud Project ID.
3333
*
3434
*/
35-
function list_hmac_keys($options = ['projectId' => 'your-project-id'])
35+
function list_hmac_keys($projectId)
3636
{
3737
$storage = new StorageClient();
3838
// By default hmacKeys will use the projectId used by StorageClient() list HMAC Keys.
39-
$hmacKeys = $storage->hmacKeys($options);
39+
$hmacKeys = $storage->hmacKeys(['projectId' => $projectId]);
4040

4141
foreach ($hmacKeys as $hmacKey) {
4242
printf("HMAC key Metadata: %s" . PHP_EOL, print_r($hmacKey->info()));

storage/storage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@
443443
->addArgument('projectId', InputArgument::REQUIRED, 'The Cloud Project ID HMAC Keys to list')
444444
->setCode(function ($input, $output) {
445445
$projectId = $input->getArgument('projectId');
446-
list_hmac_keys(['projectId' => $projectId]);
446+
list_hmac_keys($projectId);
447447
});
448448

449449
$application->add(new Command('hmac-sa-create'))
@@ -460,7 +460,7 @@
460460
->setCode(function ($input, $output) {
461461
$projectId = $input->getArgument('projectId');
462462
$serviceAccountEmail = $input->getArgument('serviceAccountEmail');
463-
create_hmac_key($serviceAccountEmail, ['projectId' => $projectId]);
463+
create_hmac_key($serviceAccountEmail, $projectId);
464464
});
465465

466466
$application->add(new Command('hmac-sa-manage'))
@@ -482,13 +482,13 @@
482482
$projectId = $input->getArgument('projectId');
483483
$accessId = $input->getArgument('accessId');
484484
if ($input->getOption('activate')) {
485-
activate_hmac_key($accessId);
485+
activate_hmac_key($accessId, $projectId);
486486
} elseif ($input->getOption('deactivate')) {
487-
deactivate_hmac_key($accessId);
487+
deactivate_hmac_key($accessId, $projectId);
488488
} elseif ($input->getOption('get')) {
489489
get_hmac_key($accessId, $projectId);
490490
} elseif ($input->getOption('delete')) {
491-
delete_hmac_key($accessId);
491+
delete_hmac_key($accessId, $projectId);
492492
} else {
493493
throw new \Exception('You must provide --activate, --deactivate, --get, or --delete with an HMAC key accessId.');
494494
}

0 commit comments

Comments
 (0)