Aws\Credentials\CredentialProvider::ini PHP Метод

ini() публичный статический Метод

Credentials provider that creates credentials using an ini file stored in the current user's home directory.
public static ini ( string | null $profile = null, string | null $filename = null ) : callable
$profile string | null Profile to use. If not specified will use the "default" profile.
$filename string | null If provided, uses a custom filename rather than looking in the home directory for the
Результат callable
    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']));
        };
    }

Usage Example

Пример #1
0
 public static function _apply_profile($_, array &$args)
 {
     $args['credentials'] = CredentialProvider::ini($args['profile']);
 }