Skip to content

Commit

Permalink
Make the unit tests run
Browse files Browse the repository at this point in the history
Add docs again
Add the files I missed last time
  • Loading branch information
skwashd committed May 17, 2010
1 parent caa392c commit 7ff0ab1
Show file tree
Hide file tree
Showing 76 changed files with 28,079 additions and 779 deletions.
154 changes: 154 additions & 0 deletions Rackspace/CloudFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Rackspace CloudFiles API
*
* PHP Version 5
*
* Copyright (C) 2008 Rackspace US, Inc.
*
* 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.
*
* Except as contained in this notice, the name of Rackspace US, Inc. shall not
* be used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from Rackspace US, Inc.
*
* @category Rackspace
* @package Rackspace_CloudFiles
* @author Eric "EJ" Johnson <[email protected]>
* @author Dave Hall <[email protected]>
* @copyright Copyright (c) 2008, Rackspace US, Inc.
* @copyright Copyright (c) 2010, Dave Hall Consulting http://davehall.com.au
* @license http://opensource.org/licenses/mit-license.php
* @link http://www.rackspacecloud.com/cloud_hosting_products/servers/api
*/
/**
* Rackspace CloudFiles API
*
* Example Code
* <code>
* # Authenticate to Cloud Files. The default is to automatically try
* # to re-authenticate if an authentication token expires.
* #
* # NOTE: Some versions of cURL include an outdated certificate authority (CA)
* # file. This API ships with a newer version obtained directly from
* # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
* # call the Rackspace_CloudFiles_Authentication instance's 'ssl_use_cabundle()' method.
* #
* $auth = new Rackspace_CloudFiles_Authentication($username, $api_key);
* # $auth->ssl_use_cabundle(); # bypass cURL's old CA bundle
* $auth->authenticate();
*
* # Establish a connection to the storage system
* #
* # NOTE: Some versions of cURL include an outdated certificate authority (CA)
* # file. This API ships with a newer version obtained directly from
* # cURL's web site (http://curl.haxx.se). To use the newer CA bundle,
* # call the Rackspace_CloudFiles_Connection instance's 'ssl_use_cabundle()' method.
* #
* $conn = new Rackspace_CloudFiles_Connection($auth);
* # $conn->ssl_use_cabundle(); # bypass cURL's old CA bundle
*
* # Create a remote Container and storage Object
* #
* $images = $conn->create_container("photos");
* $bday = $images->create_object("first_birthday.jpg");
*
* # Upload content from a local file by streaming it. Note that we use
* # a "float" for the file size to overcome PHP's 32-bit integer limit for
* # very large files.
* #
* $fname = "/home/user/photos/birthdays/birthday1.jpg"; # filename to upload
* $size = (float) sprintf("%u", filesize($fname));
* $fp = open($fname, "r");
* $bday->write($fp, $size);
*
* # Or... use a convenience function instead
* #
* $bday->load_from_filename("/home/user/photos/birthdays/birthday1.jpg");
*
* # Now, publish the "photos" container to serve the images by CDN.
* # Use the "$uri" value to put in your web pages or send the link in an
* # email message, etc.
* #
* $uri = $images->make_public();
*
* # Or... print out the Object's public URI
* #
* print $bday->public_uri();
* </code>
*
* @category Rackspace
* @package Rackspace_CloudFiles
* @author Eric "EJ" Johnson <[email protected]>
* @author Dave Hall <[email protected]>
* @copyright Copyright (c) 2008, Rackspace US, Inc.
* @copyright Copyright (c) 2010, Dave Hall Consulting http://davehall.com.au
* @license http://opensource.org/licenses/mit-license.php
* @link http://www.rackspacecloud.com/cloud_hosting_products/servers/api
*/
class Rackspace_CloudFiles
{
/**
* @var float Default CloudFiles API version
*/
const DEFAULT_API_VERSION = 1;
/**
* @var int MAX_CONTAINER_NAME_LEN Maximum length of a container name
*/
const MAX_CONTAINER_NAME_LEN = 256;
/**
* @var int MAX_OBJECT_NAME_LEN Maximum length of a storage object name
*/
const MAX_OBJECT_NAME_LEN = 1024;
/**
* @var int MAX_OBJECT SIZE Maximum possible size of an object to be stored
*/
const MAX_OBJECT_SIZE = 5368709121; // (5*1024*1024*1024)+ 1 - bigger than S3! ;-)
/**
* Autoload Rackspace CloudFiles classes
*
* Instead of filling your code with require_once statements
* you can use the following code to "automagically" include
* classes as they are needed.
*
* <code>
* require_once '/path/to/Rackspace/CloudFiles.php';
* spl_autoload_register(array('Rackspace_CloudFiles', 'autoload'));
* </code>
*
* This isn't needed if you are already using a PEAR (compatiable) autoloader.
*
* @param string $className The name of the class to load
*/
public static function autoload ($className)
{
static $path = null;
if (is_null($path)) {
$path = realpath(
dirname(__FILE__) . '/../');
}
$file = /* "{$path}/" . */ preg_replace('/_/', '/', $className) . '.php';
if (! is_file($file)) {
return False;
}
require_once $file;
}
}
132 changes: 60 additions & 72 deletions Rackspace/CloudFiles/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* PHP Version 5
*
* Copyright (C) 2008 Rackspace US, Inc.
* Copyright (C) 2008 Rackspace US, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -79,14 +79,12 @@ class Rackspace_CloudFiles_Authentication
public $api_key;
public $auth_host;
public $account;

