-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: IMDS support for providing custom endpoint
When using IMDS for fetching credentials, customers should be able to provide their custom endpoint when desired, and that is what this change does. Basically, customer can provide a custom endpoint by doing one of the following options: Please note that a valid URI value needs to be provided, otherwise a credential exception will be thrown. - Providing a parameter called 'ec2_metadata_service_endpoint' to the constructor of the InstanceProfileProvider. - By setting an environment variable called AWS_EC2_METADATA_SERVICE_ENDPOINT. - By defining a key-value config in the config file ~/.aws/config
- Loading branch information
1 parent
63c7202
commit c4a0032
Showing
3 changed files
with
261 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Aws\Credentials\Utils; | ||
|
||
final class Validator | ||
{ | ||
private function __construct() {} | ||
|
||
public static function validateURI( | ||
$uri, | ||
$ignoreNulls=true, | ||
$exceptionClass='\InvalidArgumentException', | ||
$errorMessage='The provided URI "$uri" is not a valid URI scheme' | ||
) | ||
{ | ||
if (is_null($uri) && $ignoreNulls) { | ||
return $uri; | ||
} | ||
|
||
if (filter_var($uri, FILTER_VALIDATE_URL) === false) { | ||
throw new $exceptionClass(str_replace('$uri', $uri, $errorMessage)); | ||
} | ||
|
||
return $uri; | ||
} | ||
|
||
public static function validateInOptions( | ||
$value, | ||
$options, | ||
$ignoreNulls=true, | ||
$exceptionClass='\InvalidArgumentException', | ||
$errorMessage='The provided value $value is not valid option of [$options]' | ||
) | ||
{ | ||
if (is_null($value) && $ignoreNulls) { | ||
return $value; | ||
} | ||
|
||
if (!in_array($value, $options)) { | ||
$errorMessage = str_replace('$value', $value, $errorMessage); | ||
$errorMessage = str_replace('$options', implode(',', $options), $errorMessage); | ||
throw new $exceptionClass($errorMessage); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters