Skip to content

Commit c010545

Browse files
authored
Merge validate with request (#322)
* Merge validate with request * More readable input * Fix Input request
1 parent 9cd9ec8 commit c010545

File tree

8 files changed

+37
-124
lines changed

8 files changed

+37
-124
lines changed

src/Sts/Input/AssumeRoleRequest.php

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -303,41 +303,26 @@ public function setTransitiveTagKeys(array $value): self
303303
return $this;
304304
}
305305

306-
public function validate(): void
307-
{
308-
if (null === $this->RoleArn) {
309-
throw new InvalidArgument(sprintf('Missing parameter "RoleArn" when validating the "%s". The value cannot be null.', __CLASS__));
310-
}
311-
312-
if (null === $this->RoleSessionName) {
313-
throw new InvalidArgument(sprintf('Missing parameter "RoleSessionName" when validating the "%s". The value cannot be null.', __CLASS__));
314-
}
315-
316-
foreach ($this->PolicyArns as $item) {
317-
$item->validate();
318-
}
319-
320-
foreach ($this->Tags as $item) {
321-
$item->validate();
322-
}
323-
}
324-
325306
/**
326307
* @internal
327308
*/
328309
private function requestBody(): array
329310
{
330311
$payload = [];
331-
$payload['RoleArn'] = $this->RoleArn;
332-
$payload['RoleSessionName'] = $this->RoleSessionName;
312+
if (null === $v = $this->RoleArn) {
313+
throw new InvalidArgument(sprintf('Missing parameter "RoleArn" for "%s". The value cannot be null.', __CLASS__));
314+
}
315+
$payload['RoleArn'] = $v;
316+
if (null === $v = $this->RoleSessionName) {
317+
throw new InvalidArgument(sprintf('Missing parameter "RoleSessionName" for "%s". The value cannot be null.', __CLASS__));
318+
}
319+
$payload['RoleSessionName'] = $v;
333320

334321
$index = 0;
335322
foreach ($this->PolicyArns as $mapValue) {
336323
++$index;
337-
if (null !== $v = $mapValue) {
338-
foreach ($v->requestBody() as $bodyKey => $bodyValue) {
339-
$payload["PolicyArns.member.{$index}.$bodyKey"] = $bodyValue;
340-
}
324+
foreach ($mapValue->requestBody() as $bodyKey => $bodyValue) {
325+
$payload["PolicyArns.member.{$index}.$bodyKey"] = $bodyValue;
341326
}
342327
}
343328

@@ -351,10 +336,8 @@ private function requestBody(): array
351336
$index = 0;
352337
foreach ($this->Tags as $mapValue) {
353338
++$index;
354-
if (null !== $v = $mapValue) {
355-
foreach ($v->requestBody() as $bodyKey => $bodyValue) {
356-
$payload["Tags.member.{$index}.$bodyKey"] = $bodyValue;
357-
}
339+
foreach ($mapValue->requestBody() as $bodyKey => $bodyValue) {
340+
$payload["Tags.member.{$index}.$bodyKey"] = $bodyValue;
358341
}
359342
}
360343

src/Sts/Input/AssumeRoleWithWebIdentityRequest.php

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -214,45 +214,33 @@ public function setWebIdentityToken(?string $value): self
214214
return $this;
215215
}
216216

217-
public function validate(): void
218-
{
219-
if (null === $this->RoleArn) {
220-
throw new InvalidArgument(sprintf('Missing parameter "RoleArn" when validating the "%s". The value cannot be null.', __CLASS__));
221-
}
222-
223-
if (null === $this->RoleSessionName) {
224-
throw new InvalidArgument(sprintf('Missing parameter "RoleSessionName" when validating the "%s". The value cannot be null.', __CLASS__));
225-
}
226-
227-
if (null === $this->WebIdentityToken) {
228-
throw new InvalidArgument(sprintf('Missing parameter "WebIdentityToken" when validating the "%s". The value cannot be null.', __CLASS__));
229-
}
230-
231-
foreach ($this->PolicyArns as $item) {
232-
$item->validate();
233-
}
234-
}
235-
236217
/**
237218
* @internal
238219
*/
239220
private function requestBody(): array
240221
{
241222
$payload = [];
242-
$payload['RoleArn'] = $this->RoleArn;
243-
$payload['RoleSessionName'] = $this->RoleSessionName;
244-
$payload['WebIdentityToken'] = $this->WebIdentityToken;
223+
if (null === $v = $this->RoleArn) {
224+
throw new InvalidArgument(sprintf('Missing parameter "RoleArn" for "%s". The value cannot be null.', __CLASS__));
225+
}
226+
$payload['RoleArn'] = $v;
227+
if (null === $v = $this->RoleSessionName) {
228+
throw new InvalidArgument(sprintf('Missing parameter "RoleSessionName" for "%s". The value cannot be null.', __CLASS__));
229+
}
230+
$payload['RoleSessionName'] = $v;
231+
if (null === $v = $this->WebIdentityToken) {
232+
throw new InvalidArgument(sprintf('Missing parameter "WebIdentityToken" for "%s". The value cannot be null.', __CLASS__));
233+
}
234+
$payload['WebIdentityToken'] = $v;
245235
if (null !== $v = $this->ProviderId) {
246236
$payload['ProviderId'] = $v;
247237
}
248238

249239
$index = 0;
250240
foreach ($this->PolicyArns as $mapValue) {
251241
++$index;
252-
if (null !== $v = $mapValue) {
253-
foreach ($v->requestBody() as $bodyKey => $bodyValue) {
254-
$payload["PolicyArns.member.{$index}.$bodyKey"] = $bodyValue;
255-
}
242+
foreach ($mapValue->requestBody() as $bodyKey => $bodyValue) {
243+
$payload["PolicyArns.member.{$index}.$bodyKey"] = $bodyValue;
256244
}
257245
}
258246

src/Sts/Input/GetCallerIdentityRequest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ public function request(): Request
3333
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
3434
}
3535

36-
public function validate(): void
37-
{
38-
// There are no required properties
39-
}
40-
4136
/**
4237
* @internal
4338
*/

src/Sts/StsClient.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ class StsClient extends AbstractApi
3838
*/
3939
public function assumeRole($input): AssumeRoleResponse
4040
{
41-
$input = AssumeRoleRequest::create($input);
42-
$input->validate();
43-
44-
$response = $this->getResponse($input->request());
41+
$response = $this->getResponse(AssumeRoleRequest::create($input)->request());
4542

4643
return new AssumeRoleResponse($response, $this->httpClient);
4744
}
@@ -65,10 +62,7 @@ public function assumeRole($input): AssumeRoleResponse
6562
*/
6663
public function assumeRoleWithWebIdentity($input): AssumeRoleWithWebIdentityResponse
6764
{
68-
$input = AssumeRoleWithWebIdentityRequest::create($input);
69-
$input->validate();
70-
71-
$response = $this->getResponse($input->request());
65+
$response = $this->getResponse(AssumeRoleWithWebIdentityRequest::create($input)->request());
7266

7367
return new AssumeRoleWithWebIdentityResponse($response, $this->httpClient);
7468
}
@@ -82,10 +76,7 @@ public function assumeRoleWithWebIdentity($input): AssumeRoleWithWebIdentityResp
8276
*/
8377
public function getCallerIdentity($input = []): GetCallerIdentityResponse
8478
{
85-
$input = GetCallerIdentityRequest::create($input);
86-
$input->validate();
87-
88-
$response = $this->getResponse($input->request());
79+
$response = $this->getResponse(GetCallerIdentityRequest::create($input)->request());
8980

9081
return new GetCallerIdentityResponse($response, $this->httpClient);
9182
}

src/Sts/ValueObject/AssumedRoleUser.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace AsyncAws\Core\Sts\ValueObject;
44

5-
use AsyncAws\Core\Exception\InvalidArgument;
6-
75
class AssumedRoleUser
86
{
97
/**
@@ -46,15 +44,4 @@ public function getAssumedRoleId(): string
4644
{
4745
return $this->AssumedRoleId;
4846
}
49-
50-
public function validate(): void
51-
{
52-
if (null === $this->AssumedRoleId) {
53-
throw new InvalidArgument(sprintf('Missing parameter "AssumedRoleId" when validating the "%s". The value cannot be null.', __CLASS__));
54-
}
55-
56-
if (null === $this->Arn) {
57-
throw new InvalidArgument(sprintf('Missing parameter "Arn" when validating the "%s". The value cannot be null.', __CLASS__));
58-
}
59-
}
6047
}

src/Sts/ValueObject/Credentials.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace AsyncAws\Core\Sts\ValueObject;
44

5-
use AsyncAws\Core\Exception\InvalidArgument;
6-
75
class Credentials
86
{
97
/**
@@ -66,23 +64,4 @@ public function getSessionToken(): string
6664
{
6765
return $this->SessionToken;
6866
}
69-
70-
public function validate(): void
71-
{
72-
if (null === $this->AccessKeyId) {
73-
throw new InvalidArgument(sprintf('Missing parameter "AccessKeyId" when validating the "%s". The value cannot be null.', __CLASS__));
74-
}
75-
76-
if (null === $this->SecretAccessKey) {
77-
throw new InvalidArgument(sprintf('Missing parameter "SecretAccessKey" when validating the "%s". The value cannot be null.', __CLASS__));
78-
}
79-
80-
if (null === $this->SessionToken) {
81-
throw new InvalidArgument(sprintf('Missing parameter "SessionToken" when validating the "%s". The value cannot be null.', __CLASS__));
82-
}
83-
84-
if (null === $this->Expiration) {
85-
throw new InvalidArgument(sprintf('Missing parameter "Expiration" when validating the "%s". The value cannot be null.', __CLASS__));
86-
}
87-
}
8867
}

src/Sts/ValueObject/PolicyDescriptorType.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,4 @@ public function requestBody(): array
4444

4545
return $payload;
4646
}
47-
48-
public function validate(): void
49-
{
50-
// There are no required properties
51-
}
5247
}

src/Sts/ValueObject/Tag.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,15 @@ public function getValue(): string
4949
public function requestBody(): array
5050
{
5151
$payload = [];
52-
$payload['Key'] = $this->Key;
53-
$payload['Value'] = $this->Value;
54-
55-
return $payload;
56-
}
57-
58-
public function validate(): void
59-
{
60-
if (null === $this->Key) {
61-
throw new InvalidArgument(sprintf('Missing parameter "Key" when validating the "%s". The value cannot be null.', __CLASS__));
52+
if (null === $v = $this->Key) {
53+
throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__));
6254
}
63-
64-
if (null === $this->Value) {
65-
throw new InvalidArgument(sprintf('Missing parameter "Value" when validating the "%s". The value cannot be null.', __CLASS__));
55+
$payload['Key'] = $v;
56+
if (null === $v = $this->Value) {
57+
throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__));
6658
}
59+
$payload['Value'] = $v;
60+
61+
return $payload;
6762
}
6863
}

0 commit comments

Comments
 (0)