Inheritance: extends Aws\Common\Client\AbstractClient
 /**
  * @depends testCreatesOrigins
  */
 public function testCreatesDistribution()
 {
     if (!self::$originId) {
         $this->fail('No originId was set');
     }
     self::log("Creating a distribution");
     $result = $this->client->createDistribution(array('Aliases' => array('Quantity' => 0), 'CacheBehaviors' => array('Quantity' => 0), 'Comment' => 'Testing... 123', 'Enabled' => true, 'CallerReference' => 'BazBar-' . time(), 'DefaultCacheBehavior' => array('MinTTL' => 3600, 'ViewerProtocolPolicy' => 'allow-all', 'TargetOriginId' => self::$originId, 'TrustedSigners' => array('Enabled' => true, 'Quantity' => 1, 'Items' => array('self')), 'ForwardedValues' => array('QueryString' => false)), 'DefaultRootObject' => 'foo.txt', 'Logging' => array('Enabled' => false, 'Bucket' => '', 'Prefix' => ''), 'Origins' => array('Quantity' => 1, 'Items' => array(array('Id' => self::$originId, 'DomainName' => self::$bucketName . '.s3.amazonaws.com', 'S3OriginConfig' => array('OriginAccessIdentity' => 'origin-access-identity/cloudfront/' . self::$originId))))));
     $this->assertInstanceOf('Guzzle\\Service\\Resource\\Model', $result);
     $result = $result->toArray();
     $this->assertArrayHasKey('Id', $result);
     self::$distributionId = $result['Id'];
     $this->assertArrayHasKey('Status', $result);
     $this->assertArrayHasKey('Location', $result);
     self::$distributionUrl = $result['DomainName'];
     $this->assertArrayHasKey('ETag', $result);
     $this->assertEquals(1, $result['DistributionConfig']['Origins']['Quantity']);
     $this->assertArrayHasKey(0, $result['DistributionConfig']['Origins']['Items']);
     $this->assertEquals(self::$bucketName . '.s3.amazonaws.com', $result['DistributionConfig']['Origins']['Items'][0]['DomainName']);
     $id = $result['Id'];
     $result = $this->client->listDistributions();
     $this->assertInstanceOf('Guzzle\\Service\\Resource\\Model', $result);
     $result = $result->toArray();
     $this->assertGreaterThan(0, $result['Quantity']);
     $found = false;
     foreach ($result['Items'] as $item) {
         if ($item['Id'] == $id) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found);
 }
 /**
  * Returns the CloudFrontClient
  *
  * @return CloudFrontClient|string
  */
 public function getCloudFrontClient()
 {
     if ($this->cdn === null) {
         $this->cdn = CloudFrontClient::factory(['key' => $this->key, 'secret' => $this->secret]);
     }
     return $this->cdn;
 }
