/**
  * The constructor. This class should not be instantiated directly. Rather, a service-specific class
  * should be instantiated.
  *
  * @param array $options (Optional) An associative array of parameters that can have the following keys: <ul>
  * 	<li><code>certificate_authority</code> - <code>boolean</code> - Optional - Determines which Cerificate Authority file to use. A value of boolean <code>false</code> will use the Certificate Authority file available on the system. A value of boolean <code>true</code> will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to <code>0755</code>) will use that. Leave this set to <code>false</code> if you're not sure.</li>
  * 	<li><code>credentials</code> - <code>string</code> - Optional - The name of the credential set to use for authentication.</li>
  * 	<li><code>default_cache_config</code> - <code>string</code> - 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: <code>apc</code>, <code>xcache</code>, or a file system path such as <code>./cache</code> or <code>/tmp/cache/</code>.</li>
  * 	<li><code>key</code> - <code>string</code> - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.</li>
  * 	<li><code>instance_profile_timeout</code> - <code>integer</code> - 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.</li>
  * 	<li><code>secret</code> - <code>string</code> - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.</li>
  * 	<li><code>token</code> - <code>string</code> - Optional - An AWS session token.</li>
  * 	<li><code>use_instance_profile_credentials</code> - <code>boolean</code> - Optional - Forces the use of IAM Instance Profile credentials, even when regular credentials are provided.</li></ul>
  * @return void
  */
 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;
 }
 /**
  * Constructs a new instance of <AmazonCloudFront>.
  *
  * @param array $options (Optional) An associative array of parameters that can have the following keys: <ul>
  * 	<li><code>certificate_authority</code> - <code>boolean</code> - Optional - Determines which Cerificate Authority file to use. A value of boolean <code>false</code> will use the Certificate Authority file available on the system. A value of boolean <code>true</code> will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to <code>0755</code>) will use that. Leave this set to <code>false</code> if you're not sure.</li>
  * 	<li><code>credentials</code> - <code>string</code> - Optional - The name of the credential set to use for authentication.</li>
  * 	<li><code>default_cache_config</code> - <code>string</code> - 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: <code>apc</code>, <code>xcache</code>, or a file system path such as <code>./cache</code> or <code>/tmp/cache/</code>.</li>
  * 	<li><code>key</code> - <code>string</code> - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.</li>
  * 	<li><code>secret</code> - <code>string</code> - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.</li>
  * 	<li><code>token</code> - <code>string</code> - Optional - An AWS session token.</li></ul>
  * @return void
  */
 public function __construct(array $options = array())
 {
     $this->api_version = '2010-11-01';
     $this->hostname = self::DEFAULT_URL;
     $this->auth_class = 'AuthV2REST';
     $this->base_xml = '<?xml version="1.0" encoding="UTF-8"?><%s xmlns="http://cloudfront.amazonaws.com/doc/' . $this->api_version . '/"></%1$s>';
     // Set a default key pair ID and private key
     if (isset($options['credentials'])) {
         $this->key_pair_id = CFCredentials::get($options['credentials'])->cloudfront_keypair;
         $this->private_key = CFCredentials::get($options['credentials'])->cloudfront_pem;
     } else {
         $this->key_pair_id = CFCredentials::get()->cloudfront_keypair;
         $this->private_key = CFCredentials::get()->cloudfront_pem;
     }
     return parent::__construct($options);
 }
Exemple #3
0
 /**
  * The constructor. This class should not be instantiated directly. Rather, a service-specific class
  * should be instantiated.
  *
  * @param array $options (Optional) An associative array of parameters that can have the following keys: <ul>
  * 	<li><code>certificate_authority</code> - <code>boolean</code> - Optional - Determines which Cerificate Authority file to use. A value of boolean <code>false</code> will use the Certificate Authority file available on the system. A value of boolean <code>true</code> will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to <code>0755</code>) will use that. Leave this set to <code>false</code> if you're not sure.</li>
  * 	<li><code>credentials</code> - <code>string</code> - Optional - The name of the credential set to use for authentication.</li>
  * 	<li><code>default_cache_config</code> - <code>string</code> - 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: <code>apc</code>, <code>xcache</code>, or a file system path such as <code>./cache</code> or <code>/tmp/cache/</code>.</li>
  * 	<li><code>key</code> - <code>string</code> - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.</li>
  * 	<li><code>secret</code> - <code>string</code> - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.</li>
  * 	<li><code>token</code> - <code>string</code> - Optional - An AWS session token.</li></ul>
  * @return void
  */
 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
     $instance_credentials = new CFCredential($options);
     // Retreive a credential set from config.inc.php if it exists
     if (isset($options['credentials'])) {
         // Use a specific credential set and merge with the instance credentials
         $this->credentials = CFCredentials::get($options['credentials'])->merge($instance_credentials);
     } else {
         try {
             // Use the default credential set and merge with the instance credentials
             $this->credentials = CFCredentials::get(CFCredentials::DEFAULT_KEY)->merge($instance_credentials);
         } catch (CFCredentials_Exception $e) {
             if (isset($options['key']) && isset($options['secret'])) {
                 // Only the instance credentials were provided
                 $this->credentials = $instance_credentials;
             } else {
                 // No credentials provided in the config file or constructor
                 throw new CFCredentials_Exception('No credentials were provided to ' . $this->service . '.');
             }
         }
     }
     // Set internal credentials after they are resolved
     $this->key = $this->credentials->key;
     $this->secret_key = $this->credentials->secret;
     $this->auth_token = $this->credentials->token;
     // Automatically enable whichever caching mechanism is set to default.
     $this->set_cache_config($this->credentials->default_cache_config);
 }
 /**
  * The constructor. This class should not be instantiated directly. Rather, a service-specific class
  * should be instantiated.
  *
  * @param array $options (Optional) An associative array of parameters that can have the following keys: <ul>
  * 	<li><code>certificate_authority</code> - <code>boolean</code> - Optional - Determines which Cerificate Authority file to use. A value of boolean <code>false</code> will use the Certificate Authority file available on the system. A value of boolean <code>true</code> will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to <code>0755</code>) will use that. Leave this set to <code>false</code> if you're not sure.</li>
  * 	<li><code>credentials</code> - <code>string</code> - Optional - The name of the credential set to use for authentication.</li>
  * 	<li><code>default_cache_config</code> - <code>string</code> - 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: <code>apc</code>, <code>xcache</code>, or a file system path such as <code>./cache</code> or <code>/tmp/cache/</code>.</li>
  * 	<li><code>key</code> - <code>string</code> - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.</li>
  * 	<li><code>secret</code> - <code>string</code> - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.</li>
  * 	<li><code>token</code> - <code>string</code> - Optional - An AWS session token.</li></ul>
  * @return void
  */
 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);
     // Store the requested credentials
     $this->credentials = CFCredentials::get(isset($options['credentials']) ? $options['credentials'] : CFCredentials::DEFAULT_KEY);
     $this->credentials = new CFCredential(array_merge($this->credentials->to_array(), $options));
     // Automatically enable whichever caching mechanism is set to default.
     $this->set_cache_config($this->credentials->default_cache_config);
     if (isset($options['key']) && isset($options['secret'])) {
         $this->key = $options['key'];
         $this->secret_key = $options['secret'];
         $this->auth_token = isset($options['token']) ? $options['token'] : null;
         return;
     } else {
         $this->key = $this->credentials->key;
         $this->secret_key = $this->credentials->secret;
         $this->auth_token = $this->credentials->token;
         return;
     }
 }