src/Credentials/CredentialProvider.php
public static function process($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 process credentials from $filename");
            }
            $data = \Aws\parse_ini_file($filename, true, INI_SCANNER_RAW);
            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]['credential_process'])
            ) {
                return self::reject("No credential_process present in INI profile "
                    . "'$profile' ($filename)");
            }

            $credentialProcess = $data[$profile]['credential_process'];
            $json = shell_exec($credentialProcess);

            $processData = json_decode($json, true);

            // Only support version 1
            if (isset($processData['Version'])) {
                if ($processData['Version'] !== 1) {
                    return self::reject("credential_process does not return Version == 1");
                }
            }

            if (!isset($processData['AccessKeyId']) || !isset($processData['SecretAccessKey'])) {
                return self::reject("credential_process does not return valid credentials");
            }

            if (isset($processData['Expiration'])) {
                try {
                    $expiration = new DateTimeResult($processData['Expiration']);
                } catch (\Exception $e) {
                    return self::reject("credential_process returned invalid expiration");
                }
                $now = new DateTimeResult();
                if ($expiration < $now) {
                    return self::reject("credential_process returned expired credentials");
                }
            } else {
                $processData['Expiration'] = null;
            }

            if (empty($processData['SessionToken'])) {
                $processData['SessionToken'] = null;
            }

            return Promise\promise_for(
                new Credentials(
                    $processData['AccessKeyId'],
                    $processData['SecretAccessKey'],
                    $processData['SessionToken'],
                    $processData['Expiration']
                )
            );
        };
    }
public static function process($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 process credentials from $filename");
            }
            $data = \Aws\parse_ini_file($filename, true, INI_SCANNER_RAW);
            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]['credential_process'])
            ) {
                return self::reject("No credential_process present in INI profile "
                    . "'$profile' ($filename)");
            }

            $credentialProcess = $data[$profile]['credential_process'];
            $json = shell_exec($credentialProcess);

            $processData = json_decode($json, true);

            // Only support version 1
            if (isset($processData['Version'])) {
                if ($processData['Version'] !== 1) {
                    return self::reject("credential_process does not return Version == 1");
                }
            }

            if (!isset($processData['AccessKeyId']) || !isset($processData['SecretAccessKey'])) {
                return self::reject("credential_process does not return valid credentials");
            }

            if (isset($processData['Expiration'])) {
                try {
                    $expiration = new DateTimeResult($processData['Expiration']);
                } catch (\Exception $e) {
                    return self::reject("credential_process returned invalid expiration");
                }
                $now = new DateTimeResult();
                if ($expiration < $now) {
                    return self::reject("credential_process returned expired credentials");
                }
            } else {
                $processData['Expiration'] = null;
            }

            if (empty($processData['SessionToken'])) {
                $processData['SessionToken'] = null;
            }

            return Promise\promise_for(
                new Credentials(
                    $processData['AccessKeyId'],
                    $processData['SecretAccessKey'],
                    $processData['SessionToken'],
                    $processData['Expiration']
                )
            );
        };
    }
public static function process ( $ 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 process credentials from $filename" ) ; } $ data = \ Aws \ parse_ini_file ( $ filename , true , INI_SCANNER_RAW ) ; 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 ] [ 'credential_process' ] ) ) { return self :: reject ( "No credential_process present in INI profile " . "'$profile' ($filename)" ) ; } $ credentialProcess = $ data [ $ profile ] [ 'credential_process' ] ; $ json = shell_exec ( $ credentialProcess ) ; $ processData = json_decode ( $ json , true ) ; // Only support version 1 if ( isset ( $ processData [ 'Version' ] ) ) { if ( $ processData [ 'Version' ] !== 1 ) { return self :: reject ( "credential_process does not return Version == 1" ) ; } } if ( ! isset ( $ processData [ 'AccessKeyId' ] ) || ! isset ( $ processData [ 'SecretAccessKey' ] ) ) { return self :: reject ( "credential_process does not return valid credentials" ) ; } if ( isset ( $ processData [ 'Expiration' ] ) ) { try { $ expiration = new DateTimeResult ( $ processData [ 'Expiration' ] ) ; } catch ( \ Exception $ e ) { return self :: reject ( "credential_process returned invalid expiration" ) ; } $ now = new DateTimeResult ( ) ; if ( $ expiration < $ now ) { return self :: reject ( "credential_process returned expired credentials" ) ; } } else { $ processData [ 'Expiration' ] = null ; } if ( empty ( $ processData [ 'SessionToken' ] ) ) { $ processData [ 'SessionToken' ] = null ; } return Promise \ promise_for ( new Credentials ( $ processData [ 'AccessKeyId' ] , $ processData [ 'SecretAccessKey' ] , $ processData [ 'SessionToken' ] , $ processData [ 'Expiration' ] ) ) ; } ; }
Credentials provider that creates credentials using a process configured in
ini file stored in the current user's home directory.

@param string|null $profile  Profile to use. If not specified will use
the "default" profile in "~/.aws/credentials".
@param string|null $filename If provided, uses a custom filename rather
than looking in the home directory.

@return callable
Credentials provider that creates credentials using a process configured in ini file stored in the current user s home directory .