/**
* Instance variables that are set after successful authentication
*/
public $storage_url;
public $cdnm_url;
public $auth_token;

/**
* Class constructor (PHP 5 syntax)
*
Expand All @@ -95,22 +93,18 @@ class Rackspace_CloudFiles_Authentication
* @param string $account <b>Deprecated</b> <i>Account name</i>
* @param string $auth_host <b>Deprecated</b> <i>Authentication service URI</i>
*/
public function __construct($username=NULL, $api_key=NULL, $account=NULL, $auth_host=NULL)
public function __construct ($username = NULL, $api_key = NULL, $account = NULL, $auth_host = NULL)
{

$this->dbug = False;
$this->username = $username;
$this->api_key = $api_key;
$this->account_name = $account;
$this->auth_host = $auth_host;

$this->storage_url = NULL;
$this->cdnm_url = NULL;
$this->auth_token = NULL;

$this->cfs_http = new Rackspace_CloudFiles_Http(Rackspace_CloudFiles::DEFAULT_API_VERSION);
}

/**
* Use the Certificate Authority bundle included with this API
*
Expand All @@ -132,11 +126,10 @@ public function __construct($username=NULL, $api_key=NULL, $account=NULL, $auth_
*
* @param string $path Specify path to CA bundle (default to included)
*/
public function ssl_use_cabundle($path=NULL)
public function ssl_use_cabundle ($path = NULL)
{
$this->cfs_http->ssl_use_cabundle($path);
}

