__construct ( $options )

The constructor. This class should not be instantiated directly. Rather, a service-specific class should be instantiated.

Access

public

Parameters

Parameter

Type

Required

Description

$options

array

Optional

An associative array of parameters that can have the following keys:

  • certificate_authority - boolean - Optional - Determines which Cerificate Authority file to use. A value of boolean false will use the Certificate Authority file available on the system. A value of boolean true will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to 0755) will use that. Leave this set to false if you’re not sure.
  • credentials - string - Optional - The name of the credential set to use for authentication.
  • default_cache_config - string - Optional - This option allows a preferred storage type to be configured for long-term caching. This can be changed later using the set_cache_config() method. Valid values are: apc, xcache, or a file system path such as ./cache or /tmp/cache/.
  • key - string - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.
  • instance_profile_timeout - integer - Optional - When retrieving IAM instance profile credentials, there is a hard connection timeout that defaults to 2 seconds to prevent unnecessary on non-EC2 systems. This setting allows you to change that timeout if needed.
  • secret - string - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.
  • token - string - Optional - An AWS session token.
  • use_instance_profile_credentials - boolean - Optional - Forces the use of IAM Instance Profile credentials, even when regular credentials are provided.

Source

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

public function __construct(array $options = array())
{
    // Instantiate the utilities class.
    $this->util = new $this->utilities_class();

    // Determine the current service.
    $this->service = get_class($this);

    // Create credentials based on the options
    $runtime_credentials = new CFCredential($options);
    $credentials_provided = false;

    // Retrieve a credential set from config.inc.php if it exists
    if (isset($options['credentials']))
    {
        // Use a specific credential set and merge with the runtime credentials
        $this->credentials = CFCredentials::get($options['credentials'])
            ->merge($runtime_credentials);
    }
    else
    {
        try
        {
            // Use the default credential set and merge with the runtime credentials
            $this->credentials = CFCredentials::get(CFCredentials::DEFAULT_KEY)
                ->merge($runtime_credentials);
        }
        catch (CFCredentials_Exception $e)
        {
            // Only the runtime credentials were provided
            $this->credentials = $runtime_credentials;
        }
    }

    // Check if keys were actually provided
    if (isset($this->credentials['key']) && isset($this->credentials['secret']))
    {
        $credentials_provided = true;
    }

    // Check for an instance profile credentials override
    if (isset($this->credentials['use_instance_profile_credentials']) && $this->credentials['use_instance_profile_credentials'])
    {
        $credentials_provided = false;
    }

    // Automatically enable whichever caching mechanism is set to default.
    $this->set_cache_config($this->credentials->default_cache_config);

    // If no credentials were provided, try to get them from the EC2 instance profile
    if (!$credentials_provided)
    {
        // Default caching mechanism is required
        if (!$this->credentials->default_cache_config)
        {
            // @codeCoverageIgnoreStart
            throw new CFCredentials_Exception('No credentials were provided. The SDK attempts to retrieve Instance '
                . 'Profile credentials from the EC2 Instance Metadata Service, but doing this requires the '
                . '"default_cache_config" option to be set in the config.inc.php file or constructor. In order to '
                . 'cache the retrieved credentials.');
            // @codeCoverageIgnoreEnd
        }

        // Instantiate and invoke the cache for instance profile credentials
        $cache = new $this->cache_class('instance_profile_credentials', $this->cache_location, 0, $this->cache_compress);
        if ($data = $cache->read())
        {
            $cache->expire_in((strtotime($data['expires']) - time()) * 0.85);
        }
        $instance_profile_credentials = $cache->response_manager(array($this, 'cache_instance_profile_credentials'), array($cache, $options));

        $this->credentials->key    = $instance_profile_credentials['key'];
        $this->credentials->secret = $instance_profile_credentials['secret'];
        $this->credentials->token  = $instance_profile_credentials['token'];
    }

    // Set internal credentials after they are resolved
    $this->key = $this->credentials->key;
    $this->secret_key = $this->credentials->secret;
    $this->auth_token = $this->credentials->token;
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback