Skip to content
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

Use latest as default version #2736

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/nextrelease/feature-default-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "feature",
"category": "",
"description": "Removes validation of supplying the `version` configuration option to client constructors, defaulting to 'latest'`"
}
]
29 changes: 1 addition & 28 deletions src/ClientResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class ClientResolver
'version' => [
'type' => 'value',
'valid' => ['string'],
'required' => [__CLASS__, '_missing_version'],
'doc' => 'The version of the webservice to utilize (e.g., 2006-03-01).',
'default' => 'latest',
],
'signature_provider' => [
'type' => 'value',
Expand Down Expand Up @@ -1137,33 +1137,6 @@ public static function _default_signing_region(array &$args)
: $args['region'];
}

public static function _missing_version(array $args)
{
$service = isset($args['service']) ? $args['service'] : '';
$versions = ApiProvider::defaultProvider()->getVersions($service);
$versions = implode("\n", array_map(function ($v) {
return "* \"$v\"";
}, $versions)) ?: '* (none found)';

return <<<EOT
A "version" configuration value is required. Specifying a version constraint
ensures that your code will not be affected by a breaking change made to the
service. For example, when using Amazon S3, you can lock your API version to
"2006-03-01".

Your build of the SDK has the following version(s) of "{$service}": {$versions}

You may provide "latest" to the "version" configuration value to utilize the
most recent available API version that your client's API provider can find.
Note: Using 'latest' in a production application is not recommended.

A list of available API versions can be found on each client's API documentation
page: http://docs.aws.amazon.com/aws-sdk-php/v3/api/index.html. If you are
unable to load a specific API version, then you may need to update your copy of
the SDK.
EOT;
}

public static function _missing_region(array $args)
{
$service = isset($args['service']) ? $args['service'] : '';
Expand Down
30 changes: 14 additions & 16 deletions tests/ClientResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,27 +752,25 @@ public function testSkipsNonRequiredKeys()
$r->resolve([], new HandlerList());
}

public function testHasSpecificMessageForMissingVersion()
public function testAppliesLatestAsDefaultVersionWithoutSuppliedVersion()
{
$this->expectExceptionMessage("A \"version\" configuration value is required");
$this->expectException(\InvalidArgumentException::class);
$args = ClientResolver::getDefaultArguments()['version'];
$r = new ClientResolver(['version' => $args]);
$r->resolve(['service' => 'foo'], new HandlerList());
$r = new ClientResolver(ClientResolver::getDefaultArguments());
$conf = $r->resolve([
'service' => 'ec2',
'region' => 'us-west-2',
], new HandlerList());
self::assertSame('latest', $conf['version']);
}

public function testHasSpecificMessageForNullRequiredVersion()
public function testAppliesVersion()
{
$this->expectExceptionMessage("A \"version\" configuration value is required");
$this->expectException(\InvalidArgumentException::class);
$r = new ClientResolver(ClientResolver::getDefaultArguments());
$list = new HandlerList();
$r->resolve([
'service' => 'foo',
'region' => 'x',
'credentials' => ['key' => 'a', 'secret' => 'b'],
'version' => null,
], $list);
$conf = $r->resolve([
'service' => 'ec2',
'region' => 'us-west-2',
'version' => '2015-10-01'
], new HandlerList());
self::assertSame('2015-10-01', $conf['version']);
}

public function testHasSpecificMessageForMissingRegion()
Expand Down