/**
* Attempt to validate Username/API Access Key
*
Expand All @@ -160,88 +153,83 @@ public function ssl_use_cabundle($path=NULL)
* @throws AuthenticationException invalid credentials
* @throws InvalidResponseException invalid response
*/
public function authenticate($version=Rackspace_CloudFiles::DEFAULT_API_VERSION)
public function authenticate ($version = Rackspace_CloudFiles::DEFAULT_API_VERSION)
{
list($status,$reason,$surl,$curl,$atoken) =
$this->cfs_http->authenticate($this->username, $this->api_key,
$this->account_name, $this->auth_host);
list ($status, $reason, $surl, $curl, $atoken) =
$this->cfs_http->authenticate($this->username, $this->api_key, $this->account_name, $this->auth_host);

if ($status == 401) {
throw new Rackspace_CloudFiles_AuthenticationException("Invalid username or access key.");
}

if ($status != 204) {
throw new Rackspace_CloudFiles_InvalidResponseException(
"Unexpected response (".$status."): ".$reason);
throw new Rackspace_CloudFiles_InvalidResponseException("Unexpected response ({$status}): {$reason}");
}

if (!($surl || $curl) || !$atoken) {
throw new Rackspace_CloudFiles_InvalidResponseException(
"Expected headers missing from auth service.");

if (! ($surl || $curl) || ! $atoken) {
throw new Rackspace_CloudFiles_InvalidResponseException("Expected headers missing from auth service.");
}

$this->storage_url = $surl;
$this->cdnm_url = $curl;
$this->auth_token = $atoken;
return True;
}
/**
* Use Cached Token and Storage URL's rather then grabbing from the Auth System
*
* Example:
* <code>
* #Create an Auth instance
* $auth = new CF_Authentication();
* #Pass Cached URL's and Token as Args
* $auth->load_cached_credentials("auth_token", "storage_url", "cdn_management_url");
* </code>
*
* @param string $auth_token A Cloud Files Auth Token (Required)
* @param string $storage_url The Cloud Files Storage URL (Required)
* @param string $cdnm_url CDN Management URL (Required)
* @return boolean <kbd>True</kbd> if successful
* @throws Rackspace_CloudFiles_SyntaxException If any of the Required Arguments are missing
*/
public function load_cached_credentials($auth_token, $storage_url, $cdnm_url)
/**
* Use Cached Token and Storage URL's rather then grabbing from the Auth System
*
* Example:
* <code>
* #Create an Auth instance
* $auth = new CF_Authentication();
* #Pass Cached URL's and Token as Args
* $auth->load_cached_credentials("auth_token", "storage_url", "cdn_management_url");
* </code>
*
* @param string $auth_token A Cloud Files Auth Token (Required)
* @param string $storage_url The Cloud Files Storage URL (Required)
* @param string $cdnm_url CDN Management URL (Required)
* @return boolean <kbd>True</kbd> if successful
* @throws Rackspace_CloudFiles_SyntaxException If any of the Required Arguments are missing
*/
public function load_cached_credentials ($auth_token, $storage_url, $cdnm_url)
{
if(!$storage_url || !$cdnm_url)
{
throw new Rackspace_CloudFiles_SyntaxException("Missing Required Interface URL's!");
return False;
if (! $storage_url || ! $cdnm_url) {
throw new Rackspace_CloudFiles_SyntaxException(
"Missing Required Interface URL's!");
return False;
}
if(!$auth_token)
{
throw new Rackspace_CloudFiles_SyntaxException("Missing Auth Token!");
return False;
if (! $auth_token) {
throw new Rackspace_CloudFiles_SyntaxException(
"Missing Auth Token!");
return False;
}

$this->storage_url = $storage_url;
$this->cdnm_url = $cdnm_url;
$this->auth_token = $auth_token;
$this->cdnm_url = $cdnm_url;
$this->auth_token = $auth_token;
return True;
}
/**
* Grab Cloud Files info to be Cached for later use with the load_cached_credentials method.
*
* Example:
* <code>
* #Create an Auth instance
* $auth = new CF_Authentication("UserName","API_Key");
* $auth->authenticate();
* $array = $auth->export_credentials();
* </code>
*
* @return array of url's and an auth token.
*/
public function export_credentials()
/**
* Grab Cloud Files info to be Cached for later use with the load_cached_credentials method.
*
* Example:
* <code>
* #Create an Auth instance
* $auth = new CF_Authentication("UserName","API_Key");
* $auth->authenticate();
* $array = $auth->export_credentials();
* </code>
*
* @return array of url's and an auth token.
*/
public function export_credentials ()
{
$arr = array();
$arr['storage_url'] = $this->storage_url;
$arr['cdnm_url'] = $this->cdnm_url;
$arr['auth_token'] = $this->auth_token;

$arr['cdnm_url'] = $this->cdnm_url;
$arr['auth_token'] = $this->auth_token;
return $arr;
}


/**
* Make sure the CF_Authentication instance has authenticated.
*
Expand All @@ -250,18 +238,18 @@ public function export_credentials()
*
* @return boolean <kbd>True</kbd> if successfully authenticated
*/
public function authenticated()
public function authenticated ()
{
if (!($this->storage_url || $this->cdnm_url) || !$this->auth_token) {
if (! ($this->storage_url || $this->cdnm_url) ||
! $this->auth_token) {
return False;
}
return True;
}

/**
* Toggle debugging - set cURL verbose flag
*/
public function setDebug($bool)
public function setDebug ($bool)
{
$this->dbug = $bool;
$this->cfs_http->setDebug($bool);
Expand Down
Loading

0 comments on commit 7ff0ab1

Please sign in to comment.