akamai-open / netstorage
Akamai NetStorage
0.2.0
2019-05-06 22:04 UTC
Requires
- php: >=5.5
- ext-dom: *
- ext-simplexml: *
- akamai-open/edgegrid-client: ^1.0.0
- league/flysystem: ^1.0
- twistor/flysystem-stream-wrapper: ^1.0
Requires (Dev)
- dshafik/guzzlehttp-vcr: dev-master
- phploc/phploc: ^2.1
- phpunit/phpunit: ^4.0
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^2.3
- theseer/phpdox: 0.8.1.1
This package is auto-updated.
Last update: 2024-08-23 21:29:16 UTC
README
重要
Akamai 不负责维护或管理此包。虽然它可以集成以帮助您使用 API,但如果在使用过程中出现任何问题,Akamai 技术支持将不会提供帮助,并且 Akamai 对由此使用引起的问题不承担任何责任。
概述
此库提供了以下 NetStorage 工具
- a FlySystem 适配器用于 NetStorage ObjectStore (
\Akamai\NetStorage\ObjectStoreAdapter
) 和 FileStore (\Akamai\NetStorage\FileStoreAdapter
) - 请求签名器 (
\Akamai\NetStorage\Authentication
) - 一个用于 API 请求透明签名的 Guzzle 中间件 (
\Akamai\NetStorage\Handler\Authentication
)
待办事项
- 一个 PHP 流层,这样您就可以使用
netstorage.fs://path
与 任何 内置 I/O 函数(例如fopen
,fread()
,和fputs
,或file_get_contents()
和file_put_contents()
)
安装
安装通过 composer
完成
$ composer require akamai-open/netstorage
使用请求签名器
$signer = new Akamai\NetStorage\Authentication(); $signer->setKey($key, $keyName); $signer->setPath('/' .$cpCode. '/path/to/file'); $signer->setAction('upload'); $headers = $signer->createAuthHeaders(); /* Return: [ 'X-Akamai-ACS-Auth-Data' => $authData, 'X-Akamai-ACS-Auth-Sign' => $signature ]; */
使用 Guzzle 中间件
要使用中间件,请将其添加到 \GuzzleHttp\Client
或 \Akamai\Open\EdgeGrid\Client
选项中的处理器堆栈中
$signer = new \Akamai\NetStorage\Authentication(); $signer->setKey($key, $keyName); $handler = new \Akamai\NetStorage\Handler\Authentication(); $handler->setSigner($signer); $stack = \GuzzleHttp\HandlerStack::create(); $stack->push($handler, 'netstorage-handler'); $client = new \Akamai\Open\EdgeGrid\Client([ 'base_uri' => $host, 'handler' => $stack ]); // Upload a file: // Request signature is added transparently // All parent directories must exist (e.g. /path/to) $client->put('/' . $cpCode . '/path/to/file', [ 'headers' => [ 'X-Akamai-ACS-Action' => 'version=1&action=upload&sha1=' .sha1($fileContents) ], 'body' => $fileContents ]);
使用 FlySystem 适配器
与 NetStorage ObjectStore 或 FileStore 交互的最简单方法是使用 \Akamai\NetStorage\ObjectStoreAdapter
或 \Akamai\NetStorage\FileStoreAdapter
与 FlySystem。
$signer = new \Akamai\NetStorage\Authentication(); $signer->setKey($key, $keyName); $handler = new \Akamai\NetStorage\Handler\Authentication(); $handler->setSigner($signer); $stack = \GuzzleHttp\HandlerStack::create(); $stack->push($handler, 'netstorage-handler'); $client = new \Akamai\Open\EdgeGrid\Client([ 'base_uri' => $host, 'handler' => $stack ]); $adapter = new \Akamai\NetStorage\ObjectStoreAdapter($client, $cpCode); $fs = new \League\Flysystem\Filesystem($adapter); // Upload a file: // cpCode, action, content signature, and request signature is added transparently // Additionally, all required sub-directories are created transparently $fs->write('/path/to/file', $fileContents);
请注意,$key,$keyName 和 $host 可以从 "NetStorage API 信息" 页面获取:https://control.akamai.com/storage/customer_portal.jsp?content_page=ns_api_info.jsp