Skip to content

Commit 324afd2

Browse files
authored
Provides Virtual Hosting of Buckets (#630)
* Provides Virtual Hosting of Buckets * Merge S3Configuration with Configuration * Fix SimpleS3 test * Rename pathStyleEndpoint * Improve doc and changelog * Fix FlySystem tests
1 parent bb18d53 commit 324afd2

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Add a `PsrCacheProvider` and `SymfonyCacheProvider` to persists crendentials in a cache pool
1010
- Add a `Credential::adjustExpireDate` method for adjusting the time according to the time difference with AWS clock
1111
- Support for global and regional endpoints
12+
- Add a `Configuration::optionExists` to allow third parties to check if an option is available (needed by libraries supporting several versions of core)
1213

1314
### Deprecation
1415

src/AbstractApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected function getEndpointMetadata(?string $region): array
189189
* @param array $query parameters that should go in the query string
190190
* @param ?string $region region provided by the user in the `@region` parameter of the Input
191191
*/
192-
private function getEndpoint(string $uri, array $query, ?string $region): string
192+
protected function getEndpoint(string $uri, array $query, ?string $region): string
193193
{
194194
/** @var string $region */
195195
$region = $region ?? $this->configuration->isDefault('region') ? null : $this->configuration->get('region');

src/Configuration.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ final class Configuration
2929
public const OPTION_ROLE_SESSION_NAME = 'roleSessionName';
3030
public const OPTION_CONTAINER_CREDENTIALS_RELATIVE_URI = 'containerCredentialsRelativeUri';
3131

32+
// S3 specific option
33+
public const OPTION_PATH_STYLE_ENDPOINT = 'pathStyleEndpoint';
34+
3235
private const AVAILABLE_OPTIONS = [
3336
self::OPTION_REGION => true,
3437
self::OPTION_PROFILE => true,
@@ -42,6 +45,7 @@ final class Configuration
4245
self::OPTION_WEB_IDENTITY_TOKEN_FILE => true,
4346
self::OPTION_ROLE_SESSION_NAME => true,
4447
self::OPTION_CONTAINER_CREDENTIALS_RELATIVE_URI => true,
48+
self::OPTION_PATH_STYLE_ENDPOINT => true,
4549
];
4650

4751
// Put fallback options into groups to avoid mixing of provided config and environment variables
@@ -70,6 +74,7 @@ final class Configuration
7074
self::OPTION_SHARED_CONFIG_FILE => '~/.aws/config',
7175
// https://docs.aws.amazon.com/general/latest/gr/rande.html
7276
self::OPTION_ENDPOINT => 'https://%service%.%region%.amazonaws.com',
77+
self::OPTION_PATH_STYLE_ENDPOINT => 'false',
7378
];
7479

7580
private $data = [];
@@ -82,6 +87,10 @@ public static function create(array $options)
8287
throw new InvalidArgument(\sprintf('Invalid option(s) "%s" passed to "%s::%s". ', \implode('", "', \array_keys($invalidOptions)), __CLASS__, __METHOD__));
8388
}
8489

90+
$options = \array_map(static function ($value) {
91+
return null !== $value ? (string) $value : $value;
92+
}, $options);
93+
8594
foreach (self::FALLBACK_OPTIONS as $fallbackGroup) {
8695
// prevent mixing env variables with config keys
8796
foreach ($fallbackGroup as $option => $envVariableNames) {
@@ -123,6 +132,11 @@ public static function create(array $options)
123132
return $configuration;
124133
}
125134

135+
public static function optionExists(string $optionName): bool
136+
{
137+
return isset(self::AVAILABLE_OPTIONS[$optionName]);
138+
}
139+
126140
public function get(string $name): ?string
127141
{
128142
if (!isset(self::AVAILABLE_OPTIONS[$name])) {

tests/Unit/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ public function provideConfiguration(): iterable
7676
yield 'config with env group 2' => [['accessKeySecret' => 'secret'], [], ['accessKeySecret' => 'secret', 'accessKeyId' => null, 'sessionToken' => null]];
7777
yield 'mix config and env' => [['accessKeyId' => 'key'], ['AWS_SESSION_TOKEN' => 'token'], ['accessKeyId' => 'key', 'sessionToken' => null]];
7878
yield 'null config with env group' => [['accessKeyId' => null], ['AWS_SESSION_TOKEN' => 'token'], ['accessKeyId' => null, 'sessionToken' => 'token']];
79+
80+
yield 'boolean value' => [['pathStyleEndpoint' => true], [], ['pathStyleEndpoint' => '1']];
7981
}
8082
}

0 commit comments

Comments
 (0)