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

Implemented async callbacks to PHP regardless of thread model, Sigv4 signing #24

Merged
merged 28 commits into from
Jun 8, 2021

Conversation

justinboswell
Copy link
Contributor

@justinboswell justinboswell commented May 19, 2021

Depends on:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@justinboswell justinboswell requested review from SamRemis and a team May 19, 2021 00:36
@justinboswell justinboswell marked this pull request as ready for review May 19, 2021 21:56
@justinboswell justinboswell changed the title Implemented Sigv4 Implemented async callbacks to PHP regardless of thread model, Sigv4 signing May 20, 2021
…#25)

* Broke C code into separate files, moved common stuff to php_aws_crt.h

* clang-format

* Use a unity build to make PHP do the right thing with our lib
]);
$http_request = new Request('GET', '/', [], ['Host' => 'example.amazonaws.com']);
$this->assertNotNull($http_request, "Unable to create HttpRequest for signing");
$signable = Signable::fromHttpRequest($http_request);
$this->assertNotNull($signable, "Unable to create signable from HttpRequest");

Signing::signRequestAws($signable, $signing_config, function() {

Signing::signRequestAws($signable, $signing_config, function($signing_result, $error_code) use (&$http_request) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like more than 80 characters and if it is should be split into more lines

});

$headers = $http_request->headers();
$this->assertEquals('AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31', $headers->get('Authorization'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

same with above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to shrink this, I would have to heredoc it, and then strip newlines from it. That seems a bit counter to simplicity, eh?

@SamRemis
Copy link
Collaborator

SamRemis commented Jun 2, 2021

Please add a method to expose the following line:
if (!extension_loaded('awscrt')) {}

This will reduce code duplication and enable us to throw an error when the extension isn't loaded and a feature requires sigv4a

@justinboswell
Copy link
Contributor Author

Please add a method to expose the following line:
if (!extension_loaded('awscrt')) {}

This will reduce code duplication and enable us to throw an error when the extension isn't loaded and a feature requires sigv4a

See CRT::isAvailable() and CRT::isLoaded()

src/AWS/CRT/Auth/Signing.php Outdated Show resolved Hide resolved
@@ -23,6 +23,7 @@ public static function defaults() {
'signed_body_value' => null,
'signed_body_header_type' => SignedBodyHeaderType::NONE,
'expiration_in_seconds' => 0,
'date' => time()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is a unix date, it could be named unixDate or something depending on how it is used to make it clear it has the exact timestamp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so while it is a timestamp, it will be quantized to the year/month/day, so it is a date. In the SigV4 docs:

Note that the date used in the hashing process is in the format YYYYMMDD (for example, 20150830), and does not include the time.

@@ -34,7 +35,9 @@ public function __construct(array $options = []) {
$sc = $this->acquire(self::$crt->signing_config_aws_new());
self::$crt->signing_config_aws_set_algorithm($sc, $options->algorithm->asInt());
self::$crt->signing_config_aws_set_signature_type($sc, $options->signature_type->asInt());
self::$crt->signing_config_aws_set_credentials_provider($sc, $options->credentials_provider->asObject());
if ($credentials_provider = $options->credentials_provider->asObject()) {
self::$crt->signing_config_aws_set_credentials_provider($sc, $credentials_provider->native);
Copy link
Collaborator

Choose a reason for hiding this comment

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

92 characters so it should be split among a few lines:
self::$crt->signing_config_aws_set_credentials_provider(\n \t$sc,\n \t$credentials_provider->native\n );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to pick a linter. This is going to kill me. This is what tools are for :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it anyway

}

function __destruct() {
// No release necessary, SigningResults are transient
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this comment here? And if it's not necessary, why do you do it on the next line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, this was indeed confusing as hell

src/AWS/CRT/CRT.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@SamRemis SamRemis left a comment

Choose a reason for hiding this comment

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

Hope you don't mind if I just run the whole thing through a PHP linter at some point in the future. Figure it'll be easier that way

@justinboswell
Copy link
Contributor Author

Hope you don't mind if I just run the whole thing through a PHP linter at some point in the future. Figure it'll be easier that way

I will be overjoyed! Then tell me what it is so I can use it to verify!

* Added CI runs for all versions of PHP

* PHP >= 7.1 is required for arginfo generation

* Allow PHP 5.5 to compile

* Added extension API detection for every minor version we support

* Pinned version of phpunit for ancient php 5.5

* Added special php 5.5 CI

* Updated to builder v0.8.18

* Added shim for expectException
@justinboswell justinboswell enabled auto-merge (squash) June 8, 2021 00:31
@justinboswell justinboswell merged commit 7d47316 into main Jun 8, 2021
@justinboswell justinboswell deleted the sigv4 branch June 8, 2021 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants