MediaWiki  REL1_20
SwiftFileBackend Class Reference

Class for an OpenStack Swift based file backend. More...

Inheritance diagram for SwiftFileBackend:
Collaboration diagram for SwiftFileBackend:

List of all members.

Public Member Functions

 __construct (array $config)
 getDirectoryListInternal ($fullCont, $dir, array $params)
 getDirListPageInternal ($fullCont, $dir, &$after, $limit, array $params)
 Do not call this function outside of SwiftFileBackendFileList.
 getFileContents (array $params)
 getFileListInternal ($fullCont, $dir, array $params)
 getFileListPageInternal ($fullCont, $dir, &$after, $limit, array $params)
 Do not call this function outside of SwiftFileBackendFileList.
 getLocalCopy (array $params)
 isPathUsableInternal ($storagePath)
 purgeCDNCache (array $objects)
 Purge the CDN cache of affected objects if CDN caching is enabled.

Protected Member Functions

 _getResponseCopy (CF_Async_Op $cfOp, Status $status, array $params)
 _getResponseCreate (CF_Async_Op $cfOp, Status $status, array $params)
 _getResponseDelete (CF_Async_Op $cfOp, Status $status, array $params)
 _getResponseMove (CF_Async_Op $cfOp, Status $status, array $params)
 _getResponseStore (CF_Async_Op $cfOp, Status $status, array $params)
 addMissingMetadata (CF_Object $obj, $path)
 Fill in any missing object metadata and save it to Swift.
 closeConnection ()
 Close the connection to the Swift proxy.
 createContainer ($container)
 Create a Swift container.
 deleteContainer ($container)
 Delete a Swift container.
 directoriesAreVirtual ()
 doCleanInternal ($fullCont, $dir, array $params)
 doClearCache (array $paths=null)
 doCopyInternal (array $params)
 doCreateInternal (array $params)
 doDeleteInternal (array $params)
 doDirectoryExists ($fullCont, $dir, array $params)
 doExecuteOpHandlesInternal (array $fileOpHandles)
 doGetFileSha1base36 (array $params)
 doGetFileStat (array $params)
 doMoveInternal (array $params)
 doPrepareInternal ($fullCont, $dir, array $params)
 doPrimeContainerCache (array $containerInfo)
 doPublishInternal ($fullCont, $dir, array $params)
 doSecureInternal ($fullCont, $dir, array $params)
 doStoreInternal (array $params)
 doStreamFile (array $params)
 getConnection ()
 Get an authenticated connection handle to the Swift proxy.
 getContainer ($container, $bypassCache=false)
 Get a Swift container object, possibly from process cache.
 getParentDir ($path)
 handleException (Exception $e, $status, $func, array $params)
 Log an unexpected exception for this backend.
 headersFromParams (array $params)
 Get headers to send to Swift when reading a file based on a FileBackend params array, e.g.
 resolveContainerPath ($container, $relStoragePath)
 setContainerAccess (CF_Container $contObj, array $readGrps, array $writeGrps)
 Set read/write permissions for a Swift container.
 truncDisp ($disposition)

Protected Attributes

CF_Authentication $auth
 *
 $authTTL
CF_Connection $conn
 *
ProcessCacheLRU $connContainerCache
 *
 $connErrorTime = 0
CloudFilesException $connException
 *
 $sessionStarted = 0
BagOStuff $srvCache
 *
 $swiftAnonUser
 $swiftCDNExpiry
 $swiftCDNPurgable
 $swiftUseCDN

Private Member Functions

 getCredsCacheKey ($username)
 Get the cache key for a container.

Detailed Description

Class for an OpenStack Swift based file backend.

