From e959b018e15f6ca2ef8a1a3ca75f19ca21b26efe Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 18 Dec 2014 16:11:08 +0530 Subject: [PATCH 01/61] Allow using PUT (default) or PATCH as update method depending on property. --- .../Common/Resource/PersistentResource.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index c012b8e76..9ae6582e3 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -28,6 +28,8 @@ abstract class PersistentResource extends BaseResource { + const UPDATE_METHOD = 'PUT'; + /** * Create a new resource * @@ -79,7 +81,16 @@ public function update($params = array()) $this->checkJsonError(); // send the request - return $this->getClient()->put($this->getUrl(), self::getJsonHeader(), $json)->send(); + return $this->makeUpdateRequest($json); + } + + protected function makeUpdateRequest($json) + { + if ('PATCH' === static::UPDATE_METHOD) { + return $this->getClient()->patch($this->getUrl(), self::getJsonHeader(), $json)->send(); + } else { + return $this->getClient()->put($this->getUrl(), self::getJsonHeader(), $json)->send(); + } } /** From 87d31166e56409d49198dbac7648c0970b417e44 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 19 Dec 2014 11:45:40 +0530 Subject: [PATCH 02/61] Setting memory limit needed for code coverage generation. --- phpunit.xml.dist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cd44e77df..be5f3c7e6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -25,4 +25,8 @@ + + + + From 601e18c0af9dd62785c25dcb3bea9e351bdc855f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 19 Dec 2014 12:43:38 +0530 Subject: [PATCH 03/61] Parameterize type of service in catalog so it can be specified when building a service object. --- lib/OpenCloud/Common/Service/ServiceBuilder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/Common/Service/ServiceBuilder.php b/lib/OpenCloud/Common/Service/ServiceBuilder.php index cf59f4a2b..99747e900 100644 --- a/lib/OpenCloud/Common/Service/ServiceBuilder.php +++ b/lib/OpenCloud/Common/Service/ServiceBuilder.php @@ -37,6 +37,7 @@ class ServiceBuilder public static function factory(ClientInterface $client, $class, array $options = array()) { $name = isset($options['name']) ? $options['name'] : null; + $type = isset($options['type']) ? $options['type'] : null; $urlType = isset($options['urlType']) ? $options['urlType'] : null; if (isset($options['region'])) { @@ -47,6 +48,6 @@ public static function factory(ClientInterface $client, $class, array $options = $region = null; } - return new $class($client, null, $name, $region, $urlType); + return new $class($client, $type, $name, $region, $urlType); } } From 733ddd654af767ff5b9ec8a38c311857727f8514 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 19 Dec 2014 12:47:43 +0530 Subject: [PATCH 04/61] Adding tests and implementation for the CDN service. --- lib/OpenCloud/CDN/Resource/Flavor.php | 47 ++++++ lib/OpenCloud/CDN/Resource/Service.php | 90 +++++++++++ lib/OpenCloud/CDN/Service.php | 145 ++++++++++++++++++ lib/OpenCloud/OpenStack.php | 18 +++ lib/OpenCloud/Rackspace.php | 19 +++ tests/OpenCloud/Tests/CDN/CDNTestCase.php | 49 ++++++ .../Tests/CDN/Resource/ServiceTest.php | 40 +++++ tests/OpenCloud/Tests/CDN/ServiceTest.php | 82 ++++++++++ tests/OpenCloud/Tests/_response/Auth.resp | 11 ++ 9 files changed, 501 insertions(+) create mode 100644 lib/OpenCloud/CDN/Resource/Flavor.php create mode 100644 lib/OpenCloud/CDN/Resource/Service.php create mode 100644 lib/OpenCloud/CDN/Service.php create mode 100644 tests/OpenCloud/Tests/CDN/CDNTestCase.php create mode 100644 tests/OpenCloud/Tests/CDN/Resource/ServiceTest.php create mode 100644 tests/OpenCloud/Tests/CDN/ServiceTest.php diff --git a/lib/OpenCloud/CDN/Resource/Flavor.php b/lib/OpenCloud/CDN/Resource/Flavor.php new file mode 100644 index 000000000..28bf8c1b8 --- /dev/null +++ b/lib/OpenCloud/CDN/Resource/Flavor.php @@ -0,0 +1,47 @@ +noUpdate(); + } +} diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php new file mode 100644 index 000000000..00348129b --- /dev/null +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -0,0 +1,90 @@ + 'flavorId' + ); + + protected $createKeys = array( + 'name', + 'domains', + 'origins', + 'caching', + 'restrictions', + 'flavorId' + ); + + protected $updateKeys = array( + 'name', + 'domains', + 'origins', + 'caching', + 'restrictions', + 'flavorId' + ); + + public function purgeAssets($assetUrl = null) + { + $assetsUrl = $this->assetsUrl(); + if (null === $assetUrl) { + $assetsUrl->setQuery(array('all' => 'true')); + } else { + $assetsUrl->setQuery(array('url' => $assetUrl)); + } + + return $this->getClient()->delete($assetsUrl)->send(); + } + + protected function assetsUrl() + { + $url = clone $this->getUrl(); + $url->addPath('assets'); + + return $url; + } + + protected function primaryKeyField() + { + return 'name'; + } +} diff --git a/lib/OpenCloud/CDN/Service.php b/lib/OpenCloud/CDN/Service.php new file mode 100644 index 000000000..12f8a928c --- /dev/null +++ b/lib/OpenCloud/CDN/Service.php @@ -0,0 +1,145 @@ +resource('Service', $id); + } + + /** + * Creates a new Service and returns it. + * + * @param array $params Service creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-service + * @return \OpenCloud\CDN\Resource\Service Object representing created service + */ + public function createService(array $params = array()) + { + $service = $this->service(); + $service->create($params); + return $service; + } + + /** + * Returns a Service object associated with this CDN service + * + * @param string $id ID of service to retrieve + * @return \OpenCloud\CDN\Resource\Service object + */ + public function getService($id) + { + return $this->service($id); + } + + /** + * Returns a list of services you created + * + * @param array $params + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function listServices(array $params = array()) + { + $url = clone $this->getUrl(); + $url->addPath(ServiceResource::resourceName())->setQuery($params); + + return $this->resourceList('Service', $url); + } + + /** + * Returns a Flavor object associated with this CDN service + * + * @param string $id ID of flavor to retrieve + * @return \OpenCloud\CDN\Resource\Flavor object + */ + public function flavor($id = null) + { + return $this->resource('Flavor', $id); + } + + /** + * Creates a new Flavor and returns it. + * + * @param array $params Flavor creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-flavor + * @return \OpenCloud\CDN\Resource\Flavor Object representing created flavor + */ + public function createFlavor(array $params = array()) + { + $flavor = $this->flavor(); + $flavor->create($params); + return $flavor; + } + + /** + * Returns a Flavor object associated with this CDN service + * + * @param string $id ID of flavor to retrieve + * @return \OpenCloud\CDN\Resource\Flavor object + */ + public function getFlavor($id) + { + return $this->flavor($id); + } + + /** + * Returns a list of flavors you created + * + * @param array $params + * @return \OpenCloud\Common\Collection\PaginatedIterator + */ + public function listFlavors(array $params = array()) + { + $url = clone $this->getUrl(); + $url->addPath(Flavor::resourceName())->setQuery($params); + + return $this->resourceList('Flavor', $url); + } + + /** + * Return namespaces. + * + * @return array + */ + public function namespaces() + { + return array(); + } +} diff --git a/lib/OpenCloud/OpenStack.php b/lib/OpenCloud/OpenStack.php index 25e576959..6bc6eeba1 100644 --- a/lib/OpenCloud/OpenStack.php +++ b/lib/OpenCloud/OpenStack.php @@ -566,4 +566,22 @@ public function networkingService($name = null, $region = null, $urltype = null) 'urlType' => $urltype )); } + + /** + * Creates a new CDN (Poppy) service object + * + * @param string $name The name of the service as it appears in the Catalog + * @param string $region The region (DFW, IAD, ORD, LON, SYD) + * @param string $urltype The URL type ("publicURL" or "internalURL") + * @return \OpenCloud\Cdn\Service + * @codeCoverageIgnore + */ + public function cdnService($name = null, $region = null, $urltype = null) + { + return ServiceBuilder::factory($this, 'OpenCloud\CDN\Service', array( + 'name' => $name, + 'region' => $region, + 'urlType' => $urltype + )); + } } diff --git a/lib/OpenCloud/Rackspace.php b/lib/OpenCloud/Rackspace.php index 8480a0d71..40473a4b0 100644 --- a/lib/OpenCloud/Rackspace.php +++ b/lib/OpenCloud/Rackspace.php @@ -174,4 +174,23 @@ public function queuesService($name = null, $region = null, $urltype = null) 'urlType' => $urltype )); } + + /** + * Creates a new CDN (Rackspace CDN) service object + * + * @param string $name The name of the service as it appears in the Catalog + * @param string $region The region (DFW, IAD, ORD, LON, SYD) + * @param string $urltype The URL type ("publicURL" or "internalURL") + * @return \OpenCloud\Cdn\Service + * @codeCoverageIgnore + */ + public function cdnService($name = null, $region = null, $urltype = null) + { + return ServiceBuilder::factory($this, 'OpenCloud\CDN\Service', array( + 'name' => $name, + 'type' => 'rax:cdn', + 'region' => $region, + 'urlType' => $urltype + )); + } } diff --git a/tests/OpenCloud/Tests/CDN/CDNTestCase.php b/tests/OpenCloud/Tests/CDN/CDNTestCase.php new file mode 100644 index 000000000..4f07d58f4 --- /dev/null +++ b/tests/OpenCloud/Tests/CDN/CDNTestCase.php @@ -0,0 +1,49 @@ +service = $this->getClient()->cdnService(); + + $this->addMockSubscriber($this->makeResponse('{"name":"mywebsite.com","domains":[{"domain":"blog.mywebsite.com"}],"origins":[{"origin":"mywebsite.com","port":80,"ssl":false},{"origin":"77.66.55.44","port":80,"ssl":false,"rules":[{"name":"videos","request_url":"^/videos/*.m3u"}]}],"caching":[{"name":"default","ttl":3600},{"name":"home","ttl":17200,"rules":[{"name":"index","request_url":"/index.htm"}]},{"name":"images","ttl":12800,"rules":[{"name":"images","request_url":"*.png"}]}],"restrictions":[{"name":"website only","rules":[{"name":"mywebsite.com","http_host":"www.mywebsite.com"}]}],"flavor_id":"cdn","status":"deployed","links":[{"href":"https://global.cdn.api.rackspacecloud.com/v1.0/services/mywebsite.com","rel":"self"},{"href":"mywebsite.com","rel":"access_url"}]}')); + $this->serviceResource = $this->service->getService('mywebsite.com'); + } + + protected function assertIsService($object) + { + $this->assertInstanceOf('OpenCloud\CDN\Service', $object); + } + + protected function assertIsServiceResource($object) + { + $this->assertInstanceOf('OpenCloud\CDN\Resource\Service', $object); + } + + protected function assertIsFlavorResource($object) + { + $this->assertInstanceOf('OpenCloud\CDN\Resource\Flavor', $object); + } +} diff --git a/tests/OpenCloud/Tests/CDN/Resource/ServiceTest.php b/tests/OpenCloud/Tests/CDN/Resource/ServiceTest.php new file mode 100644 index 000000000..37bd61a50 --- /dev/null +++ b/tests/OpenCloud/Tests/CDN/Resource/ServiceTest.php @@ -0,0 +1,40 @@ +addMockSubscriber($this->makeResponse(null, 202)); + + $actualResponse = $this->serviceResource->purgeAssets('/images/foo.png'); + $this->assertEquals(202, $actualResponse->getStatusCode()); + } + + public function testPurgeAllAssets() + { + $this->addMockSubscriber($this->makeResponse(null, 202)); + + $actualResponse = $this->serviceResource->purgeAssets(); + $this->assertEquals(202, $actualResponse->getStatusCode()); + } +} diff --git a/tests/OpenCloud/Tests/CDN/ServiceTest.php b/tests/OpenCloud/Tests/CDN/ServiceTest.php new file mode 100644 index 000000000..e24298e00 --- /dev/null +++ b/tests/OpenCloud/Tests/CDN/ServiceTest.php @@ -0,0 +1,82 @@ +getClient()->cdnService(); + $this->assertIsService($service); + } + + public function testCreateService() + { + $this->assertIsServiceResource($this->service->createService(array( + 'name' => 'mywebsite' + ))); + } + + public function testListServices() + { + $this->addMockSubscriber($this->makeResponse('{"links":[{"rel":"next","href":"https://global.cdn.api.rackspacecloud.com/v1.0/services?marker=www.myothersite.com&limit=20"}],"services":[{"name":"mywebsite.com","domains":[{"domain":"www.mywebsite.com"}],"origins":[{"origin":"mywebsite.com","port":80,"ssl":false}],"caching":[{"name":"default","ttl":3600},{"name":"home","ttl":17200,"rules":[{"name":"index","request_url":"/index.htm"}]},{"name":"images","ttl":12800,"rules":[{"name":"images","request_url":"*.png"}]}],"restrictions":[{"name":"website only","rules":[{"name":"mywebsite.com","http_host":"www.mywebsite.com"}]}],"flavor_id":"cdn","status":"deployed","links":[{"href":"https://global.cdn.api.rackspacecloud.com/v1.0/services/mywebsite.com","rel":"self"},{"href":"mywebsite.com","rel":"access_url"}]},{"name":"myothersite.com","domains":[{"domain":"www.myothersite.com"}],"origins":[{"origin":"44.33.22.11","port":80,"ssl":false},{"origin":"77.66.55.44","port":80,"ssl":false,"rules":[{"name":"videos","request_url":"^/videos/*.m3u"}]}],"caching":[{"name":"default","ttl":3600}],"restrictions":[{}],"flavor_id":"cdn","status":"deployed","links":[{"href":"https://global.cdn.api.rackspacecloud.com/v1.0/services/myothersite.com","rel":"self"},{"href":"myothersite.com","rel":"access_url"}]}]}')); + + $services = $this->service->listServices(); + $this->isCollection($services); + $this->assertIsServiceResource($services->getElement(0)); + } + + public function testGetService() + { + $this->addMockSubscriber($this->makeResponse('{"name":"mywebsite.com","domains":[{"domain":"blog.mywebsite.com"}],"origins":[{"origin":"mywebsite.com","port":80,"ssl":false},{"origin":"77.66.55.44","port":80,"ssl":false,"rules":[{"name":"videos","request_url":"^/videos/*.m3u"}]}],"caching":[{"name":"default","ttl":3600},{"name":"home","ttl":17200,"rules":[{"name":"index","request_url":"/index.htm"}]},{"name":"images","ttl":12800,"rules":[{"name":"images","request_url":"*.png"}]}],"restrictions":[{"name":"website only","rules":[{"name":"mywebsite.com","http_host":"www.mywebsite.com"}]}],"flavor_id":"cdn","status":"deployed","links":[{"href":"https://global.cdn.api.rackspacecloud.com/v1.0/services/mywebsite.com","rel":"self"},{"href":"mywebsite.com","rel":"access_url"}]}')); + + $service = $this->service->getService('mywebsite.com'); + $this->assertIsServiceResource($service); + $this->assertEquals('mywebsite.com', $service->getName()); + $this->assertEquals('cdn', $service->getFlavorId()); + } + + public function testCreateFlavor() + { + $this->assertIsFlavorResource($this->service->createFlavor(array( + 'id' => 'asia' + ))); + } + + public function testListFlavors() + { + $this->addMockSubscriber($this->makeResponse('{"flavors":[{"id":"cdn","limits":{"origins":{"min":1,"max":5},"domains":{"min":1,"max":5},"caching":{"min":3600,"max":604800,"incr":300}},"providers":[{"provider":"akamai","links":[{"href":"http://www.akamai.com","rel":"provider_url"}]}],"links":[{"href":"https://global.cdn.api.rackspacecloud.com/v1.0/flavors/cdn","rel":"self"}]} ]}')); + + $flavors = $this->service->listFlavors(); + $this->isCollection($flavors); + $this->assertIsFlavorResource($flavors->getElement(0)); + } + + public function testGetFlavor() + { + $this->addMockSubscriber($this->makeResponse('{"id":"cdn","providers":[{"provider":"akamai","links":[{"href":"http://www.akamai.com","rel":"provider_url"}]}],"links":[{"href":"http://preview.cdn.api.rackspacecloud.com/v1.0/flavors/cdn","rel":"self"}]}')); + + $flavor = $this->service->getFlavor('cdn'); + $this->assertIsFlavorResource($flavor); + $this->assertEquals('cdn', $flavor->getId()); + $this->assertEquals('akamai', $flavor->getProviders()[0]->provider); + } +} diff --git a/tests/OpenCloud/Tests/_response/Auth.resp b/tests/OpenCloud/Tests/_response/Auth.resp index 518a634e7..add5174dc 100644 --- a/tests/OpenCloud/Tests/_response/Auth.resp +++ b/tests/OpenCloud/Tests/_response/Auth.resp @@ -364,6 +364,17 @@ Front-End-Https: on } ], "type": "network" + }, + { + "name": "rackCDN", + "endpoints": [ + { + "tenantId": "123456", + "publicURL": "https://global.cdn.api.rackspacecloud.com/v1.0/123456", + "internalURL": "https://global.cdn.api.rackspacecloud.com/v1.0/123456" + } + ], + "type": "rax:cdn" } ], "token": { From f156f4774c05d58993279532174e9f3a64cfb8fa Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 19 Dec 2014 12:50:40 +0530 Subject: [PATCH 05/61] Whitespace fixes. --- lib/OpenCloud/CDN/Resource/Flavor.php | 2 +- lib/OpenCloud/CDN/Resource/Service.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenCloud/CDN/Resource/Flavor.php b/lib/OpenCloud/CDN/Resource/Flavor.php index 28bf8c1b8..d8cdbad6a 100644 --- a/lib/OpenCloud/CDN/Resource/Flavor.php +++ b/lib/OpenCloud/CDN/Resource/Flavor.php @@ -22,7 +22,7 @@ /** * A service represents your application that has its content cached to the * edge nodes. - * + * * @package OpenCloud\CDN\Resource */ class Flavor extends PersistentResource diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index 00348129b..521d2921a 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -22,7 +22,7 @@ /** * A service represents your application that has its content cached to the * edge nodes. - * + * * @package OpenCloud\CDN\Resource */ class Service extends PersistentResource From bde9c6606120ac60677b7cecb09ca1bbc31e5b1a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 19 Dec 2014 13:06:07 +0530 Subject: [PATCH 06/61] Fixing docblock for Flavor class. --- lib/OpenCloud/CDN/Resource/Flavor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenCloud/CDN/Resource/Flavor.php b/lib/OpenCloud/CDN/Resource/Flavor.php index d8cdbad6a..31788bd40 100644 --- a/lib/OpenCloud/CDN/Resource/Flavor.php +++ b/lib/OpenCloud/CDN/Resource/Flavor.php @@ -20,8 +20,8 @@ use OpenCloud\Common\Resource\PersistentResource; /** - * A service represents your application that has its content cached to the - * edge nodes. + * A flavor is a configuration for the CDN service. A flavor enables you to + * choose from a generic setting that is powered by one or more CDN providers. * * @package OpenCloud\CDN\Resource */ From 95eada81549af52060ba5e81d6e09a4a0a5b7878 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 23 Dec 2014 08:37:36 +0530 Subject: [PATCH 07/61] Looping over object properties while changing them is a bad idea! --- lib/OpenCloud/Common/Resource/PersistentResource.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index 9ae6582e3..f769f9856 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -276,7 +276,8 @@ protected function recursivelyAliasPropertyValue($propertyValue) } } } elseif (is_object($propertyValue) && ($propertyValue instanceof \stdClass)) { - foreach ($propertyValue as $key => $subValue) { + $objectVars = get_object_vars($propertyValue); + foreach ($objectVars as $key => $subValue) { unset($propertyValue->$key); $propertyValue->{$this->getAlias($key)} = $this->recursivelyAliasPropertyValue($subValue); } From 6d65fca97fcd96298a36833bf998f27273995b38 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 23 Dec 2014 08:38:09 +0530 Subject: [PATCH 08/61] Use the maximum pagination limit supported by the API, unless client provides a lower one. --- lib/OpenCloud/CDN/Service.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/OpenCloud/CDN/Service.php b/lib/OpenCloud/CDN/Service.php index 12f8a928c..fafc63d6e 100644 --- a/lib/OpenCloud/CDN/Service.php +++ b/lib/OpenCloud/CDN/Service.php @@ -32,6 +32,7 @@ class Service extends CatalogService const SUPPORTED_VERSION = 'v1.0'; const DEFAULT_TYPE = 'cdn'; const DEFAULT_NAME = 'rackCDN'; + const MAX_LIMIT = 20; protected $regionless = true; @@ -78,6 +79,8 @@ public function getService($id) */ public function listServices(array $params = array()) { + $params['limit'] = isset($params['limit']) && $params['limit'] <= self::MAX_LIMIT ?: self::MAX_LIMIT; + $url = clone $this->getUrl(); $url->addPath(ServiceResource::resourceName())->setQuery($params); From f963aefddf2a5ce733aa70ba62cb59fdc293e891 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 23 Dec 2014 08:39:29 +0530 Subject: [PATCH 09/61] Do not use the top-level property in the create JSON. --- lib/OpenCloud/CDN/Resource/Flavor.php | 6 ++++++ lib/OpenCloud/CDN/Resource/Service.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/OpenCloud/CDN/Resource/Flavor.php b/lib/OpenCloud/CDN/Resource/Flavor.php index 31788bd40..140516d65 100644 --- a/lib/OpenCloud/CDN/Resource/Flavor.php +++ b/lib/OpenCloud/CDN/Resource/Flavor.php @@ -44,4 +44,10 @@ public function update($params = array()) { return $this->noUpdate(); } + + protected function createJson() + { + $createJson = parent::createJson(); + return $createJson->{self::$json_name}; + } } diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index 521d2921a..98ce5a2dc 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -87,4 +87,10 @@ protected function primaryKeyField() { return 'name'; } + + protected function createJson() + { + $createJson = parent::createJson(); + return $createJson->{self::$json_name}; + } } From 020f7b3fc33cf448185b4b5af23720d5148c20e9 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 23 Dec 2014 08:43:17 +0530 Subject: [PATCH 10/61] Adding smoke tests for CDN. --- tests/OpenCloud/Smoke/Runner.php | 1 + tests/OpenCloud/Smoke/Unit/CDN.php | 87 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/OpenCloud/Smoke/Unit/CDN.php diff --git a/tests/OpenCloud/Smoke/Runner.php b/tests/OpenCloud/Smoke/Runner.php index d1925ba83..57dc8852a 100644 --- a/tests/OpenCloud/Smoke/Runner.php +++ b/tests/OpenCloud/Smoke/Runner.php @@ -37,6 +37,7 @@ class Runner 'Autoscale', 'Compute', 'CloudMonitoring', + 'CDN', 'DNS', 'Database', 'Identity', diff --git a/tests/OpenCloud/Smoke/Unit/CDN.php b/tests/OpenCloud/Smoke/Unit/CDN.php new file mode 100644 index 000000000..7fba1cb6b --- /dev/null +++ b/tests/OpenCloud/Smoke/Unit/CDN.php @@ -0,0 +1,87 @@ +getConnection()->cdnService(); + // TODO: Remove shim below to replace prod with preview endpoint + $service->getEndpoint()->getPublicUrl()->setHost('preview.cdn.api.rackspacecloud.com'); + return $service; + + } + + public function main() + { + $this->step('List flavors'); + $flavors = $this->getService()->listFlavors(); + $this->stepInfo('%-40s | %s', 'Flavor ID', 'Number of providers'); + $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + foreach ($flavors as $flavor) { + $this->stepInfo('%-40s | %d', $flavor->getId(), count($flavor->getProviders())); + } + + $this->step('Create service'); + $createdService = $this->getService()->createService(array( + 'name' => 'php-opencloud.com', + 'domains' => array( + array( 'domain' => 'php-opencloud.com' ), + array( 'domain' => 'www.php-opencloud.com' ) + ), + 'origins' => array( + array( 'origin' => 'origin.php-opencloud.com' ) + ), + 'flavorId' => 'cdn' + )); + $this->stepInfo('Service name: ' . $createdService->getName()); + + $this->step('List services'); + $services = $this->getService()->listServices(); + $this->stepInfo('%-40s | %s', 'Service Name', 'Number of domains'); + $this->stepInfo('%-40s | %s', str_repeat('-', 40), str_repeat('-', 40)); + foreach ($services as $service) { + $this->stepInfo('%-40s | %d', $service->getName(), count($service->getDomains())); + } + + $this->step('Get service'); + $service = $this->getService()->getService('php-opencloud.com'); + $this->stepInfo('Service name: ' . $service->getName()); + $this->stepInfo('Status: ' . $service->getStatus()); + $this->stepInfo('Origin: ' . $service->getOrigins()[0]->origin); + + $this->step('Update service'); + $service->update(array( + 'origins' => array( + array( 'origin' => 'updated-origin.php-opencloud.com' ) + ) + )); + + $this->step('Purge ALL cached service assets'); + $service->purgeAssets(); + + $this->step('Delete service'); + $createdService->delete(); + } + + public function teardown() + { + } +} \ No newline at end of file From 1b0eef9c91cadce71fb020b1a0e6f7047db1cc2b Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 23 Dec 2014 08:43:55 +0530 Subject: [PATCH 11/61] Adding code samples. --- samples/CDN/create-flavor.php | 47 +++++++++++++++++++++ samples/CDN/create-service.php | 47 +++++++++++++++++++++ samples/CDN/delete-flavor.php | 36 ++++++++++++++++ samples/CDN/delete-service.php | 36 ++++++++++++++++ samples/CDN/get-flavor.php | 34 +++++++++++++++ samples/CDN/get-service.php | 34 +++++++++++++++ samples/CDN/list-flavors.php | 36 ++++++++++++++++ samples/CDN/list-services.php | 36 ++++++++++++++++ samples/CDN/purge-cached-service-asset.php | 36 ++++++++++++++++ samples/CDN/purge-cached-service-assets.php | 36 ++++++++++++++++ samples/CDN/update-service.php | 44 +++++++++++++++++++ 11 files changed, 422 insertions(+) create mode 100644 samples/CDN/create-flavor.php create mode 100644 samples/CDN/create-service.php create mode 100644 samples/CDN/delete-flavor.php create mode 100644 samples/CDN/delete-service.php create mode 100644 samples/CDN/get-flavor.php create mode 100644 samples/CDN/get-service.php create mode 100644 samples/CDN/list-flavors.php create mode 100644 samples/CDN/list-services.php create mode 100644 samples/CDN/purge-cached-service-asset.php create mode 100644 samples/CDN/purge-cached-service-assets.php create mode 100644 samples/CDN/update-service.php diff --git a/samples/CDN/create-flavor.php b/samples/CDN/create-flavor.php new file mode 100644 index 000000000..c9811cf85 --- /dev/null +++ b/samples/CDN/create-flavor.php @@ -0,0 +1,47 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Create flavor. +$flavor = $cdnFlavor->createFlavor(array( + 'id' => '{id}', + 'providers' => array( + array( + 'provider' => 'akamai', + 'links' => array( + array( + 'rel' => 'provider_url', + 'href' => 'http://www.akamai.com' + ) + ) + ) + ) +)); +/** @var $flavor OpenCloud\CDN\Resource\Flavor **/ diff --git a/samples/CDN/create-service.php b/samples/CDN/create-service.php new file mode 100644 index 000000000..2df1f5c5e --- /dev/null +++ b/samples/CDN/create-service.php @@ -0,0 +1,47 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Create service. +$service = $cdnService->createService(array( + 'name' => '{name}', + 'domains' => array( + array( + 'domain' => '{domain name}' + ) + ), + 'origins' => array( + array( + 'origin' => '{origin address}' + ) + ), + 'flavorId' => '{flavor ID}' +)); +/** @var $service OpenCloud\CDN\Resource\Service **/ diff --git a/samples/CDN/delete-flavor.php b/samples/CDN/delete-flavor.php new file mode 100644 index 000000000..760a0306b --- /dev/null +++ b/samples/CDN/delete-flavor.php @@ -0,0 +1,36 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get flavor. +$flavor = $cdnFlavor->getFlavors('{id}'); + +// 4. Delete it. +$flavor->delete(); diff --git a/samples/CDN/delete-service.php b/samples/CDN/delete-service.php new file mode 100644 index 000000000..345479084 --- /dev/null +++ b/samples/CDN/delete-service.php @@ -0,0 +1,36 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get service. +$service = $cdnService->getServices('{name}'); + +// 4. Delete it. +$service->delete(); diff --git a/samples/CDN/get-flavor.php b/samples/CDN/get-flavor.php new file mode 100644 index 000000000..e63ffcc29 --- /dev/null +++ b/samples/CDN/get-flavor.php @@ -0,0 +1,34 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get flavor. +$flavor = $cdnService->getFlavor('{flavor ID}'); +/** @var $flavor OpenCloud\CDN\Resource\Flavor **/ diff --git a/samples/CDN/get-service.php b/samples/CDN/get-service.php new file mode 100644 index 000000000..7a4a72dae --- /dev/null +++ b/samples/CDN/get-service.php @@ -0,0 +1,34 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get service. +$service = $cdnService->getService('{name}'); +/** @var $service OpenCloud\CDN\Resource\Service **/ diff --git a/samples/CDN/list-flavors.php b/samples/CDN/list-flavors.php new file mode 100644 index 000000000..8ddf9c4ce --- /dev/null +++ b/samples/CDN/list-flavors.php @@ -0,0 +1,36 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get flavor list. +$flavors = $cdnService->listFlavors(); +foreach ($flavors as $flavor) { + /** @var $flavor OpenCloud\CDN\Resource\Flavor **/ +} diff --git a/samples/CDN/list-services.php b/samples/CDN/list-services.php new file mode 100644 index 000000000..67f5d63a4 --- /dev/null +++ b/samples/CDN/list-services.php @@ -0,0 +1,36 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get service list. +$services = $cdnService->listServices(); +foreach ($services as $service) { + /** @var $service OpenCloud\CDN\Resource\Service **/ +} diff --git a/samples/CDN/purge-cached-service-asset.php b/samples/CDN/purge-cached-service-asset.php new file mode 100644 index 000000000..6d5e83c5c --- /dev/null +++ b/samples/CDN/purge-cached-service-asset.php @@ -0,0 +1,36 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get service. +$service = $cdnService->getServices('{name}'); + +// 4. Purge a specific asset belonging to service. +$service->purgeAsset('{asset URL}'); diff --git a/samples/CDN/purge-cached-service-assets.php b/samples/CDN/purge-cached-service-assets.php new file mode 100644 index 000000000..0d032c89c --- /dev/null +++ b/samples/CDN/purge-cached-service-assets.php @@ -0,0 +1,36 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get service. +$service = $cdnService->getServices('{name}'); + +// 4. Purge all assets belonging to service. +$service->purgeAssets(); diff --git a/samples/CDN/update-service.php b/samples/CDN/update-service.php new file mode 100644 index 000000000..13b34b7bf --- /dev/null +++ b/samples/CDN/update-service.php @@ -0,0 +1,44 @@ + '{username}', + 'apiKey' => '{apiKey}', +)); + +// 2. Obtain an CDN service object from the client. +$cdnService = $client->cdnService(); + +// 3. Get service. +$service = $cdnService->getService('{name}'); + +// 4. Update it. +$service->update(array( + 'origins' => array( + array( + 'origin' => '44.33.22.11', + 'port' => 80, + 'ssl' => false + ) + ) +)); From 07d62a0fd6bf990e5db578ed6db07821fafa19fb Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 08:46:03 +0530 Subject: [PATCH 12/61] Adding Getting Started Guide for CDN service. --- docs/userguide/CDN/README.md | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 docs/userguide/CDN/README.md diff --git a/docs/userguide/CDN/README.md b/docs/userguide/CDN/README.md new file mode 100644 index 000000000..76ba95735 --- /dev/null +++ b/docs/userguide/CDN/README.md @@ -0,0 +1,95 @@ +# CDN + +**CDN** is a service that you can use to manage your CDN-enabled domains and the origins and assets associated with those domains. + +## Concepts + +To use the CDN service effectively, you should understand the following key concepts: + +* **Content delivery network**: A content delivery network (CDN) is a system of multiple computers that contains copies of data stored at various network nodes. A CDN is designed to improve performance of publicly distributed assets. Assets can be anything from website content, to web application components, to media such as videos, ads, and interactive experiences.  CDNs decrease the load time of these assets by caching them on edge servers, also called points of presence (PoPs).  Edge servers are distributed around the globe, meaning requests only travel to a local location to grab assets, rather than to and from a data center based far from the end user. + +* **Edge node**: CDN providers have many points of presence (PoP) servers around the world. These servers are known as edge nodes. These edge nodes cache the content and serve it directly to customers, thus reducing transit time to a customers location. + +* **Edge server**: An edge server is the same as an edge node. + +* **Origin**: An origin is an address (IP or domain) from which the CDN provider pulls content. A service can have multiple origins. + +* **Flavor**: A flavor is a configuration option. A flavor enables you to choose from a generic setting that is powered by one or more CDN providers. + +* **Service**: A service represents your application that has its content cached to the edge nodes. + +* **Status**: The status indicates the current state of the service. The time it takes for a service configuration to be distributed amongst a CDN provider cache can vary. + +* **Purge**: Purging removes content from the edge servers - thus invalidating the content - so that it can be refreshed from your origin servers. + +* **Caching rule**: A caching rule provides you with fine-grained control over the time-to-live (TTL) of an object. When the TTL expires for an object, the edge node pulls the object from the origin again. + +* **Restriction**: A restriction enables you to define rules about who can or cannot access content from the cache. Examples of a restriction are allowing requests only from certain domains, geographies, or IP addresses. + +## Getting started + +### 1. Instantiate an OpenStack or Rackspace client. + +To use the CDN service, you must first instantiate a `OpenStack` or `Rackspace` client object. + +* If you are working with an OpenStack cloud, instantiate an `OpenCloud\OpenStack` client as follows: + + ```php + use OpenCloud\OpenStack; + + $client = new OpenStack('', array( + 'username' => '', + 'password' => '' + )); + ``` + +* If you are working with the Rackspace cloud, instantiate a `OpenCloud\Rackspace` client as follows: + + ```php + use OpenCloud\Rackspace; + + $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array( + 'username' => '', + 'apiKey' => '' + )); + ``` + +### 2. Obtain a CDN service object from the client. +All CDN operations are done via an _CDN service object_. To +instantiate this object, call the `cdnService` method on the `$client` +object. This method takes one argument: + +| Position | Description | Data type | Required? | Default value | Example value | +| -------- | ----------- | ----------| --------- | ------------- | ------------- | +| 1 | Name of the service, as it appears in the service catalog | String | No | `null`; automatically determined when possible | `rackCDN` | + + +```php +$cdnService = $client->cdnService(); +``` + +### 3. Create a service. +```php +$service = $cdnService->createService(array( + 'name' => 'acme_site', + 'domains' => array( + array( + 'domain' => 'www.acme.com' + ), + array( + 'domain' => 'acme.com' + ) + ), + 'origins' => array( + array( + 'origin' => 'origin.acme.com' + ) + ), + 'flavorId' => 'cdn' +));``` + +[ [Get the executable PHP script for this example](/samples/CDN/create-cdn.php) ] + +## Next steps + +Once you have created a service, there is more you can do with it. See [complete user guide for CDN](USERGUIDE.md). From 8f54c4eafd302b678873b28b67914adf25f9b7c5 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 09:37:11 +0530 Subject: [PATCH 13/61] Adding another property alias. --- lib/OpenCloud/CDN/Resource/Service.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index 98ce5a2dc..444266f12 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -42,7 +42,8 @@ class Service extends PersistentResource protected $links; protected $aliases = array( - 'flavor_id' => 'flavorId' + 'flavor_id' => 'flavorId', + 'http_host' => 'httpHost' ); protected $createKeys = array( From 260f68f3b1a89f79591b09ff81a4fe7747897518 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 09:38:21 +0530 Subject: [PATCH 14/61] Clarifying definition. --- docs/userguide/CDN/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/README.md b/docs/userguide/CDN/README.md index 76ba95735..6a7fc864f 100644 --- a/docs/userguide/CDN/README.md +++ b/docs/userguide/CDN/README.md @@ -16,7 +16,7 @@ To use the CDN service effectively, you should understand the following key conc * **Flavor**: A flavor is a configuration option. A flavor enables you to choose from a generic setting that is powered by one or more CDN providers. -* **Service**: A service represents your application that has its content cached to the edge nodes. +* **Service**: A service represents your web application that has its content cached to the edge nodes. * **Status**: The status indicates the current state of the service. The time it takes for a service configuration to be distributed amongst a CDN provider cache can vary. From 038e2da00a463a158bac036bc893fb248f65c7ce Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 09:38:42 +0530 Subject: [PATCH 15/61] Disambiguating "service" by providing additional context. --- docs/userguide/CDN/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/README.md b/docs/userguide/CDN/README.md index 6a7fc864f..04ce14bc7 100644 --- a/docs/userguide/CDN/README.md +++ b/docs/userguide/CDN/README.md @@ -68,7 +68,7 @@ object. This method takes one argument: $cdnService = $client->cdnService(); ``` -### 3. Create a service. +### 3. Create a service (to represent your web application). ```php $service = $cdnService->createService(array( 'name' => 'acme_site', From f525941e65d71f71528aa98445ca6f22e02d57e9 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 09:39:17 +0530 Subject: [PATCH 16/61] Fixing link. --- docs/userguide/CDN/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/README.md b/docs/userguide/CDN/README.md index 04ce14bc7..ba959ce11 100644 --- a/docs/userguide/CDN/README.md +++ b/docs/userguide/CDN/README.md @@ -88,7 +88,7 @@ $service = $cdnService->createService(array( 'flavorId' => 'cdn' ));``` -[ [Get the executable PHP script for this example](/samples/CDN/create-cdn.php) ] +[ [Get the executable PHP script for this example](/samples/CDN/create-service.php) ] ## Next steps From 157ea27bf0b3f3f95ffee62caa1d1e9479476d91 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 09:39:38 +0530 Subject: [PATCH 17/61] Adding Complete User Guide for CDN service. --- docs/userguide/CDN/USERGUIDE.md | 264 ++++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 docs/userguide/CDN/USERGUIDE.md diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md new file mode 100644 index 000000000..8c0abb7d4 --- /dev/null +++ b/docs/userguide/CDN/USERGUIDE.md @@ -0,0 +1,264 @@ +# Complete User Guide for the CDN Service + +CDN is a service that you can use to manage your CDN-enabled domains and the origins and assets associated with those domains. + +## Table of contents + * [Concepts](#concepts) + * [Prerequisites](#prerequisites) + * [Client](#client) + * [CDN service](#cdn-service) + * [Services](#services) + * [Create a service](#create-a-service-to-represent-your-web-application) + * [List Services](#list-Services) + * [Get a service](#get-a-service) + * [Purge cached service assets](#purge-cached-service-assets) + * [Update a service](#update-a-service) + * [Delete a service](#delete-a-service) + * [Flavors](#flavors) + * [Create a flavor](#create-a-flavor) + * [List flavors](#list-flavors) + * [Get a flavor](#get-a-flavor) + * [Delete a flavor](#delete-a-flavor) + +## Concepts + +To use the CDN service effectively, you should understand the following +key concepts: + +* **Content delivery service**: A content delivery service (CDN) is a system of multiple computers that contains copies of data stored at various service nodes. A CDN is designed to improve performance of publicly distributed assets. Assets can be anything from website content, to web application components, to media such as videos, ads, and interactive experiences.  CDNs decrease the load time of these assets by caching them on edge servers, also called points of presence (PoPs).  Edge servers are distributed around the globe, meaning requests only travel to a local location to grab assets, rather than to and from a data center based far from the end user. + +* **Edge node**: CDN providers have many points of presence (PoP) servers around the world. These servers are known as edge nodes. These edge nodes cache the content and serve it directly to customers, thus reducing transit time to a customers location. + +* **Edge server**: An edge server is the same as an edge node. + +* **Origin**: An origin is an address (IP or domain) from which the CDN provider pulls content. A service can have multiple origins. + +* **Flavor**: A flavor is a configuration option. A flavor enables you to choose from a generic setting that is powered by one or more CDN providers. + +* **Service**: A service represents your web application that has its content cached to the edge nodes. + +* **Status**: The status indicates the current state of the service. The time it takes for a service configuration to be distributed amongst a CDN provider cache can vary. + +* **Purge**: Purging removes content from the edge servers - thus invalidating the content - so that it can be refreshed from your origin servers. + +* **Caching rule**: A caching rule provides you with fine-grained control over the time-to-live (TTL) of an object. When the TTL expires for an object, the edge node pulls the object from the origin again. + +* **Restriction**: A restriction enables you to define rules about who can or cannot access content from the cache. Examples of a restriction are allowing requests only from certain domains, geographies, or IP addresses. + + +## Prerequisites + +### Client +To use the CDN service, you must first instantiate a `OpenStack` or `Rackspace` client object. + +* If you are working with an OpenStack cloud, instantiate an `OpenCloud\OpenStack` client as follows: + + ```php + use OpenCloud\OpenStack; + + $client = new OpenStack('', array( + 'username' => '', + 'password' => '' + )); + ``` + +* If you are working with the Rackspace cloud, instantiate a `OpenCloud\Rackspace` client as follows: + + ```php + use OpenCloud\Rackspace; + + $client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array( + 'username' => '', + 'apiKey' => '' + )); + ``` + +### CDN service + +All CDN operations are done via an _CDN service object_. To +instantiate this object, call the `cdnService` method on the `$client` +object. This method takes one argument: + +| Position | Description | Data type | Required? | Default value | Example value | +| -------- | ----------- | ----------| --------- | ------------- | ------------- | +| 1 | Name of the service, as it appears in the service catalog | String | No | `null`; automatically determined when possible | `rackCDN` | + + +```php +$cdnService = $client->cdnService(); +``` + +## Services + +A service represents your web application that has its content cached to the edge nodes. + +### Create a service (to represent your web application) + + +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `name` | A human-readable name for the service. This name must be unique. | String | No | `null` | `acme_site` | +| `domains` | An array of associative arrays, each specifying a domain name for your service. | Array of associative arrays | Yes | `null` | `array( array( 'domain' => 'www.acme.com' ), array ( 'domain' => 'acme.com' ) )` | +| `origins` | An array of associative arrays, each specifying an origin server for your service. The `port`, `ssl`, and `rules` elements for each origin server are optional. | Array of associative arrays | Yes | `null` | `array( array( 'origin' => 'origin.acme.com', 'port' => 80, 'ssl' => false, 'rules' => array() ) )` | +| `flavorId` | The flavor used to configure this service. Use the [list flavors](#list-flavors) operation to retrieve a list of all available flavors. | String | Yes| `null` | `cdn` | +| `restrictions` | An array of associative arrays, each specifying a restriction for who can or cannot access content from the CDN cache. | Array of associative arrays | No | `null` | `array( array( 'name' => 'website only', 'rules' => array( array( 'name' => 'mywebsite.com', 'httpHost' => 'www.mywebsite.com' ) ) ) )` | +| `caching` | An array of associative arrays, each specifying a caching rule for your service's assets. | No | `null` | `array( array( 'name' => 'default', 'ttl' => 3600 ) )` | + +You can create a service as shown in the following example: + +```php +$service = $cdnService->createService(array( + 'name' => 'acme_site', + 'domains' => array( + array( + 'domain' => 'www.acme.com' + ), + array( + 'domain' => 'acme.com' + ) + ), + 'origins' => array( + array( + 'origin' => 'origin.acme.com' + ) + ), + 'flavorId' => 'cdn' +));``` + +[ [Get the executable PHP script for this example](/samples/CDN/create-service.php) ] + +### List Services + +You can list all the services you have created as shown in the following example: + +```php +$services = $cdnService->listServices(); +foreach ($services as $service) { + /** @var $service OpenCloud\CDN\Resource\Service **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/CDN/list-services.php) ] + +### Get a service + +You can retrieve a specific service by using that service's name, as shown in the following example: + +```php +$service = $cdnService->getservice('acme_site'); +/** @var $service OpenCloud\CDN\Resource\Service **/ +``` + +[ [Get the executable PHP script for this example](/samples/CDN/get-service.php) ] + +### Update a service + +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `domains` | An array of associative arrays, each specifying a domain name for your service. | Array of associative arrays | Yes | `null` | `array( array( 'domain' => 'www.acme.com' ), array ( 'domain' => 'acme.com' ) )` | +| `origins` | An array of associative arrays, each specifying an origin server for your service. The `port`, `ssl`, and `rules` elements for each origin server are optional. | Array of associative arrays | Yes | `null` | `array( array( 'origin' => 'origin.acme.com', 'port' => 80, 'ssl' => false, 'rules' => array() ) )` | +| `flavorId` | The flavor used to configure this service. Use the [list flavors](#list-flavors) operation to retrieve a list of all available flavors. | String | Yes| `null` | `cdn` | +| `restrictions` | An array of associative arrays, each specifying a restriction for who can or cannot access content from the CDN cache. | Array of associative arrays | No | `null` | `array( array( 'name' => 'website only', 'rules' => array( array( 'name' => 'mywebsite.com', 'httpHost' => 'www.mywebsite.com' ) ) ) )` | +| `caching` | An array of associative arrays, each specifying a caching rule for your service's assets. | No | `null` | `array( array( 'name' => 'default', 'ttl' => 3600 ) )` | + +You can update a service as shown in the following example: + +```php +$service->update(array( + 'origins' => array( + array( + 'origin' => '44.33.22.11', + 'port' => 80, + 'ssl' => false + ) + ) +)); +``` + +[ [Get the executable PHP script for this example](/samples/CDN/update-service.php) ] + +### Delete a service + +You can delete a service as shown in the following example: + +```php +$service->delete(); +``` + +[ [Get the executable PHP script for this example](/samples/CDN/delete-service.php) ] + +## Flavors + +A flavor is a configuration option. A flavor enables you to choose from a generic setting that is powered by one or more CDN providers. + +### Create a flavor + +Note: When working with the Rackspace Cloud, this operation requires the `cdn:operator` role. + +This operation takes one parameter, an associative array, with the following keys: + +| Name | Description | Data type | Required? | Default value | Example value | +| ---- | ----------- | --------- | --------- | ------------- | ------------- | +| `id` | ID of flavor. This ID must be unique. | String | Yes | `null` | `cdn` | +| `providers` | An array of associative arrays, each representing a CDN provider. | Array of associative arrays | Yes | `null` | `array( array( 'provider' => 'akamai', 'links' => array( array( 'rel' => 'provider_url', 'href' => 'http://www.akamai.com' ) ) ) )` | + +You can create a flavor as shown in the following example: + +```php +$Flavor = $CDNService->createFlavor(array( + 'id' => 'cdn', + 'providers' => array( + array( + 'name' => 'akamai', + 'links' => array( + 'rel' => 'provider_url', + 'href' => 'http://www.akamai.com' + ) + ) + ) +)); +/** @var $Flavor OpenCloud\CDN\Resource\Flavor **/ +``` + +[ [Get the executable PHP script for this example](/samples/CDN/create-flavor.php) ] + +### List flavors + +You can list all available flavors as shown in the following example: + +```php +$flavors = $cdnService->listFlavors(); +foreach ($flavors as $flavor) { + /** @var $flavor OpenCloud\CDN\Resource\Flavor **/ +} +``` + +[ [Get the executable PHP script for this example](/samples/CDN/list-flavors.php) ] + +### Get a flavor + +You can retrieve a specific flavor by using that flavor's ID, as shown in the +following example: + +```php +$flavor = $cdnService->getFlavor('cdn'); +/** @var $flavor OpenCloud\CDN\Resource\Flavor **/ +``` + +[ [Get the executable PHP script for this example](/samples/CDN/get-flavor.php) ] + +### Delete a flavor + +Note: When working with the Rackspace Cloud, this operation requires the `cdn:operator` role. + +You can delete a flavor as shown in the following example: + +```php +$flavor->delete(); +``` + +[ [Get the executable PHP script for this example](/samples/CDN/delete-flavor.php) ] From ad715657092677debe1b6d22af15c1f736baf18c Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 11:54:27 +0530 Subject: [PATCH 18/61] Whitespace lint fixes. --- tests/OpenCloud/Smoke/Unit/CDN.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/OpenCloud/Smoke/Unit/CDN.php b/tests/OpenCloud/Smoke/Unit/CDN.php index 7fba1cb6b..e996ab3d4 100644 --- a/tests/OpenCloud/Smoke/Unit/CDN.php +++ b/tests/OpenCloud/Smoke/Unit/CDN.php @@ -16,6 +16,7 @@ */ namespace OpenCloud\Smoke\Unit; + use Guzzle\Http\Exception\ClientErrorResponseException; class CDN extends AbstractUnit implements UnitInterface @@ -26,7 +27,6 @@ public function setupService() // TODO: Remove shim below to replace prod with preview endpoint $service->getEndpoint()->getPublicUrl()->setHost('preview.cdn.api.rackspacecloud.com'); return $service; - } public function main() @@ -84,4 +84,4 @@ public function main() public function teardown() { } -} \ No newline at end of file +} From 1c59c458dd7a4ac50e01c7718ead9ab913dcd273 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 25 Dec 2014 12:10:34 +0530 Subject: [PATCH 19/61] Removing limits. --- lib/OpenCloud/CDN/Resource/Flavor.php | 2 -- tests/OpenCloud/Tests/CDN/ServiceTest.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/OpenCloud/CDN/Resource/Flavor.php b/lib/OpenCloud/CDN/Resource/Flavor.php index 140516d65..de13eb9f2 100644 --- a/lib/OpenCloud/CDN/Resource/Flavor.php +++ b/lib/OpenCloud/CDN/Resource/Flavor.php @@ -31,12 +31,10 @@ class Flavor extends PersistentResource protected static $json_name = 'flavor'; protected $id; - protected $limits; protected $providers; protected $createKeys = array( 'id', - 'limits', 'providers' ); diff --git a/tests/OpenCloud/Tests/CDN/ServiceTest.php b/tests/OpenCloud/Tests/CDN/ServiceTest.php index e24298e00..dba96d576 100644 --- a/tests/OpenCloud/Tests/CDN/ServiceTest.php +++ b/tests/OpenCloud/Tests/CDN/ServiceTest.php @@ -63,7 +63,7 @@ public function testCreateFlavor() public function testListFlavors() { - $this->addMockSubscriber($this->makeResponse('{"flavors":[{"id":"cdn","limits":{"origins":{"min":1,"max":5},"domains":{"min":1,"max":5},"caching":{"min":3600,"max":604800,"incr":300}},"providers":[{"provider":"akamai","links":[{"href":"http://www.akamai.com","rel":"provider_url"}]}],"links":[{"href":"https://global.cdn.api.rackspacecloud.com/v1.0/flavors/cdn","rel":"self"}]} ]}')); + $this->addMockSubscriber($this->makeResponse('{"flavors":[{"id":"cdn","providers":[{"provider":"akamai","links":[{"href":"http://www.akamai.com","rel":"provider_url"}]}],"links":[{"href":"https://global.cdn.api.rackspacecloud.com/v1.0/flavors/cdn","rel":"self"}]} ]}')); $flavors = $this->service->listFlavors(); $this->isCollection($flavors); From ffb915dcd84ad5381e654f127106e73e33eef4aa Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 03:06:05 -0800 Subject: [PATCH 20/61] Fixing formatting. --- docs/userguide/CDN/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/userguide/CDN/README.md b/docs/userguide/CDN/README.md index ba959ce11..a64cca833 100644 --- a/docs/userguide/CDN/README.md +++ b/docs/userguide/CDN/README.md @@ -86,7 +86,8 @@ $service = $cdnService->createService(array( ) ), 'flavorId' => 'cdn' -));``` +)); +``` [ [Get the executable PHP script for this example](/samples/CDN/create-service.php) ] From 92cbf9895b12fa7adb5f2d097123803ce0b8b9e4 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 03:08:06 -0800 Subject: [PATCH 21/61] Fixing typo. --- docs/userguide/CDN/USERGUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index 8c0abb7d4..9468f2404 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -25,7 +25,7 @@ CDN is a service that you can use to manage your CDN-enabled domains and the ori To use the CDN service effectively, you should understand the following key concepts: -* **Content delivery service**: A content delivery service (CDN) is a system of multiple computers that contains copies of data stored at various service nodes. A CDN is designed to improve performance of publicly distributed assets. Assets can be anything from website content, to web application components, to media such as videos, ads, and interactive experiences.  CDNs decrease the load time of these assets by caching them on edge servers, also called points of presence (PoPs).  Edge servers are distributed around the globe, meaning requests only travel to a local location to grab assets, rather than to and from a data center based far from the end user. +* **Content delivery network**: A content delivery network (CDN) is a system of multiple computers that contains copies of data stored at various network nodes. A CDN is designed to improve performance of publicly distributed assets. Assets can be anything from website content, to web application components, to media such as videos, ads, and interactive experiences.  CDNs decrease the load time of these assets by caching them on edge servers, also called points of presence (PoPs).  Edge servers are distributed around the globe, meaning requests only travel to a local location to grab assets, rather than to and from a data center based far from the end user. * **Edge node**: CDN providers have many points of presence (PoP) servers around the world. These servers are known as edge nodes. These edge nodes cache the content and serve it directly to customers, thus reducing transit time to a customers location. From ee471356b0af824fc772a1dcb92b4cbce528b12f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 03:37:01 -0800 Subject: [PATCH 22/61] Changing syntax to be PHP5.3-compliant. --- tests/OpenCloud/Smoke/Unit/CDN.php | 3 ++- tests/OpenCloud/Tests/CDN/ServiceTest.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/OpenCloud/Smoke/Unit/CDN.php b/tests/OpenCloud/Smoke/Unit/CDN.php index e996ab3d4..97921d11f 100644 --- a/tests/OpenCloud/Smoke/Unit/CDN.php +++ b/tests/OpenCloud/Smoke/Unit/CDN.php @@ -65,7 +65,8 @@ public function main() $service = $this->getService()->getService('php-opencloud.com'); $this->stepInfo('Service name: ' . $service->getName()); $this->stepInfo('Status: ' . $service->getStatus()); - $this->stepInfo('Origin: ' . $service->getOrigins()[0]->origin); + $origins = $service->getOrigins(); + $this->stepInfo('Origin: ' . $origins[0]->origin); $this->step('Update service'); $service->update(array( diff --git a/tests/OpenCloud/Tests/CDN/ServiceTest.php b/tests/OpenCloud/Tests/CDN/ServiceTest.php index dba96d576..e37be35b9 100644 --- a/tests/OpenCloud/Tests/CDN/ServiceTest.php +++ b/tests/OpenCloud/Tests/CDN/ServiceTest.php @@ -77,6 +77,8 @@ public function testGetFlavor() $flavor = $this->service->getFlavor('cdn'); $this->assertIsFlavorResource($flavor); $this->assertEquals('cdn', $flavor->getId()); - $this->assertEquals('akamai', $flavor->getProviders()[0]->provider); + + $providers = $flavor->getProviders(); + $this->assertEquals('akamai', $providers[0]->provider); } } From 5804006358b13cdf4352d37f9a0dfdc94c040c54 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 03:45:47 -0800 Subject: [PATCH 23/61] Fixing link. --- docs/userguide/CDN/USERGUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index 9468f2404..a2cb7fceb 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -9,7 +9,7 @@ CDN is a service that you can use to manage your CDN-enabled domains and the ori * [CDN service](#cdn-service) * [Services](#services) * [Create a service](#create-a-service-to-represent-your-web-application) - * [List Services](#list-Services) + * [List Services](#list-services) * [Get a service](#get-a-service) * [Purge cached service assets](#purge-cached-service-assets) * [Update a service](#update-a-service) From 72182f3ddb6c567a9e15cc99b4e7a6011fdaaada Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 03:55:07 -0800 Subject: [PATCH 24/61] Adding section on service assets. --- docs/userguide/CDN/USERGUIDE.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index a2cb7fceb..eaff6aea6 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -11,9 +11,11 @@ CDN is a service that you can use to manage your CDN-enabled domains and the ori * [Create a service](#create-a-service-to-represent-your-web-application) * [List Services](#list-services) * [Get a service](#get-a-service) - * [Purge cached service assets](#purge-cached-service-assets) * [Update a service](#update-a-service) * [Delete a service](#delete-a-service) + * [Service Assets](#service-assets) + * [Purge all cached service assets](#purge-all-cached-service-assets) + * [Purge a specific cached service asset](#purge-a-specific-cached-service-asset) * [Flavors](#flavors) * [Create a flavor](#create-a-flavor) * [List flavors](#list-flavors) @@ -191,6 +193,29 @@ $service->delete(); [ [Get the executable PHP script for this example](/samples/CDN/delete-service.php) ] +## Service Assets +A service will have its assets distributed and cached across a CDN's edge nodes. + +### Purge all cached service assets + +You can purge all cached assets of a service as shown in the following example: + +```php +$service->purgeAssets(); +``` + +[ [Get the executable PHP script for this example](/samples/CDN/purge-cached-service-assets.php) ] + +### Purge a specific cached service asset + +You can purge a specific asset of a service by providing its relative URL, as shown in the following example: + +```php +$service->purgeAssets('/images/logo.png'); +``` + +[ [Get the executable PHP script for this example](/samples/CDN/purge-cached-service-asset.php) ] + ## Flavors A flavor is a configuration option. A flavor enables you to choose from a generic setting that is powered by one or more CDN providers. From 8b179f62c5f108d71894a6c236d9b140f6b6a3f1 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 03:55:21 -0800 Subject: [PATCH 25/61] Fixing typo in variable name. --- docs/userguide/CDN/USERGUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index eaff6aea6..4760e6da0 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -234,7 +234,7 @@ This operation takes one parameter, an associative array, with the following key You can create a flavor as shown in the following example: ```php -$Flavor = $CDNService->createFlavor(array( +$flavor = $CDNService->createFlavor(array( 'id' => 'cdn', 'providers' => array( array( From 5f4976e89ab6d790bde31198d7e6e1c8036d32f5 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 03:59:04 -0800 Subject: [PATCH 26/61] Fixing case in variable names. --- docs/userguide/CDN/USERGUIDE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index 4760e6da0..de26dac3a 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -234,7 +234,7 @@ This operation takes one parameter, an associative array, with the following key You can create a flavor as shown in the following example: ```php -$flavor = $CDNService->createFlavor(array( +$flavor = $cdnService->createFlavor(array( 'id' => 'cdn', 'providers' => array( array( @@ -246,7 +246,7 @@ $flavor = $CDNService->createFlavor(array( ) ) )); -/** @var $Flavor OpenCloud\CDN\Resource\Flavor **/ +/** @var $flavor OpenCloud\CDN\Resource\Flavor **/ ``` [ [Get the executable PHP script for this example](/samples/CDN/create-flavor.php) ] From f45dc272c6997947bda9bb75884e2517a6df5b84 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 26 Dec 2014 04:00:01 -0800 Subject: [PATCH 27/61] Fixing method name. --- samples/CDN/purge-cached-service-asset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/CDN/purge-cached-service-asset.php b/samples/CDN/purge-cached-service-asset.php index 6d5e83c5c..715a80699 100644 --- a/samples/CDN/purge-cached-service-asset.php +++ b/samples/CDN/purge-cached-service-asset.php @@ -33,4 +33,4 @@ $service = $cdnService->getServices('{name}'); // 4. Purge a specific asset belonging to service. -$service->purgeAsset('{asset URL}'); +$service->purgeAssets('{asset URL}'); From 36336cbc9662c05b2a7060b100ae1e14a99d30b2 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 30 Dec 2014 04:45:48 -0800 Subject: [PATCH 28/61] Adding support for GET / and GET /ping APIs. --- lib/OpenCloud/CDN/Service.php | 24 +++++++++++++++++++++++ tests/OpenCloud/Tests/CDN/ServiceTest.php | 17 ++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/OpenCloud/CDN/Service.php b/lib/OpenCloud/CDN/Service.php index fafc63d6e..20143cc00 100644 --- a/lib/OpenCloud/CDN/Service.php +++ b/lib/OpenCloud/CDN/Service.php @@ -136,6 +136,30 @@ public function listFlavors(array $params = array()) return $this->resourceList('Flavor', $url); } + /** + * Returns the home document for the CDN service + * + * @return \stdClass home document response + */ + public function getHomeDocument() + { + $response = $this->getClient()->get($this->getUrl())->send(); + return Formatter::decode($response); + } + + /** + * Returns the ping (status) response for the CDN service + * + * @return Guzzle\Http\Message\Response + */ + public function getPing() + { + $url = clone $this->getUrl(); + $url->addPath('ping'); + + return $this->getClient()->get($url)->send(); + } + /** * Return namespaces. * diff --git a/tests/OpenCloud/Tests/CDN/ServiceTest.php b/tests/OpenCloud/Tests/CDN/ServiceTest.php index e37be35b9..b3a2bb7f7 100644 --- a/tests/OpenCloud/Tests/CDN/ServiceTest.php +++ b/tests/OpenCloud/Tests/CDN/ServiceTest.php @@ -81,4 +81,21 @@ public function testGetFlavor() $providers = $flavor->getProviders(); $this->assertEquals('akamai', $providers[0]->provider); } + + public function testGetHomeDocument() + { + $this->addMockSubscriber($this->makeResponse('{"resources":{"rel/cdn":{"href-template":"services{?marker,limit}","href-vars":{"marker":"param/marker","limit":"param/limit"},"hints":{"allow":["GET"],"formats":{"application/json":{}}}}}}')); + + $homeDocument = $this->service->getHomeDocument(); + $this->assertNotEmpty($homeDocument); + $this->assertEquals("services{?marker,limit}", $homeDocument->resources->{"rel/cdn"}->{"href-template"}); + } + + public function testGetPing() + { + $this->addMockSubscriber($this->makeResponse(null, 204)); + + $ping = $this->service->getPing(); + $this->assertEquals(204, $ping->getStatusCode()); + } } From f2fe5ab4b32cb45c3ca62ac673f1db2809bc0f64 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 30 Dec 2014 05:38:25 -0800 Subject: [PATCH 29/61] Adding errors property to Service resource. --- lib/OpenCloud/CDN/Resource/Service.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index 444266f12..beef278cd 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -40,6 +40,7 @@ class Service extends PersistentResource protected $flavorId; protected $status; protected $links; + protected $errors; protected $aliases = array( 'flavor_id' => 'flavorId', From 138e0962365cacf4ef40d75969f96c12dc9c986b Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 30 Dec 2014 05:39:19 -0800 Subject: [PATCH 30/61] Remove Accept request header for APIs that don't return responses. --- lib/OpenCloud/CDN/Resource/Service.php | 9 ++++++++- lib/OpenCloud/CDN/Service.php | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index beef278cd..2823286d1 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -74,7 +74,14 @@ public function purgeAssets($assetUrl = null) $assetsUrl->setQuery(array('url' => $assetUrl)); } - return $this->getClient()->delete($assetsUrl)->send(); + $request = $this->getClient()->delete($assetsUrl); + + // This is necessary because the response does not include a body + // and fails with a 406 Not Acceptable if the default + // 'Accept: application/json' header is used in the request. + $request->removeHeader('Accept'); + + return $request->send(); } protected function assetsUrl() diff --git a/lib/OpenCloud/CDN/Service.php b/lib/OpenCloud/CDN/Service.php index 20143cc00..2fbef781c 100644 --- a/lib/OpenCloud/CDN/Service.php +++ b/lib/OpenCloud/CDN/Service.php @@ -156,8 +156,15 @@ public function getPing() { $url = clone $this->getUrl(); $url->addPath('ping'); - - return $this->getClient()->get($url)->send(); + + $request = $this->getClient()->get($url); + + // This is necessary because the response does not include a body + // and fails with a 406 Not Acceptable if the default + // 'Accept: application/json' header is used in the request. + $request->removeHeader('Accept'); + + return $request->send(); } /** From cae80de1d2a0dec9e2523a100f5e916eb45bf451 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 30 Dec 2014 05:40:25 -0800 Subject: [PATCH 31/61] Force addition of trailing slash to URL in order to make GET / work. --- lib/OpenCloud/CDN/Service.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/OpenCloud/CDN/Service.php b/lib/OpenCloud/CDN/Service.php index 2fbef781c..14f2281a7 100644 --- a/lib/OpenCloud/CDN/Service.php +++ b/lib/OpenCloud/CDN/Service.php @@ -143,8 +143,15 @@ public function listFlavors(array $params = array()) */ public function getHomeDocument() { - $response = $this->getClient()->get($this->getUrl())->send(); - return Formatter::decode($response); + $url = clone $this->getUrl(); + + // This hack is necessary otherwise Guzzle will remove the trailing + // slash from the URL and the request will fail because the service + // expects the trailing slash :( + $url->setPath($url->getPath() . '/'); + + $response = $this->getClient()->get($url)->send(); + return Formatter::decode($response); } /** From 97f8037cb0d8e971033275ca2a8f99e1014edf41 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 30 Dec 2014 05:41:14 -0800 Subject: [PATCH 32/61] Adding smoke tests for GET / and GET /ping APIs. --- tests/OpenCloud/Smoke/Unit/CDN.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/OpenCloud/Smoke/Unit/CDN.php b/tests/OpenCloud/Smoke/Unit/CDN.php index 97921d11f..59366bb93 100644 --- a/tests/OpenCloud/Smoke/Unit/CDN.php +++ b/tests/OpenCloud/Smoke/Unit/CDN.php @@ -24,13 +24,19 @@ class CDN extends AbstractUnit implements UnitInterface public function setupService() { $service = $this->getConnection()->cdnService(); - // TODO: Remove shim below to replace prod with preview endpoint - $service->getEndpoint()->getPublicUrl()->setHost('preview.cdn.api.rackspacecloud.com'); return $service; } public function main() { + $this->step('Get home document'); + $homeDocument = $this->getService()->getHomeDocument(); + $this->stepInfo('Home document: %s', json_encode($homeDocument)); + + $this->step('Get ping'); + $ping = $this->getService()->getPing(); + $this->stepInfo('Ping successful'); + $this->step('List flavors'); $flavors = $this->getService()->listFlavors(); $this->stepInfo('%-40s | %s', 'Flavor ID', 'Number of providers'); From 9686882b3418fbad36e53412bf5140ffb32ca7d6 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 30 Dec 2014 05:41:53 -0800 Subject: [PATCH 33/61] Wait for service to return to a status where further changes can be made. --- tests/OpenCloud/Smoke/Unit/CDN.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/OpenCloud/Smoke/Unit/CDN.php b/tests/OpenCloud/Smoke/Unit/CDN.php index 59366bb93..c6ec30209 100644 --- a/tests/OpenCloud/Smoke/Unit/CDN.php +++ b/tests/OpenCloud/Smoke/Unit/CDN.php @@ -75,6 +75,9 @@ public function main() $this->stepInfo('Origin: ' . $origins[0]->origin); $this->step('Update service'); + $service->waitFor('deployed', null, function ($s) { + $this->stepInfo('Service is still being created. Waiting...'); + }); $service->update(array( 'origins' => array( array( 'origin' => 'updated-origin.php-opencloud.com' ) @@ -82,6 +85,9 @@ public function main() )); $this->step('Purge ALL cached service assets'); + $service->waitFor('deployed', null, function ($s) { + $this->stepInfo('Service is still being updated. Waiting...'); + }); $service->purgeAssets(); $this->step('Delete service'); From a9de5fcf5de9bafea3c028624f298cc52f495b1f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 30 Dec 2014 05:43:42 -0800 Subject: [PATCH 34/61] Removing trailing space to make the linter happy. --- lib/OpenCloud/CDN/Service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenCloud/CDN/Service.php b/lib/OpenCloud/CDN/Service.php index 14f2281a7..af4669e81 100644 --- a/lib/OpenCloud/CDN/Service.php +++ b/lib/OpenCloud/CDN/Service.php @@ -157,7 +157,7 @@ public function getHomeDocument() /** * Returns the ping (status) response for the CDN service * - * @return Guzzle\Http\Message\Response + * @return Guzzle\Http\Message\Response */ public function getPing() { From 3386d76ef298cf64f2c819a4395844e01e984453 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 31 Dec 2014 09:22:26 -0800 Subject: [PATCH 35/61] Adding ID property (primary key; generated) to Service resource. --- docs/userguide/CDN/USERGUIDE.md | 4 ++-- lib/OpenCloud/CDN/Resource/Service.php | 6 +----- samples/CDN/delete-service.php | 2 +- samples/CDN/get-service.php | 2 +- samples/CDN/purge-cached-service-asset.php | 2 +- samples/CDN/purge-cached-service-assets.php | 2 +- samples/CDN/update-service.php | 2 +- tests/OpenCloud/Smoke/Unit/CDN.php | 2 +- 8 files changed, 9 insertions(+), 13 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index de26dac3a..113fe46a4 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -146,10 +146,10 @@ foreach ($services as $service) { ### Get a service -You can retrieve a specific service by using that service's name, as shown in the following example: +You can retrieve a specific service by using that service's ID, as shown in the following example: ```php -$service = $cdnService->getservice('acme_site'); +$service = $cdnService->getService('0e09ad12-2bfe-4607-80fd-116fa68d9c79'); /** @var $service OpenCloud\CDN\Resource\Service **/ ``` diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index 2823286d1..0a4977329 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -32,6 +32,7 @@ class Service extends PersistentResource const UPDATE_METHOD = 'PATCH'; + protected $id; protected $name; protected $domains; protected $origins; @@ -92,11 +93,6 @@ protected function assetsUrl() return $url; } - protected function primaryKeyField() - { - return 'name'; - } - protected function createJson() { $createJson = parent::createJson(); diff --git a/samples/CDN/delete-service.php b/samples/CDN/delete-service.php index 345479084..6b6fc1914 100644 --- a/samples/CDN/delete-service.php +++ b/samples/CDN/delete-service.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getServices('{name}'); +$service = $cdnService->getServices('{id}'); // 4. Delete it. $service->delete(); diff --git a/samples/CDN/get-service.php b/samples/CDN/get-service.php index 7a4a72dae..3b2d9044e 100644 --- a/samples/CDN/get-service.php +++ b/samples/CDN/get-service.php @@ -30,5 +30,5 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getService('{name}'); +$service = $cdnService->getService('{id}'); /** @var $service OpenCloud\CDN\Resource\Service **/ diff --git a/samples/CDN/purge-cached-service-asset.php b/samples/CDN/purge-cached-service-asset.php index 715a80699..33b785209 100644 --- a/samples/CDN/purge-cached-service-asset.php +++ b/samples/CDN/purge-cached-service-asset.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getServices('{name}'); +$service = $cdnService->getServices('{id}'); // 4. Purge a specific asset belonging to service. $service->purgeAssets('{asset URL}'); diff --git a/samples/CDN/purge-cached-service-assets.php b/samples/CDN/purge-cached-service-assets.php index 0d032c89c..5e74c989e 100644 --- a/samples/CDN/purge-cached-service-assets.php +++ b/samples/CDN/purge-cached-service-assets.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getServices('{name}'); +$service = $cdnService->getServices('{id}'); // 4. Purge all assets belonging to service. $service->purgeAssets(); diff --git a/samples/CDN/update-service.php b/samples/CDN/update-service.php index 13b34b7bf..a839a07e2 100644 --- a/samples/CDN/update-service.php +++ b/samples/CDN/update-service.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getService('{name}'); +$service = $cdnService->getService('{id}'); // 4. Update it. $service->update(array( diff --git a/tests/OpenCloud/Smoke/Unit/CDN.php b/tests/OpenCloud/Smoke/Unit/CDN.php index c6ec30209..da828676b 100644 --- a/tests/OpenCloud/Smoke/Unit/CDN.php +++ b/tests/OpenCloud/Smoke/Unit/CDN.php @@ -68,7 +68,7 @@ public function main() } $this->step('Get service'); - $service = $this->getService()->getService('php-opencloud.com'); + $service = $this->getService()->getService($createdService->getId()); $this->stepInfo('Service name: ' . $service->getName()); $this->stepInfo('Status: ' . $service->getStatus()); $origins = $service->getOrigins(); From 67da4ede71f0d97708824a0c0ad0704db3cddcbd Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 04:41:18 -0800 Subject: [PATCH 36/61] Expanding on arguments. --- docs/userguide/CDN/USERGUIDE.md | 71 ++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index 113fe46a4..1569b8d4b 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -101,12 +101,36 @@ This operation takes one parameter, an associative array, with the following key | Name | Description | Data type | Required? | Default value | Example value | | ---- | ----------- | --------- | --------- | ------------- | ------------- | -| `name` | A human-readable name for the service. This name must be unique. | String | No | `null` | `acme_site` | -| `domains` | An array of associative arrays, each specifying a domain name for your service. | Array of associative arrays | Yes | `null` | `array( array( 'domain' => 'www.acme.com' ), array ( 'domain' => 'acme.com' ) )` | -| `origins` | An array of associative arrays, each specifying an origin server for your service. The `port`, `ssl`, and `rules` elements for each origin server are optional. | Array of associative arrays | Yes | `null` | `array( array( 'origin' => 'origin.acme.com', 'port' => 80, 'ssl' => false, 'rules' => array() ) )` | -| `flavorId` | The flavor used to configure this service. Use the [list flavors](#list-flavors) operation to retrieve a list of all available flavors. | String | Yes| `null` | `cdn` | -| `restrictions` | An array of associative arrays, each specifying a restriction for who can or cannot access content from the CDN cache. | Array of associative arrays | No | `null` | `array( array( 'name' => 'website only', 'rules' => array( array( 'name' => 'mywebsite.com', 'httpHost' => 'www.mywebsite.com' ) ) ) )` | -| `caching` | An array of associative arrays, each specifying a caching rule for your service's assets. | No | `null` | `array( array( 'name' => 'default', 'ttl' => 3600 ) )` | +| `name` | A human-readable name for the service. This name must be unique. | String | Yes | - | `acme_site` | +| `flavorId` | The ID of the flavor to use for this service. | String | Yes | - | `cdn` | +| `domains` | List of domain for your service. | Array of associative arrays | Yes | - | `array( ... )` | +| `domains[n]` | Information about a domain for your service. | Associative array | Yes | - | `array( ... )` | +| `domains[n]['domain'] | The domain name for your service. | String | Yes | - | 'www.acme.com' | +| `domains[n]['protocol'] | The protocol used by your service web site, `http` or `https`. | String | No | `http` | `http` | +| `origins` | List of origin servers for your service. | Array of associative arrays | Yes | - | `array( ... )` | +| `origins[n]` | Information about an origin server for your service. | Associative array | Yes | - | `array( ... )` | +| `origins[n]['origin']` | The origin server address, from where the CDN will pull your web site's assets. | String | Yes | - | `origin.acme.com` | +| `origins[n]['origin']['port']` | The origin server's port. | Integer | No | 80 | `8080` | +| `origins[n]['origin']['ssl']` | Whether origin server uses SSL. | Boolean | No | `false` | `true` | +| `origins[n]['origin']['rules'] | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n] | Information about an access rule. | Associative array | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n]['name'] | A human-readable name of the rule. | String | No | `null` | `images` | +| `origins[n]['origin']['rules'][n]['request_url'] | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `caching` | List of TTL rules for assets of this service. | Array of associative arrays | No | `null` | `array( ... )` | +| `caching[n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | +| `caching[n]['name']` | A human-readable name of the TTL rule. | String | No | `null` | `long_ttl` | +| `caching[n]['ttl']` | The TTL value, in seconds. | Integer | No | `null` | `604800` | +| `caching[n]['rules']` | List of rules that determine if this TTL should be applied to an asset. | Array of associative arrays | No | `null` | `array( ... )` | +| `caching[n]['rules'][n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | +| `caching[n]['rules'][n]['name']` | A human-readable name of the TTL rule. | No | `null` | `images` | +| `caching[n]['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `restrictions` | List of restrictions on who can access new service. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | +| `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | +| `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | +| `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | +| `restrictions[n]['rules'][n]['referrer'] | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | You can create a service as shown in the following example: @@ -161,11 +185,36 @@ This operation takes one parameter, an associative array, with the following key | Name | Description | Data type | Required? | Default value | Example value | | ---- | ----------- | --------- | --------- | ------------- | ------------- | -| `domains` | An array of associative arrays, each specifying a domain name for your service. | Array of associative arrays | Yes | `null` | `array( array( 'domain' => 'www.acme.com' ), array ( 'domain' => 'acme.com' ) )` | -| `origins` | An array of associative arrays, each specifying an origin server for your service. The `port`, `ssl`, and `rules` elements for each origin server are optional. | Array of associative arrays | Yes | `null` | `array( array( 'origin' => 'origin.acme.com', 'port' => 80, 'ssl' => false, 'rules' => array() ) )` | -| `flavorId` | The flavor used to configure this service. Use the [list flavors](#list-flavors) operation to retrieve a list of all available flavors. | String | Yes| `null` | `cdn` | -| `restrictions` | An array of associative arrays, each specifying a restriction for who can or cannot access content from the CDN cache. | Array of associative arrays | No | `null` | `array( array( 'name' => 'website only', 'rules' => array( array( 'name' => 'mywebsite.com', 'httpHost' => 'www.mywebsite.com' ) ) ) )` | -| `caching` | An array of associative arrays, each specifying a caching rule for your service's assets. | No | `null` | `array( array( 'name' => 'default', 'ttl' => 3600 ) )` | +| `name` | A human-readable name for the service. This name must be unique. | String | Yes | - | `acme_site` | +| `flavorId` | The ID of the flavor to use for this service. | String | Yes | - | `cdn` | +| `domains` | List of domain for your service. | Array of associative arrays | Yes | - | `array( ... )` | +| `domains[n]` | Information about a domain for your service. | Associative array | Yes | - | `array( ... )` | +| `domains[n]['domain'] | The domain name for your service. | String | Yes | - | 'www.acme.com' | +| `domains[n]['protocol'] | The protocol used by your service web site, `http` or `https`. | String | No | `http` | `http` | +| `origins` | List of origin servers for your service. | Array of associative arrays | Yes | - | `array( ... )` | +| `origins[n]` | Information about an origin server for your service. | Associative array | Yes | - | `array( ... )` | +| `origins[n]['origin']` | The origin server address, from where the CDN will pull your web site's assets. | String | Yes | - | `origin.acme.com` | +| `origins[n]['origin']['port']` | The origin server's port. | Integer | No | 80 | `8080` | +| `origins[n]['origin']['ssl']` | Whether origin server uses SSL. | Boolean | No | `false` | `true` | +| `origins[n]['origin']['rules'] | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n] | Information about an access rule. | Associative array | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n]['name'] | A human-readable name of the rule. | String | No | `null` | `images` | +| `origins[n]['origin']['rules'][n]['request_url'] | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `caching` | List of TTL rules for assets of this service. | Array of associative arrays | No | `null` | `array( ... )` | +| `caching[n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | +| `caching[n]['name']` | A human-readable name of the TTL rule. | String | No | `null` | `long_ttl` | +| `caching[n]['ttl']` | The TTL value, in seconds. | Integer | No | `null` | `604800` | +| `caching[n]['rules']` | List of rules that determine if this TTL should be applied to an asset. | Array of associative arrays | No | `null` | `array( ... )` | +| `caching[n]['rules'][n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | +| `caching[n]['rules'][n]['name']` | A human-readable name of the TTL rule. | No | `null` | `images` | +| `caching[n]['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `restrictions` | List of restrictions on who can access new service. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | +| `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | +| `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | +| `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | +| `restrictions[n]['rules'][n]['referrer'] | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | You can update a service as shown in the following example: From e29681eda1c5d505f9836e44d1f01beb014104a0 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 04:42:49 -0800 Subject: [PATCH 37/61] Moving @see annotations to new line. --- lib/OpenCloud/CDN/Service.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/OpenCloud/CDN/Service.php b/lib/OpenCloud/CDN/Service.php index af4669e81..57c880052 100644 --- a/lib/OpenCloud/CDN/Service.php +++ b/lib/OpenCloud/CDN/Service.php @@ -50,7 +50,8 @@ public function service($id = null) /** * Creates a new Service and returns it. * - * @param array $params Service creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-service + * @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-service + * @param array $params Service creation parameters. * @return \OpenCloud\CDN\Resource\Service Object representing created service */ public function createService(array $params = array()) @@ -101,7 +102,8 @@ public function flavor($id = null) /** * Creates a new Flavor and returns it. * - * @param array $params Flavor creation parameters. @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-flavor + * @see https://github.com/rackspace/php-opencloud/blob/master/docs/userguide/CDN/USERGUIDE.md#create-a-flavor + * @param array $params Flavor creation parameters. * @return \OpenCloud\CDN\Resource\Flavor Object representing created flavor */ public function createFlavor(array $params = array()) From b7b020e5e3a22d5d275897a4f8e048f9838151ff Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 04:46:47 -0800 Subject: [PATCH 38/61] Doing the same things with fewer lines of code. --- lib/OpenCloud/Common/Resource/PersistentResource.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index f769f9856..bd6111675 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -86,11 +86,8 @@ public function update($params = array()) protected function makeUpdateRequest($json) { - if ('PATCH' === static::UPDATE_METHOD) { - return $this->getClient()->patch($this->getUrl(), self::getJsonHeader(), $json)->send(); - } else { - return $this->getClient()->put($this->getUrl(), self::getJsonHeader(), $json)->send(); - } + $updateMethod = ('PATCH' === static::UPDATE_METHOD) ? 'patch' : 'post'; + return $this->getClient()->$updateMethod($this->getUrl(), self::getJsonHeader(), $json)->send(); } /** From 70be88b5bcefdc4be5af2d9570d40b49f33f545e Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 04:48:34 -0800 Subject: [PATCH 39/61] Refactoring to remove single-use local variable. --- lib/OpenCloud/Common/Resource/PersistentResource.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index bd6111675..35e86529e 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -273,8 +273,7 @@ protected function recursivelyAliasPropertyValue($propertyValue) } } } elseif (is_object($propertyValue) && ($propertyValue instanceof \stdClass)) { - $objectVars = get_object_vars($propertyValue); - foreach ($objectVars as $key => $subValue) { + foreach (get_object_vars($propertyValue) as $key => $subValue) { unset($propertyValue->$key); $propertyValue->{$this->getAlias($key)} = $this->recursivelyAliasPropertyValue($subValue); } From 5dc7b411c0c3882f97d57997ad8fc819e08bed10 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 04:52:45 -0800 Subject: [PATCH 40/61] Condensing single-element array literals to single line. --- samples/CDN/create-service.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/samples/CDN/create-service.php b/samples/CDN/create-service.php index 2df1f5c5e..a35c8ec61 100644 --- a/samples/CDN/create-service.php +++ b/samples/CDN/create-service.php @@ -33,14 +33,10 @@ $service = $cdnService->createService(array( 'name' => '{name}', 'domains' => array( - array( - 'domain' => '{domain name}' - ) + array( 'domain' => '{domain name}' ) ), 'origins' => array( - array( - 'origin' => '{origin address}' - ) + array( 'origin' => '{origin address}' ) ), 'flavorId' => '{flavor ID}' )); From 8908d8a5a170145b9425080c04dd3c450fa14d5e Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 04:53:14 -0800 Subject: [PATCH 41/61] Fixing typo in method names. --- samples/CDN/delete-flavor.php | 2 +- samples/CDN/delete-service.php | 2 +- samples/CDN/purge-cached-service-asset.php | 2 +- samples/CDN/purge-cached-service-assets.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/CDN/delete-flavor.php b/samples/CDN/delete-flavor.php index 760a0306b..9d2f291ef 100644 --- a/samples/CDN/delete-flavor.php +++ b/samples/CDN/delete-flavor.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get flavor. -$flavor = $cdnFlavor->getFlavors('{id}'); +$flavor = $cdnFlavor->getFlavor('{id}'); // 4. Delete it. $flavor->delete(); diff --git a/samples/CDN/delete-service.php b/samples/CDN/delete-service.php index 6b6fc1914..0947bcd60 100644 --- a/samples/CDN/delete-service.php +++ b/samples/CDN/delete-service.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getServices('{id}'); +$service = $cdnService->getService('{id}'); // 4. Delete it. $service->delete(); diff --git a/samples/CDN/purge-cached-service-asset.php b/samples/CDN/purge-cached-service-asset.php index 33b785209..8bbf61a38 100644 --- a/samples/CDN/purge-cached-service-asset.php +++ b/samples/CDN/purge-cached-service-asset.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getServices('{id}'); +$service = $cdnService->getService('{id}'); // 4. Purge a specific asset belonging to service. $service->purgeAssets('{asset URL}'); diff --git a/samples/CDN/purge-cached-service-assets.php b/samples/CDN/purge-cached-service-assets.php index 5e74c989e..36a5e37b5 100644 --- a/samples/CDN/purge-cached-service-assets.php +++ b/samples/CDN/purge-cached-service-assets.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getServices('{id}'); +$service = $cdnService->getService('{id}'); // 4. Purge all assets belonging to service. $service->purgeAssets(); From 9acbae5aa4af846b808cdc554dd70faea8d69f2c Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 04:57:34 -0800 Subject: [PATCH 42/61] Using better ID placeholder names. --- samples/CDN/create-flavor.php | 2 +- samples/CDN/delete-flavor.php | 2 +- samples/CDN/delete-service.php | 2 +- samples/CDN/get-flavor.php | 2 +- samples/CDN/get-service.php | 2 +- samples/CDN/purge-cached-service-asset.php | 2 +- samples/CDN/purge-cached-service-assets.php | 2 +- samples/CDN/update-service.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/CDN/create-flavor.php b/samples/CDN/create-flavor.php index c9811cf85..5e2433ad7 100644 --- a/samples/CDN/create-flavor.php +++ b/samples/CDN/create-flavor.php @@ -31,7 +31,7 @@ // 3. Create flavor. $flavor = $cdnFlavor->createFlavor(array( - 'id' => '{id}', + 'id' => '{flavorId}', 'providers' => array( array( 'provider' => 'akamai', diff --git a/samples/CDN/delete-flavor.php b/samples/CDN/delete-flavor.php index 9d2f291ef..28f901c50 100644 --- a/samples/CDN/delete-flavor.php +++ b/samples/CDN/delete-flavor.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get flavor. -$flavor = $cdnFlavor->getFlavor('{id}'); +$flavor = $cdnFlavor->getFlavor('{flavorId}'); // 4. Delete it. $flavor->delete(); diff --git a/samples/CDN/delete-service.php b/samples/CDN/delete-service.php index 0947bcd60..2b223cdf7 100644 --- a/samples/CDN/delete-service.php +++ b/samples/CDN/delete-service.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getService('{id}'); +$service = $cdnService->getService('{serviceId}'); // 4. Delete it. $service->delete(); diff --git a/samples/CDN/get-flavor.php b/samples/CDN/get-flavor.php index e63ffcc29..90e605c21 100644 --- a/samples/CDN/get-flavor.php +++ b/samples/CDN/get-flavor.php @@ -30,5 +30,5 @@ $cdnService = $client->cdnService(); // 3. Get flavor. -$flavor = $cdnService->getFlavor('{flavor ID}'); +$flavor = $cdnService->getFlavor('{flavorId}'); /** @var $flavor OpenCloud\CDN\Resource\Flavor **/ diff --git a/samples/CDN/get-service.php b/samples/CDN/get-service.php index 3b2d9044e..113d4ae24 100644 --- a/samples/CDN/get-service.php +++ b/samples/CDN/get-service.php @@ -30,5 +30,5 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getService('{id}'); +$service = $cdnService->getService('{serviceId}'); /** @var $service OpenCloud\CDN\Resource\Service **/ diff --git a/samples/CDN/purge-cached-service-asset.php b/samples/CDN/purge-cached-service-asset.php index 8bbf61a38..2ab5141d0 100644 --- a/samples/CDN/purge-cached-service-asset.php +++ b/samples/CDN/purge-cached-service-asset.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getService('{id}'); +$service = $cdnService->getService('{serviceId}'); // 4. Purge a specific asset belonging to service. $service->purgeAssets('{asset URL}'); diff --git a/samples/CDN/purge-cached-service-assets.php b/samples/CDN/purge-cached-service-assets.php index 36a5e37b5..afc9cb1c6 100644 --- a/samples/CDN/purge-cached-service-assets.php +++ b/samples/CDN/purge-cached-service-assets.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getService('{id}'); +$service = $cdnService->getService('{serviceId}'); // 4. Purge all assets belonging to service. $service->purgeAssets(); diff --git a/samples/CDN/update-service.php b/samples/CDN/update-service.php index a839a07e2..8f5c9db6f 100644 --- a/samples/CDN/update-service.php +++ b/samples/CDN/update-service.php @@ -30,7 +30,7 @@ $cdnService = $client->cdnService(); // 3. Get service. -$service = $cdnService->getService('{id}'); +$service = $cdnService->getService('{serviceId}'); // 4. Update it. $service->update(array( From e16e9a03b55691f1647deb17c39cc09e12641fb9 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 05:46:37 -0800 Subject: [PATCH 43/61] Fixing formatting issues due to missing backticks. --- docs/userguide/CDN/USERGUIDE.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index 1569b8d4b..cc285834d 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -105,17 +105,17 @@ This operation takes one parameter, an associative array, with the following key | `flavorId` | The ID of the flavor to use for this service. | String | Yes | - | `cdn` | | `domains` | List of domain for your service. | Array of associative arrays | Yes | - | `array( ... )` | | `domains[n]` | Information about a domain for your service. | Associative array | Yes | - | `array( ... )` | -| `domains[n]['domain'] | The domain name for your service. | String | Yes | - | 'www.acme.com' | -| `domains[n]['protocol'] | The protocol used by your service web site, `http` or `https`. | String | No | `http` | `http` | +| `domains[n]['domain']` | The domain name for your service. | String | Yes | - | 'www.acme.com' | +| `domains[n]['protocol']` | The protocol used by your service web site, `http` or `https`. | String | No | `http` | `http` | | `origins` | List of origin servers for your service. | Array of associative arrays | Yes | - | `array( ... )` | | `origins[n]` | Information about an origin server for your service. | Associative array | Yes | - | `array( ... )` | | `origins[n]['origin']` | The origin server address, from where the CDN will pull your web site's assets. | String | Yes | - | `origin.acme.com` | | `origins[n]['origin']['port']` | The origin server's port. | Integer | No | 80 | `8080` | | `origins[n]['origin']['ssl']` | Whether origin server uses SSL. | Boolean | No | `false` | `true` | -| `origins[n]['origin']['rules'] | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | -| `origins[n]['origin']['rules'][n] | Information about an access rule. | Associative array | No | `null` | `array( ... )` | -| `origins[n]['origin']['rules'][n]['name'] | A human-readable name of the rule. | String | No | `null` | `images` | -| `origins[n]['origin']['rules'][n]['request_url'] | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `origins[n]['origin']['rules']` | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n]` | Information about an access rule. | Associative array | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n]['name']` | A human-readable name of the rule. | String | No | `null` | `images` | +| `origins[n]['origin']['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | | `caching` | List of TTL rules for assets of this service. | Array of associative arrays | No | `null` | `array( ... )` | | `caching[n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['name']` | A human-readable name of the TTL rule. | String | No | `null` | `long_ttl` | @@ -130,7 +130,7 @@ This operation takes one parameter, an associative array, with the following key | `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | -| `restrictions[n]['rules'][n]['referrer'] | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | +| `restrictions[n]['rules'][n]['referrer']` | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | You can create a service as shown in the following example: @@ -189,17 +189,17 @@ This operation takes one parameter, an associative array, with the following key | `flavorId` | The ID of the flavor to use for this service. | String | Yes | - | `cdn` | | `domains` | List of domain for your service. | Array of associative arrays | Yes | - | `array( ... )` | | `domains[n]` | Information about a domain for your service. | Associative array | Yes | - | `array( ... )` | -| `domains[n]['domain'] | The domain name for your service. | String | Yes | - | 'www.acme.com' | -| `domains[n]['protocol'] | The protocol used by your service web site, `http` or `https`. | String | No | `http` | `http` | +| `domains[n]['domain']` | The domain name for your service. | String | Yes | - | 'www.acme.com' | +| `domains[n]['protocol']` | The protocol used by your service web site, `http` or `https`. | String | No | `http` | `http` | | `origins` | List of origin servers for your service. | Array of associative arrays | Yes | - | `array( ... )` | | `origins[n]` | Information about an origin server for your service. | Associative array | Yes | - | `array( ... )` | | `origins[n]['origin']` | The origin server address, from where the CDN will pull your web site's assets. | String | Yes | - | `origin.acme.com` | | `origins[n]['origin']['port']` | The origin server's port. | Integer | No | 80 | `8080` | | `origins[n]['origin']['ssl']` | Whether origin server uses SSL. | Boolean | No | `false` | `true` | -| `origins[n]['origin']['rules'] | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | -| `origins[n]['origin']['rules'][n] | Information about an access rule. | Associative array | No | `null` | `array( ... )` | -| `origins[n]['origin']['rules'][n]['name'] | A human-readable name of the rule. | String | No | `null` | `images` | -| `origins[n]['origin']['rules'][n]['request_url'] | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `origins[n]['origin']['rules']` | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n]` | Information about an access rule. | Associative array | No | `null` | `array( ... )` | +| `origins[n]['origin']['rules'][n]['name']` | A human-readable name of the rule. | String | No | `null` | `images` | +| `origins[n]['origin']['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | | `caching` | List of TTL rules for assets of this service. | Array of associative arrays | No | `null` | `array( ... )` | | `caching[n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['name']` | A human-readable name of the TTL rule. | String | No | `null` | `long_ttl` | @@ -214,7 +214,7 @@ This operation takes one parameter, an associative array, with the following key | `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | -| `restrictions[n]['rules'][n]['referrer'] | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | +| `restrictions[n]['rules'][n]['referrer']` | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | You can update a service as shown in the following example: From 7f1b97127dd01c1d255332efac0ee467b7f1b806 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 05:48:26 -0800 Subject: [PATCH 44/61] Trimming whitespace. --- samples/CDN/create-service.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/CDN/create-service.php b/samples/CDN/create-service.php index a35c8ec61..33967d470 100644 --- a/samples/CDN/create-service.php +++ b/samples/CDN/create-service.php @@ -33,10 +33,10 @@ $service = $cdnService->createService(array( 'name' => '{name}', 'domains' => array( - array( 'domain' => '{domain name}' ) + array('domain' => '{domain name}') ), 'origins' => array( - array( 'origin' => '{origin address}' ) + array('origin' => '{origin address}') ), 'flavorId' => '{flavor ID}' )); From c908eb9ade929c045988846d3668b9600a296cc8 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Fri, 2 Jan 2015 05:49:58 -0800 Subject: [PATCH 45/61] Standardizing placeholders to use camelCase. --- samples/CDN/create-service.php | 6 +++--- samples/CDN/purge-cached-service-asset.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/CDN/create-service.php b/samples/CDN/create-service.php index 33967d470..102fd1f18 100644 --- a/samples/CDN/create-service.php +++ b/samples/CDN/create-service.php @@ -33,11 +33,11 @@ $service = $cdnService->createService(array( 'name' => '{name}', 'domains' => array( - array('domain' => '{domain name}') + array('domain' => '{domainName}') ), 'origins' => array( - array('origin' => '{origin address}') + array('origin' => '{originAddress}') ), - 'flavorId' => '{flavor ID}' + 'flavorId' => '{flavorId}' )); /** @var $service OpenCloud\CDN\Resource\Service **/ diff --git a/samples/CDN/purge-cached-service-asset.php b/samples/CDN/purge-cached-service-asset.php index 2ab5141d0..fdb2f97c4 100644 --- a/samples/CDN/purge-cached-service-asset.php +++ b/samples/CDN/purge-cached-service-asset.php @@ -33,4 +33,4 @@ $service = $cdnService->getService('{serviceId}'); // 4. Purge a specific asset belonging to service. -$service->purgeAssets('{asset URL}'); +$service->purgeAssets('{assetUrl}'); From 959a48975eea23b11485a8b7a62dc95a3c62c211 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Sat, 3 Jan 2015 05:00:22 -0800 Subject: [PATCH 46/61] Fixing parameter paths. --- docs/userguide/CDN/USERGUIDE.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index cc285834d..ff908e1d7 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -110,12 +110,12 @@ This operation takes one parameter, an associative array, with the following key | `origins` | List of origin servers for your service. | Array of associative arrays | Yes | - | `array( ... )` | | `origins[n]` | Information about an origin server for your service. | Associative array | Yes | - | `array( ... )` | | `origins[n]['origin']` | The origin server address, from where the CDN will pull your web site's assets. | String | Yes | - | `origin.acme.com` | -| `origins[n]['origin']['port']` | The origin server's port. | Integer | No | 80 | `8080` | -| `origins[n]['origin']['ssl']` | Whether origin server uses SSL. | Boolean | No | `false` | `true` | -| `origins[n]['origin']['rules']` | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | -| `origins[n]['origin']['rules'][n]` | Information about an access rule. | Associative array | No | `null` | `array( ... )` | -| `origins[n]['origin']['rules'][n]['name']` | A human-readable name of the rule. | String | No | `null` | `images` | -| `origins[n]['origin']['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `origins[n]['port']` | The origin server's port. | Integer | No | 80 | `8080` | +| `origins[n]['ssl']` | Whether origin server uses SSL. | Boolean | No | `false` | `true` | +| `origins[n]['rules']` | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | +| `origins[n]['rules'][n]` | Information about an access rule. | Associative array | No | `null` | `array( ... )` | +| `origins[n]['rules'][n]['name']` | A human-readable name of the rule. | String | No | `null` | `images` | +| `origins[n]['rules'][n]['requestUrl']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | | `caching` | List of TTL rules for assets of this service. | Array of associative arrays | No | `null` | `array( ... )` | | `caching[n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['name']` | A human-readable name of the TTL rule. | String | No | `null` | `long_ttl` | From 6d0a4e0ca5a75649425fd9afddaa7f12bb871de9 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Sat, 3 Jan 2015 05:00:44 -0800 Subject: [PATCH 47/61] Aliasing requestUrl -> request_url. --- docs/userguide/CDN/USERGUIDE.md | 6 +++--- lib/OpenCloud/CDN/Resource/Service.php | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index ff908e1d7..be9404778 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -123,7 +123,7 @@ This operation takes one parameter, an associative array, with the following key | `caching[n]['rules']` | List of rules that determine if this TTL should be applied to an asset. | Array of associative arrays | No | `null` | `array( ... )` | | `caching[n]['rules'][n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['rules'][n]['name']` | A human-readable name of the TTL rule. | No | `null` | `images` | -| `caching[n]['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `caching[n]['rules'][n]['requestUrl']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | | `restrictions` | List of restrictions on who can access new service. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | @@ -199,7 +199,7 @@ This operation takes one parameter, an associative array, with the following key | `origins[n]['origin']['rules']` | List of rules defining the conditions when this origin should be accessed. | Array of associative arrays | No | `null` | `array( ... )` | | `origins[n]['origin']['rules'][n]` | Information about an access rule. | Associative array | No | `null` | `array( ... )` | | `origins[n]['origin']['rules'][n]['name']` | A human-readable name of the rule. | String | No | `null` | `images` | -| `origins[n]['origin']['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `origins[n]['origin']['rules'][n]['requestUrl']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | | `caching` | List of TTL rules for assets of this service. | Array of associative arrays | No | `null` | `array( ... )` | | `caching[n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['name']` | A human-readable name of the TTL rule. | String | No | `null` | `long_ttl` | @@ -207,7 +207,7 @@ This operation takes one parameter, an associative array, with the following key | `caching[n]['rules']` | List of rules that determine if this TTL should be applied to an asset. | Array of associative arrays | No | `null` | `array( ... )` | | `caching[n]['rules'][n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['rules'][n]['name']` | A human-readable name of the TTL rule. | No | `null` | `images` | -| `caching[n]['rules'][n]['request_url']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | +| `caching[n]['rules'][n]['requestUrl']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | | `restrictions` | List of restrictions on who can access new service. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index 0a4977329..233faacc9 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -45,7 +45,8 @@ class Service extends PersistentResource protected $aliases = array( 'flavor_id' => 'flavorId', - 'http_host' => 'httpHost' + 'http_host' => 'httpHost', + 'request_url' => 'requestUrl' ); protected $createKeys = array( From 7a7ff518c58373be9ded148b9891774d0547a9f7 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Sat, 3 Jan 2015 05:09:31 -0800 Subject: [PATCH 48/61] Clarifying parameter descriptions. --- docs/userguide/CDN/USERGUIDE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index be9404778..e02599b5d 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -124,13 +124,13 @@ This operation takes one parameter, an associative array, with the following key | `caching[n]['rules'][n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['rules'][n]['name']` | A human-readable name of the TTL rule. | No | `null` | `images` | | `caching[n]['rules'][n]['requestUrl']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | -| `restrictions` | List of restrictions on who can access new service. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions` | List of restrictions on where the service can be accessed from. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | | `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | -| `restrictions[n]['rules'][n]['referrer']` | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | +| `restrictions[n]['rules'][n]['referrer']` | The domain from which the service can be accessed. | String | No | `null` | `www.wilecoyote.com` | You can create a service as shown in the following example: @@ -208,13 +208,13 @@ This operation takes one parameter, an associative array, with the following key | `caching[n]['rules'][n]` | Information about a TTL rule. | Associative array | No | `null` | `array( ... )` | | `caching[n]['rules'][n]['name']` | A human-readable name of the TTL rule. | No | `null` | `images` | | `caching[n]['rules'][n]['requestUrl']` | The request URL this rule should match (regex supported). | String | No | `null` | `^/images/.+$` | -| `restrictions` | List of restrictions on who can access new service. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions` | List of restrictions on where the service can be accessed from. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | | `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | -| `restrictions[n]['rules'][n]['referrer']` | The domain from which the new service can be accessed. | String | No | `null` | `www.wilecoyote.com` | +| `restrictions[n]['rules'][n]['referrer']` | The domain from which the service can be accessed. | String | No | `null` | `www.wilecoyote.com` | You can update a service as shown in the following example: From 5f550f9aef8a21ba71367f60266c77f735bef892 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Sat, 3 Jan 2015 05:09:40 -0800 Subject: [PATCH 49/61] Fixing typos. --- docs/userguide/CDN/USERGUIDE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index e02599b5d..8093b7c39 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -127,7 +127,7 @@ This operation takes one parameter, an associative array, with the following key | `restrictions` | List of restrictions on where the service can be accessed from. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | -| `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions[n]['rules']` | List of restriction rules. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | | `restrictions[n]['rules'][n]['referrer']` | The domain from which the service can be accessed. | String | No | `null` | `www.wilecoyote.com` | @@ -211,7 +211,7 @@ This operation takes one parameter, an associative array, with the following key | `restrictions` | List of restrictions on where the service can be accessed from. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]` | Information about an access restriction. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['name']` | A human-readable name of the restriction. | String | No | `null` | `affiliate_sites_only` | -| `restrictions[n]['rules']` | List of restrition rules. | Array of associative arrays | No | `null` | `array( ... )` | +| `restrictions[n]['rules']` | List of restriction rules. | Array of associative arrays | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]` | Information about a restriction rule. | Associative array | No | `null` | `array( ... )` | | `restrictions[n]['rules'][n]['name']` | A human-readable name of the restriction rule. | String | No | `null` | `Wile E. Coyote's site` | | `restrictions[n]['rules'][n]['referrer']` | The domain from which the service can be accessed. | String | No | `null` | `www.wilecoyote.com` | From 013d768e8af72143e0476e2ba9fc200cf4ab02a7 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Sat, 3 Jan 2015 05:15:38 -0800 Subject: [PATCH 50/61] Clarifying parameter description. --- docs/userguide/CDN/USERGUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index 8093b7c39..1db7acebe 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -105,7 +105,7 @@ This operation takes one parameter, an associative array, with the following key | `flavorId` | The ID of the flavor to use for this service. | String | Yes | - | `cdn` | | `domains` | List of domain for your service. | Array of associative arrays | Yes | - | `array( ... )` | | `domains[n]` | Information about a domain for your service. | Associative array | Yes | - | `array( ... )` | -| `domains[n]['domain']` | The domain name for your service. | String | Yes | - | 'www.acme.com' | +| `domains[n]['domain']` | A domain name used by your service. | String | Yes | - | 'www.acme.com' | | `domains[n]['protocol']` | The protocol used by your service web site, `http` or `https`. | String | No | `http` | `http` | | `origins` | List of origin servers for your service. | Array of associative arrays | Yes | - | `array( ... )` | | `origins[n]` | Information about an origin server for your service. | Associative array | Yes | - | `array( ... )` | From a0671b8c46dfb615d61c92f617e0ad80ae3efe99 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 5 Jan 2015 12:17:10 -0800 Subject: [PATCH 51/61] Adding helper methods to generate JSON Patch representation for resource. --- composer.json | 9 ++- .../Common/Resource/PersistentResource.php | 43 +++++++++++ .../Resource/PersistentResourceTest.php | 74 +++++++++++++++++++ 3 files changed, 125 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eed385e82..71d8b7903 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,17 @@ "OpenCloud": ["lib/", "tests/"] } }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/ycombinator/json-patch-php" + } + ], "require": { "php" : ">=5.3.3", "guzzle/http" : "~3.8", - "psr/log": "~1.0" + "psr/log": "~1.0", + "mikemccabe/json-patch-php": "dev-master" }, "require-dev" : { "phpunit/phpunit": "4.3.*", diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index 35e86529e..57d2dca8e 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -25,6 +25,7 @@ use OpenCloud\Common\Exceptions\NameError; use OpenCloud\Common\Exceptions\UnsupportedExtensionError; use OpenCloud\Common\Exceptions\UpdateError; +use mikemccabe\JsonPatch\JsonPatch; abstract class PersistentResource extends BaseResource { @@ -345,6 +346,48 @@ public function checkExtension($alias) return true; } + /** + * Returns the object's properties as an array + */ + protected function getPropertiesAsArray() + { + $properties = get_object_vars($this); + + $propertiesToRemove = array('aliases', 'service', 'parent', 'metadata'); + foreach ($propertiesToRemove as $property) { + unset($properties[$property]); + } + + return $properties; + } + + /** + * Generates a JSON Patch representation and return its + * + * @param mixed $updatedProperties Properties of the resource to update + * @return String JSON Patch representation for updates + */ + protected function generateJsonPatch($updatedProperties) + { + // Normalize current and updated properties into nested arrays + $currentProperties = json_decode(json_encode($this->getPropertiesAsArray()), true); + $updatedProperties = json_decode(json_encode($updatedProperties), true); + + // Add any properties that haven't changed to generate the correct patch + // (otherwise unchanging properties are marked as removed in the patch) + foreach ($currentProperties as $key => $value) { + if (!array_key_exists($key, $updatedProperties)) { + $updatedProperties[$key] = $value; + } + } + + // Generate JSON Patch representation + $json = json_encode(JsonPatch::diff($currentProperties, $updatedProperties)); + $this->checkJsonError(); + + return $json; + } + /******** DEPRECATED METHODS ********/ /** diff --git a/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php index cd81b93ab..b0dffeb80 100644 --- a/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php +++ b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php @@ -31,6 +31,16 @@ public function recursivelyAliasPropertyValue($propertyValue) { return parent::recursivelyAliasPropertyValue($propertyValue); } + + public function getPropertiesAsArray() + { + return parent::getPropertiesAsArray(); + } + + public function generateJsonPatch($updateParams) + { + return parent::generateJsonPatch($updateParams); + } } class PersistentResourceTest extends OpenCloudTestCase @@ -106,4 +116,68 @@ public function testRecursivelyAliasPropertyValueWithObjects() $this->assertEquals($obj3Expected, $this->persistentResource->recursivelyAliasPropertyValue($obj3)); } + + public function testGetPropertiesAsArray() + { + $this->persistentResource->id = 17; + $this->persistentResource->tags = array('foo', 'bar'); + $this->persistentResource->domains = array( + (object) array('domain' => 'foo.phpopencloud.com'), + array('domain' => 'bar.phpopencloud.com') + ); + $this->persistentResource->origins = array( + array('origin' => 'origin1.phpopencloud.com') + ); + $this->persistentResource->status = (object) array('message' => 'Creation in progress'); + + $expectedArray = array( + 'id' => 17, + 'tags' => array('foo', 'bar'), + 'domains' => array( + (object) array('domain' => 'foo.phpopencloud.com'), + array('domain' => 'bar.phpopencloud.com') + ), + 'origins' => array( + array('origin' => 'origin1.phpopencloud.com'), + ), + 'status' => (object) array('message' => 'Creation in progress'), + ); + + $this->assertEquals($expectedArray, $this->persistentResource->getPropertiesAsArray()); + } + + public function testGenerateJsonPatch() + { + $this->persistentResource->id = 17; + $this->persistentResource->tags = array('foo', 'bar'); + $this->persistentResource->domains = array( + array('domain' => 'foo.phpopencloud.com'), + array('domain' => 'bar.phpopencloud.com') + ); + $this->persistentResource->origins = array( + array('origin' => 'origin1.phpopencloud.com') + ); + $this->persistentResource->status = array('message' => 'Creation in progress'); + + $updateParams = array( + 'tags' => array('foo', 'qux', 'baz'), + 'domains' => array( + array('domain' => 'foo.phpopencloud.com') + ), + 'origins' => array( + array('origin' => 'origin1.phpopencloud.com'), + array('origin' => 'origin2.phpopencloud.com') + ) + ); + + $expectedJsonPatch = json_encode(array( + array('op' => 'add', 'path' => '/tags/2', 'value' => 'baz'), + array('op' => 'replace', 'path' => '/tags/1', 'value' => 'qux'), + array('op' => 'remove', 'path' => '/domains/1'), + array('op' => 'add', 'path' => '/origins/1', 'value' => array("origin" => "origin2.phpopencloud.com")) + )); + + $actualJsonPatch = $this->persistentResource->generateJsonPatch($updateParams); + $this->assertEquals($expectedJsonPatch, $actualJsonPatch); + } } From 703941cb665f3efbda968fdc7d9be4150ea405d3 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 5 Jan 2015 13:00:09 -0800 Subject: [PATCH 52/61] Refactoring PATCH headers to Base. --- lib/OpenCloud/Common/Base.php | 7 +++++++ lib/OpenCloud/Common/Constants/Mime.php | 1 + lib/OpenCloud/Image/Resource/Image.php | 4 +++- lib/OpenCloud/Image/Service.php | 13 ------------- tests/OpenCloud/Tests/Common/BaseTest.php | 15 +++++++++++++++ .../Tests/Image/Resource/ImageTest.php | 19 ++++++++++++++++++- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/lib/OpenCloud/Common/Base.php b/lib/OpenCloud/Common/Base.php index 3e0bc3dfb..fd638cc81 100644 --- a/lib/OpenCloud/Common/Base.php +++ b/lib/OpenCloud/Common/Base.php @@ -32,6 +32,8 @@ */ abstract class Base { + const PATCH_CONTENT_TYPE = MimeConst::JSON_PATCH; + /** * Holds all the properties added by overloading. * @@ -419,4 +421,9 @@ protected static function getJsonHeader() { return array(HeaderConst::CONTENT_TYPE => MimeConst::JSON); } + + protected static function getPatchHeaders() + { + return array(HeaderConst::CONTENT_TYPE => static::PATCH_CONTENT_TYPE); + } } diff --git a/lib/OpenCloud/Common/Constants/Mime.php b/lib/OpenCloud/Common/Constants/Mime.php index 23df6cfe9..4e2942ebb 100644 --- a/lib/OpenCloud/Common/Constants/Mime.php +++ b/lib/OpenCloud/Common/Constants/Mime.php @@ -21,4 +21,5 @@ class Mime { const JSON = 'application/json'; const TEXT = 'text/plain'; + const JSON_PATCH = 'application/json-patch+json'; } diff --git a/lib/OpenCloud/Image/Resource/Image.php b/lib/OpenCloud/Image/Resource/Image.php index b8ab7407c..f24eb510b 100644 --- a/lib/OpenCloud/Image/Resource/Image.php +++ b/lib/OpenCloud/Image/Resource/Image.php @@ -35,6 +35,8 @@ class Image extends AbstractSchemaResource implements ImageInterface protected static $json_name = ''; protected static $json_collection_name = 'images'; + const PATCH_CONTENT_TYPE = 'application/openstack-images-v2.1-json-patch'; + /** * Update this resource * @@ -85,7 +87,7 @@ public function update(array $params, Schema $schema = null) $body = $document->toString(); return $this->getClient() - ->patch($this->getUrl(), $this->getService()->getPatchHeaders(), $body) + ->patch($this->getUrl(), $this->getPatchHeaders(), $body) ->send(); } diff --git a/lib/OpenCloud/Image/Service.php b/lib/OpenCloud/Image/Service.php index 86462c8d6..f0ed4d72a 100644 --- a/lib/OpenCloud/Image/Service.php +++ b/lib/OpenCloud/Image/Service.php @@ -17,7 +17,6 @@ namespace OpenCloud\Image; -use OpenCloud\Common\Constants\Header; use OpenCloud\Common\Service\CatalogService; use OpenCloud\Image\Resource\Image; use OpenCloud\Image\Resource\Schema\Schema; @@ -32,18 +31,6 @@ class Service extends CatalogService const DEFAULT_TYPE = 'image'; const DEFAULT_NAME = 'cloudImages'; - const PATCH_CONTENT_TYPE = 'application/openstack-images-v2.1-json-patch'; - - /** - * Get the default headers to send for PATCH requests - * - * @return array - */ - public function getPatchHeaders() - { - return array(Header::CONTENT_TYPE => self::PATCH_CONTENT_TYPE); - } - /** * This operation returns images you created, shared images that you accepted, and standard images. * diff --git a/tests/OpenCloud/Tests/Common/BaseTest.php b/tests/OpenCloud/Tests/Common/BaseTest.php index c0a1c44ea..625863fb7 100644 --- a/tests/OpenCloud/Tests/Common/BaseTest.php +++ b/tests/OpenCloud/Tests/Common/BaseTest.php @@ -36,6 +36,11 @@ public function getBar() { return $this->bar; } + + public static function getPatchHeaders() + { + return parent::getPatchHeaders(); + } } class BaseTest extends \OpenCloud\Tests\OpenCloudTestCase @@ -100,4 +105,14 @@ public function testSetProperty() $this->my->setBaz('goodbye'); $this->assertEquals('goodbye', $this->my->getBaz()); } + + public function testGetPatchHeaders() + { + $expectedHeaders = array( + 'Content-Type' => 'application/json-patch+json' + ); + + $my = $this->my; + $this->assertEquals($expectedHeaders, $my::getPatchHeaders()); + } } diff --git a/tests/OpenCloud/Tests/Image/Resource/ImageTest.php b/tests/OpenCloud/Tests/Image/Resource/ImageTest.php index 5b9fc03b4..bcea3e089 100644 --- a/tests/OpenCloud/Tests/Image/Resource/ImageTest.php +++ b/tests/OpenCloud/Tests/Image/Resource/ImageTest.php @@ -22,11 +22,19 @@ use OpenCloud\Image\Resource\Schema\Schema; use OpenCloud\Tests\OpenCloudTestCase; +class PublicImage extends Image +{ + public static function getPatchHeaders() + { + return parent::getPatchHeaders(); + } +} + class ImageTest extends OpenCloudTestCase { public function setupObjects() { - $this->image = new Image($this->getClient()->imageService('cloudImages', 'IAD')); + $this->image = new PublicImage($this->getClient()->imageService('cloudImages', 'IAD')); } protected function getSchemaData() @@ -139,4 +147,13 @@ public function test_Delete_Tag() $this->assertInstanceOf('Guzzle\Http\Message\Response', $this->image->deleteTag(12345)); } + + public function testGetPatchHeaders() + { + $expectedHeaders = array( + 'Content-Type' => 'application/openstack-images-v2.1-json-patch' + ); + + $this->assertEquals($expectedHeaders, $this->image->getPatchHeaders()); + } } From 4d8688166543a52ef97746d60f18a83df09fd47a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 5 Jan 2015 13:51:34 -0800 Subject: [PATCH 53/61] Overriding update() for Service resource; getting rid of update logic in PersistentResource. --- lib/OpenCloud/CDN/Resource/Service.php | 17 +++++++++++++++-- .../Common/Resource/PersistentResource.php | 10 +--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/OpenCloud/CDN/Resource/Service.php b/lib/OpenCloud/CDN/Resource/Service.php index 233faacc9..5e3a2ff48 100644 --- a/lib/OpenCloud/CDN/Resource/Service.php +++ b/lib/OpenCloud/CDN/Resource/Service.php @@ -30,8 +30,6 @@ class Service extends PersistentResource protected static $url_resource = 'services'; protected static $json_name = 'service'; - const UPDATE_METHOD = 'PATCH'; - protected $id; protected $name; protected $domains; @@ -99,4 +97,19 @@ protected function createJson() $createJson = parent::createJson(); return $createJson->{self::$json_name}; } + + /** + * Update this resource + * + * @param array $params + * @return \Guzzle\Http\Message\Response + */ + public function update($params = array()) + { + $json = $this->generateJsonPatch($params); + + return $this->getClient() + ->patch($this->getUrl(), $this->getPatchHeaders(), $json) + ->send(); + } } diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index 57d2dca8e..6a3bc19d8 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -29,8 +29,6 @@ abstract class PersistentResource extends BaseResource { - const UPDATE_METHOD = 'PUT'; - /** * Create a new resource * @@ -82,13 +80,7 @@ public function update($params = array()) $this->checkJsonError(); // send the request - return $this->makeUpdateRequest($json); - } - - protected function makeUpdateRequest($json) - { - $updateMethod = ('PATCH' === static::UPDATE_METHOD) ? 'patch' : 'post'; - return $this->getClient()->$updateMethod($this->getUrl(), self::getJsonHeader(), $json)->send(); + return $this->getClient()->put($this->getUrl(), self::getJsonHeader(), $json)->send(); } /** From 650e80dcaa83032f98f00fa011785bad4b472ebe Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 5 Jan 2015 18:27:42 -0800 Subject: [PATCH 54/61] Removing newline to trigger build. --- docs/userguide/CDN/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguide/CDN/README.md b/docs/userguide/CDN/README.md index a64cca833..fbe813627 100644 --- a/docs/userguide/CDN/README.md +++ b/docs/userguide/CDN/README.md @@ -93,4 +93,4 @@ $service = $cdnService->createService(array( ## Next steps -Once you have created a service, there is more you can do with it. See [complete user guide for CDN](USERGUIDE.md). +Once you have created a service, there is more you can do with it. See [complete user guide for CDN](USERGUIDE.md). \ No newline at end of file From b610917b7ebeb4d33e49ac5e4a727cf4b4199dc9 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 6 Jan 2015 02:56:13 -0800 Subject: [PATCH 55/61] Removing docs for administrative operations. --- docs/userguide/CDN/USERGUIDE.md | 45 --------------------------------- 1 file changed, 45 deletions(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index 1db7acebe..b59ffdb2e 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -17,10 +17,8 @@ CDN is a service that you can use to manage your CDN-enabled domains and the ori * [Purge all cached service assets](#purge-all-cached-service-assets) * [Purge a specific cached service asset](#purge-a-specific-cached-service-asset) * [Flavors](#flavors) - * [Create a flavor](#create-a-flavor) * [List flavors](#list-flavors) * [Get a flavor](#get-a-flavor) - * [Delete a flavor](#delete-a-flavor) ## Concepts @@ -269,37 +267,6 @@ $service->purgeAssets('/images/logo.png'); A flavor is a configuration option. A flavor enables you to choose from a generic setting that is powered by one or more CDN providers. -### Create a flavor - -Note: When working with the Rackspace Cloud, this operation requires the `cdn:operator` role. - -This operation takes one parameter, an associative array, with the following keys: - -| Name | Description | Data type | Required? | Default value | Example value | -| ---- | ----------- | --------- | --------- | ------------- | ------------- | -| `id` | ID of flavor. This ID must be unique. | String | Yes | `null` | `cdn` | -| `providers` | An array of associative arrays, each representing a CDN provider. | Array of associative arrays | Yes | `null` | `array( array( 'provider' => 'akamai', 'links' => array( array( 'rel' => 'provider_url', 'href' => 'http://www.akamai.com' ) ) ) )` | - -You can create a flavor as shown in the following example: - -```php -$flavor = $cdnService->createFlavor(array( - 'id' => 'cdn', - 'providers' => array( - array( - 'name' => 'akamai', - 'links' => array( - 'rel' => 'provider_url', - 'href' => 'http://www.akamai.com' - ) - ) - ) -)); -/** @var $flavor OpenCloud\CDN\Resource\Flavor **/ -``` - -[ [Get the executable PHP script for this example](/samples/CDN/create-flavor.php) ] - ### List flavors You can list all available flavors as shown in the following example: @@ -324,15 +291,3 @@ $flavor = $cdnService->getFlavor('cdn'); ``` [ [Get the executable PHP script for this example](/samples/CDN/get-flavor.php) ] - -### Delete a flavor - -Note: When working with the Rackspace Cloud, this operation requires the `cdn:operator` role. - -You can delete a flavor as shown in the following example: - -```php -$flavor->delete(); -``` - -[ [Get the executable PHP script for this example](/samples/CDN/delete-flavor.php) ] From 2377b064c15f7a959309d7926b3b4827960c0d8c Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 6 Jan 2015 02:56:30 -0800 Subject: [PATCH 56/61] Fixing ``` alignment. --- docs/userguide/CDN/USERGUIDE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/userguide/CDN/USERGUIDE.md b/docs/userguide/CDN/USERGUIDE.md index b59ffdb2e..971175219 100644 --- a/docs/userguide/CDN/USERGUIDE.md +++ b/docs/userguide/CDN/USERGUIDE.md @@ -149,7 +149,8 @@ $service = $cdnService->createService(array( ) ), 'flavorId' => 'cdn' -));``` +)); +``` [ [Get the executable PHP script for this example](/samples/CDN/create-service.php) ] From 49d5ed85c0168f32429a00f3376bb1823894a729 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 6 Jan 2015 03:42:41 -0800 Subject: [PATCH 57/61] Using $this->updateKeys to determine the current values of updateable properties. --- .../Common/Resource/PersistentResource.php | 14 ++++++++------ .../Resource/PersistentResourceTest.php | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index 6a3bc19d8..803112472 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -341,16 +341,18 @@ public function checkExtension($alias) /** * Returns the object's properties as an array */ - protected function getPropertiesAsArray() + protected function getUpdateablePropertiesAsArray() { $properties = get_object_vars($this); - $propertiesToRemove = array('aliases', 'service', 'parent', 'metadata'); - foreach ($propertiesToRemove as $property) { - unset($properties[$property]); + $propertiesToKeep = array(); + foreach ($this->updateKeys as $key) { + if (isset($properties[$key])) { + $propertiesToKeep[$key] = $properties[$key]; + } } - return $properties; + return $propertiesToKeep; } /** @@ -362,7 +364,7 @@ protected function getPropertiesAsArray() protected function generateJsonPatch($updatedProperties) { // Normalize current and updated properties into nested arrays - $currentProperties = json_decode(json_encode($this->getPropertiesAsArray()), true); + $currentProperties = json_decode(json_encode($this->getUpdateablePropertiesAsArray()), true); $updatedProperties = json_decode(json_encode($updatedProperties), true); // Add any properties that haven't changed to generate the correct patch diff --git a/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php index b0dffeb80..0cf9342f0 100644 --- a/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php +++ b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php @@ -27,14 +27,22 @@ class PublicPersistentResource extends PersistentResource 'foo_bar' => 'fooBar' ); + protected $updateKeys = array( + 'baz', + 'tags', + 'domains', + 'origins', + 'status' + ); + public function recursivelyAliasPropertyValue($propertyValue) { return parent::recursivelyAliasPropertyValue($propertyValue); } - public function getPropertiesAsArray() + public function getUpdateablePropertiesAsArray() { - return parent::getPropertiesAsArray(); + return parent::getUpdateablePropertiesAsArray(); } public function generateJsonPatch($updateParams) @@ -117,7 +125,7 @@ public function testRecursivelyAliasPropertyValueWithObjects() $this->persistentResource->recursivelyAliasPropertyValue($obj3)); } - public function testGetPropertiesAsArray() + public function testGetUpdateablePropertiesAsArray() { $this->persistentResource->id = 17; $this->persistentResource->tags = array('foo', 'bar'); @@ -131,7 +139,6 @@ public function testGetPropertiesAsArray() $this->persistentResource->status = (object) array('message' => 'Creation in progress'); $expectedArray = array( - 'id' => 17, 'tags' => array('foo', 'bar'), 'domains' => array( (object) array('domain' => 'foo.phpopencloud.com'), @@ -140,10 +147,10 @@ public function testGetPropertiesAsArray() 'origins' => array( array('origin' => 'origin1.phpopencloud.com'), ), - 'status' => (object) array('message' => 'Creation in progress'), + 'status' => (object) array('message' => 'Creation in progress') ); - $this->assertEquals($expectedArray, $this->persistentResource->getPropertiesAsArray()); + $this->assertEquals($expectedArray, $this->persistentResource->getUpdateablePropertiesAsArray()); } public function testGenerateJsonPatch() From 28a423451ac9c5b52f4519ee1b6bfce91ebb3543 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 6 Jan 2015 03:43:17 -0800 Subject: [PATCH 58/61] Using property aliases when generating JSON Patch representation. --- lib/OpenCloud/Common/Resource/PersistentResource.php | 4 ++++ .../Tests/Common/Resource/PersistentResourceTest.php | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/Common/Resource/PersistentResource.php b/lib/OpenCloud/Common/Resource/PersistentResource.php index 803112472..bb11b79be 100644 --- a/lib/OpenCloud/Common/Resource/PersistentResource.php +++ b/lib/OpenCloud/Common/Resource/PersistentResource.php @@ -375,6 +375,10 @@ protected function generateJsonPatch($updatedProperties) } } + // Recursively alias current and updated properties + $currentProperties = $this->recursivelyAliasPropertyValue($currentProperties); + $updatedProperties = $this->recursivelyAliasPropertyValue($updatedProperties); + // Generate JSON Patch representation $json = json_encode(JsonPatch::diff($currentProperties, $updatedProperties)); $this->checkJsonError(); diff --git a/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php index 0cf9342f0..79d350e3b 100644 --- a/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php +++ b/tests/OpenCloud/Tests/Common/Resource/PersistentResourceTest.php @@ -165,6 +165,7 @@ public function testGenerateJsonPatch() array('origin' => 'origin1.phpopencloud.com') ); $this->persistentResource->status = array('message' => 'Creation in progress'); + $this->persistentResource->baz = (object) array( 'fooBar' => 'barbar'); $updateParams = array( 'tags' => array('foo', 'qux', 'baz'), @@ -174,10 +175,12 @@ public function testGenerateJsonPatch() 'origins' => array( array('origin' => 'origin1.phpopencloud.com'), array('origin' => 'origin2.phpopencloud.com') - ) + ), + 'baz' => array('fooBar' => 'barbarbar') ); $expectedJsonPatch = json_encode(array( + array('op' => 'replace', 'path' => '/baz/foo_bar', 'value' => 'barbarbar'), array('op' => 'add', 'path' => '/tags/2', 'value' => 'baz'), array('op' => 'replace', 'path' => '/tags/1', 'value' => 'qux'), array('op' => 'remove', 'path' => '/domains/1'), From 8257700c121704eddf0abf59ef23331e475bbd42 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 6 Jan 2015 03:53:24 -0800 Subject: [PATCH 59/61] Accessing static method... statically. --- tests/OpenCloud/Tests/Image/Resource/ImageTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/OpenCloud/Tests/Image/Resource/ImageTest.php b/tests/OpenCloud/Tests/Image/Resource/ImageTest.php index bcea3e089..4a7554edc 100644 --- a/tests/OpenCloud/Tests/Image/Resource/ImageTest.php +++ b/tests/OpenCloud/Tests/Image/Resource/ImageTest.php @@ -154,6 +154,7 @@ public function testGetPatchHeaders() 'Content-Type' => 'application/openstack-images-v2.1-json-patch' ); - $this->assertEquals($expectedHeaders, $this->image->getPatchHeaders()); + $image = $this->image; + $this->assertEquals($expectedHeaders, $image::getPatchHeaders()); } } From 74a900a6803645169a2457505aa091429bd0aa29 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 6 Jan 2015 05:34:25 -0800 Subject: [PATCH 60/61] Trying GC disabling to kill the segfault. --- phpunit.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index be5f3c7e6..1ec5cd508 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -27,6 +27,7 @@ + From 859c7251d1631fa40972a63581175a290bfc9f75 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 6 Jan 2015 05:44:14 -0800 Subject: [PATCH 61/61] Increasing memory limit further to try and kill the segfault. --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1ec5cd508..3d4b02cd2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -26,7 +26,7 @@ - +