|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AsyncAws\Kms\Input; |
| 4 | + |
| 5 | +use AsyncAws\Core\Exception\InvalidArgument; |
| 6 | +use AsyncAws\Core\Input; |
| 7 | +use AsyncAws\Core\Request; |
| 8 | +use AsyncAws\Core\Stream\StreamFactory; |
| 9 | + |
| 10 | +final class GetPublicKeyRequest extends Input |
| 11 | +{ |
| 12 | + /** |
| 13 | + * Identifies the asymmetric KMS key that includes the public key. |
| 14 | + * |
| 15 | + * To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix it with |
| 16 | + * `"alias/"`. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN or alias ARN. |
| 17 | + * |
| 18 | + * For example: |
| 19 | + * |
| 20 | + * - Key ID: `1234abcd-12ab-34cd-56ef-1234567890ab` |
| 21 | + * - Key ARN: `arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab` |
| 22 | + * - Alias name: `alias/ExampleAlias` |
| 23 | + * - Alias ARN: `arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias` |
| 24 | + * |
| 25 | + * To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. To get the alias name and alias ARN, use |
| 26 | + * ListAliases. |
| 27 | + * |
| 28 | + * @required |
| 29 | + * |
| 30 | + * @var string|null |
| 31 | + */ |
| 32 | + private $keyId; |
| 33 | + |
| 34 | + /** |
| 35 | + * A list of grant tokens. |
| 36 | + * |
| 37 | + * Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved |
| 38 | + * *eventual consistency*. For more information, see Grant token [^1] and Using a grant token [^2] in the *Key |
| 39 | + * Management Service Developer Guide*. |
| 40 | + * |
| 41 | + * [^1]: https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#grant_token |
| 42 | + * [^2]: https://docs.aws.amazon.com/kms/latest/developerguide/grant-manage.html#using-grant-token |
| 43 | + * |
| 44 | + * @var string[]|null |
| 45 | + */ |
| 46 | + private $grantTokens; |
| 47 | + |
| 48 | + /** |
| 49 | + * @param array{ |
| 50 | + * KeyId?: string, |
| 51 | + * GrantTokens?: null|string[], |
| 52 | + * '@region'?: string|null, |
| 53 | + * } $input |
| 54 | + */ |
| 55 | + public function __construct(array $input = []) |
| 56 | + { |
| 57 | + $this->keyId = $input['KeyId'] ?? null; |
| 58 | + $this->grantTokens = $input['GrantTokens'] ?? null; |
| 59 | + parent::__construct($input); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @param array{ |
| 64 | + * KeyId?: string, |
| 65 | + * GrantTokens?: null|string[], |
| 66 | + * '@region'?: string|null, |
| 67 | + * }|GetPublicKeyRequest $input |
| 68 | + */ |
| 69 | + public static function create($input): self |
| 70 | + { |
| 71 | + return $input instanceof self ? $input : new self($input); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * @return string[] |
| 76 | + */ |
| 77 | + public function getGrantTokens(): array |
| 78 | + { |
| 79 | + return $this->grantTokens ?? []; |
| 80 | + } |
| 81 | + |
| 82 | + public function getKeyId(): ?string |
| 83 | + { |
| 84 | + return $this->keyId; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @internal |
| 89 | + */ |
| 90 | + public function request(): Request |
| 91 | + { |
| 92 | + // Prepare headers |
| 93 | + $headers = [ |
| 94 | + 'Content-Type' => 'application/x-amz-json-1.1', |
| 95 | + 'X-Amz-Target' => 'TrentService.GetPublicKey', |
| 96 | + 'Accept' => 'application/json', |
| 97 | + ]; |
| 98 | + |
| 99 | + // Prepare query |
| 100 | + $query = []; |
| 101 | + |
| 102 | + // Prepare URI |
| 103 | + $uriString = '/'; |
| 104 | + |
| 105 | + // Prepare Body |
| 106 | + $bodyPayload = $this->requestBody(); |
| 107 | + $body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304); |
| 108 | + |
| 109 | + // Return the Request |
| 110 | + return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body)); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * @param string[] $value |
| 115 | + */ |
| 116 | + public function setGrantTokens(array $value): self |
| 117 | + { |
| 118 | + $this->grantTokens = $value; |
| 119 | + |
| 120 | + return $this; |
| 121 | + } |
| 122 | + |
| 123 | + public function setKeyId(?string $value): self |
| 124 | + { |
| 125 | + $this->keyId = $value; |
| 126 | + |
| 127 | + return $this; |
| 128 | + } |
| 129 | + |
| 130 | + private function requestBody(): array |
| 131 | + { |
| 132 | + $payload = []; |
| 133 | + if (null === $v = $this->keyId) { |
| 134 | + throw new InvalidArgument(\sprintf('Missing parameter "KeyId" for "%s". The value cannot be null.', __CLASS__)); |
| 135 | + } |
| 136 | + $payload['KeyId'] = $v; |
| 137 | + if (null !== $v = $this->grantTokens) { |
| 138 | + $index = -1; |
| 139 | + $payload['GrantTokens'] = []; |
| 140 | + foreach ($v as $listValue) { |
| 141 | + ++$index; |
| 142 | + $payload['GrantTokens'][$index] = $listValue; |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + return $payload; |
| 147 | + } |
| 148 | +} |
0 commit comments