Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd548d2

Browse files
authored
Add new operation Ssm::deleteParameters (async-aws#1167)
* Add operation Ssm::deleteParameters * php-cs-fixer * Update CHANGELOG.md
1 parent 945bd30 commit dd548d2

9 files changed

Lines changed: 279 additions & 0 deletions

File tree

manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@
487487
"api-reference": "https://docs.aws.amazon.com/systems-manager/latest/APIReference",
488488
"methods": [
489489
"DeleteParameter",
490+
"DeleteParameters",
490491
"GetParameter",
491492
"GetParameters",
492493
"GetParametersByPath",

src/Service/Ssm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- AWS api-change: Added `ca-central-1` region
88
- AWS api-change: Use specific configuration for `us` regions
99
- AWS enhancement: Documentation updates.
10+
- Added operation `DeleteParameters`
1011

1112
## 1.2.1
1213

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace AsyncAws\Ssm\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 DeleteParametersRequest extends Input
11+
{
12+
/**
13+
* The names of the parameters to delete. After deleting a parameter, wait for at least 30 seconds to create a parameter
14+
* with the same name.
15+
*
16+
* @required
17+
*
18+
* @var string[]|null
19+
*/
20+
private $names;
21+
22+
/**
23+
* @param array{
24+
* Names?: string[],
25+
* @region?: string,
26+
* } $input
27+
*/
28+
public function __construct(array $input = [])
29+
{
30+
$this->names = $input['Names'] ?? null;
31+
parent::__construct($input);
32+
}
33+
34+
public static function create($input): self
35+
{
36+
return $input instanceof self ? $input : new self($input);
37+
}
38+
39+
/**
40+
* @return string[]
41+
*/
42+
public function getNames(): array
43+
{
44+
return $this->names ?? [];
45+
}
46+
47+
/**
48+
* @internal
49+
*/
50+
public function request(): Request
51+
{
52+
// Prepare headers
53+
$headers = [
54+
'Content-Type' => 'application/x-amz-json-1.1',
55+
'X-Amz-Target' => 'AmazonSSM.DeleteParameters',
56+
];
57+
58+
// Prepare query
59+
$query = [];
60+
61+
// Prepare URI
62+
$uriString = '/';
63+
64+
// Prepare Body
65+
$bodyPayload = $this->requestBody();
66+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304);
67+
68+
// Return the Request
69+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
70+
}
71+
72+
/**
73+
* @param string[] $value
74+
*/
75+
public function setNames(array $value): self
76+
{
77+
$this->names = $value;
78+
79+
return $this;
80+
}
81+
82+
private function requestBody(): array
83+
{
84+
$payload = [];
85+
if (null === $v = $this->names) {
86+
throw new InvalidArgument(sprintf('Missing parameter "Names" for "%s". The value cannot be null.', __CLASS__));
87+
}
88+
89+
$index = -1;
90+
$payload['Names'] = [];
91+
foreach ($v as $listValue) {
92+
++$index;
93+
$payload['Names'][$index] = $listValue;
94+
}
95+
96+
return $payload;
97+
}
98+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace AsyncAws\Ssm\Result;
4+
5+
use AsyncAws\Core\Response;
6+
use AsyncAws\Core\Result;
7+
8+
class DeleteParametersResult extends Result
9+
{
10+
/**
11+
* The names of the deleted parameters.
12+
*/
13+
private $deletedParameters;
14+
15+
/**
16+
* The names of parameters that weren't deleted because the parameters aren't valid.
17+
*/
18+
private $invalidParameters;
19+
20+
/**
21+
* @return string[]
22+
*/
23+
public function getDeletedParameters(): array
24+
{
25+
$this->initialize();
26+
27+
return $this->deletedParameters;
28+
}
29+
30+
/**
31+
* @return string[]
32+
*/
33+
public function getInvalidParameters(): array
34+
{
35+
$this->initialize();
36+
37+
return $this->invalidParameters;
38+
}
39+
40+
protected function populateResult(Response $response): void
41+
{
42+
$data = $response->toArray();
43+
44+
$this->deletedParameters = empty($data['DeletedParameters']) ? [] : $this->populateResultParameterNameList($data['DeletedParameters']);
45+
$this->invalidParameters = empty($data['InvalidParameters']) ? [] : $this->populateResultParameterNameList($data['InvalidParameters']);
46+
}
47+
48+
/**
49+
* @return string[]
50+
*/
51+
private function populateResultParameterNameList(array $json): array
52+
{
53+
$items = [];
54+
foreach ($json as $item) {
55+
$a = isset($item) ? (string) $item : null;
56+
if (null !== $a) {
57+
$items[] = $a;
58+
}
59+
}
60+
61+
return $items;
62+
}
63+
}

src/Service/Ssm/src/SsmClient.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
use AsyncAws\Ssm\Exception\TooManyUpdatesException;
3232
use AsyncAws\Ssm\Exception\UnsupportedParameterTypeException;
3333
use AsyncAws\Ssm\Input\DeleteParameterRequest;
34+
use AsyncAws\Ssm\Input\DeleteParametersRequest;
3435
use AsyncAws\Ssm\Input\GetParameterRequest;
3536
use AsyncAws\Ssm\Input\GetParametersByPathRequest;
3637
use AsyncAws\Ssm\Input\GetParametersRequest;
3738
use AsyncAws\Ssm\Input\PutParameterRequest;
3839
use AsyncAws\Ssm\Result\DeleteParameterResult;
40+
use AsyncAws\Ssm\Result\DeleteParametersResult;
3941
use AsyncAws\Ssm\Result\GetParameterResult;
4042
use AsyncAws\Ssm\Result\GetParametersByPathResult;
4143
use AsyncAws\Ssm\Result\GetParametersResult;
@@ -72,6 +74,30 @@ public function deleteParameter($input): DeleteParameterResult
7274
return new DeleteParameterResult($response);
7375
}
7476

77+
/**
78+
* Delete a list of parameters. After deleting a parameter, wait for at least 30 seconds to create a parameter with the
79+
* same name.
80+
*
81+
* @see https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DeleteParameters.html
82+
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ssm-2014-11-06.html#deleteparameters
83+
*
84+
* @param array{
85+
* Names: string[],
86+
* @region?: string,
87+
* }|DeleteParametersRequest $input
88+
*
89+
* @throws InternalServerErrorException
90+
*/
91+
public function deleteParameters($input): DeleteParametersResult
92+
{
93+
$input = DeleteParametersRequest::create($input);
94+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DeleteParameters', 'region' => $input->getRegion(), 'exceptionMapping' => [
95+
'InternalServerError' => InternalServerErrorException::class,
96+
]]));
97+
98+
return new DeleteParametersResult($response);
99+
}
100+
75101
/**
76102
* Get information about a single parameter by specifying the parameter name.
77103
*

src/Service/Ssm/tests/Integration/SsmClientTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use AsyncAws\Ssm\Enum\ParameterTier;
99
use AsyncAws\Ssm\Enum\ParameterType;
1010
use AsyncAws\Ssm\Input\DeleteParameterRequest;
11+
use AsyncAws\Ssm\Input\DeleteParametersRequest;
1112
use AsyncAws\Ssm\Input\GetParameterRequest;
1213
use AsyncAws\Ssm\Input\GetParametersByPathRequest;
1314
use AsyncAws\Ssm\Input\GetParametersRequest;
@@ -74,6 +75,21 @@ public function testDeleteParameter(): void
7475
$result->resolve();
7576
}
7677

78+
public function testDeleteParameters(): void
79+
{
80+
$client = $this->getClient();
81+
82+
$input = new DeleteParametersRequest([
83+
'Names' => ['/app/database/host'],
84+
]);
85+
$result = $client->deleteParameters($input);
86+
87+
$result->resolve();
88+
89+
self::assertEquals(['/app/database/host'], $result->getDeletedParameters());
90+
self::assertEquals([], $result->getInvalidParameters());
91+
}
92+
7793
public function testGetParameter(): void
7894
{
7995
$client = $this->getClient();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace AsyncAws\Ssm\Tests\Unit\Input;
4+
5+
use AsyncAws\Core\Test\TestCase;
6+
use AsyncAws\Ssm\Input\DeleteParametersRequest;
7+
8+
class DeleteParametersRequestTest extends TestCase
9+
{
10+
public function testRequest(): void
11+
{
12+
$input = new DeleteParametersRequest([
13+
'Names' => ['DB_HOST'],
14+
]);
15+
16+
// see https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DeleteParameters.html
17+
$expected = '
18+
POST / HTTP/1.0
19+
Content-Type: application/x-amz-json-1.1
20+
X-Amz-Target: AmazonSSM.DeleteParameters
21+
22+
{
23+
"Names": [
24+
"DB_HOST"
25+
]
26+
}
27+
';
28+
29+
self::assertRequestEqualsHttpRequest($expected, $input->request());
30+
}
31+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace AsyncAws\Ssm\Tests\Unit\Result;
4+
5+
use AsyncAws\Core\Response;
6+
use AsyncAws\Core\Test\Http\SimpleMockedResponse;
7+
use AsyncAws\Core\Test\TestCase;
8+
use AsyncAws\Ssm\Result\DeleteParametersResult;
9+
use Psr\Log\NullLogger;
10+
use Symfony\Component\HttpClient\MockHttpClient;
11+
12+
class DeleteParametersResultTest extends TestCase
13+
{
14+
public function testDeleteParametersResult(): void
15+
{
16+
// see https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DeleteParameters.html
17+
$response = new SimpleMockedResponse('{
18+
"DeletedParameters": ["DB_HOST"],
19+
"InvalidParameters": ["DB_USER"]
20+
}');
21+
22+
$client = new MockHttpClient($response);
23+
$result = new DeleteParametersResult(new Response($client->request('POST', 'http://localhost'), $client, new NullLogger()));
24+
25+
self::assertEquals(['DB_HOST'], $result->getDeletedParameters());
26+
self::assertEquals(['DB_USER'], $result->getInvalidParameters());
27+
}
28+
}

src/Service/Ssm/tests/Unit/SsmClientTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
use AsyncAws\Core\Test\TestCase;
77
use AsyncAws\Ssm\Enum\ParameterType;
88
use AsyncAws\Ssm\Input\DeleteParameterRequest;
9+
use AsyncAws\Ssm\Input\DeleteParametersRequest;
910
use AsyncAws\Ssm\Input\GetParameterRequest;
1011
use AsyncAws\Ssm\Input\GetParametersByPathRequest;
1112
use AsyncAws\Ssm\Input\GetParametersRequest;
1213
use AsyncAws\Ssm\Input\PutParameterRequest;
1314
use AsyncAws\Ssm\Result\DeleteParameterResult;
15+
use AsyncAws\Ssm\Result\DeleteParametersResult;
1416
use AsyncAws\Ssm\Result\GetParameterResult;
1517
use AsyncAws\Ssm\Result\GetParametersByPathResult;
1618
use AsyncAws\Ssm\Result\GetParametersResult;
@@ -33,6 +35,19 @@ public function testDeleteParameter(): void
3335
self::assertFalse($result->info()['resolved']);
3436
}
3537

38+
public function testDeleteParameters(): void
39+
{
40+
$client = new SsmClient([], new NullProvider(), new MockHttpClient());
41+
42+
$input = new DeleteParametersRequest([
43+
'Names' => ['change me'],
44+
]);
45+
$result = $client->deleteParameters($input);
46+
47+
self::assertInstanceOf(DeleteParametersResult::class, $result);
48+
self::assertFalse($result->info()['resolved']);
49+
}
50+
3651
public function testGetParameter(): void
3752
{
3853
$client = new SsmClient([], new NullProvider(), new MockHttpClient());

0 commit comments

Comments
 (0)