Skip to content
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

Merged
merged 30 commits into from Sep 11, 2019
Merged

[Storage] HMAC key samples #946

merged 30 commits into from Sep 11, 2019

Conversation

frankyn
Copy link
Member

@frankyn frankyn commented Aug 20, 2019

  • Integration tests pending adding env var for service account email.
  • hmac key create, list, get, activate, deactivate, delete samples
  • lint

@frankyn frankyn added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Aug 20, 2019
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 20, 2019
@bshaffer
Copy link
Contributor

bshaffer commented Aug 20, 2019

The tests are failing because of the php-cs-fixer command. Download and run it to fix your code styles.

cd storage
php-cs-fixer fix --config=../.php_cs.dist .

@frankyn
Copy link
Member Author

frankyn commented Aug 20, 2019

Thanks @bshaffer. I also need to add an environment variable into kokoro CI to pass in a service account for tests.

@frankyn frankyn removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Aug 27, 2019
@frankyn frankyn requested a review from bshaffer August 28, 2019 16:13
->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')
Copy link
Collaborator

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

$this->assertContains("HMAC key Metadata:", $this->getActualOutput());
}

/** @depends testHmacKeyGet */
Copy link
Collaborator

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';
Copy link
Collaborator

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.

Copy link
Member Author

@frankyn frankyn Sep 5, 2019

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.

$hmacKey = $storage->hmacKey($accessId, $projectId);

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

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.

@frankyn frankyn requested a review from jkwlui September 5, 2019 23:42
@frankyn frankyn added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 9, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 9, 2019

$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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ...results.

@frankyn frankyn requested review from dwsupplee and removed request for bshaffer September 9, 2019 20:38
Copy link
Contributor

@dwsupplee dwsupplee left a 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 Show resolved Hide resolved
storage/src/activate_hmac_key.php Outdated Show resolved Hide resolved
storage/README.md Outdated Show resolved Hide resolved
storage/src/activate_hmac_key.php Outdated Show resolved Hide resolved

$hmacKey->update('ACTIVE');

print("The HMAC key is now active." . PHP_EOL);
Copy link
Contributor

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 Show resolved Hide resolved
storage/storage.php Outdated Show resolved Hide resolved
} 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.');
Copy link
Contributor

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.'
);

storage/test/HmacCommandTest.php Outdated Show resolved Hide resolved
public function testHmacKeyList()
{
$this->commandTesterList->execute(
[
Copy link
Contributor

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).

Copy link
Member Author

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.

Copy link
Contributor

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 :).

Copy link
Member Author

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.

frankyn and others added 5 commits September 10, 2019 16:28
Co-Authored-By: David Supplee <dwsupplee@gmail.com>
Co-Authored-By: David Supplee <dwsupplee@gmail.com>
Co-Authored-By: David Supplee <dwsupplee@gmail.com>
Copy link
Member Author

@frankyn frankyn left a 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(
[
Copy link
Member Author

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.

@frankyn frankyn merged commit 3629c3e into master Sep 11, 2019
@frankyn frankyn deleted the hmac-sa branch September 11, 2019 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants