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

Skip to content

Commit 06c6f58

Browse files
Implement GetBucketEncryption and ListBuckets (async-aws#1182)
* Support generation of operations without input * Implement `GetBucketEncryption` and `ListBuckets` * Fixes * Update GetBucketEncryptionOutputTest.php * Update src/Service/S3/tests/Integration/S3ClientTest.php Co-authored-by: Jérémy Derussé <[email protected]> * Update Operation.php * Update Operation.php * Update S3ClientTest.php Co-authored-by: Jérémy Derussé <[email protected]>
1 parent 110c914 commit 06c6f58

18 files changed

Lines changed: 727 additions & 11 deletions

manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,11 @@
366366
"DeleteObject",
367367
"DeleteObjects",
368368
"GetBucketCors",
369+
"GetBucketEncryption",
369370
"GetObject",
370371
"GetObjectAcl",
371372
"HeadObject",
373+
"ListBuckets",
372374
"ListMultipartUploads",
373375
"ListObjectsV2",
374376
"ListParts",

src/CodeGenerator/src/Definition/Operation.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,13 @@ public function getErrors(): array
120120

121121
public function getInput(): StructureShape
122122
{
123-
if (isset($this->data['input']['shape'])) {
124-
$shape = ($this->shapeLocator)($this->data['input']['shape']);
125-
126-
if (!$shape instanceof StructureShape) {
127-
throw new \InvalidArgumentException(sprintf('The operation "%s" should have an Structure Input.', $this->getName()));
128-
}
123+
$shape = $this->getInputShape();
129124

130-
return $shape;
125+
if (!$shape instanceof StructureShape) {
126+
throw new \InvalidArgumentException(sprintf('The operation "%s" should have an Structure Input.', $this->getName()));
131127
}
132128

133-
throw new \InvalidArgumentException(sprintf('The operation "%s" does not have Input.', $this->getName()));
129+
return $shape;
134130
}
135131

136132
public function getInputLocation(): ?string
@@ -176,4 +172,22 @@ public function isDeprecated(): bool
176172
{
177173
return $this->data['deprecated'] ?? false;
178174
}
175+
176+
private function getInputShape(): Shape
177+
{
178+
if (isset($this->data['input']['shape'])) {
179+
return ($this->shapeLocator)($this->data['input']['shape']);
180+
}
181+
182+
return Shape::create(
183+
sprintf('%sRequest', $this->getName()),
184+
['type' => 'structure', 'required' => [], 'members' => []],
185+
function () {
186+
return null;
187+
},
188+
function () {
189+
return null;
190+
}
191+
);
192+
}
179193
}

src/CodeGenerator/src/Definition/Shape.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getName(): string
6464

6565
public function getDocumentation(): ?string
6666
{
67-
return $this->data['_documentation'];
67+
return $this->data['_documentation'] ?? null;
6868
}
6969

7070
public function getType(): string
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace AsyncAws\S3\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 GetBucketEncryptionRequest extends Input
11+
{
12+
/**
13+
* The name of the bucket from which the server-side encryption configuration is retrieved.
14+
*
15+
* @required
16+
*
17+
* @var string|null
18+
*/
19+
private $bucket;
20+
21+
/**
22+
* The account ID of the expected bucket owner. If the bucket is owned by a different account, the request will fail
23+
* with an HTTP `403 (Access Denied)` error.
24+
*
25+
* @var string|null
26+
*/
27+
private $expectedBucketOwner;
28+
29+
/**
30+
* @param array{
31+
* Bucket?: string,
32+
* ExpectedBucketOwner?: string,
33+
* @region?: string,
34+
* } $input
35+
*/
36+
public function __construct(array $input = [])
37+
{
38+
$this->bucket = $input['Bucket'] ?? null;
39+
$this->expectedBucketOwner = $input['ExpectedBucketOwner'] ?? null;
40+
parent::__construct($input);
41+
}
42+
43+
public static function create($input): self
44+
{
45+
return $input instanceof self ? $input : new self($input);
46+
}
47+
48+
public function getBucket(): ?string
49+
{
50+
return $this->bucket;
51+
}
52+
53+
public function getExpectedBucketOwner(): ?string
54+
{
55+
return $this->expectedBucketOwner;
56+
}
57+
58+
/**
59+
* @internal
60+
*/
61+
public function request(): Request
62+
{
63+
// Prepare headers
64+
$headers = ['content-type' => 'application/xml'];
65+
if (null !== $this->expectedBucketOwner) {
66+
$headers['x-amz-expected-bucket-owner'] = $this->expectedBucketOwner;
67+
}
68+
69+
// Prepare query
70+
$query = [];
71+
72+
// Prepare URI
73+
$uri = [];
74+
if (null === $v = $this->bucket) {
75+
throw new InvalidArgument(sprintf('Missing parameter "Bucket" for "%s". The value cannot be null.', __CLASS__));
76+
}
77+
$uri['Bucket'] = $v;
78+
$uriString = '/' . rawurlencode($uri['Bucket']) . '?encryption';
79+
80+
// Prepare Body
81+
$body = '';
82+
83+
// Return the Request
84+
return new Request('GET', $uriString, $query, $headers, StreamFactory::create($body));
85+
}
86+
87+
public function setBucket(?string $value): self
88+
{
89+
$this->bucket = $value;
90+
91+
return $this;
92+
}
93+
94+
public function setExpectedBucketOwner(?string $value): self
95+
{
96+
$this->expectedBucketOwner = $value;
97+
98+
return $this;
99+
}
100+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace AsyncAws\S3\Input;
4+
5+
use AsyncAws\Core\Input;
6+
use AsyncAws\Core\Request;
7+
use AsyncAws\Core\Stream\StreamFactory;
8+
9+
final class ListBucketsRequest extends Input
10+
{
11+
/**
12+
* @param array{
13+
* @region?: string,
14+
* } $input
15+
*/
16+
public function __construct(array $input = [])
17+
{
18+
parent::__construct($input);
19+
}
20+
21+
public static function create($input): self
22+
{
23+
return $input instanceof self ? $input : new self($input);
24+
}
25+
26+
/**
27+
* @internal
28+
*/
29+
public function request(): Request
30+
{
31+
// Prepare headers
32+
$headers = ['content-type' => 'application/xml'];
33+
34+
// Prepare query
35+
$query = [];
36+
37+
// Prepare URI
38+
$uriString = '/';
39+
40+
// Prepare Body
41+
$body = '';
42+
43+
// Return the Request
44+
return new Request('GET', $uriString, $query, $headers, StreamFactory::create($body));
45+
}
46+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace AsyncAws\S3\Result;
4+
5+
use AsyncAws\Core\Response;
6+
use AsyncAws\Core\Result;
7+
use AsyncAws\S3\ValueObject\ServerSideEncryptionByDefault;
8+
use AsyncAws\S3\ValueObject\ServerSideEncryptionConfiguration;
9+
use AsyncAws\S3\ValueObject\ServerSideEncryptionRule;
10+
11+
class GetBucketEncryptionOutput extends Result
12+
{
13+
private $serverSideEncryptionConfiguration;
14+
15+
public function getServerSideEncryptionConfiguration(): ?ServerSideEncryptionConfiguration
16+
{
17+
$this->initialize();
18+
19+
return $this->serverSideEncryptionConfiguration;
20+
}
21+
22+
protected function populateResult(Response $response): void
23+
{
24+
$data = new \SimpleXMLElement($response->getContent());
25+
$this->serverSideEncryptionConfiguration = new ServerSideEncryptionConfiguration([
26+
'Rules' => $this->populateResultServerSideEncryptionRules($data->Rule),
27+
]);
28+
}
29+
30+
/**
31+
* @return ServerSideEncryptionRule[]
32+
*/
33+
private function populateResultServerSideEncryptionRules(\SimpleXMLElement $xml): array
34+
{
35+
$items = [];
36+
foreach ($xml as $item) {
37+
$items[] = new ServerSideEncryptionRule([
38+
'ApplyServerSideEncryptionByDefault' => !$item->ApplyServerSideEncryptionByDefault ? null : new ServerSideEncryptionByDefault([
39+
'SSEAlgorithm' => (string) $item->ApplyServerSideEncryptionByDefault->SSEAlgorithm,
40+
'KMSMasterKeyID' => ($v = $item->ApplyServerSideEncryptionByDefault->KMSMasterKeyID) ? (string) $v : null,
41+
]),
42+
'BucketKeyEnabled' => ($v = $item->BucketKeyEnabled) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
43+
]);
44+
}
45+
46+
return $items;
47+
}
48+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace AsyncAws\S3\Result;
4+
5+
use AsyncAws\Core\Response;
6+
use AsyncAws\Core\Result;
7+
use AsyncAws\S3\ValueObject\Bucket;
8+
use AsyncAws\S3\ValueObject\Owner;
9+
10+
/**
11+
* @implements \IteratorAggregate<Bucket>
12+
*/
13+
class ListBucketsOutput extends Result implements \IteratorAggregate
14+
{
15+
/**
16+
* The list of buckets owned by the requestor.
17+
*/
18+
private $buckets;
19+
20+
/**
21+
* The owner of the buckets listed.
22+
*/
23+
private $owner;
24+
25+
/**
26+
* @return iterable<Bucket>
27+
*/
28+
public function getBuckets(): iterable
29+
{
30+
$this->initialize();
31+
32+
return $this->buckets;
33+
}
34+
35+
/**
36+
* Iterates over Buckets.
37+
*
38+
* @return \Traversable<Bucket>
39+
*/
40+
public function getIterator(): \Traversable
41+
{
42+
yield from $this->getBuckets();
43+
}
44+
45+
public function getOwner(): ?Owner
46+
{
47+
$this->initialize();
48+
49+
return $this->owner;
50+
}
51+
52+
protected function populateResult(Response $response): void
53+
{
54+
$data = new \SimpleXMLElement($response->getContent());
55+
$this->buckets = !$data->Buckets ? [] : $this->populateResultBuckets($data->Buckets);
56+
$this->owner = !$data->Owner ? null : new Owner([
57+
'DisplayName' => ($v = $data->Owner->DisplayName) ? (string) $v : null,
58+
'ID' => ($v = $data->Owner->ID) ? (string) $v : null,
59+
]);
60+
}
61+
62+
/**
63+
* @return Bucket[]
64+
*/
65+
private function populateResultBuckets(\SimpleXMLElement $xml): array
66+
{
67+
$items = [];
68+
foreach ($xml->Bucket as $item) {
69+
$items[] = new Bucket([
70+
'Name' => ($v = $item->Name) ? (string) $v : null,
71+
'CreationDate' => ($v = $item->CreationDate) ? new \DateTimeImmutable((string) $v) : null,
72+
]);
73+
}
74+
75+
return $items;
76+
}
77+
}

0 commit comments

Comments
 (0)