use Aws\Credentials\CredentialProvider; $provider = CredentialProvider::defaultProvider(); Returns a CredentialsInterface or throws. $creds = $provider()->wait(); Credential providers can be composed to create credentials using conditional logic that can create different credentials in different environments. You can compose multiple providers into a single provider using {@see \Aws\Credentials\CredentialProvider::chain}. This function accepts providers as variadic arguments and returns a new function that will invoke each provider until a successful set of credentials is returned. First try an INI file at this location. $a = CredentialProvider::ini(null, '/path/to/file.ini'); Then try an INI file at this location. $b = CredentialProvider::ini(null, '/path/to/other-file.ini'); Then try loading from environment variables. $c = CredentialProvider::env(); Combine the three providers together. $composed = CredentialProvider::chain($a, $b, $c); Returns a promise that is fulfilled with credentials or throws. $promise = $composed(); Wait on the credentials to resolve. $creds = $promise->wait();
Example #1
0
 private function getCredentialProvider()
 {
     $connection = $this->getConnection();
     if ($connection->hasParam('aws_secret_access_key')) {
         return CredentialProvider::fromCredentials(new Credentials($connection->getParam('aws_access_key_id'), $connection->getParam('aws_secret_access_key'), $connection->hasParam('aws_session_token') ? $connection->getParam('aws_session_token') : null));
     }
     return CredentialProvider::defaultProvider();
 }
 /**
  * This function keeps state for the credential provider
  * @return mixed
  */
 private function getCredentialProvider()
 {
     if ($this->CredentialProvider) {
         return $this->CredentialProvider;
     }
     $provider = $this->getCredentials();
     $this->CredentialProvider = CredentialProvider::memoize($provider);
     return $this->CredentialProvider;
 }
 private function refresh()
 {
     $this->credentials = null;
     $fn = $this->provider;
     $creds = CredentialProvider::resolve($fn);
     if ($creds->isExpired()) {
         throw new CredentialsException('Could not refresh credentials');
     }
     $this->credentials = $creds;
 }
Example #4
0
 public static function _apply_profile($_, array &$args)
 {
     $args['credentials'] = CredentialProvider::ini($args['profile']);
 }
Example #5
0
 public static function _default_credentials()
 {
     return CredentialProvider::resolve(CredentialProvider::defaultProvider());
 }
Example #6
0
 /**
  * Get events by event name
  *
  * @param null $event_name
  * @return array
  * @throws Exception
  */
 public function getEvents($event_name = null)
 {
     if (empty($event_name)) {
         throw new BusAPIException('Event name not specified.');
     }
     $signer = new SignatureV4('execute-api', 'us-west-2');
     $client = new GuzzleClient(['base_uri' => "https://{$this->host}", 'timeout' => 30, 'curl' => [CURLOPT_SSL_VERIFYPEER => false]]);
     $request = new Request('GET', $this->endpoint, ['Host' => $this->host]);
     if ($this->private_key && $this->public_key) {
         $credentials = new Credentials($this->public_key, $this->private_key);
     } else {
         $credentials = call_user_func(CredentialProvider::defaultProvider())->wait();
     }
     $request = $signer->signRequest($request, $credentials);
     $response = $client->send($request);
     return ['response' => $response, 'results' => json_decode($response->getBody())];
 }