This requires the SwiftCloudFiles MediaWiki extension, which includes the php-cloudfiles library (https://github.com/rackspace/php-cloudfiles). php-cloudfiles requires the curl, fileinfo, and mb_string PHP extensions.

Status messages should avoid mentioning the Swift account name. Likewise, error suppression should be used to avoid path disclosure.

Since:
1.19

Definition at line 39 of file SwiftFileBackend.php.


Constructor & Destructor Documentation

SwiftFileBackend::__construct ( array $  config)
See also:
FileBackendStore::__construct() Additional $config params include:
  • swiftAuthUrl : Swift authentication server URL
  • swiftUser : Swift user used by MediaWiki (account:username)
  • swiftKey : Swift authentication key for the above user
  • swiftAuthTTL : Swift authentication TTL (seconds)
  • swiftAnonUser : Swift user used for end-user requests (account:username). If set, then views of public containers are assumed to go through this user. If not set, then public containers are accessible to unauthenticated requests via ".r:*" in the ACL.
  • swiftUseCDN : Whether a Cloud Files Content Delivery Network is set up
  • swiftCDNExpiry : How long (in seconds) to store content in the CDN. If files may likely change, this should probably not exceed a few days. For example, deletions may take this long to apply. If object purging is enabled, however, this is not an issue.
  • swiftCDNPurgable : Whether object purge requests are allowed by the CDN.
  • shardViaHashLevels : Map of container names to sharding config with:
    • base : base of hash characters, 16 or 36
    • levels : the number of hash levels (and digits)
    • repeat : hash subdirectories are prefixed with all the parent hash directory names (e.g. "a/ab/abc")
  • cacheAuthInfo : Whether to cache authentication tokens in APC, XCache, ect. If those are not available, then the main cache will be used. This is probably insecure in shared hosting environments.

Reimplemented from FileBackendStore.

Definition at line 83 of file SwiftFileBackend.php.


Member Function Documentation

SwiftFileBackend::_getResponseCopy ( CF_Async_Op $  cfOp,
Status status,
array $  params 
) [protected]
SwiftFileBackend::_getResponseCreate ( CF_Async_Op $  cfOp,
Status status,
array $  params 
) [protected]
SwiftFileBackend::_getResponseDelete ( CF_Async_Op $  cfOp,
Status status,
array $  params 
) [protected]
SwiftFileBackend::_getResponseMove ( CF_Async_Op $  cfOp,
Status status,
array $  params 
) [protected]
SwiftFileBackend::_getResponseStore ( CF_Async_Op $  cfOp,
Status status,
array $  params 
) [protected]
SwiftFileBackend::addMissingMetadata ( CF_Object $  obj,
path 
) [protected]

Fill in any missing object metadata and save it to Swift.

Parameters:
$objCF_Object
$pathstring Storage path to object
Returns:
bool Success
Exceptions:
Exceptioncloudfiles exceptions

Definition at line 779 of file SwiftFileBackend.php.

Referenced by doGetFileStat().

Close the connection to the Swift proxy.

Returns:
void

Definition at line 1246 of file SwiftFileBackend.php.

SwiftFileBackend::createContainer ( container) [protected]

Create a Swift container.

Parameters:
$containerstring Container name
Returns:
CF_Container
Exceptions:
CloudFilesException

Definition at line 1307 of file SwiftFileBackend.php.

Referenced by doPrepareInternal().

SwiftFileBackend::deleteContainer ( container) [protected]

Delete a Swift container.

Parameters:
$containerstring Container name
Returns:
void
Exceptions:
CloudFilesException

Definition at line 1321 of file SwiftFileBackend.php.

Referenced by doCleanInternal().

See also:
FileBackendStore::directoriesAreVirtual()
Returns:
bool

Reimplemented from FileBackendStore.

Definition at line 1080 of file SwiftFileBackend.php.

SwiftFileBackend::doCleanInternal ( fullCont,
dir,
array $  params 
) [protected]
SwiftFileBackend::doClearCache ( array $  paths = null) [protected]
See also:
FileBackendStore::doClearCache()

Reimplemented from FileBackendStore.

Definition at line 1267 of file SwiftFileBackend.php.

SwiftFileBackend::doDirectoryExists ( fullCont,
dir,
array $  params 
) [protected]
See also:
FileBackendStore::doDirectoryExists()
Returns:
bool|null

Reimplemented from FileBackendStore.

Definition at line 835 of file SwiftFileBackend.php.

References $dir, getContainer(), and handleException().

SwiftFileBackend::doExecuteOpHandlesInternal ( array $  fileOpHandles) [protected]
See also:
FileBackendStore::doExecuteOpHandlesInternal()
Returns:
Array List of corresponding Status objects

Reimplemented from FileBackendStore.

Definition at line 1104 of file SwiftFileBackend.php.

References handleException(), Status\newGood(), and purgeCDNCache().

SwiftFileBackend::doGetFileSha1base36 ( array $  params) [protected]
See also:
FileBackendStore::doGetFileSha1base36()
Returns:
bool

Definition at line 991 of file SwiftFileBackend.php.

References FileBackendStore\getFileStat().

SwiftFileBackend::doGetFileStat ( array $  params) [protected]
See also:
FileBackendStore::doFileExists()
Returns:
array|bool|null

Reimplemented from FileBackendStore.

Definition at line 744 of file SwiftFileBackend.php.

References addMissingMetadata(), getContainer(), handleException(), headersFromParams(), FileBackendStore\resolveStoragePathReal(), and wfTimestamp().

SwiftFileBackend::doPrepareInternal ( fullCont,
dir,
array $  params 
) [protected]
SwiftFileBackend::doPrimeContainerCache ( array $  containerInfo) [protected]
See also:
FileBackendStore::doPrimeContainerCache()
Returns:
void

Reimplemented from FileBackendStore.

Definition at line 1331 of file SwiftFileBackend.php.

References $conn, getConnection(), and handleException().

SwiftFileBackend::doPublishInternal ( fullCont,
dir,
array $  params 
) [protected]
SwiftFileBackend::doSecureInternal ( fullCont,
dir,
array $  params 
) [protected]

Get an authenticated connection handle to the Swift proxy.

Returns:
CF_Connection|bool False on failure
Exceptions:
CloudFilesException

Definition at line 1200 of file SwiftFileBackend.php.

Referenced by doPrimeContainerCache().

SwiftFileBackend::getContainer ( container,
bypassCache = false 
) [protected]

Get a Swift container object, possibly from process cache.

Use $reCache if the file count or byte count is needed.

Parameters:
$containerstring Container name
$bypassCachebool Bypass all caches and load from Swift
Returns:
CF_Container
Exceptions:
CloudFilesException

Definition at line 1280 of file SwiftFileBackend.php.

Referenced by doCleanInternal(), doCopyInternal(), doCreateInternal(), doDeleteInternal(), doDirectoryExists(), doGetFileStat(), doMoveInternal(), doPrepareInternal(), doPublishInternal(), doSecureInternal(), doStoreInternal(), doStreamFile(), getFileContents(), getLocalCopy(), and isPathUsableInternal().

SwiftFileBackend::getCredsCacheKey ( username) [private]

Get the cache key for a container.

Parameters:
$usernamestring
Returns:
string

Definition at line 1260 of file SwiftFileBackend.php.

SwiftFileBackend::getDirectoryListInternal ( fullCont,
dir,
array $  params 
)
See also:
FileBackendStore::getDirectoryListInternal()
Returns:
SwiftFileBackendDirList

Reimplemented from FileBackendStore.

Definition at line 854 of file SwiftFileBackend.php.

References $dir.

SwiftFileBackend::getDirListPageInternal ( fullCont,
dir,
&$  after,
limit,
array $  params 
)

Do not call this function outside of SwiftFileBackendFileList.

Parameters:
$fullContstring Resolved container name
$dirstring Resolved storage directory with no trailing slash
$afterstring|null Storage path of file to list items after
$limitinteger Max number of items to list
$paramsArray Includes flag for 'topOnly'
Returns:
Array List of relative paths of dirs directly under $dir

Definition at line 876 of file SwiftFileBackend.php.

SwiftFileBackend::getFileListInternal ( fullCont,
dir,
array $  params 
)
See also:
FileBackendStore::getFileListInternal()
Returns:
SwiftFileBackendFileList

Reimplemented from FileBackendStore.

Definition at line 862 of file SwiftFileBackend.php.

References $dir.

SwiftFileBackend::getFileListPageInternal ( fullCont,
dir,
&$  after,
limit,
array $  params 
)

Do not call this function outside of SwiftFileBackendFileList.

Parameters:
$fullContstring Resolved container name
$dirstring Resolved storage directory with no trailing slash
$afterstring|null Storage path of file to list items after
$limitinteger Max number of items to list
$paramsArray Includes flag for 'topOnly'
Returns:
Array List of relative paths of files under $dir

Definition at line 949 of file SwiftFileBackend.php.

SwiftFileBackend::getParentDir ( path) [protected]

Definition at line 935 of file SwiftFileBackend.php.

SwiftFileBackend::handleException ( Exception $  e,
status,
func,
array $  params 
) [protected]

Log an unexpected exception for this backend.

This also sets the Status object to have a fatal error.

Parameters:
$eException
$statusStatus|null
$funcstring
$paramsArray
Returns:
void

Definition at line 1354 of file SwiftFileBackend.php.

Referenced by doCleanInternal(), doCopyInternal(), doCreateInternal(), doDeleteInternal(), doDirectoryExists(), doExecuteOpHandlesInternal(), doGetFileStat(), doMoveInternal(), doPrepareInternal(), doPrimeContainerCache(), doPublishInternal(), doSecureInternal(), doStoreInternal(), doStreamFile(), getFileContents(), getLocalCopy(), and isPathUsableInternal().

SwiftFileBackend::headersFromParams ( array $  params) [protected]

Get headers to send to Swift when reading a file based on a FileBackend params array, e.g.

that of getLocalCopy(). $params is currently only checked for a 'latest' flag.

Parameters:
$paramsArray
Returns:
Array

Definition at line 1092 of file SwiftFileBackend.php.

Referenced by doGetFileStat(), doStreamFile(), getFileContents(), and getLocalCopy().

SwiftFileBackend::purgeCDNCache ( array $  objects)

Purge the CDN cache of affected objects if CDN caching is enabled.

This is for Rackspace/Akamai CDNs.

Parameters:
$objectsArray List of CF_Object items
Returns:
void

Definition at line 1179 of file SwiftFileBackend.php.

Referenced by doCopyInternal(), doCreateInternal(), doDeleteInternal(), doExecuteOpHandlesInternal(), doMoveInternal(), and doStoreInternal().

SwiftFileBackend::resolveContainerPath ( container,
relStoragePath 
) [protected]
See also:
FileBackendStore::resolveContainerPath()
Returns:
null

Reimplemented from FileBackendStore.

Definition at line 135 of file SwiftFileBackend.php.

SwiftFileBackend::setContainerAccess ( CF_Container $  contObj,
array $  readGrps,
array $  writeGrps 
) [protected]

Set read/write permissions for a Swift container.

$readGrps is a list of the possible criteria for a request to have access to read a container. Each item is one of the following formats:

  • account:user : Grants access if the request is by the given user
  • .r:<regex> : Grants access if the request is from a referrer host that matches the expression and the request is not for a listing. Setting this to '*' effectively makes a container public.
  • .rlistings:<regex> : Grants access if the request is from a referrer host that matches the expression and the request for a listing.

$writeGrps is a list of the possible criteria for a request to have access to write to a container. Each item is of the following format:

  • account:user : Grants access if the request is by the given user
See also:
http://swift.openstack.org/misc.html#acls

In general, we don't allow listings to end-users. It's not useful, isn't well-defined (lists are truncated to 10000 item with no way to page), and is just a performance risk.

Parameters:
$contObjCF_Container Swift container
$readGrpsArray List of read access routes
$writeGrpsArray List of write access routes
Returns:
Status

Definition at line 1156 of file SwiftFileBackend.php.

Referenced by doPublishInternal(), and doSecureInternal().

SwiftFileBackend::truncDisp ( disposition) [protected]
Parameters:
$dispositionstring Content-Disposition header value
Returns:
string Truncated Content-Disposition header value to meet Swift limits

Definition at line 169 of file SwiftFileBackend.php.

References $res.

Referenced by doCopyInternal(), doCreateInternal(), doMoveInternal(), and doStoreInternal().


Member Data Documentation

CF_Authentication SwiftFileBackend::$auth [protected]

*

Definition at line 40 of file SwiftFileBackend.php.

SwiftFileBackend::$authTTL [protected]

Definition at line 41 of file SwiftFileBackend.php.

CF_Connection SwiftFileBackend::$conn [protected]

*

Definition at line 47 of file SwiftFileBackend.php.

Referenced by doPrimeContainerCache().

ProcessCacheLRU SwiftFileBackend::$connContainerCache [protected]

*

Definition at line 55 of file SwiftFileBackend.php.

SwiftFileBackend::$connErrorTime = 0 [protected]

Definition at line 51 of file SwiftFileBackend.php.

CloudFilesException SwiftFileBackend::$connException [protected]

*

Definition at line 50 of file SwiftFileBackend.php.

SwiftFileBackend::$sessionStarted = 0 [protected]

Definition at line 48 of file SwiftFileBackend.php.

BagOStuff SwiftFileBackend::$srvCache [protected]

*

Definition at line 53 of file SwiftFileBackend.php.

SwiftFileBackend::$swiftAnonUser [protected]

Definition at line 42 of file SwiftFileBackend.php.

SwiftFileBackend::$swiftCDNExpiry [protected]

Definition at line 44 of file SwiftFileBackend.php.

SwiftFileBackend::$swiftCDNPurgable [protected]

Definition at line 45 of file SwiftFileBackend.php.

SwiftFileBackend::$swiftUseCDN [protected]

Definition at line 43 of file SwiftFileBackend.php.


The documentation for this class was generated from the following file: