New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Storage] HMAC key samples #946
Conversation
frankyn
commented
Aug 20, 2019
•
edited
edited
- Integration tests pending adding env var for service account email.
- hmac key create, list, get, activate, deactivate, delete samples
- lint
The tests are failing because of the
|
Thanks @bshaffer. I also need to add an environment variable into kokoro CI to pass in a service account for tests. |
storage/storage.php
Outdated
->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 metadata') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Get an HMAC key's metadata
storage/test/HmacCommandTest.php
Outdated
$this->assertContains("HMAC key Metadata:", $this->getActualOutput()); | ||
} | ||
|
||
/** @depends testHmacKeyGet */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok, but ideally each one should test a single command.
$this->commandTesterCreate = new CommandTester($application->get('hmac-sa-create')); | ||
$this->commandTesterManage = new CommandTester($application->get('hmac-sa-manage')); | ||
$this->storage = new StorageClient(); | ||
$this->hmacServiceAccount = self::$projectId . '@appspot.gserviceaccount.com'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to make it configurable via an environment variable, right? Otherwise it conflicts with integration tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests use a separate project per PHP version.
storage/src/delete_hmac_key.php
Outdated
$hmacKey = $storage->hmacKey($accessId, $projectId); | ||
|
||
$hmacKey->delete(); | ||
print("The key is deleted, though it may still appear in StorageClient.hmacKeys() results." . PHP_EOL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JesseLovelace brought up a good point. We should indicate that it will show up if showDeletedKeys = true
in hmacKeys()
results.
storage/src/delete_hmac_key.php
Outdated
|
||
$hmacKey->delete(); | ||
print("The key is deleted, though it may still appear in StorageClient.hmacKeys(\$options=['showDeletedKeys'=>true])"); | ||
print("results when is used." . PHP_EOL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ...results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really nice 👍. Most of my comments are just small quick hits.
storage/src/activate_hmac_key.php
Outdated
|
||
$hmacKey->update('ACTIVE'); | ||
|
||
print("The HMAC key is now active." . PHP_EOL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a minor note, but WDYT about using single quotes? It is typically a best practice unless you need string interpolation.
storage/storage.php
Outdated
} 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.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes just a bit over 120 characters, WDYT about?:
throw new \Exception(
'You must provide --activate, --deactivate, --get, or --delete with an HMAC key accessId.'
);
public function testHmacKeyList() | ||
{ | ||
$this->commandTesterList->execute( | ||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation is off a bit here (should be 4 spaces in from the line above) and the closing parenthesis should be on a newline (applies to the rest of the execute commands as well).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm following the linter for php-docs-samples. I'm not sure if they follow different specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think either of those things will get flagged by the PSR-2 standard used by the linter, however it is fairly common practice to help with readability. The other tests in the suite seem to use the suggested style as well. If you prefer this style, don't consider my suggestion blocking by any means :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dwsupplee I'll move forward for now.
Co-Authored-By: David Supplee <dwsupplee@gmail.com>
Co-Authored-By: David Supplee <dwsupplee@gmail.com>
Co-Authored-By: David Supplee <dwsupplee@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated PTAL, thanks @dwsupplee!
public function testHmacKeyList() | ||
{ | ||
$this->commandTesterList->execute( | ||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm following the linter for php-docs-samples. I'm not sure if they follow different specs.