| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
namespace AWS\CRT\Auth; |
| 7 |
|
| 8 |
use AWS\CRT\NativeResource as NativeResource; |
| 9 |
use AWS\CRT\Options as Options; |
| 10 |
|
| 11 |
class SigningConfigAWS extends NativeResource { |
| 12 |
|
| 13 |
public static function defaults() { |
| 14 |
return [ |
| 15 |
'algorithm' => SigningAlgorithm::SIGv4, |
| 16 |
'signature_type' => SignatureType::HTTP_REQUEST_HEADERS, |
| 17 |
'credentials_provider' => null, |
| 18 |
'region' => null, |
| 19 |
'service' => null, |
| 20 |
'use_double_uri_encode' => false, |
| 21 |
'should_normalize_uri_path' => false, |
| 22 |
'omit_session_token' => false, |
| 23 |
'signed_body_value' => null, |
| 24 |
'signed_body_header_type' => SignedBodyHeaderType::NONE, |
| 25 |
'expiration_in_seconds' => 0, |
| 26 |
'date' => time(), |
| 27 |
'should_sign_header' => null, |
| 28 |
]; |
| 29 |
} |
| 30 |
|
| 31 |
private $options; |
| 32 |
|
| 33 |
public function __construct(array $options = []) { |
| 34 |
parent::__construct(); |
| 35 |
$this->options = $options = new Options($options, self::defaults()); |
| 36 |
$sc = $this->acquire(self::$crt->signing_config_aws_new()); |
| 37 |
self::$crt->signing_config_aws_set_algorithm($sc, $options->algorithm->asInt()); |
| 38 |
self::$crt->signing_config_aws_set_signature_type($sc, $options->signature_type->asInt()); |
| 39 |
if ($credentials_provider = $options->credentials_provider->asObject()) { |
| 40 |
self::$crt->signing_config_aws_set_credentials_provider( |
| 41 |
$sc, |
| 42 |
$credentials_provider->native); |
| 43 |
} |
| 44 |
self::$crt->signing_config_aws_set_region( |
| 45 |
$sc, $options->region->asString()); |
| 46 |
self::$crt->signing_config_aws_set_service( |
| 47 |
$sc, $options->service->asString()); |
| 48 |
self::$crt->signing_config_aws_set_use_double_uri_encode( |
| 49 |
$sc, $options->use_double_uri_encode->asBool()); |
| 50 |
self::$crt->signing_config_aws_set_should_normalize_uri_path( |
| 51 |
$sc, $options->should_normalize_uri_path->asBool()); |
| 52 |
self::$crt->signing_config_aws_set_omit_session_token( |
| 53 |
$sc, $options->omit_session_token->asBool()); |
| 54 |
self::$crt->signing_config_aws_set_signed_body_value( |
| 55 |
$sc, $options->signed_body_value->asString()); |
| 56 |
self::$crt->signing_config_aws_set_signed_body_header_type( |
| 57 |
$sc, $options->signed_body_header_type->asInt()); |
| 58 |
self::$crt->signing_config_aws_set_expiration_in_seconds( |
| 59 |
$sc, $options->expiration_in_seconds->asInt()); |
| 60 |
self::$crt->signing_config_aws_set_date($sc, $options->date->asInt()); |
| 61 |
if ($should_sign_header = $options->should_sign_header->asCallable()) { |
| 62 |
self::$crt->signing_config_aws_set_should_sign_header_fn($sc, $should_sign_header); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
function __destruct() |
| 67 |
{ |
| 68 |
self::$crt->signing_config_aws_release($this->release()); |
| 69 |
parent::__destruct(); |
| 70 |
} |
| 71 |
|
| 72 |
public function __get($name) { |
| 73 |
return $this->options->get($name); |
| 74 |
} |
| 75 |
} |