public static function ini($profile = null, $filename = null)
{
$filename = $filename ?: self::getHomeDir() . '/.aws/credentials';
$profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default');
return function () use($profile, $filename) {
if (!is_readable($filename)) {
return self::reject("Cannot read credentials from {$filename}");
}
$data = parse_ini_file($filename, true);
if ($data === false) {
return self::reject("Invalid credentials file: {$filename}");
}
if (!isset($data[$profile])) {
return self::reject("'{$profile}' not found in credentials file");
}
if (!isset($data[$profile]['aws_access_key_id']) || !isset($data[$profile]['aws_secret_access_key'])) {
return self::reject("No credentials present in INI profile " . "'{$profile}' ({$filename})");
}
if (empty($data[$profile]['aws_session_token'])) {
$data[$profile]['aws_session_token'] = isset($data[$profile]['aws_security_token']) ? $data[$profile]['aws_security_token'] : null;
}
return Promise\promise_for(new Credentials($data[$profile]['aws_access_key_id'], $data[$profile]['aws_secret_access_key'], $data[$profile]['aws_session_token']));
};
}