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

fix: set use_aws_shared_config_files opts-in #2894

Merged
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
16 changes: 11 additions & 5 deletions src/Credentials/InstanceProfileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class InstanceProfileProvider
/** @var string */
private $endpointMode;

/** @var array */
private $config;

/**
* The constructor accepts the following options:
*
Expand All @@ -68,10 +71,12 @@ class InstanceProfileProvider
* - retries: Optional number of retries to be attempted.
* - ec2_metadata_v1_disabled: Optional for disabling the fallback to IMDSv1.
* - endpoint: Optional for overriding the default endpoint to be used for fetching credentials.
* The value must contain a valid URI scheme. If the URI scheme is not https, it must
* resolve to a loopback address.
* The value must contain a valid URI scheme. If the URI scheme is not https, it must
* resolve to a loopback address.
* - endpoint_mode: Optional for overriding the default endpoint mode (IPv4|IPv6) to be used for
* resolving the default endpoint.
* - use_aws_shared_config_files: Decides whether the shared config file should be considered when
* using the ConfigurationResolver::resolve method.
*
* @param array $config Configuration options.
*/
Expand All @@ -88,6 +93,7 @@ public function __construct(array $config = [])
}

$this->endpointMode = $config[self::CFG_EC2_METADATA_SERVICE_ENDPOINT_MODE] ?? null;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -344,7 +350,7 @@ private function shouldFallbackToIMDSv1(): bool
self::CFG_EC2_METADATA_V1_DISABLED,
self::DEFAULT_AWS_EC2_METADATA_V1_DISABLED,
'bool',
['use_aws_shared_config_files' => true]
$this->config
)
)
?? self::DEFAULT_AWS_EC2_METADATA_V1_DISABLED;
Expand All @@ -369,7 +375,7 @@ private function resolveEndpoint(): string
self::CFG_EC2_METADATA_SERVICE_ENDPOINT,
$this->getDefaultEndpoint(),
'string',
['use_aws_shared_config_files' => true]
$this->config
);
}

Expand Down Expand Up @@ -420,7 +426,7 @@ private function resolveEndpointMode(): string
self::CFG_EC2_METADATA_SERVICE_ENDPOINT_MODE,
self::ENDPOINT_MODE_IPv4,
'string',
['use_aws_shared_config_files' => true]
$this->config
);
}

Expand Down
7 changes: 5 additions & 2 deletions tests/Credentials/InstanceProfileProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ private function fetchMockedCredentialsAndAlwaysExpectAToken($config=[]) {

return Promise\Create::rejectionFor(['exception' => new \Exception('Unexpected error!')]);
};
$config['use_aws_shared_config_files'] = true;
$provider = new InstanceProfileProvider(array_merge(($config ?? []), ['client' => $mockHandler]));
try {
$provider()->wait();
Expand Down Expand Up @@ -1385,7 +1386,8 @@ public function testEndpointModeResolution($endpointModeClientConfig, $endpointM
default:
$this->fail("The expected value for endpoint_mode should be either one of the following options[" . InstanceProfileProvider::ENDPOINT_MODE_IPv4 . ', ' . InstanceProfileProvider::ENDPOINT_MODE_IPv6 . "]");
}
})
}),
'use_aws_shared_config_files' => true
];
if (!is_null($endpointModeClientConfig)) {
$providerConfig[InstanceProfileProvider::CFG_EC2_METADATA_SERVICE_ENDPOINT_MODE] = $endpointModeClientConfig;
Expand Down Expand Up @@ -1498,7 +1500,8 @@ public function testEndpointResolution($endpointMode, $endpointEnv, $endpointCon
'client' => $this->getClientForEndpointTesting(function ($uri) use ($expectedEndpoint) {
$endpoint = $uri->getScheme() . '://' . $uri->getHost();
$this->assertSame($expectedEndpoint, $endpoint);
})
}),
'use_aws_shared_config_files' => true
];
$deferredTasks = [];
if (!is_null($endpointEnv)) {
Expand Down