Coder Social home page Coder Social logo

netstoragekit-php's Introduction

Akamai NetStorage for PHP

This library provides the following NetStorage tools

  • a FlySystem adapter for NetStorage FileStore (\Akamai\NetStorage\FileStoreAdapter)
  • a request signer (\Akamai\NetStorage\Authentication)
  • a Guzzle middleware for transparently signing requests to the API (\Akamai\NetStorage\Handler\Authentication)

To Do:

  • A PHP streams layer, so you can use netstorage.fs://path with any built-in I/O functions (e.g. fopen, fread(), and fputs, or file_get_contents() and file_put_contents())
  • A FlySystem adapter for NetStorage ObjectStore

Installation

Installation is done via composer:

$ composer require akamai-open/netstorage

Using the Request Signer

$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
];
*/

Using the Guzzle Middleware

To use the middle, add it to the handler stack in the \GuzzleHttp\Client or \Akamai\Open\EdgeGrid\Client options:

$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
]);

Using the FlySystem Adapter

The simplest way to interact with NetStorage FileStore is using the \Akamai\NetStorage\FileStoreAdapter for 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\FileStoreAdapter($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);

Please note that $key, $keyName & $host can be obtained from "NetStorage API Information" page: https://control.akamai.com/storage/customer_portal.jsp?content_page=ns_api_info.jsp

netstoragekit-php's People

Contributors

dshafik avatar m1ch3lp3r3z avatar sumoanand avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.