-
-
Notifications
You must be signed in to change notification settings - Fork 144
Add SQS AddPermission operation #1773
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93cc4c1
Add SQS AddPermission operation
stevenbrookes 98c79d8
Add missing SQS AddPermission test
stevenbrookes 9b7d15a
Fix PHPCSFixer issue
stevenbrookes 4a4636c
Add to changelog
stevenbrookes 339070e
Fixup changelog
stevenbrookes 9c07d90
Fix order
stevenbrookes 57fe32c
Fixup composer
stevenbrookes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
<?php | ||
|
||
namespace AsyncAws\Sqs\Input; | ||
|
||
use AsyncAws\Core\Exception\InvalidArgument; | ||
use AsyncAws\Core\Input; | ||
use AsyncAws\Core\Request; | ||
use AsyncAws\Core\Stream\StreamFactory; | ||
|
||
final class AddPermissionRequest extends Input | ||
{ | ||
/** | ||
* The URL of the Amazon SQS queue to which permissions are added. | ||
* | ||
* Queue URLs and names are case-sensitive. | ||
* | ||
* @required | ||
* | ||
* @var string|null | ||
*/ | ||
private $queueUrl; | ||
|
||
/** | ||
* The unique identification of the permission you're setting (for example, `AliceSendMessage`). Maximum 80 characters. | ||
* Allowed characters include alphanumeric characters, hyphens (`-`), and underscores (`_`). | ||
* | ||
* @required | ||
* | ||
* @var string|null | ||
*/ | ||
private $label; | ||
|
||
/** | ||
* The Amazon Web Services account numbers of the principals [^1] who are to receive permission. For information about | ||
* locating the Amazon Web Services account identification, see Your Amazon Web Services Identifiers [^2] in the *Amazon | ||
* SQS Developer Guide*. | ||
* | ||
* [^1]: https://docs.aws.amazon.com/general/latest/gr/glos-chap.html#P | ||
* [^2]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-making-api-requests.html#sqs-api-request-authentication | ||
* | ||
* @required | ||
* | ||
* @var string[]|null | ||
*/ | ||
private $awsAccountIds; | ||
|
||
/** | ||
* The action the client wants to allow for the specified principal. Valid values: the name of any action or `*`. | ||
* | ||
* For more information about these actions, see Overview of Managing Access Permissions to Your Amazon Simple Queue | ||
* Service Resource [^1] in the *Amazon SQS Developer Guide*. | ||
* | ||
* Specifying `SendMessage`, `DeleteMessage`, or `ChangeMessageVisibility` for `ActionName.n` also grants permissions | ||
* for the corresponding batch versions of those actions: `SendMessageBatch`, `DeleteMessageBatch`, and | ||
* `ChangeMessageVisibilityBatch`. | ||
* | ||
* [^1]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-overview-of-managing-access.html | ||
* | ||
* @required | ||
* | ||
* @var string[]|null | ||
*/ | ||
private $actions; | ||
|
||
/** | ||
* @param array{ | ||
* QueueUrl?: string, | ||
* Label?: string, | ||
* AWSAccountIds?: string[], | ||
* Actions?: string[], | ||
* '@region'?: string|null, | ||
* } $input | ||
*/ | ||
public function __construct(array $input = []) | ||
{ | ||
$this->queueUrl = $input['QueueUrl'] ?? null; | ||
$this->label = $input['Label'] ?? null; | ||
$this->awsAccountIds = $input['AWSAccountIds'] ?? null; | ||
$this->actions = $input['Actions'] ?? null; | ||
parent::__construct($input); | ||
} | ||
|
||
/** | ||
* @param array{ | ||
* QueueUrl?: string, | ||
* Label?: string, | ||
* AWSAccountIds?: string[], | ||
* Actions?: string[], | ||
* '@region'?: string|null, | ||
* }|AddPermissionRequest $input | ||
*/ | ||
public static function create($input): self | ||
{ | ||
return $input instanceof self ? $input : new self($input); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getActions(): array | ||
{ | ||
return $this->actions ?? []; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getAwsAccountIds(): array | ||
{ | ||
return $this->awsAccountIds ?? []; | ||
} | ||
|
||
public function getLabel(): ?string | ||
{ | ||
return $this->label; | ||
} | ||
|
||
public function getQueueUrl(): ?string | ||
{ | ||
return $this->queueUrl; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function request(): Request | ||
{ | ||
// Prepare headers | ||
$headers = [ | ||
'Content-Type' => 'application/x-amz-json-1.0', | ||
'X-Amz-Target' => 'AmazonSQS.AddPermission', | ||
'Accept' => 'application/json', | ||
]; | ||
|
||
// Prepare query | ||
$query = []; | ||
|
||
// Prepare URI | ||
$uriString = '/'; | ||
|
||
// Prepare Body | ||
$bodyPayload = $this->requestBody(); | ||
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304); | ||
|
||
// Return the Request | ||
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body)); | ||
} | ||
|
||
/** | ||
* @param string[] $value | ||
*/ | ||
public function setActions(array $value): self | ||
{ | ||
$this->actions = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string[] $value | ||
*/ | ||
public function setAwsAccountIds(array $value): self | ||
{ | ||
$this->awsAccountIds = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function setLabel(?string $value): self | ||
{ | ||
$this->label = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function setQueueUrl(?string $value): self | ||
{ | ||
$this->queueUrl = $value; | ||
|
||
return $this; | ||
} | ||
|
||
private function requestBody(): array | ||
{ | ||
$payload = []; | ||
if (null === $v = $this->queueUrl) { | ||
throw new InvalidArgument(\sprintf('Missing parameter "QueueUrl" for "%s". The value cannot be null.', __CLASS__)); | ||
} | ||
$payload['QueueUrl'] = $v; | ||
if (null === $v = $this->label) { | ||
throw new InvalidArgument(\sprintf('Missing parameter "Label" for "%s". The value cannot be null.', __CLASS__)); | ||
} | ||
$payload['Label'] = $v; | ||
if (null === $v = $this->awsAccountIds) { | ||
throw new InvalidArgument(\sprintf('Missing parameter "AWSAccountIds" for "%s". The value cannot be null.', __CLASS__)); | ||
} | ||
|
||
$index = -1; | ||
$payload['AWSAccountIds'] = []; | ||
foreach ($v as $listValue) { | ||
++$index; | ||
$payload['AWSAccountIds'][$index] = $listValue; | ||
} | ||
|
||
if (null === $v = $this->actions) { | ||
throw new InvalidArgument(\sprintf('Missing parameter "Actions" for "%s". The value cannot be null.', __CLASS__)); | ||
} | ||
|
||
$index = -1; | ||
$payload['Actions'] = []; | ||
foreach ($v as $listValue) { | ||
++$index; | ||
$payload['Actions'][$index] = $listValue; | ||
} | ||
|
||
return $payload; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Service/Sqs/tests/Unit/Input/AddPermissionRequestTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace AsyncAws\Sqs\Tests\Unit\Input; | ||
|
||
use AsyncAws\Core\Test\TestCase; | ||
use AsyncAws\Sqs\Input\AddPermissionRequest; | ||
|
||
class AddPermissionRequestTest extends TestCase | ||
{ | ||
public function testRequest(): void | ||
{ | ||
$input = new AddPermissionRequest([ | ||
'QueueUrl' => 'https://sqs.us-east-1.amazonaws.com/177715257436/MyQueue/', | ||
'Label' => 'MyLabel', | ||
'AWSAccountIds' => ['177715257436', '111111111111'], | ||
'Actions' => ['SendMessage', 'ReceiveMessage'], | ||
]); | ||
|
||
// see https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_AddPermission.html | ||
$expected = ' | ||
POST / HTTP/1.0 | ||
Content-Type: application/x-amz-json-1.0 | ||
x-amz-target: AmazonSQS.AddPermission | ||
Accept: application/json | ||
|
||
{ | ||
"QueueUrl": "https://sqs.us-east-1.amazonaws.com/177715257436/MyQueue/", | ||
"Label": "MyLabel", | ||
"Actions": ["SendMessage", "ReceiveMessage"], | ||
"AWSAccountIds": ["177715257436", "111111111111"] | ||
}'; | ||
|
||
self::assertRequestEqualsHttpRequest($expected, $input->request()); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.