Removed HP Cloud CDN extension.
This commit is contained in:
parent
458084e7b1
commit
d49b08f99b
3
Makefile
3
Makefile
@ -17,9 +17,6 @@ fulltest:
|
||||
phpunit --color --exclude-group=deprecated --bootstrap=test/bootstrap_curl.php $(TESTS);
|
||||
phpunit --color --exclude-group=deprecated --bootstrap=test/bootstrap_phpstream.php $(TESTS)
|
||||
|
||||
test-cdn :
|
||||
php test/CDNTest.php
|
||||
|
||||
test-group :
|
||||
phpunit --color -v --group $(GROUP) $(TESTS)
|
||||
|
||||
|
10
README.md
10
README.md
@ -6,7 +6,6 @@ You can use this library to:
|
||||
|
||||
* Authenticate your application to the HP Cloud.
|
||||
* Interact with Object Storage (aka Swift).
|
||||
* Interact with CDN service (Content Delivery Network).
|
||||
|
||||
Coming soon:
|
||||
|
||||
@ -62,15 +61,6 @@ With full stream wrapper support, you can use built-in
|
||||
PHP functions like `file_get_contents()`, `fopen()`, and `stat()` for
|
||||
reading and writing files into object storage.
|
||||
|
||||
#### CDN
|
||||
|
||||
With CDN service enabled, objects in Object Storage can be pushed onto
|
||||
the HP Cloud edge server network.
|
||||
|
||||
With this library, manage CDN integration for object storage containers,
|
||||
and manage individual objects. The library allows you to fetch cached
|
||||
objects either from object storage or from the CDN cache.
|
||||
|
||||
#### Autoloading
|
||||
|
||||
HPCloud is [PSR-0 compliant](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md),
|
||||
|
@ -225,7 +225,7 @@
|
||||
* HPCloud classes providing access to various services.
|
||||
*
|
||||
* HPCloud offers a number of services, including Compute (Nova),
|
||||
* IdentityServices, and CDN.
|
||||
* and IdentityServices.
|
||||
*
|
||||
* This package is reserved for classes that provide access to
|
||||
* services.
|
||||
@ -237,7 +237,6 @@
|
||||
* Services for now and the future:
|
||||
*
|
||||
*- ObjectStorage
|
||||
*- CDN caching of storage
|
||||
*- Others coming.
|
||||
*
|
||||
*/
|
||||
@ -247,10 +246,6 @@
|
||||
*
|
||||
* The main class is HPCloud::Storage::ObjectStorage.
|
||||
*/
|
||||
/*
|
||||
* @package HPCloud.Storage.CDN
|
||||
* Classes specific to CDN.
|
||||
*/
|
||||
/**
|
||||
* @package HPCloud.Transport
|
||||
* HTTP/REST/JSON classes.
|
||||
|
@ -157,7 +157,7 @@ page. It's all there.
|
||||
### Identity Services
|
||||
|
||||
The HPCloud is composed of numerous services. There's the Compute
|
||||
service, the Object Storage service, the CDN service... and so on.
|
||||
service, the Object Storage service... and so on.
|
||||
|
||||
Authenticating separately to each of these would be a collosal waste of
|
||||
network resources. And behind the scenes, account management would be
|
||||
@ -300,7 +300,6 @@ Instances of HPCloud::Storage::ObjectStorage are responsbile for:
|
||||
- Providing high-level information about the Object Storage service
|
||||
- Creating, deleting, loading, and listing Containers
|
||||
- Modifying Container ACLs
|
||||
- Attaching a HPCloud::Storage::CDN service object to a Container (advanced)
|
||||
|
||||
## Step 5: Adding a Container
|
||||
|
||||
@ -355,7 +354,6 @@ A HPCloud::Storage::ObjectStorage::Container instance is responsible for the fol
|
||||
- Creating, saving, deleting, and listing objects in the container
|
||||
- Providing path-like traversal of objects
|
||||
- Copying objects across containers
|
||||
- Interacting with CDN objects (advanced)
|
||||
- Loading a lightweight representation of an object without fetching the
|
||||
entire object (more on this later).
|
||||
|
||||
@ -501,7 +499,6 @@ Instances of a HPCloud::Storage::ObjectStorage::RemoteObject offer the following
|
||||
|
||||
- Access to an object stored on the remote object storage
|
||||
- A proxying mechanism for lazily loading objects
|
||||
- Support for loading via CDN (advanced)
|
||||
- A stream-based API for using stream and file-based PHP functions
|
||||
- Automatic tempfile-based caching for large objects (using
|
||||
`php://temp`).
|
||||
|
@ -582,7 +582,6 @@ class IdentityServices /*implements Serializable*/ {
|
||||
* - identity: Identity Services (i.e. Keystone)
|
||||
* - compute: Compute instance (Nova)
|
||||
* - object-store: Object Storage (Swift)
|
||||
* - hpext:cdn: HPCloud CDN service (yes, the colon belongs in there)
|
||||
*
|
||||
* Other services will be added.
|
||||
*
|
||||
|
@ -1,582 +0,0 @@
|
||||
<?php
|
||||
/* ============================================================================
|
||||
(c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
============================================================================ */
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* This file contains the CDN (Content Distribution Network) class.
|
||||
*/
|
||||
|
||||
namespace HPCloud\Storage;
|
||||
|
||||
/**
|
||||
* Provides CDN services for ObjectStorage.
|
||||
*
|
||||
* CDN stands for "Content Distribution Network." It provides distributed
|
||||
* caching in the cloud. When a Container is CDN-enabled, objects will be
|
||||
* stored not @em just in the ObjectStorage, but temporary cached copies
|
||||
* will be stored on servers around the world.
|
||||
*
|
||||
* @attention
|
||||
* Caches are not protected by authentication. If you store an object in
|
||||
* a CDN, cached versions of that object are publically accessible. Setting
|
||||
* an ACL will have very little impact on this.
|
||||
*
|
||||
* CDN is an HPCloud extension service, and is not presently part of OpenStack
|
||||
* proper. The current REST API documentation can be found at
|
||||
* http://api-docs.hpcloud.com/
|
||||
*
|
||||
* <b>Usage</b>
|
||||
*
|
||||
* The CDN service functions as an <i>add-on</i> to ObjectStorage. It adds a
|
||||
* caching layer. So terms used here, such as Container and Object, refer
|
||||
* to the ObjectStorage items.
|
||||
*
|
||||
* For the most part, CDN operates on the Container level. You can choose to
|
||||
* tell the CDN about a particular Container in ObjectStorage, and it will
|
||||
* cache items in that container.
|
||||
*
|
||||
* The CDN service keeps a list of ObjectStorage Containers that it knows
|
||||
* about. CDN does not automatically discover ObjectStorage Containers; you
|
||||
* must tell CDN about the ObjectStorage instances you want it to know
|
||||
* about. This is done using CDN::enable().
|
||||
*
|
||||
* Once the CDN service knows about an ObjectStorage Container, it will
|
||||
* begin caching objects in that container.
|
||||
*
|
||||
* This library gives the the ability to do the following:
|
||||
*
|
||||
* - List the containers that CDN knows about: CDN::containers()
|
||||
* - Retrieve the CDN properties for a particular Container: CDN::container().
|
||||
* - Add and enable containers: CDN::enable().
|
||||
* - Remove a Container from CDN: CDN::delete().
|
||||
* - Modify the caching properties of a Container: CDN::update().
|
||||
* - Temporarily enable or disable caching for a container with
|
||||
* CDN::update().
|
||||
*
|
||||
* <b>Example</b>
|
||||
*
|
||||
* @code
|
||||
* <?php
|
||||
* // Authentication info:
|
||||
* $endpoint = 'https://auth.example.com';
|
||||
* $username = 'butcher@hp.com';
|
||||
* $password = 'secret';
|
||||
* $tenantId = '123456789';
|
||||
*
|
||||
* // First we need to authenticate:
|
||||
* $identity = new \HPCloud\Services\IdentityServices($endpoint);
|
||||
* $token = $identity->authenticateAsUser($username, $password, $tenantId);
|
||||
*
|
||||
* // Get the service catalog. We will try to have CDN build itself from
|
||||
* // the service catalog.
|
||||
* $catalog = $identity->serviceCatalog();
|
||||
*
|
||||
* // Get a new CDN instance:
|
||||
* $cdn = CDN::newFromServiceCatalog($catalog, $token);
|
||||
*
|
||||
* // Add a container to CDN; set cache lifetime to an hour:
|
||||
* $cdn->enable('myContainer', 3600);
|
||||
*
|
||||
* // Get a list of all containers that CDN knows about,
|
||||
* // and print cache lifetime for each:
|
||||
* foreach ($cdn->containers() as $container) {
|
||||
* print $container['name'] . ':' . $container['ttl'] . PHP_EOL;
|
||||
* }
|
||||
*
|
||||
* // Change the cache lifetime on our container
|
||||
* $cdn->update('myContainer', array('ttl' => 7200));
|
||||
*
|
||||
* // Temporarily stop the container from caching:
|
||||
* $cdn->update('myContainer', array('cdn_enabled' => FALSE);
|
||||
*
|
||||
* //This can be re-enabled again:
|
||||
* $cdn->update('myContainer', array('cdn_enabled' => TRUE);
|
||||
*
|
||||
* // If we no longer want this Container in CDN, we
|
||||
* // should delete it, not just disable it:
|
||||
* $cdn->delete('myContainer');
|
||||
*
|
||||
* ?>
|
||||
* @endcode
|
||||
*/
|
||||
class CDN {
|
||||
|
||||
/**
|
||||
* The name of the CDN service type.
|
||||
*/
|
||||
const SERVICE_TYPE = 'hpext:cdn';
|
||||
/**
|
||||
* The API version.
|
||||
*/
|
||||
const API_VERSION = '1.0';
|
||||
|
||||
const DEFAULT_REGION = 'region-a.geo-1';
|
||||
|
||||
/**
|
||||
* The URL to the CDN endpoint.
|
||||
*/
|
||||
protected $url;
|
||||
/**
|
||||
* The authentication/authorization token.
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* Create a new instance from an IdentityServices object.
|
||||
*
|
||||
* This builds a new CDN instance form an authenticated
|
||||
* IdentityServices object.
|
||||
*
|
||||
* In the service catalog, this selects the first service entry
|
||||
* for CDN. At this time, that is sufficient.
|
||||
*
|
||||
* @param HPCloud::Services::IdentityServices $identity
|
||||
* The identity to use.
|
||||
* @retval boolean
|
||||
* @retval HPCloud::Storage::CDN
|
||||
* @return \HPCloud\Storage\CDN|boolean
|
||||
* A CDN object or FALSE if no CDN services could be found
|
||||
* in the catalog.
|
||||
*/
|
||||
public static function newFromIdentity($identity, $region = CDN::DEFAULT_REGION) {
|
||||
$tok = $identity->token();
|
||||
$cat = $identity->serviceCatalog();
|
||||
|
||||
return self::newFromServiceCatalog($cat, $tok, $region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new CDN object based on a service catalog.
|
||||
*
|
||||
* The IdentityServices class contains a service catalog, which tracks all
|
||||
* services that the present account can access. The service catalog
|
||||
* contains data necessary to connect to a CDN endpoint. This builder
|
||||
* simplifies the process of creating a new CDN by accepting a service
|
||||
* catalog and discovering the CDN service automatically.
|
||||
*
|
||||
* In the vast majority of cases, this is the easiest way to proceed. If,
|
||||
* however, a service catalog has multiple CDN instances (a possibility,
|
||||
* though not currently supported), the present method has no means of
|
||||
* determining which should be used. It simply chooses the first CDN
|
||||
* service endpoint.
|
||||
*
|
||||
* This uses the tenant ID that is found in the service catalog.
|
||||
*
|
||||
* Either of the following work:
|
||||
* @code
|
||||
* <?php
|
||||
*
|
||||
* // Use a full service catalog:
|
||||
* $fullCatalog = $identityService->serviceCatalog();
|
||||
* $cdn = CDN::newFromServiceCatalog($fullCatalog);
|
||||
*
|
||||
* // Use a filtered service catalog:
|
||||
* $catalog = $identitySerice->serviceCatalog(CDN::SERVICE_TYPE);
|
||||
* $cdn = CDN::newFromServiceCatalog($catalog);
|
||||
* ?>
|
||||
* @endcode
|
||||
*
|
||||
* @param array $catalog
|
||||
* A service catalog; see HPCloud::Services::IdentityServices::serviceCatalog().
|
||||
* @param string $token
|
||||
* The token.
|
||||
* @retval boolean
|
||||
* @retval HPCloud::Storage::CDN
|
||||
* @return boolean|\HPCloud\Storage\CDN
|
||||
* A CDN object or FALSE if no CDN services could be found
|
||||
* in the catalog.
|
||||
*/
|
||||
public static function newFromServiceCatalog($catalog, $token, $region = CDN::DEFAULT_REGION) {
|
||||
$c = count($catalog);
|
||||
for ($i = 0; $i < $c; ++$i) {
|
||||
if ($catalog[$i]['type'] == self::SERVICE_TYPE) {
|
||||
foreach ($catalog[$i]['endpoints'] as $endpoint) {
|
||||
if (isset($endpoint['publicURL']) && $endpoint['region'] == $region) {
|
||||
/*
|
||||
$parts = parse_url($endpoint['publicURL']);
|
||||
$base = $parts['scheme'] . '://' . $parts['host'];
|
||||
if (isset($parts['port'])) {
|
||||
$base .= ':' . $parts['port'];
|
||||
}
|
||||
//$base = $endpoint['publicURL'];
|
||||
$cdn = new CDN($token, $base, $endpoint['tenantId']);
|
||||
//$cdn->url = $endpoint['publicURL'];
|
||||
*/
|
||||
$cdn = new CDN($token, $endpoint['publicURL']);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new CDN object.
|
||||
*
|
||||
* This object facilitates communication with the CDN cloud service.
|
||||
*
|
||||
* This creates a new CDN object that will view as its endpoint the server
|
||||
* with the URL $endpoint, which has the form:
|
||||
*
|
||||
* @code
|
||||
* https://ENDPOINT/API_VERSION/ACCOUNT
|
||||
* @endcode
|
||||
*
|
||||
*
|
||||
* On older SwiftAuth-based services, the token should be the swauth token.
|
||||
* On newer releaes, the token is retrieved from IdentityServices.
|
||||
*
|
||||
* @param string $endpoint
|
||||
* The URL of the CDN service. It should look something like this:
|
||||
* @c https://cdnmgmt.rndd.aw1.hpcloud.net/v1.0/72020596871800
|
||||
* @param string $token
|
||||
* The authentication token. This can be retrieved from IdentityServices::token().
|
||||
*/
|
||||
public function __construct($token, $endpoint/*, $account*/) {
|
||||
//$this->url = $endpoint . '/v' . self::API_VERSION . '/' . $account;
|
||||
$this->url = $endpoint;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of containers that the CDN system knows of.
|
||||
*
|
||||
* This returns a list of ObjectStorage Containers that the
|
||||
* CDN service knows of. These containers can be either enabled or
|
||||
* disabled.
|
||||
*
|
||||
* The CDN service does not attempt to discover all of the containers
|
||||
* from a Swift endpoint. Instead, it passively acquires a list of
|
||||
* containers (added via, for example, enabledContainer()).
|
||||
*
|
||||
* Once a container has been added to the CDN service, it can be in
|
||||
* one of two states:
|
||||
*
|
||||
* - enabled (\c cdn_enabled=TRUE)
|
||||
* - disabled (\c cdn_enabled=FALSE)
|
||||
*
|
||||
* This listing will retrieve both enabled and disabled unless
|
||||
* $enabledOnly is set to TRUE.
|
||||
*
|
||||
* Returned data is in this format:
|
||||
* @code
|
||||
* <?php
|
||||
* array(
|
||||
* array(
|
||||
* 'log_retention' => 0
|
||||
* 'cdn_enabled' => 1
|
||||
* 'name' => 'I♡HPCloud'
|
||||
* 'x-cdn-uri' => 'http://hcf937838.cdn.aw1.hpcloud.net'
|
||||
* 'x-cdn-ssl-uri' => 'https://hcf937838.cdn.aw1.hpcloud.net'
|
||||
* 'ttl' => 1234
|
||||
* ),
|
||||
* array(
|
||||
* 'log_retention' => 0
|
||||
* 'cdn_enabled' => 0
|
||||
* 'name' => 'HPCloud2'
|
||||
* 'x-cdn-uri' => 'http://hcf9abc38.cdn.aw1.hpcloud.net'
|
||||
* 'x-cdn-ssl-uri' => 'https://hcf937838.cdn.aw1.hpcloud.net'
|
||||
* 'ttl' => 1234
|
||||
* ),
|
||||
* );
|
||||
* ?>
|
||||
* @endcode
|
||||
*
|
||||
* @attention
|
||||
* The $enabledOnly flag sendes \c enabled_only to the
|
||||
* endpoint. The endpoint may or may not honor this.
|
||||
*
|
||||
* @param boolean $enabledOnly
|
||||
* If this is set to TRUE, then only containers that are
|
||||
* CDN-enabled will be returned.
|
||||
* @retval array
|
||||
* @return array
|
||||
* An indexed array of associative arrays. The format of each
|
||||
* associative array is explained on container().
|
||||
* @throws HPCloud::Exception
|
||||
* An HTTP-level exception on error.
|
||||
*/
|
||||
public function containers($enabledOnly = NULL) {
|
||||
$client = \HPCloud\Transport::instance();
|
||||
$url = $this->url . '/?format=json';
|
||||
|
||||
if ($enabledOnly) {
|
||||
$url .= '&enabled_only=true';
|
||||
}
|
||||
// DEVEX-1733 suggests that this should result in the
|
||||
// server listing only DISABLED containers.
|
||||
elseif ($enabledOnly === FALSE) {
|
||||
$url .= '&enabled_only=false';
|
||||
}
|
||||
|
||||
$headers = array(
|
||||
'X-Auth-Token' => $this->token,
|
||||
);
|
||||
|
||||
$response = $client->doRequest($url, 'GET', $headers);
|
||||
|
||||
$raw = $response->content();
|
||||
$json = json_decode($raw, TRUE);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a container by name.
|
||||
*
|
||||
* @todo The current (1.0) version does not support a verb for getting
|
||||
* just one container, so we have to get the entire list of containers.
|
||||
*
|
||||
* Example return value:
|
||||
* @code
|
||||
* <?php
|
||||
* array(
|
||||
* 'log_retention' => 1
|
||||
* 'cdn_enabled' => 1
|
||||
* 'name' => 'I♡HPCloud'
|
||||
* 'x-cdn-uri' => 'http://hcf937838.cdn.aw1.hpcloud.net'
|
||||
* 'ttl' => 1234
|
||||
* );
|
||||
* ?>
|
||||
* @endcode
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the container to fetch.
|
||||
* @retval array
|
||||
* @return array
|
||||
* An associative array in the exact format as in containers.
|
||||
*/
|
||||
public function container($name) {
|
||||
//$result = $this->modifyContainer($name, 'GET', array(), '?format=json');
|
||||
|
||||
$containers = $this->containers();
|
||||
foreach ($containers as $container) {
|
||||
if ($container['name'] == $name) {
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a container.
|
||||
*
|
||||
* This adds the container to the CDN service and turns on caching.
|
||||
*
|
||||
* In the CDN API, there are two meanings for the term "enable":
|
||||
*
|
||||
* 1. To "CDN-enable" a container means to add that container to the CDN
|
||||
* service. There is no "CDN-disable".
|
||||
* 2. To "enable" a container means to cache that container's
|
||||
* content in a publically available CDN server. There is also a
|
||||
* way to "disable" in this sense -- which blocks a container from
|
||||
* caching.
|
||||
*
|
||||
* This method does the first -- it adds a container to the CDN
|
||||
* service. It so happens that adding a container also enables (in the
|
||||
* second sense) the
|
||||
* container. (This is a feature of the remote service, not the API).
|
||||
*
|
||||
* Enabling and disabling (in the second sense) are considered temporary operations
|
||||
* to switch on and off caching on a particular container. Both of
|
||||
* these operations are done with the update() method.
|
||||
*
|
||||
* The endpoint is supposed to return different results based on the above;
|
||||
* accordingly this method should return TRUE if the container was added
|
||||
* to the list, and FALSE if it was already there. HOWEVER, in some versions
|
||||
* of the CDN service the endpoint returns the same code for both operations,
|
||||
* so the result cannot be relied upon.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the container.
|
||||
* @param int $ttl
|
||||
* Time to live.
|
||||
* The number of seconds an object may stay in the cache. This is the
|
||||
* maximum amount of time. There is, however, no assurance that the object
|
||||
* will remain for the full TTL. 15 minutes is the minimum time. Five years
|
||||
* is the max.
|
||||
* @param boolean $created
|
||||
* If this is passed, then its value will be set to TRUE if the
|
||||
* container was created in the CDN, or FALSE if the container
|
||||
* already existed in CDN.
|
||||
* @retval string
|
||||
* @return string
|
||||
* TRUE if the container was created, FALSE if the container was already
|
||||
* added to the CDN (and thus nothing happened).
|
||||
* @throws HPCloud::Exception
|
||||
* Several HTTP-level exceptions can be thrown.
|
||||
* @see http://api-docs.hpcloud.com/hpcloud-cdn-storage/1.0/content/cdn-enable-container.html
|
||||
*/
|
||||
public function enable($name, $ttl = NULL, &$created = FALSE) {
|
||||
$headers = array();
|
||||
if (!empty($ttl)) {
|
||||
$headers['X-TTL'] = (int) $ttl;
|
||||
}
|
||||
$res = $this->modifyContainer($name, 'PUT', $headers);
|
||||
$created = $res->status() == 201;
|
||||
|
||||
$url = $res->header('X-Cdn-Uri', 'UNKNOWN');
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attributes on a CDN container.
|
||||
*
|
||||
* This updates the attributes (that is, properties) of a container.
|
||||
*
|
||||
* The following attributes are supported:
|
||||
*
|
||||
* - 'ttl': Time to life in seconds (int).
|
||||
* - 'cdn_enabled': Whether the CDN is enabled (boolean).
|
||||
* - 'log_retention': Whether logs are retained (boolean). UNSUPPORTED.
|
||||
*
|
||||
* Future versions of the CDN service will likely provide other
|
||||
* properties.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the container.
|
||||
* @param array $attrs
|
||||
* An associative array of attributes.
|
||||
* @retval boolean
|
||||
* @return boolean
|
||||
* TRUE if the update was successful.
|
||||
* @throws HPCloud::Exception
|
||||
* Possibly throws one of the HTTP exceptions.
|
||||
*/
|
||||
public function update($name, $attrs) {
|
||||
|
||||
$headers = array();
|
||||
foreach ($attrs as $item => $val) {
|
||||
switch ($item) {
|
||||
case 'ttl':
|
||||
$headers['X-TTL'] = (int) $val;
|
||||
break;
|
||||
case 'enabled':
|
||||
case 'cdn_enabled':
|
||||
if (isset($val) && $val == FALSE) {
|
||||
$flag = 'False';
|
||||
}
|
||||
// Default is TRUE.
|
||||
else {
|
||||
$flag = 'True';
|
||||
}
|
||||
$headers['X-CDN-Enabled'] = $flag;
|
||||
break;
|
||||
case 'logs':
|
||||
case 'log_retention':
|
||||
// The default is TRUE.
|
||||
if (isset($val) && $val == FALSE) {
|
||||
$flag = 'False';
|
||||
}
|
||||
else {
|
||||
$flag = 'True';
|
||||
}
|
||||
$headers['X-Log-Retention'] = $flag;
|
||||
break;
|
||||
default:
|
||||
$headers[$item] = (string) $val;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$response = $this->modifyContainer($name, 'POST', $headers);
|
||||
|
||||
return $response->status() == 204;
|
||||
}
|
||||
|
||||
/*
|
||||
* Temporarily disable CDN for a container.
|
||||
*
|
||||
* This will suspend caching on the named container. It is intended to be a
|
||||
* temporary measure. See delete() for completely removing a container from
|
||||
* CDN service.
|
||||
*
|
||||
* Disabled items will still show up in the list returned by containers(),
|
||||
* and will also be retrievable via container().
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the container whose cache should be suspended.
|
||||
* @retval boolean
|
||||
* @return boolean
|
||||
* TRUE if the container is disabled.
|
||||
* @throws HPCloud::Exception
|
||||
* HTTP exceptions may be thrown if an error occurs.
|
||||
*/
|
||||
/*
|
||||
public function disable($name) {
|
||||
$headers = array('X-CDN-Enabled' => 'False');
|
||||
$res = $this->modifyContainer($name, 'POST', $headers);
|
||||
return $res->status() == 204;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Attempt to remove a container from CDN.
|
||||
*
|
||||
* This will remove a container from CDN services,
|
||||
* completely stopping all caching on that container.
|
||||
*
|
||||
* Deleted containers will no longer show up in the containers()
|
||||
* list, nor will they be accessible via container().
|
||||
*
|
||||
* Deleted containers can be added back with enable().
|
||||
*
|
||||
* @param string $name
|
||||
* The Container name.
|
||||
* @retval boolean
|
||||
* @return boolean
|
||||
* TRUE if the container was successfully deleted,
|
||||
* FALSE if the container was not removed, but no
|
||||
* error occurred.
|
||||
* @throws HPCloud::Exception
|
||||
* Any of the HTTP error subclasses can be thrown.
|
||||
*/
|
||||
public function delete($name) {
|
||||
$res = $this->modifyContainer($name, 'DELETE');
|
||||
return $res->status() == 204;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the given method on the given container.
|
||||
*
|
||||
* Checks to see if the expected result is returned.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the container.
|
||||
* @param string $method
|
||||
* The appropriate HTTP verb.
|
||||
* @param int $expects
|
||||
* The expected HTTP code.
|
||||
*/
|
||||
protected function modifyContainer($name, $method, $headers = array(), $qstring = '') {
|
||||
$url = $this->url . '/' . rawurlencode($name) . $qstring;
|
||||
$headers['X-Auth-Token'] = $this->token;
|
||||
|
||||
$client = \HPCloud\Transport::instance();
|
||||
$response = $client->doRequest($url, $method, $headers);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -64,8 +64,7 @@ use HPCloud\Storage\ObjectStorage\ACL;
|
||||
*
|
||||
* @todo ObjectStorage is not yet constrained to a particular version
|
||||
* of the API. It attempts to use whatever version is passed in to the
|
||||
* URL. This is different than IdentityServices and CDN, which use a
|
||||
* fixed version.
|
||||
* URL. This is different than IdentityServices, which used a fixed version.
|
||||
*/
|
||||
class ObjectStorage {
|
||||
|
||||
@ -89,14 +88,6 @@ class ObjectStorage {
|
||||
*/
|
||||
protected $url = NULL;
|
||||
|
||||
/**
|
||||
* CDN containers.
|
||||
*
|
||||
* This is an associative array of container names to URLs.
|
||||
*/
|
||||
protected $cdnContainers;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance after getting an authenitcation token.
|
||||
*
|
||||
@ -210,7 +201,6 @@ class ObjectStorage {
|
||||
foreach ($catalog[$i]['endpoints'] as $endpoint) {
|
||||
if (isset($endpoint['publicURL']) && $endpoint['region'] == $region) {
|
||||
$os= new ObjectStorage($authToken, $endpoint['publicURL']);
|
||||
//$cdn->url = $endpoint['publicURL'];
|
||||
|
||||
return $os;
|
||||
}
|
||||
@ -238,75 +228,6 @@ class ObjectStorage {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that this ObjectStorage instance should use the given CDN service.
|
||||
*
|
||||
* This will cause this ObjectStorage instance to use CDN as often as it can.
|
||||
* Any containers (and subsequently container objects) that can leverage
|
||||
* CDN services will act accordingly.
|
||||
*
|
||||
* CDN is used for *read* operations. Because CDN is a time-based cache,
|
||||
* objects in CDN can be older than objects in Swift itself. For that
|
||||
* reason, CDN should not be used when a combination of read and write
|
||||
* operations occur.
|
||||
*
|
||||
* @retval HPCloud::Storage::ObjectStorage
|
||||
* @return \HPCloud\Storage\ObjectStorage
|
||||
* $this for current object so the method can be used in chaining.
|
||||
*/
|
||||
public function useCDN($cdn) {
|
||||
|
||||
// This should not happen, but has happened when service
|
||||
// catalog was bad.
|
||||
if (empty($cdn)) {
|
||||
throw new \HPCloud\Exception('Cannot use CDN: No CDN provided.');
|
||||
}
|
||||
|
||||
$containers = $cdn->containers(TRUE);
|
||||
$buffer = array();
|
||||
|
||||
foreach ($containers as $item) {
|
||||
// This is needed b/c of a bug in SOS that sometimes
|
||||
// returns disabled containers (DEVEX-1733).
|
||||
if ($item['cdn_enabled'] == 1) {
|
||||
$buffer[$item['name']] = array(
|
||||
'url' => $item['x-cdn-uri'],
|
||||
'sslUrl' => $item['x-cdn-ssl-uri'],
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->cdnContainers = $buffer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasCDN() {
|
||||
return !empty($this->cdnContainers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the CDN URL for a particular container.
|
||||
*
|
||||
* If CDN is enabled, this will attempt to get the URL
|
||||
* to the CDN endpoint for the given container.
|
||||
*
|
||||
* @param string $containerName
|
||||
* The name of the container.
|
||||
* @param boolean $ssl
|
||||
* If this is TRUE (default), get the URL to the SSL CDN;
|
||||
* otherwise get the URL to the plain HTTP CDN.
|
||||
* @retval string
|
||||
* @return string
|
||||
* The URL to the CDN container, or NULL if no such
|
||||
* URL is found.
|
||||
*/
|
||||
public function cdnUrl($containerName, $ssl = TRUE) {
|
||||
if (!empty($this->cdnContainers[$containerName])) {
|
||||
$key = $ssl ? 'sslUrl' : 'url';
|
||||
return $this->cdnContainers[$containerName][$key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authentication token.
|
||||
*
|
||||
@ -383,11 +304,6 @@ class ObjectStorage {
|
||||
foreach ($containers as $container) {
|
||||
$cname = $container['name'];
|
||||
$containerList[$cname] = Container::newFromJSON($container, $this->token(), $this->url());
|
||||
|
||||
if (!empty($this->cdnContainers[$cname])) {
|
||||
$cdnList = $this->cdnContainers[$cname];
|
||||
$containerList[$cname]->useCDN($cdnList['url'], $cdnList['sslUrl']);
|
||||
}
|
||||
}
|
||||
|
||||
return $containerList;
|
||||
@ -415,11 +331,6 @@ class ObjectStorage {
|
||||
if ($status == 204) {
|
||||
$container = Container::newFromResponse($name, $data, $this->token(), $this->url());
|
||||
|
||||
if (isset($this->cdnContainers[$name])) {
|
||||
$cdnList = $this->cdnContainers[$name];
|
||||
$container->useCDN($cdnList['url'], $cdnList['sslUrl']);
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,6 @@ namespace HPCloud\Storage\ObjectStorage;
|
||||
* container.
|
||||
*
|
||||
* @todo Add support for container metadata.
|
||||
* @todo Add CDN support fo container listings.
|
||||
*/
|
||||
class Container implements \Countable, \IteratorAggregate {
|
||||
/**
|
||||
@ -93,10 +92,6 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
protected $acl;
|
||||
protected $metadata;
|
||||
|
||||
// This is only set if CDN service is activated.
|
||||
protected $cdnUrl;
|
||||
protected $cdnSslUrl;
|
||||
|
||||
/**
|
||||
* Transform a metadata array into headers.
|
||||
*
|
||||
@ -331,27 +326,6 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URL of the CDN to use.
|
||||
*
|
||||
* If this is set, the Container will attempt to fetch objects
|
||||
* from the CDN instead of the Swift storage whenever possible.
|
||||
*
|
||||
* If ObjectStorage::useCDN() is already called, this is not necessary.
|
||||
*
|
||||
* Setting this to NULL will have the effect of turning off CDN for this
|
||||
* container.
|
||||
*
|
||||
* @param string $url
|
||||
* The URL to the CDN for this container.
|
||||
* @param string $sslUrl
|
||||
* The SSL URL to the CDN for this container.
|
||||
*/
|
||||
public function useCDN($url, $sslUrl) {
|
||||
$this->cdnUrl = $url;
|
||||
$this->cdnSslUrl = $sslUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this container.
|
||||
*
|
||||
@ -699,25 +673,15 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
* - If-Modified-Since/If-Unmodified-Since
|
||||
* - If-Match/If-None-Match
|
||||
*
|
||||
* If a CDN has been specified either using useCDN() or
|
||||
* ObjectStorage::useCDN(), this will attempt to fetch the object
|
||||
* from the CDN.
|
||||
*
|
||||
* @param string $name
|
||||
* The name of the object to load.
|
||||
* @param boolean $requireSSL
|
||||
* If this is TRUE (the default), then SSL will always be
|
||||
* used. If this is FALSE, then CDN-based fetching will
|
||||
* use non-SSL, which is faster.
|
||||
* @retval HPCloud::Storage::ObjectStorage::RemoteObject
|
||||
* @return \HPCloud\Storage\ObjectStorage\RemoteObject
|
||||
* A remote object with the content already stored locally.
|
||||
*/
|
||||
public function object($name, $requireSSL = TRUE) {
|
||||
public function object($name) {
|
||||
|
||||
$url = self::objectUrl($this->url, $name);
|
||||
$cdn = self::objectUrl($this->cdnUrl, $name);
|
||||
$cdnSsl = self::objectUrl($this->cdnSslUrl, $name);
|
||||
$headers = array();
|
||||
|
||||
// Auth token.
|
||||
@ -725,14 +689,7 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
|
||||
$client = \HPCloud\Transport::instance();
|
||||
|
||||
if (empty($this->cdnUrl)) {
|
||||
$response = $client->doRequest($url, 'GET', $headers);
|
||||
}
|
||||
else {
|
||||
$from = $requireSSL ? $cdnSsl : $cdn;
|
||||
// print "Fetching object from $from\n";
|
||||
$response = $client->doRequest($from, 'GET', $headers);
|
||||
}
|
||||
$response = $client->doRequest($url, 'GET', $headers);
|
||||
|
||||
if ($response->status() != 200) {
|
||||
throw new \HPCloud\Exception('An unknown error occurred while saving: ' . $response->status());
|
||||
@ -741,10 +698,6 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
$remoteObject = RemoteObject::newFromHeaders($name, $response->headers(), $this->token, $url);
|
||||
$remoteObject->setContent($response->content());
|
||||
|
||||
if (!empty($this->cdnUrl)) {
|
||||
$remoteObject->useCDN($cdn, $cdnSsl);
|
||||
}
|
||||
|
||||
return $remoteObject;
|
||||
}
|
||||
|
||||
@ -780,8 +733,6 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
*/
|
||||
public function proxyObject($name) {
|
||||
$url = self::objectUrl($this->url, $name);
|
||||
$cdn = self::objectUrl($this->cdnUrl, $name);
|
||||
$cdnSsl = self::objectUrl($this->cdnSslUrl, $name);
|
||||
$headers = array(
|
||||
'X-Auth-Token' => $this->token,
|
||||
);
|
||||
@ -789,12 +740,7 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
|
||||
$client = \HPCloud\Transport::instance();
|
||||
|
||||
if (empty($this->cdnUrl)) {
|
||||
$response = $client->doRequest($url, 'HEAD', $headers);
|
||||
}
|
||||
else {
|
||||
$response = $client->doRequest($cdnSsl, 'HEAD', $headers);
|
||||
}
|
||||
$response = $client->doRequest($url, 'HEAD', $headers);
|
||||
|
||||
if ($response->status() != 200) {
|
||||
throw new \HPCloud\Exception('An unknown error occurred while saving: ' . $response->status());
|
||||
@ -804,10 +750,6 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
|
||||
$obj = RemoteObject::newFromHeaders($name, $headers, $this->token, $url);
|
||||
|
||||
if (!empty($this->cdnUrl)) {
|
||||
$obj->useCDN($cdn, $cdnSsl);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
/**
|
||||
@ -981,10 +923,6 @@ class Container implements \Countable, \IteratorAggregate {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function cdnUrl($ssl = TRUE) {
|
||||
return $ssl ? $this->cdnSslUrl : $this->cdnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ACL.
|
||||
*
|
||||
|
@ -67,9 +67,6 @@ class RemoteObject extends Object {
|
||||
*/
|
||||
protected $allHeaders = array();
|
||||
|
||||
protected $cdnUrl;
|
||||
protected $cdnSslUrl;
|
||||
|
||||
/**
|
||||
* Create a new RemoteObject from JSON data.
|
||||
*
|
||||
@ -114,19 +111,12 @@ class RemoteObject extends Object {
|
||||
* @param string $url
|
||||
* The URL to the object in the object storage. Used for issuing
|
||||
* subsequent requests.
|
||||
* @param string $cdnUrl
|
||||
* The URL to the CDN version of the object. Used for issuing
|
||||
* subsequent requests. If this is set, this object may use
|
||||
* CDN to make subsequent requests. It may also return the
|
||||
* CDN URL when requested.
|
||||
* @param string $cdnSslUrl
|
||||
* The URL to the SSL-protected CDN version of the object.
|
||||
*
|
||||
* @retval HPCloud::Storage::ObjectStorage::RemoteObject
|
||||
* @return \HPCloud\Storage\ObjectStorage\RemoteObject
|
||||
* A new RemoteObject.
|
||||
*/
|
||||
public static function newFromHeaders($name, $headers, $token, $url, $cdnUrl = NULL, $cdnSslUrl = NULL) {
|
||||
public static function newFromHeaders($name, $headers, $token, $url) {
|
||||
$object = new RemoteObject($name);
|
||||
|
||||
//$object->allHeaders = $headers;
|
||||
@ -160,82 +150,26 @@ class RemoteObject extends Object {
|
||||
|
||||
$object->token = $token;
|
||||
$object->url = $url;
|
||||
$object->cdnUrl = $cdnUrl;
|
||||
$object->cdnSslUrl = $cdnSslUrl;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URL to this object in a CDN service.
|
||||
*
|
||||
* A CDN may be used to expedite *reading* the object. Write
|
||||
* operations are never performed on a CDN. Since a RemoteObject
|
||||
* can be partially loaded, it is possible that part of the object
|
||||
* is read from a CDN, and part from Swift. However, to accomplish
|
||||
* this would require one to set CDN services in one place, and
|
||||
* not in the other.
|
||||
*
|
||||
* Note that if CDN was set using ObjectStorage::useCDN() or
|
||||
* Container::useCDN(), you needn't call this method. CDN will
|
||||
* be automatically enabled during object construction.
|
||||
*
|
||||
* Setting this to NULL has the effect of turning off CDN for
|
||||
* this object.
|
||||
*
|
||||
* @param string $url
|
||||
* The URL to this object in CDN.
|
||||
* @param string $sslUrl
|
||||
* The SSL URL to this object in CDN.
|
||||
*
|
||||
* @retval HPCloud::Storage::ObjectStorage::RemoteObject
|
||||
* @return \HPCloud\Storage\ObjectStorage\RemoteObject
|
||||
* $this for the current object so it can be used in chaining methods.
|
||||
*/
|
||||
public function useCDN($url, $sslUrl) {
|
||||
$this->cdnUrl = $url;
|
||||
$this->cdnSslUrl = $sslUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to this object.
|
||||
*
|
||||
* If this object has been stored remotely, it will have
|
||||
* a valid URL.
|
||||
*
|
||||
* @param boolean $cached
|
||||
* If this value is set to TRUE, this call *may* return the
|
||||
* URL to a cached (CDN) URL. Reading from a cached URL should
|
||||
* be substantially faster than reading from a normal URL. Note,
|
||||
* however, that a container must have CDN enabled on it before
|
||||
* caching can be used, and a CDN must be passed into this
|
||||
* object. See ObjectStorage::useCDN(), Container::useCDN() and
|
||||
* RemoteObject::useCDN(). (Generally, using ObjectStorage::useCDN()
|
||||
* is all you need to do.)
|
||||
* @param boolean $useSSL
|
||||
* FOR CACHED URLS ONLY, there is an option for either SSL or non-SSL
|
||||
* URLs. By default, we use SSL URLs because (a) it's safer, and
|
||||
* (b) it mirrors non-CDN behavior. This can be turned off by setting
|
||||
* $useSSL to FALSE.
|
||||
* @retval string
|
||||
* @return string
|
||||
* A URL to the object. The following considerations apply:
|
||||
* - If the container is public, this URL can be loaded without
|
||||
* authentication. You can, for example, pass the URL to a browser
|
||||
* user agent.
|
||||
* - If a CDN URL has been provided to useCDN() and $cached is TRUE...
|
||||
* - If the container is CDN enabled, a URL to the cache will be returned.
|
||||
* - Otherwise, the Swift URL will be returned.
|
||||
* - If this object has never been saved remotely, then there will be
|
||||
* no URL, and this will return NULL.
|
||||
*/
|
||||
public function url($cached = FALSE, $useSSL = TRUE) {
|
||||
|
||||
if ($cached && !empty($this->cdnUrl)) {
|
||||
return $useSSL ? $this->cdnSslUrl : $this->cdnUrl;
|
||||
}
|
||||
public function url() {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
@ -680,12 +614,7 @@ class RemoteObject extends Object {
|
||||
'X-Auth-Token' => $this->token,
|
||||
);
|
||||
|
||||
if (empty($this->cdnUrl)) {
|
||||
$response = $client->doRequest($this->url, $method, $headers);
|
||||
}
|
||||
else {
|
||||
$response = $client->doRequest($this->cdnUrl, $method, $headers);
|
||||
}
|
||||
$response = $client->doRequest($this->url, $method, $headers);
|
||||
|
||||
if ($response->status() != 200) {
|
||||
throw new \HPCloud\Exception('An unknown exception occurred during transmission.');
|
||||
|
@ -245,25 +245,11 @@ use \HPCloud\Storage\ObjectStorage;
|
||||
* In general, you should avoid using this.
|
||||
* - content_type: This is effective only when writing files. It will
|
||||
* set the Content-Type of the file during upload.
|
||||
* - use_cdn: If this is set to TRUE, then whenever possible assets will be
|
||||
* loaded from CDN instead of from the object store. The following
|
||||
* conditions must obtain for this to work:
|
||||
* - The container must allow public reading (ACL)
|
||||
* - The container must have CDN enabled
|
||||
* - The CDN container must be active ("cdn-enabled")
|
||||
* - Authentication info must be accessible to the stream wrapper.
|
||||
* - cdn_require_ssl: If this is set to FALSE, then CDN-based requests
|
||||
* may use plain HTTP instead of HTTPS. This will spead up CDN
|
||||
* fetches at the cost of security.
|
||||
* - tenantid: The tenant ID for the services you will use. (An account may
|
||||
* have multiple tenancies associated.)
|
||||
* - tenantname: The tenant name for the services you will use. You may use
|
||||
* this in lieu of tenant ID.
|
||||
*
|
||||
* @attention
|
||||
* ADVANCED: You can also pass an HPCloud::Storage::CDN object in use_cdn instead of
|
||||
* a boolean.
|
||||
*
|
||||
* @see http://us3.php.net/manual/en/class.streamwrapper.php
|
||||
*
|
||||
* @todo The service catalog should be cached in the context like the token so that
|
||||
@ -841,28 +827,6 @@ class StreamWrapper {
|
||||
|
||||
//syslog(LOG_WARNING, "Container: " . $containerName);
|
||||
|
||||
// EXPERIMENTAL:
|
||||
// If we can get the resource from CDN, we do so now. Note that we try to sidestep
|
||||
// the Container creation, which saves us an HTTP request.
|
||||
$cdnUrl = $this->store->cdnUrl($containerName, FALSE);
|
||||
$cdnSslUrl = $this->store->cdnUrl($containerName, TRUE);
|
||||
if (!empty($cdnUrl) && !$this->isWriting && !$this->isAppending) {
|
||||
$requireSSL = (boolean) $this->cxt('cdn_require_ssl', TRUE);
|
||||
try {
|
||||
$newUrl = $this->store->url() . '/' . $containerName;
|
||||
$token = $this->store->token();
|
||||
$this->container = new \HPCloud\Storage\ObjectStorage\Container($containerName, $newUrl, $token);
|
||||
$this->container->useCDN($cdnUrl, $cdnSslUrl);
|
||||
$this->obj = $this->container->object($objectName, $requireSSL);
|
||||
$this->objStream = $this->obj->stream();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
// If there is an error, fall back to regular handling.
|
||||
catch (\HPCloud\Exception $e) {}
|
||||
}
|
||||
// End EXPERIMENTAL section.
|
||||
|
||||
// Now we need to get the container. Doing a server round-trip here gives
|
||||
// us the peace of mind that we have an actual container.
|
||||
// XXX: Should we make it possible to get a container blindly, without the
|
||||
@ -1579,62 +1543,10 @@ class StreamWrapper {
|
||||
*/
|
||||
}
|
||||
|
||||
try {
|
||||
$this->initializeCDN($token, $serviceCatalog);
|
||||
}
|
||||
catch (\HPCloud\Exception $e) {
|
||||
//fwrite(STDOUT, $e);
|
||||
throw new \HPCloud\Exception('CDN could not be initialized', 1, $e);
|
||||
|
||||
}
|
||||
|
||||
return !empty($this->store);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize CDN service.
|
||||
*
|
||||
* When the `use_cdn` parameter is passed into the context, we try
|
||||
* to use a CDN service wherever possible.
|
||||
*
|
||||
* If `use_cdn` is set to TRUE, we try to create a new CDN object.
|
||||
* This will require a service catalog.
|
||||
*
|
||||
* When use_cdn is set to TRUE, the wrapper tries to use CDN service.
|
||||
* In such cases, we need a handle to the CDN object. This initializes
|
||||
* that handle, which can later be used to get other information.
|
||||
*
|
||||
* Also note that CDN's default behavior is to fetch over SSL CDN.
|
||||
* To disable this, set 'cdn_require_ssl' to FALSE.
|
||||
*/
|
||||
protected function initializeCDN($token, $catalog) {
|
||||
$cdn = $this->cxt('use_cdn', FALSE);
|
||||
|
||||
// No CDN should be enabled.
|
||||
if (empty($cdn)) {
|
||||
return FALSE;
|
||||
}
|
||||
// Use the CDN object, if provided.
|
||||
elseif ($cdn instanceof \HPCloud\Storage\CDN) {
|
||||
$this->cdn = $cdn;
|
||||
}
|
||||
// Or try to create a new CDN from the catalog.
|
||||
else {
|
||||
if (empty($catalog)) {
|
||||
$ident = $this->authenticate();
|
||||
$catalog = $ident->serviceCatalog();
|
||||
$token = $ident->token();
|
||||
}
|
||||
$this->cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($catalog, $token);
|
||||
}
|
||||
|
||||
if (!empty($this->cdn)) {
|
||||
$this->store->useCDN($this->cdn);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
protected function authenticate() {
|
||||
$username = $this->cxt('username');
|
||||
$password = $this->cxt('password');
|
||||
|
145
test/CDNTest.php
145
test/CDNTest.php
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
/* ============================================================================
|
||||
(c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
============================================================================ */
|
||||
/**
|
||||
* @file
|
||||
* A commandline demonstration of the PHP API.
|
||||
*/
|
||||
|
||||
// Name of the container to test. It must have
|
||||
// CDN enabled. Using the one you use for standard
|
||||
// tests is ill advised.
|
||||
define('TEST_CONTAINER', 'mycontainer');
|
||||
|
||||
$base = __dir__ . '/../src';
|
||||
|
||||
require_once $base . '/HPCloud/Bootstrap.php';
|
||||
|
||||
\HPCloud\Bootstrap::useAutoloader();
|
||||
|
||||
$inifile = __DIR__ . '/settings.ini';
|
||||
if (!is_readable($inifile)) {
|
||||
die('Could not find ' . $inifile);
|
||||
}
|
||||
|
||||
$ini = parse_ini_file($inifile, FALSE);
|
||||
|
||||
\HPCloud\Bootstrap::setConfiguration($ini);
|
||||
\HPCloud\Bootstrap::useStreamWrappers();
|
||||
|
||||
|
||||
$id = new \HPCloud\Services\IdentityServices($ini['hpcloud.identity.url']);
|
||||
//$token = $id->authenticateAsAccount($ini['hpcloud.identity.account'], $ini['hpcloud.identity.secret'], $ini['hpcloud.identity.tenantId']);
|
||||
$token = $id->authenticateAsUser($ini['hpcloud.identity.username'], $ini['hpcloud.identity.password'], $ini['hpcloud.identity.tenantId']);
|
||||
|
||||
$objstore = \HPCloud\Storage\ObjectStorage::newFromServiceCatalog($id->serviceCatalog(), $token);
|
||||
$cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($id->serviceCatalog(), $token);
|
||||
|
||||
$objstore->useCDN($cdn);
|
||||
|
||||
//var_dump($cdn->containers());
|
||||
|
||||
// Check that the container has CDN.
|
||||
$cname = TEST_CONTAINER; //$ini['hpcloud.swift.container'];
|
||||
$isEnabled = FALSE;
|
||||
|
||||
$cdnData = $cdn->container($cname);
|
||||
print "***** TESTING CDN ENABLED" . PHP_EOL;
|
||||
if ($cdnData['cdn_enabled'] != 1) {
|
||||
die('Cannot test CDN: You must enable CDN on ' . $cname);
|
||||
}
|
||||
$container = $objstore->container($cname);
|
||||
|
||||
print "***** TESTING CDN URL" . PHP_EOL;
|
||||
$cdnSsl = $objstore->cdnUrl($cname);
|
||||
$cdnPlain = $objstore->cdnUrl($cname, FALSE);
|
||||
if ($cdnSsl == $cdnPlain) {
|
||||
die(sprintf("Surprise! %s matches %s\n", $cdnSsl, $cdnPlain));
|
||||
}
|
||||
print 'SSL CDN: ' . $cdnSsl. PHP_EOL;
|
||||
print 'Plain CDN: ' . $cdnPlain . PHP_EOL;
|
||||
print 'Container CDN URL: ' . $container->cdnUrl() . PHP_EOL;
|
||||
if ($container->cdnUrl() == NULL) {
|
||||
die('No CDN URL for Container ' . $cname);
|
||||
}
|
||||
|
||||
if ($cdnSsl != $container->cdnUrl()) {
|
||||
die(sprintf("Expected SSL CDN %s to match Container CDN %s\n", $cdnSsl, $container->cdnUrl()));
|
||||
}
|
||||
|
||||
$o = new \HPCloud\Storage\ObjectStorage\Object('CDNTest.txt', 'TEST');
|
||||
|
||||
$container->save($o);
|
||||
|
||||
$copy = $container->object($o->name());
|
||||
|
||||
print "***** TESTING OBJECT CDN URLS." . PHP_EOL;
|
||||
print "Object SSL URL: " . $copy->url() . PHP_EOL;
|
||||
print "Object CDN SSL URL: " . $copy->url(TRUE) . PHP_EOL;
|
||||
print "Object CDN URL: " . $copy->url(TRUE, FALSE) . PHP_EOL;
|
||||
if ($copy->url(TRUE) == $copy->url(TRUE, FALSE)) {
|
||||
die(sprintf("Object SSL URL %s should not match non-SSL URL %s\n", $copy->url(TRUE), $copy->url(TRUE, FALSE)));
|
||||
}
|
||||
|
||||
print "***** TESTING THAT CDN WAS USED." . PHP_EOL;
|
||||
if ($copy->url() == $copy->url(TRUE)) {
|
||||
die('Object Storage not used for ' . $o->name());
|
||||
}
|
||||
|
||||
print "***** TESTING STREAM WRAPPERS " . PHP_EOL;
|
||||
$cxt = stream_context_create(array(
|
||||
'swift' => array(
|
||||
//'token' => $token,
|
||||
'tenantid' => $ini['hpcloud.identity.tenantId'],
|
||||
'account' => $ini['hpcloud.identity.account'],
|
||||
'key' => $ini['hpcloud.identity.secret'],
|
||||
'endpoint' => $ini['hpcloud.identity.url'],
|
||||
'use_cdn' => TRUE,
|
||||
),
|
||||
));
|
||||
$cxt2 = stream_context_create(array(
|
||||
'swift' => array(
|
||||
//'token' => $token,
|
||||
'tenantid' => $ini['hpcloud.identity.tenantId'],
|
||||
'account' => $ini['hpcloud.identity.account'],
|
||||
'key' => $ini['hpcloud.identity.secret'],
|
||||
'endpoint' => $ini['hpcloud.identity.url'],
|
||||
'use_cdn' => TRUE,
|
||||
'cdn_require_ssl' => FALSE,
|
||||
),
|
||||
));
|
||||
|
||||
print "***** TESTING RETURNED DATA" . PHP_EOL;
|
||||
$res = array(
|
||||
'internal' => file_get_contents('swift://' . TEST_CONTAINER . '/CDNTest.txt', FALSE, $cxt),
|
||||
'internalNoSSL' => file_get_contents('swift://' . TEST_CONTAINER . '/CDNTest.txt', FALSE, $cxt2),
|
||||
'external' => file_get_contents($copy->url()),
|
||||
'externalSslCdn' => file_get_contents($copy->url(TRUE)),
|
||||
'externalCdn' => file_get_contents($copy->url(TRUE, FALSE)),
|
||||
);
|
||||
|
||||
foreach ($res as $name => $val) {
|
||||
if ($val != 'TEST') {
|
||||
die(sprintf("Facility %s failed, returning '%s' instead of TEST.", $name, $val));
|
||||
}
|
||||
}
|
||||
|
||||
print PHP_EOL . "***** All tests passed." . PHP_EOL;
|
@ -111,14 +111,7 @@ By default, this will run ALL of the unit tests. However, you can run
|
||||
a subset of the tests using the TESTS argument:
|
||||
|
||||
```
|
||||
$ make test TESTS=test/Tests/CDNTest.php
|
||||
```
|
||||
|
||||
The above only runs the CDN unit tests. To specify a list of tests,
|
||||
make sure you put quotes around the entire string:
|
||||
|
||||
```
|
||||
$ make test TESTS="test/Tests/CDNTest.php test/Tests/ACLTest.php"
|
||||
$ make test TESTS="test/Tests/BootstrapTest.php test/Tests/ACLTest.php"
|
||||
```
|
||||
|
||||
If you know which *group* of tests you want to run, you can run just
|
||||
|
@ -1,252 +0,0 @@
|
||||
<?php
|
||||
/* ============================================================================
|
||||
(c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
============================================================================ */
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Unit tests for CDN.
|
||||
*/
|
||||
namespace HPCloud\Tests\Storage;
|
||||
|
||||
require_once 'src/HPCloud/Bootstrap.php';
|
||||
require_once 'test/TestCase.php';
|
||||
|
||||
use \HPCloud\Storage\CDN;
|
||||
|
||||
/**
|
||||
* @ingroup Tests
|
||||
*/
|
||||
class CDNTest extends \HPCloud\Tests\TestCase {
|
||||
|
||||
const TTL = 1234;
|
||||
|
||||
protected function destroyCDNFixture($cdn) {
|
||||
$cname = $this->conf('hpcloud.swift.container');
|
||||
try {
|
||||
$cdn->delete($cname);
|
||||
}
|
||||
catch (\HPCloud\Exception $e) {
|
||||
syslog(LOG_WARNING, $e);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConstructor() {
|
||||
$ident = $this->identity();
|
||||
|
||||
$catalog = $ident->serviceCatalog(CDN::SERVICE_TYPE);
|
||||
$token = $ident->token();
|
||||
|
||||
$this->assertNotEmpty($catalog[0]['endpoints'][0]['publicURL']);
|
||||
$parts = parse_url($catalog[0]['endpoints'][0]['publicURL']);
|
||||
$url = 'https://' . $parts['host'];
|
||||
$tenantId = $catalog[0]['endpoints'][0]['tenantId'];
|
||||
|
||||
$cdn = new CDN($token, $url, $tenantId);
|
||||
|
||||
$this->assertInstanceOf('\HPCloud\Storage\CDN', $cdn);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructor
|
||||
*/
|
||||
public function testNewFromServiceCatalog() {
|
||||
$ident = $this->identity();
|
||||
$token = $ident->token();
|
||||
$catalog = $ident->serviceCatalog();
|
||||
|
||||
$cdn = CDN::newFromServiceCatalog($catalog, $token, $this->conf('hpcloud.swift.region'));
|
||||
|
||||
$this->assertInstanceOf('\HPCloud\Storage\CDN', $cdn);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstructor
|
||||
*/
|
||||
public function testNewFromIdentity() {
|
||||
$ident = $this->identity();
|
||||
$cdn = CDN::newFromIdentity($ident, $this->conf('hpcloud.swift.region'));
|
||||
|
||||
$this->assertInstanceOf('\HPCloud\Storage\CDN', $cdn);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testNewFromServiceCatalog
|
||||
*/
|
||||
public function testEnable($cdn) {
|
||||
$container = $this->conf('hpcloud.swift.container');
|
||||
|
||||
$this->destroyCDNFixture($cdn);
|
||||
$was_created = FALSE;
|
||||
$retval = $cdn->enable($container, self::TTL, $was_created);
|
||||
|
||||
$this->assertRegexp('/^http[s]?:\/\//', $retval);
|
||||
$this->assertTrue($was_created);
|
||||
|
||||
// Enabling twice STILL returns 201.
|
||||
//$was_created = FALSE;
|
||||
//$retval = $cdn->enable($container, self::TTL, $was_created);
|
||||
//$this->assertFalse($was_created);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEnable
|
||||
*/
|
||||
public function testContainers($cdn) {
|
||||
$containerList = $cdn->containers();
|
||||
$cname = $this->conf('hpcloud.swift.container');
|
||||
|
||||
$this->assertTrue(is_array($containerList));
|
||||
|
||||
$this->assertGreaterThanOrEqual(1, count($containerList));
|
||||
|
||||
$find = NULL;
|
||||
foreach ($containerList as $container) {
|
||||
if ($container['name'] == $cname) {
|
||||
$find = $container;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertNotEmpty($find);
|
||||
$this->assertEquals(self::TTL, $find['ttl']);
|
||||
$this->assertNotEmpty($find['x-cdn-uri']);
|
||||
$this->assertFalse($find['log_retention']);
|
||||
$this->assertTrue($find['cdn_enabled']);
|
||||
|
||||
// Test that the URI returned is valid:
|
||||
//$res = file_get_contents($find['x-cdn-uri'] . '/' . $cname);
|
||||
//$this->assertEquals('Foo', $res);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testContainers
|
||||
*/
|
||||
public function testContainer($cdn) {
|
||||
$cname = $this->conf('hpcloud.swift.container');
|
||||
$properties = $cdn->container($cname);
|
||||
|
||||
//throw new \Exception(print_r($properties, TRUE));
|
||||
|
||||
$this->assertNotEmpty($properties);
|
||||
|
||||
$this->assertEquals(self::TTL, $properties['ttl']);
|
||||
$this->assertNotEmpty($properties['x-cdn-uri']);
|
||||
$this->assertFalse($properties['log_retention']);
|
||||
$this->assertTrue($properties['cdn_enabled']);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testContainer
|
||||
*/
|
||||
public function testUpdate($cdn) {
|
||||
$cname = $this->conf('hpcloud.swift.container');
|
||||
|
||||
$cdn->update($cname, array('ttl' => '4321'));
|
||||
|
||||
$props = $cdn->container($cname);
|
||||
|
||||
$this->assertEquals('4321', $props['ttl']);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDisable($cdn) {
|
||||
$cname = $this->conf('hpcloud.swift.container');
|
||||
|
||||
//$cdn->disable($cname);
|
||||
$cdn->update($cname, array('cdn_enabled' => FALSE));
|
||||
|
||||
$props = $cdn->container($cname);
|
||||
$this->assertFalse($props['cdn_enabled']);
|
||||
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDisable
|
||||
* @group CDN-129
|
||||
*/
|
||||
public function testContainersEnabledOnly($cdn) {
|
||||
$cname = $this->conf('hpcloud.swift.container');
|
||||
|
||||
//\HPCloud\Bootstrap::setConfiguration(array('transport.debug' => 1));
|
||||
$containers = $cdn->containers(TRUE);
|
||||
|
||||
//throw new \Exception(print_r($containers, TRUE));
|
||||
|
||||
$found = 0;
|
||||
foreach ($containers as $container) {
|
||||
if ($container['name'] == $cname) {
|
||||
++$found;
|
||||
//throw new \Exception(print_r($container, TRUE));
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $found, "A disabled container should not be returned.");
|
||||
|
||||
$containers = $cdn->containers(FALSE);
|
||||
$found = 0;
|
||||
foreach ($containers as $container) {
|
||||
if ($container['name'] == $cname) {
|
||||
++$found;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals(1, $found);
|
||||
//\HPCloud\Bootstrap::setConfiguration(array('transport.debug' => 0));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testDisable
|
||||
*/
|
||||
public function testDelete($cdn) {
|
||||
$cname = $this->conf('hpcloud.swift.container');
|
||||
|
||||
$cdn->delete($cname);
|
||||
|
||||
$containers = $cdn->containers();
|
||||
|
||||
$match = 0;
|
||||
foreach ($containers as $container) {
|
||||
if ($container['name'] == $cname) {
|
||||
++$match;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(0, $match);
|
||||
return $cdn;
|
||||
}
|
||||
|
||||
}
|
@ -251,46 +251,6 @@ class StreamWrapperFSTest extends \HPCloud\Tests\TestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testOpen
|
||||
*/
|
||||
public function testOpenWithCDN() {
|
||||
// Unfortunately we cannot test with CDN directly, because CDN requires ten
|
||||
// minutes to an our to configure itself. Use the `php test/CDNTest.php` program
|
||||
// to directly test CDN on an already-prepared container.
|
||||
|
||||
$this->containerFixture();
|
||||
|
||||
// Simple write test.
|
||||
$oUrl = $this->newUrl('foo→/test.csv');
|
||||
|
||||
// Now we test the same, but re-using the auth token:
|
||||
$cxt = $this->authSwiftContext(array('use_cdn' => TRUE));
|
||||
$res = fopen($oUrl, 'nope', FALSE, $cxt);
|
||||
|
||||
$this->assertTrue(is_resource($res));
|
||||
|
||||
// For this to work, we need to re-use auth tokens.
|
||||
$md = stream_get_meta_data($res);
|
||||
$wrapper = $md['wrapper_data'];
|
||||
|
||||
fclose($res);
|
||||
|
||||
// Test with auth token.
|
||||
$cxt = $this->basicSwiftContext(array('token' => $wrapper->token(), 'use_cdn' => TRUE));
|
||||
$res = fopen($oUrl, 'nope', FALSE, $cxt);
|
||||
$this->assertTrue(is_resource($res));
|
||||
fclose($res);
|
||||
|
||||
// Test with CDN object
|
||||
$cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($wrapper->serviceCatalog(), $wrapper->token());
|
||||
$cxt = $this->basicSwiftContext(array('use_cdn' => $cdn));
|
||||
$res = fopen($oUrl, 'nope', FALSE, $cxt);
|
||||
$this->assertTrue(is_resource($res));
|
||||
fclose($res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testOpen
|
||||
*/
|
||||
|
@ -253,46 +253,6 @@ class StreamWrapperTest extends \HPCloud\Tests\TestCase {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testOpen
|
||||
*/
|
||||
public function testOpenWithCDN() {
|
||||
// Unfortunately we cannot test with CDN directly, because CDN requires ten
|
||||
// minutes to an our to configure itself. Use the `php test/CDNTest.php` program
|
||||
// to directly test CDN on an already-prepared container.
|
||||
|
||||
$this->containerFixture();
|
||||
|
||||
// Simple write test.
|
||||
$oUrl = $this->newUrl('foo→/test.csv');
|
||||
|
||||
// Now we test the same, but re-using the auth token:
|
||||
$cxt = $this->authSwiftContext(array('use_cdn' => TRUE));
|
||||
$res = fopen($oUrl, 'nope', FALSE, $cxt);
|
||||
|
||||
$this->assertTrue(is_resource($res));
|
||||
|
||||
// For this to work, we need to re-use auth tokens.
|
||||
$md = stream_get_meta_data($res);
|
||||
$wrapper = $md['wrapper_data'];
|
||||
|
||||
fclose($res);
|
||||
|
||||
// Test with auth token.
|
||||
$cxt = $this->basicSwiftContext(array('token' => $wrapper->token(), 'use_cdn' => TRUE));
|
||||
$res = fopen($oUrl, 'nope', FALSE, $cxt);
|
||||
$this->assertTrue(is_resource($res));
|
||||
fclose($res);
|
||||
|
||||
// Test with CDN object
|
||||
$cdn = \HPCloud\Storage\CDN::newFromServiceCatalog($wrapper->serviceCatalog(), $wrapper->token());
|
||||
$cxt = $this->basicSwiftContext(array('use_cdn' => $cdn));
|
||||
$res = fopen($oUrl, 'nope', FALSE, $cxt);
|
||||
$this->assertTrue(is_resource($res));
|
||||
fclose($res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testOpen
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user