|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace AsyncAws\Sqs\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 AddPermissionRequest extends Input |
| 11 | +{ |
| 12 | + /** |
| 13 | + * The URL of the Amazon SQS queue to which permissions are added. |
| 14 | + * |
| 15 | + * Queue URLs and names are case-sensitive. |
| 16 | + * |
| 17 | + * @required |
| 18 | + * |
| 19 | + * @var string|null |
| 20 | + */ |
| 21 | + private $queueUrl; |
| 22 | + |
| 23 | + /** |
| 24 | + * The unique identification of the permission you're setting (for example, `AliceSendMessage`). Maximum 80 characters. |
| 25 | + * Allowed characters include alphanumeric characters, hyphens (`-`), and underscores (`_`). |
| 26 | + * |
| 27 | + * @required |
| 28 | + * |
| 29 | + * @var string|null |
| 30 | + */ |
| 31 | + private $label; |
| 32 | + |
| 33 | + /** |
| 34 | + * The Amazon Web Services account numbers of the principals [^1] who are to receive permission. For information about |
| 35 | + * locating the Amazon Web Services account identification, see Your Amazon Web Services Identifiers [^2] in the *Amazon |
| 36 | + * SQS Developer Guide*. |
| 37 | + * |
| 38 | + * [^1]: https://docs.aws.amazon.com/general/latest/gr/glos-chap.html#P |
| 39 | + * [^2]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-making-api-requests.html#sqs-api-request-authentication |
| 40 | + * |
| 41 | + * @required |
| 42 | + * |
| 43 | + * @var string[]|null |
| 44 | + */ |
| 45 | + private $awsAccountIds; |
| 46 | + |
| 47 | + /** |
| 48 | + * The action the client wants to allow for the specified principal. Valid values: the name of any action or `*`. |
| 49 | + * |
| 50 | + * For more information about these actions, see Overview of Managing Access Permissions to Your Amazon Simple Queue |
| 51 | + * Service Resource [^1] in the *Amazon SQS Developer Guide*. |
| 52 | + * |
| 53 | + * Specifying `SendMessage`, `DeleteMessage`, or `ChangeMessageVisibility` for `ActionName.n` also grants permissions |
| 54 | + * for the corresponding batch versions of those actions: `SendMessageBatch`, `DeleteMessageBatch`, and |
| 55 | + * `ChangeMessageVisibilityBatch`. |
| 56 | + * |
| 57 | + * [^1]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-overview-of-managing-access.html |
| 58 | + * |
| 59 | + * @required |
| 60 | + * |
| 61 | + * @var string[]|null |
| 62 | + */ |
| 63 | + private $actions; |
| 64 | + |
| 65 | + /** |
| 66 | + * @param array{ |
| 67 | + * QueueUrl?: string, |
| 68 | + * Label?: string, |
| 69 | + * AWSAccountIds?: string[], |
| 70 | + * Actions?: string[], |
| 71 | + * '@region'?: string|null, |
| 72 | + * } $input |
| 73 | + */ |
| 74 | + public function __construct(array $input = []) |
| 75 | + { |
| 76 | + $this->queueUrl = $input['QueueUrl'] ?? null; |
| 77 | + $this->label = $input['Label'] ?? null; |
| 78 | + $this->awsAccountIds = $input['AWSAccountIds'] ?? null; |
| 79 | + $this->actions = $input['Actions'] ?? null; |
| 80 | + parent::__construct($input); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @param array{ |
| 85 | + * QueueUrl?: string, |
| 86 | + * Label?: string, |
| 87 | + * AWSAccountIds?: string[], |
| 88 | + * Actions?: string[], |
| 89 | + * '@region'?: string|null, |
| 90 | + * }|AddPermissionRequest $input |
| 91 | + */ |
| 92 | + public static function create($input): self |
| 93 | + { |
| 94 | + return $input instanceof self ? $input : new self($input); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * @return string[] |
| 99 | + */ |
| 100 | + public function getActions(): array |
| 101 | + { |
| 102 | + return $this->actions ?? []; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * @return string[] |
| 107 | + */ |
| 108 | + public function getAwsAccountIds(): array |
| 109 | + { |
| 110 | + return $this->awsAccountIds ?? []; |
| 111 | + } |
| 112 | + |
| 113 | + public function getLabel(): ?string |
| 114 | + { |
| 115 | + return $this->label; |
| 116 | + } |
| 117 | + |
| 118 | + public function getQueueUrl(): ?string |
| 119 | + { |
| 120 | + return $this->queueUrl; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * @internal |
| 125 | + */ |
| 126 | + public function request(): Request |
| 127 | + { |
| 128 | + // Prepare headers |
| 129 | + $headers = [ |
| 130 | + 'Content-Type' => 'application/x-amz-json-1.0', |
| 131 | + 'X-Amz-Target' => 'AmazonSQS.AddPermission', |
| 132 | + 'Accept' => 'application/json', |
| 133 | + ]; |
| 134 | + |
| 135 | + // Prepare query |
| 136 | + $query = []; |
| 137 | + |
| 138 | + // Prepare URI |
| 139 | + $uriString = '/'; |
| 140 | + |
| 141 | + // Prepare Body |
| 142 | + $bodyPayload = $this->requestBody(); |
| 143 | + $body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304); |
| 144 | + |
| 145 | + // Return the Request |
| 146 | + return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body)); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * @param string[] $value |
| 151 | + */ |
| 152 | + public function setActions(array $value): self |
| 153 | + { |
| 154 | + $this->actions = $value; |
| 155 | + |
| 156 | + return $this; |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * @param string[] $value |
| 161 | + */ |
| 162 | + public function setAwsAccountIds(array $value): self |
| 163 | + { |
| 164 | + $this->awsAccountIds = $value; |
| 165 | + |
| 166 | + return $this; |
| 167 | + } |
| 168 | + |
| 169 | + public function setLabel(?string $value): self |
| 170 | + { |
| 171 | + $this->label = $value; |
| 172 | + |
| 173 | + return $this; |
| 174 | + } |
| 175 | + |
| 176 | + public function setQueueUrl(?string $value): self |
| 177 | + { |
| 178 | + $this->queueUrl = $value; |
| 179 | + |
| 180 | + return $this; |
| 181 | + } |
| 182 | + |
| 183 | + private function requestBody(): array |
| 184 | + { |
| 185 | + $payload = []; |
| 186 | + if (null === $v = $this->queueUrl) { |
| 187 | + throw new InvalidArgument(\sprintf('Missing parameter "QueueUrl" for "%s". The value cannot be null.', __CLASS__)); |
| 188 | + } |
| 189 | + $payload['QueueUrl'] = $v; |
| 190 | + if (null === $v = $this->label) { |
| 191 | + throw new InvalidArgument(\sprintf('Missing parameter "Label" for "%s". The value cannot be null.', __CLASS__)); |
| 192 | + } |
| 193 | + $payload['Label'] = $v; |
| 194 | + if (null === $v = $this->awsAccountIds) { |
| 195 | + throw new InvalidArgument(\sprintf('Missing parameter "AWSAccountIds" for "%s". The value cannot be null.', __CLASS__)); |
| 196 | + } |
| 197 | + |
| 198 | + $index = -1; |
| 199 | + $payload['AWSAccountIds'] = []; |
| 200 | + foreach ($v as $listValue) { |
| 201 | + ++$index; |
| 202 | + $payload['AWSAccountIds'][$index] = $listValue; |
| 203 | + } |
| 204 | + |
| 205 | + if (null === $v = $this->actions) { |
| 206 | + throw new InvalidArgument(\sprintf('Missing parameter "Actions" for "%s". The value cannot be null.', __CLASS__)); |
| 207 | + } |
| 208 | + |
| 209 | + $index = -1; |
| 210 | + $payload['Actions'] = []; |
| 211 | + foreach ($v as $listValue) { |
| 212 | + ++$index; |
| 213 | + $payload['Actions'][$index] = $listValue; |
| 214 | + } |
| 215 | + |
| 216 | + return $payload; |
| 217 | + } |
| 218 | +} |
0 commit comments