예제 #1
0
 /**
  * The callback function that is executed  while caching the session credentials.
  *
  * @param string $key (Optional) Your AWS key, or a session key. If blank, it will look for the <code>AWS_KEY</code> constant.
  * @param string $secret_key (Optional) Your AWS secret key, or a session secret key. If blank, it will look for the <code>AWS_SECRET_KEY</code> constant.
  * @return mixed The data to be cached or null.
  */
 public function cache_token($key, $secret_key)
 {
     $token = new AmazonSTS($key, $secret_key);
     $response = $token->get_session_token();
     if ($response->isOK()) {
         /*
         Array
         (
             [AccessKeyId] => ******
             [Expiration] => ******
             [SecretAccessKey] => ******
         	[SessionToken] => ******
         )
         */
         return $response->body->GetSessionTokenResult->Credentials->to_array()->getArrayCopy();
     }
     return null;
 }
예제 #2
0
 /**
  * Fetches and caches STS credentials. This is meant to be used by the constructor, and is not to be
  * manually invoked.
  *
  * @param CacheCore $cache (Required) The a reference to the cache object that is being used to handle the caching.
  * @param array $options (Required) The options that were passed into the constructor.
  * @return mixed The data to be cached, or NULL.
  */
 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
 }
예제 #3
0
 /**
  * Fetches and caches STS credentials. This is meant to be used by the constructor, and is not to be
  * manually invoked.
  *
  * @param CacheCore $cache (Required) The a reference to the cache object that is being used to handle the caching.
  * @param array $options (Required) The options that were passed into the constructor.
  * @return mixed The data to be cached, or NULL.
  */
 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
         return array('key' => (string) $response->body->GetSessionTokenResult->Credentials->AccessKeyId, 'secret' => (string) $response->body->GetSessionTokenResult->Credentials->SecretAccessKey, 'token' => (string) $response->body->GetSessionTokenResult->Credentials->SessionToken, 'expires' => (string) $response->body->GetSessionTokenResult->Credentials->Expiration);
     }
     return null;
 }