Skip to content

Commit

Permalink
fix: honor use_aws_shared_config_files
Browse files Browse the repository at this point in the history
Honor the `use_aws_shared_config_files` config from `default_region` and `default_sigv4a_signing_region_set` by passing `$args` along to the `ConfigurationResolver::resolve` call.
  • Loading branch information
yenfryherrerafeliz committed Nov 14, 2024
1 parent 5420284 commit 850a278
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ClientResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1318,12 +1318,13 @@ public static function _apply_sigv4a_signing_region_set($value, array &$args)
}
}

public static function _default_sigv4a_signing_region_set(array &$args)
public static function _default_sigv4a_signing_region_set(array $args)
{
return ConfigurationResolver::resolve(
'sigv4a_signing_region_set',
'',
'string'
'string',
$args
);
}

Expand All @@ -1335,9 +1336,14 @@ public static function _apply_region($value, array &$args)
$args['region'] = $value;
}

public static function _default_region(&$args)
public static function _default_region($args)
{
return ConfigurationResolver::resolve('region', '', 'string');
return ConfigurationResolver::resolve(
'region',
'',
'string',
$args
);
}

public static function _missing_region(array $args)
Expand Down
165 changes: 165 additions & 0 deletions tests/ClientResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Aws\ClientSideMonitoring\Configuration;
use Aws\ClientSideMonitoring\ConfigurationProvider;
use Aws\CommandInterface;
use Aws\Configuration\ConfigurationResolver;
use Aws\Credentials\CredentialProvider;
use Aws\Credentials\Credentials;
use Aws\Credentials\CredentialsInterface;
Expand Down Expand Up @@ -1696,4 +1697,168 @@ public function testEmitsDeprecationWarning()
putenv('AWS_SUPPRESS_PHP_DEPRECATION_WARNING=true');
}
}

/**
* @dataProvider defaultRegionUseAwsSharedFileProvider
*
* @param $args
* @param $region
* @param $expected
* @return void
*/
public function testDefaultRegionHonorUseAwsSharedFiles(
$args,
$region,
$expected
): void
{
$tempHomeDir = sys_get_temp_dir() . "/default_region_test";
$awsDir = $tempHomeDir . "/.aws";
if (!is_dir($awsDir)) {
mkdir($tempHomeDir, 0777, true);
mkdir($awsDir, 0777, true);
}
$configPath = $awsDir . "/config";
$config = <<<EOF
[default]
region=$region
EOF;
$currentEnvConfigFile = getenv(ConfigurationResolver::ENV_CONFIG_FILE);
putenv(
ConfigurationResolver::ENV_CONFIG_FILE
. "="
. $configPath
);
try {
file_put_contents($configPath, $config);
$resolvedRegion = ClientResolver::_default_region($args);

$this->assertEquals($expected, $resolvedRegion);
} finally {
if ($currentEnvConfigFile) {
putenv(
ConfigurationResolver::ENV_CONFIG_FILE
. "="
. $currentEnvConfigFile
);
} else {
putenv(ConfigurationResolver::ENV_CONFIG_FILE);
}
unlink($configPath);
rmdir($awsDir);
rmdir($tempHomeDir);
}
}

/**
* @return array[]
*/
public function defaultRegionUseAwsSharedFileProvider(): array
{
$configRegion = 'test-region';

return [
'expect_region' => [
'args' => [
'use_aws_shared_config_files' => true,
],
'region' => $configRegion,
'expected' => $configRegion
],
'expect_region_when_flag_not_present' => [
'args' => [
],
'region' => $configRegion,
'expected' => $configRegion
],
'expect_region_to_be_empty' => [
'args' => [
'use_aws_shared_config_files' => false,
],
'region' => $configRegion,
'expected' => '' // empty
]
];
}

/**
* @dataProvider defaultSigv4aSigningRegionSetUseAwsSharedFileProvider
*
* @param $args
* @param $sigv4aSigningRegionSet
* @param $expected
* @return void
*/
public function testDefaultSigv4aSigningRegionSetHonorUseAwsSharedFiles(
$args,
$sigv4aSigningRegionSet,
$expected
): void
{
$tempHomeDir = sys_get_temp_dir() . "/default_sigv4a_signing_region_set_test";
$awsDir = $tempHomeDir . "/.aws";
if (!is_dir($awsDir)) {
mkdir($tempHomeDir, 0777, true);
mkdir($awsDir, 0777, true);
}
$configPath = $awsDir . "/config";
$config = <<<EOF
[default]
sigv4a_signing_region_set=$sigv4aSigningRegionSet
EOF;
$currentEnvConfigFile = getenv(ConfigurationResolver::ENV_CONFIG_FILE);
putenv(
ConfigurationResolver::ENV_CONFIG_FILE
. "="
. $configPath
);
try {
file_put_contents($configPath, $config);
$resolved =
ClientResolver::_default_sigv4a_signing_region_set($args);

$this->assertEquals($expected, $resolved);
} finally {
if ($currentEnvConfigFile) {
putenv(
ConfigurationResolver::ENV_CONFIG_FILE
. "="
. $currentEnvConfigFile
);
} else {
putenv(ConfigurationResolver::ENV_CONFIG_FILE);
}
unlink($configPath);
rmdir($awsDir);
rmdir($tempHomeDir);
}
}

public function defaultSigv4aSigningRegionSetUseAwsSharedFileProvider(): array
{
$configSigv4aSigningRegionSet = 'test-sigv4-signing-region-set';

return [
'expect_sigv4a_signing_region_set' => [
'args' => [
'use_aws_shared_config_files' => true,
],
'sigv4a_signing_region_set' => $configSigv4aSigningRegionSet,
'expected' => $configSigv4aSigningRegionSet
],
'expect_sigv4a_signing_region_set_when_flag_not_present' => [
'args' => [
],
'sigv4a_signing_region_set' => $configSigv4aSigningRegionSet,
'expected' => $configSigv4aSigningRegionSet
],
'eexpect_sigv4a_signing_region_set_to_be_empty' => [
'args' => [
'use_aws_shared_config_files' => false,
],
'sigv4a_signing_region_set' => $configSigv4aSigningRegionSet,
'expected' => '' // empty
]
];
}
}

0 comments on commit 850a278

Please sign in to comment.