cache_sts_credentials ( $cache, $options )

Fetches and caches STS credentials. This is meant to be used by the constructor, and is not to be manually invoked.

Access

public

Parameters

Parameter

Type

Required

Description

$cache

CacheCore

Required

The a reference to the cache object that is being used to handle the caching.

$options

array

Required

The options that were passed into the constructor.

Returns

Type

Description

mixed

The data to be cached, or NULL.

Source

Method defined in sdk.class.php | Toggle source view (30 lines) | View on GitHub

public function cache_sts_credentials($cache, $options)
{
    $token = new AmazonSTS($options);
    $response = $token->get_session_token();

    if ($response->isOK())
    {
        // Update the expiration
        $expiration_time = strtotime((string) $response->body->GetSessionTokenResult->Credentials->Expiration);
        $expiration_duration = round(($expiration_time - time()) * 0.85);
        $cache->expire_in($expiration_duration);

        // Return the important data
        $credentials = $response->body->GetSessionTokenResult->Credentials;

        return array(
            'key'     => (string) $credentials->AccessKeyId,
            'secret'  => (string) $credentials->SecretAccessKey,
            'token'   => (string) $credentials->SessionToken,
            'expires' => (string) $credentials->Expiration,
        );
    }

    // @codeCoverageIgnoreStart
    throw new STS_Exception('Temporary credentials from the AWS Security '
        . 'Token Service could not be retrieved using the provided long '
        . 'term credentials. It\'s possible that the provided long term '
        . 'credentials were invalid.');
    // @codeCoverageIgnoreEnd
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback