/** * @test */ public function testFunctional() { $this->skipIfEc2PlatformDisabled(); $aws = $this->aws; //$aws->setDebug(true); $list = $aws->cloudFront->distribution->describe(); $this->assertInstanceOf($this->getCloudFrontClassName('DataType\\DistributionList'), $list); /* @var $dist CloudFrontDataType\DistirbutionData */ foreach ($list as $dist) { $dist->refresh(); $this->assertNotEmpty($dist->getOriginalXml()); $this->assertNotNull($dist->distributionConfig->getETag()); $dist->refreshConfig(); $this->assertNotNull($dist->getETag()); $this->assertInstanceOf($this->getCloudFrontClassName('DataType\\DistributionConfigData'), $dist->distributionConfig); $this->assertNotEmpty($dist->distributionConfig->getOriginalXml()); $dom = new \DOMDocument(); $dom->loadXML($dist->distributionConfig->getOriginalXml()); $this->assertEqualXMLStructure($dom->firstChild, $dist->distributionConfig->toXml(true)->firstChild); unset($dist); } unset($list); //Creates distribution $origin = new CloudFrontDataType\DistributionConfigOriginData(); $origin->originId = 'MyOriginId'; $origin->domainName = 'test.s3.amazonaws.com'; $origin->setS3OriginConfig(new CloudFrontDataType\DistributionS3OriginConfigData('')); $fvd = new CloudFrontDataType\ForwardedValuesData(); $fvd->queryString = false; $fvd->setCookies(new CloudFrontDataType\ForwardedValuesCookiesData(CloudFrontDataType\ForwardedValuesCookiesData::FORWARD_NONE)); $ts = new CloudFrontDataType\TrustedSignerList(); $ts->setEnabled(false); $dcb = new CloudFrontDataType\CacheBehaviorData(); $dcb->minTtl = 3600; $dcb->targetOriginId = $origin->originId; $dcb->viewerProtocolPolicy = 'allow-all'; $dcb->setForwardedValues($fvd); $dcb->setTrustedSigners($ts); $dc = new CloudFrontDataType\DistributionConfigData(); $dc->comment = 'phpunit test distribution'; $dc->enabled = false; $dc->setAliases(array(array('cname' => 'test2.scalr.com'))); $dc->priceClass = 'PriceClass_All'; $dc->setOrigins($origin); $dc->setDefaultCacheBehavior($dcb); $dist = $aws->cloudFront->distribution->create($dc); $this->assertInstanceOf($this->getCloudFrontClassName('DataType\\DistributionData'), $dist); $dist->refresh(); //Too time consuming test // $ret = $dist->delete(); // $this->assertTrue($ret); //Releases all memory from storage. $aws->getEntityManager()->detachAll(); }
public function xCreateDistributionAction() { $aws = $this->environment->aws('us-east-1'); $distributionConfig = new DistributionConfigData(); if ($this->getParam('localDomain') && $this->getParam('zone')) { $distributionConfig->aliases->append(array('cname' => $this->getParam('localDomain') . '.' . $this->getParam('zone'))); } else { if ($this->getParam('remoteDomain')) { $distributionConfig->aliases->append(array('cname' => $this->getParam('remoteDomain'))); } } $distributionConfig->comment = $this->getParam('comment'); $distributionConfig->enabled = true; $origin = new DistributionConfigOriginData('MyOrigin', $this->getParam('bucketName') . ".s3.amazonaws.com"); $origin->setS3OriginConfig(new DistributionS3OriginConfigData()); $distributionConfig->origins->append($origin); $distributionConfig->priceClass = DistributionConfigData::PRICE_CLASS_ALL; $distributionConfig->setDefaultCacheBehavior(new CacheBehaviorData($origin->originId, CacheBehaviorData::VIEWER_PROTOCOL_POLICY_ALLOW_ALL, 3600)); $result = $aws->cloudFront->distribution->create($distributionConfig); $this->db->Execute("INSERT INTO distributions SET\n cfid\t= ?,\n cfurl\t= ?,\n cname\t= ?,\n zone\t= ?,\n bucket\t= ?,\n clientid= ?\n ", array($result->distributionId, $result->domainName, $this->getParam('localDomain') ? $this->getParam('localDomain') : $result->distributionConfig->aliases[0]->cname, $this->getParam('zone') ? $this->getParam('zone') : $result->distributionConfig->aliases[0]->cname, $this->getParam('bucketName'), $this->user->getAccountId())); // $zoneinfo = $this->db->GetRow("SELECT * FROM dns_zones WHERE zone_name=? AND client_id=? LIMIT 1", // array( // $this->getParam('zone')? $this->getParam('zone') : $distributionConfig->CNAME, // $this->user->getAccountId() // )); // if ($zoneinfo) // { // $this->db->Execute("INSERT INTO dns_zone_records SET // zone_id = ?, // type = ?, // ttl = ?, // name = ?, // value = ?, // issystem= ? // ", array($zoneinfo['id'], 'CNAME', 14400, $distributionConfig->CNAME, $result['DomainName'], 0)); // } $this->response->success("Distribution successfully created"); }
public function xCreateDistributionAction() { $this->request->restrictAccess(Acl::RESOURCE_AWS_S3, Acl::PERM_AWS_S3_MANAGE); $distributionConfig = new DistributionConfigData(); if ($this->getParam('localDomain') && $this->getParam('zone')) { $distributionConfig->aliases->append(['cname' => $this->getParam('localDomain') . '.' . $this->getParam('zone')]); } else { if ($this->getParam('remoteDomain')) { $distributionConfig->aliases->append(['cname' => $this->getParam('remoteDomain')]); } } $distributionConfig->comment = $this->getParam('comment'); $distributionConfig->enabled = true; $origin = new DistributionConfigOriginData('MyOrigin', $this->getParam('bucketName') . ".s3.amazonaws.com"); $origin->setS3OriginConfig(new DistributionS3OriginConfigData()); $distributionConfig->origins->append($origin); $distributionConfig->priceClass = DistributionConfigData::PRICE_CLASS_ALL; $distributionConfig->setDefaultCacheBehavior(new CacheBehaviorData($origin->originId, CacheBehaviorData::VIEWER_PROTOCOL_POLICY_ALLOW_ALL, 3600, 86400, 31536000)); $result = $this->getAws(Aws::REGION_US_EAST_1)->cloudFront->distribution->create($distributionConfig); $this->db->Execute("\n INSERT INTO distributions\n SET cfid = ?,\n cfurl = ?,\n cname = ?,\n zone = ?,\n bucket = ?,\n clientid = ?\n ", [$result->distributionId, $result->domainName, $this->getParam('localDomain') ? $this->getParam('localDomain') : $result->distributionConfig->aliases[0]->cname, $this->getParam('zone') ? $this->getParam('zone') : $result->distributionConfig->aliases[0]->cname, $this->getParam('bucketName'), $this->user->getAccountId()]); $this->response->success("Distribution successfully created"); }