Skip to content

Commit

Permalink
fix: set use_aws_shared_config_files opts-in (#2894)
Browse files Browse the repository at this point in the history
  • Loading branch information
yenfryherrerafeliz authored Mar 13, 2024
1 parent d6afaea commit ea4de54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
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

0 comments on commit ea4de54

Please sign in to comment.