function modify_cf_distro($origin, $cname)
{
    //echo $cname; exit();
    //$cname = 'www.mydomain.com'; //remove hard-coded stuff
    //$did = 'E5DX7PPTMIQN'; //remove hard-coded stuff
    $did = get_option('bapi_cloudfrontid');
    // Instantiate the S3 client with your AWS credentials and desired AWS region
    $client = CloudFrontClient::factory(array('key' => AWS_ACCESS_KEY, 'secret' => AWS_SECRET_KEY));
    $r = $client->getDistributionConfig(array('Id' => $did));
    $etag = $r['ETag'];
    $cref = $r['CallerReference'];
    $od = $r['Origins']['Items'][0]['DomainName'];
    //print_r($r);exit();
    $exceptionMessage = "";
    try {
        $result = $client->updateDistribution(array('CallerReference' => $cref, 'Aliases' => array('Quantity' => 1, 'Items' => array($cname)), 'DefaultRootObject' => '', 'Origins' => array('Quantity' => 1, 'Items' => array(array('Id' => 'InstaSites-' . $origin, 'DomainName' => $od, 'CustomOriginConfig' => array('HTTPPort' => 80, 'HTTPSPort' => 443, 'OriginProtocolPolicy' => 'http-only')))), 'DefaultCacheBehavior' => array('MinTTL' => 3600, 'ViewerProtocolPolicy' => 'allow-all', 'TargetOriginId' => 'InstaSites-' . $origin, 'TrustedSigners' => array('Enabled' => true, 'Quantity' => 1, 'Items' => array('self')), 'ForwardedValues' => array('QueryString' => true, 'Cookies' => array('Forward' => 'none')), 'TrustedSigners' => array('Enabled' => false, 'Quantity' => 0)), 'CacheBehaviors' => array('Quantity' => 0), 'Comment' => 'InstaSite Signup', 'ViewerCertificate' => array('CloudFrontDefaultCertificate' => true), 'Enabled' => true, 'Logging' => array('Enabled' => false, 'Bucket' => '', 'Prefix' => '', 'IncludeCookies' => true), 'PriceClass' => 'PriceClass_All', 'Id' => $did, 'IfMatch' => $etag));
    } catch (Exception $e) {
        echo 'Caught exception: ', $e->getMessage(), "\n";
    }
    //printf('%s - %s - %s', $result['Status'], $result['Location'], $result['DomainName']) . "\n";
    if ($result['Status'] == "InProgress") {
        //print_r($result);exit();
        return $result;
    }
    //we check if the exceptionMessage was updated meaning there was an exception
    if ($exceptionMessage != '') {
        $resultException = array('CreatingDistrib' => false, 'Message' => $exceptionMessage);
        return $resultException;
    }
    //return false;
}
 /**
  * Override factory() to set credential defaults.
  */
 public static function factory($config = array())
 {
     if (!isset($config['private_key'])) {
         $config['private_key'] = static::variable_get('amazons3_cloudfront_private_key');
         $config['key_pair_id'] = static::variable_get('amazons3_cloudfront_keypair_id');
     }
     return parent::factory($config);
 }
 public function testCanInstantiateRegionlessClientsWithoutParameters()
 {
     $config = array('key' => 'foo', 'secret' => 'bar');
     try {
         // Instantiate all of the clients that do not require a region
         \Aws\S3\S3Client::factory($config);
         \Aws\CloudFront\CloudFrontClient::factory($config);
         \Aws\Route53\Route53Client::factory($config);
         \Aws\Sts\StsClient::factory($config);
     } catch (\InvalidArgumentException $e) {
         $this->fail('All of the above clients should have been instantiated without errors: ' . $e->getMessage());
     }
 }
 /**
  * Create CloudFront Client
  *
  * @return Object (Aws\Common\Credentials\Credentials)
  * @since 4.0.0
  * @access public
  */
 public function create_cloudfront_client($options = false)
 {
     $credential = $this->create_credentials($options);
     $credential = apply_filters('c3_credential', $credential);
     if (is_wp_error($credential)) {
         return $credential;
     }
     if ($credential) {
         $cf_client = CloudFrontClient::factory($credential);
     } else {
         $cf_client = CloudFrontClient::factory();
     }
     return $cf_client;
 }
 private function _createClient()
 {
     $client_config = array('key' => $this->_cf_settings['signed_url']['credential']['key'], 'secret' => $this->_cf_settings['signed_url']['credential']['secret'], 'private_key' => $this->_cf_settings['signed_url']['key_pair']['private_key'], 'key_pair_id' => $this->_cf_settings['signed_url']['key_pair']['key_pair_id']);
     return CloudFrontClient::factory($client_config);
 }
 /**
  * Return a CloudFrontClient.
  *
  * @return CloudFrontClient
  */
 private function getClient()
 {
     if (!$this->client) {
         $this->client = CloudFrontClient::factory(array('key' => $this->key, 'secret' => $this->secret));
     }
     return $this->client;
 }
 public function c3_invalidation($post = null)
 {
     $key = 'exclusion-process';
     if (get_transient($key)) {
         return;
     }
     $c3_settings = $this->c3_get_settings();
     if (!$c3_settings) {
         return;
     }
     $credentials = new Credentials(esc_attr($c3_settings['access_key']), esc_attr($c3_settings['secret_key']));
     $cloudFront = CloudFrontClient::factory(array('credentials' => $credentials));
     $args = $this->c3_make_args($c3_settings, $post);
     set_transient($key, true, 5 * 60);
     try {
         $result = $cloudFront->createInvalidation($args);
     } catch (Aws\CloudFront\Exception\TooManyInvalidationsInProgressException $e) {
         error_log($e->__toString(), 0);
     }
 }
 public function testFactoryCreatesClient()
 {
     $client = CloudFrontClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-east-1'));
     $this->assertInstanceOf('Aws\\CloudFront\\CloudFrontSignature', $client->getSignature());
 }
 /**
  * @dataProvider dataForCorrectSignatureIsInstantiatedTest
  */
 public function testCorrectSignatureIsInstantiated(array $config, $signatureClass)
 {
     $client = CloudFrontClient::factory($config);
     $this->assertInstanceOf($signatureClass, $client->getSignature());
 }