src/Volume.php
private static function _buildConfigArray($keyId = null, $secret = null, $region = null)
    {
        $config = [
            'region' => $region,
            'version' => 'latest'
        ];

        if (empty($keyId) || empty($secret)) {
            // Assume we're running on EC2 and we have an IAM role assigned. Kick back and relax.
        } else {
            $tokenKey = static::CACHE_KEY_PREFIX . md5($keyId . $secret);
            $credentials = new Credentials($keyId, $secret);

            if (Craft::$app->cache->exists($tokenKey)) {
                $cached = Craft::$app->cache->get($tokenKey);
                $credentials->unserialize($cached);
            } else {
                $config['credentials'] = $credentials;
                $stsClient = new StsClient($config);
                $result = $stsClient->getSessionToken(['DurationSeconds' => static::CACHE_DURATION_SECONDS]);
                $credentials = $stsClient->createCredentials($result);
                Craft::$app->cache->set($tokenKey, $credentials->serialize(), static::CACHE_DURATION_SECONDS);
            }

            // TODO Add support for different credential supply methods
            $config['credentials'] = $credentials;
        }

        $client = Craft::createGuzzleClient();
        $config['http_handler'] = new GuzzleHandler($client);

        return $config;
    }
private static function _buildConfigArray($keyId = null, $secret = null, $region = null)
    {
        $config = [
            'region' => $region,
            'version' => 'latest'
        ];

        if (empty($keyId) || empty($secret)) {
            // Assume we're running on EC2 and we have an IAM role assigned. Kick back and relax.
        } else {
            $tokenKey = static::CACHE_KEY_PREFIX . md5($keyId . $secret);
            $credentials = new Credentials($keyId, $secret);

            if (Craft::$app->cache->exists($tokenKey)) {
                $cached = Craft::$app->cache->get($tokenKey);
                $credentials->unserialize($cached);
            } else {
                $config['credentials'] = $credentials;
                $stsClient = new StsClient($config);
                $result = $stsClient->getSessionToken(['DurationSeconds' => static::CACHE_DURATION_SECONDS]);
                $credentials = $stsClient->createCredentials($result);
                Craft::$app->cache->set($tokenKey, $credentials->serialize(), static::CACHE_DURATION_SECONDS);
            }

            // TODO Add support for different credential supply methods
            $config['credentials'] = $credentials;
        }

        $client = Craft::createGuzzleClient();
        $config['http_handler'] = new GuzzleHandler($client);

        return $config;
    }
private static function _buildConfigArray ( $ keyId = null , $ secret = null , $ region = null ) { $ config = [ 'region' => $ region , 'version' => 'latest' ] ; if ( empty ( $ keyId ) || empty ( $ secret ) ) { // Assume we're running on EC2 and we have an IAM role assigned. Kick back and relax. } else { $ tokenKey = static :: CACHE_KEY_PREFIX . md5 ( $ keyId . $ secret ) ; $ credentials = new Credentials ( $ keyId , $ secret ) ; if ( Craft :: $ app -> cache -> exists ( $ tokenKey ) ) { $ cached = Craft :: $ app -> cache -> get ( $ tokenKey ) ; $ credentials -> unserialize ( $ cached ) ; } else { $ config [ 'credentials' ] = $ credentials ; $ stsClient = new StsClient ( $ config ) ; $ result = $ stsClient -> getSessionToken ( [ 'DurationSeconds' => static :: CACHE_DURATION_SECONDS ] ) ; $ credentials = $ stsClient -> createCredentials ( $ result ) ; Craft :: $ app -> cache -> set ( $ tokenKey , $ credentials -> serialize ( ) , static :: CACHE_DURATION_SECONDS ) ; } // TODO Add support for different credential supply methods $ config [ 'credentials' ] = $ credentials ; } $ client = Craft :: createGuzzleClient ( ) ; $ config [ 'http_handler' ] = new GuzzleHandler ( $ client ) ; return $ config ; }
Build the config array based on a keyID and secret

@param $keyId
@param $secret
@param $region
@return array
Build the config array based on a keyID and secret