Skip to content

Commit

Permalink
fix: set use_aws_shared_config_files opts-in
Browse files Browse the repository at this point in the history
This change makes the ConfigurationResolver to load configuration from aws shared config files based on the configuration `use_aws_shared_config_files` either provided as provider arguments or as service client arguments.
  • Loading branch information
yenfryherrerafeliz committed Mar 6, 2024
1 parent b1c05a5 commit a831949
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 7 additions & 3 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 bool */
private $useAwsSharedConfigFiles;

/**
* The constructor accepts the following options:
*
Expand Down Expand Up @@ -88,6 +91,7 @@ public function __construct(array $config = [])
}

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

/**
Expand Down Expand Up @@ -344,7 +348,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]
['use_aws_shared_config_files' => $this->useAwsSharedConfigFiles]
)
)
?? self::DEFAULT_AWS_EC2_METADATA_V1_DISABLED;
Expand All @@ -369,7 +373,7 @@ private function resolveEndpoint(): string
self::CFG_EC2_METADATA_SERVICE_ENDPOINT,
$this->getDefaultEndpoint(),
'string',
['use_aws_shared_config_files' => true]
['use_aws_shared_config_files' => $this->useAwsSharedConfigFiles]
);
}

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

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 a831949

Please sign in to comment.