lbausch / ceph-radosgw-admin
PHP Ceph Radosgw Admin
Installs: 15 647
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 2
Open Issues: 1
Requires
- php: ^7.4|^8.0
- aws/aws-sdk-php: ^3.131
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- rector/rector: ~0.11
This package is auto-updated.
Last update: 2024-11-19 14:37:31 UTC
README
PHP Ceph Radosgw Admin
A PHP REST client for the Ceph Object Gateway Admin Ops API
Features
- Supports all endpoints of the Admin Ops API, including currently undocumented
metadata/
endpoints - Requests are signed using AWS Signature V2 and V4
- Provides S3 client with no extra configuration by utilizing the AWS SDK for PHP
- Extensible and customizable
Requirements
- PHP ^7.4 or PHP ^8.0
- Ceph Nautilus (14) or newer
Installation
Use Composer to install the library:
composer require lbausch/ceph-radosgw-admin
On the Ceph side an admin user with sufficient capabilities is required:
radosgw-admin user create \ --uid="admin" \ --display-name="Admin User" \ --admin \ --caps="users=read,write;usage=read,write;buckets=read,write;metadata=read,write;zone=read,write" \ --access-key="<redacted>" \ --secret="<redacted>"
Usage
Admin Client
use LBausch\CephRadosgwAdmin\Client; require 'vendor/autoload.php'; $client = Client::make('http://gateway:8080', 'access key', 'secret key'); $response = $client->bucket()->list(); print_r($response->get()); /* Array ( [0] => mybucket ) */
Handling Exceptions
Upon failed requests the exception LBausch\CephRadosgwAdmin\ApiException
is thrown.
use LBausch\CephRadosgwAdmin\ApiException; use LBausch\CephRadosgwAdmin\Client; require 'vendor/autoload.php'; $client = Client::make('http://gateway:8080', 'access key', 'secret key'); try { $client->user()->remove('non existent user'); } catch (ApiException $exception) { // Exception handling }
S3 Client
use LBausch\CephRadosgwAdmin\Client; require 'vendor/autoload.php'; $client = Client::make('http://gateway:8080', 'access key', 'secret key'); $s3client = $client->getS3Client(); // Use different credentials // $s3client = $client->getS3Client('different access key', 'different secret key'); // Pass arbitrary options to S3 client // $s3client = $client->getS3Client('different access key', 'different secret key', [ // 'http' => [ // 'verify' => false, // ], // ]); // Create a bucket $s3client->createBucket([ 'Bucket' => 'mybucket', ]); // List all buckets $buckets = $s3client->listBuckets(); foreach ($buckets['Buckets'] as $bucket) { echo $bucket['Name'].PHP_EOL; // mybucket } // Put an object in the bucket $s3client->putObject([ 'Bucket' => 'mybucket', 'SourceFile' => 'foobar.png', 'Key' => 'foobar.png', ]);
Custom Configuration
Many settings may be overriden if needed. See LBausch\CephRadosgwAdmin\Config::defaults()
for a list of configurable options.
use LBausch\CephRadosgwAdmin\Client; use LBausch\CephRadosgwAdmin\Config; require 'vendor/autoload.php'; $config = Config::make([ // Set a custom admin path 'adminPath' => 'mgt/', ]); // Override settings after instantiation, e.g. specify a timeout for requests $config->set('httpClientConfig', [ 'timeout' => 10, ]); $client = Client::make('http://gateway:8080', 'access key', 'secret key', $config);