From 16c49d35150b71c46b2932e01f477a2ffde9fdb5 Mon Sep 17 00:00:00 2001 From: basichacker881 Date: Mon, 2 Oct 2023 16:59:28 +0530 Subject: [PATCH 1/5] adds ceph adapter file and tests --- src/Storage/Device/Ceph.php | 47 +++++++++++++++++++++++++++++++ src/Storage/Storage.php | 2 ++ tests/Storage/Device/CephTest.php | 34 ++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 src/Storage/Device/Ceph.php create mode 100644 tests/Storage/Device/CephTest.php diff --git a/src/Storage/Device/Ceph.php b/src/Storage/Device/Ceph.php new file mode 100644 index 00000000..fc54651d --- /dev/null +++ b/src/Storage/Device/Ceph.php @@ -0,0 +1,47 @@ +headers['host'] = $bucket.'.'.'s3'.'.'.$region.'.ceph.io'; + } + /** + * @return string + */ + public function getName(): string + { + return 'Ceph Storage'; + } + + /** + * @return string + */ + public function getDescription(): string + { + return 'Ceph Storage'; + } + + public function getType(): string + { + return Storage::DEVICE_CEPH; + } +} \ No newline at end of file diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index cabd18c8..d8aa3de3 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -21,6 +21,8 @@ class Storage const DEVICE_LINODE = 'linode'; + const DEVICE_CEPH = 'ceph'; + /** * Devices. * diff --git a/tests/Storage/Device/CephTest.php b/tests/Storage/Device/CephTest.php new file mode 100644 index 00000000..d87d2251 --- /dev/null +++ b/tests/Storage/Device/CephTest.php @@ -0,0 +1,34 @@ +root = '/root'; + $key = $_SERVER['CEPH_ACCESS_KEY'] ?? ''; + $secret = $_SERVER['CEPH_SECRET'] ?? ''; + $bucket = 'utopia-storage-test'; + + $this->object = new Ceph($this->root, $key, $secret, $bucket, Ceph::US_EAST_1, Ceph::ACL_PRIVATE); + } + + protected function getAdapterName(): string + { + return 'Ceph Storage'; + } + + protected function getAdapterType(): string + { + return $this->object->getType(); + } + + protected function getAdapterDescription(): string + { + return 'Ceph Storage'; + } +} From 6f071d845f02c69e66ed95838b776be7e163f09f Mon Sep 17 00:00:00 2001 From: basichacker881 Date: Mon, 2 Oct 2023 18:53:27 +0530 Subject: [PATCH 2/5] Fixed region typo --- src/Storage/Device/Ceph.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Device/Ceph.php b/src/Storage/Device/Ceph.php index fc54651d..3a43e7b9 100644 --- a/src/Storage/Device/Ceph.php +++ b/src/Storage/Device/Ceph.php @@ -19,7 +19,7 @@ class Ceph extends S3 * @param string $region * @param string $acl */ - public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_WEST_004, string $acl = self::ACL_PRIVATE) + public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_WEST_001, string $acl = self::ACL_PRIVATE) { parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); $this->headers['host'] = $bucket.'.'.'s3'.'.'.$region.'.ceph.io'; From 856ff23aedcc2f84ba33a9f9f1b3f3b7c626bd4c Mon Sep 17 00:00:00 2001 From: basichacker881 Date: Tue, 17 Oct 2023 09:50:45 +0530 Subject: [PATCH 3/5] adds test fixes --- src/Storage/Device/Ceph.php | 30 +++++++++++++----------------- src/Storage/Storage.php | 3 --- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Storage/Device/Ceph.php b/src/Storage/Device/Ceph.php index 3a43e7b9..897011d9 100644 --- a/src/Storage/Device/Ceph.php +++ b/src/Storage/Device/Ceph.php @@ -2,6 +2,8 @@ namespace Utopia\Storage\Device; +use Utopia\Storage\Storage; + class Ceph extends S3 { /** @@ -9,39 +11,33 @@ class Ceph extends S3 */ const US_EAST_1 = 'us-east-1'; + const US_EAST_2 = 'us-east-2'; + + const US_WEST_1 = 'us-west-1'; + + const US_WEST_2 = 'us-west-2'; + /** * Ceph Constructor - * - * @param string $root - * @param string $accessKey - * @param string $secretKey - * @param string $bucket - * @param string $region - * @param string $acl */ - public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_WEST_001, string $acl = self::ACL_PRIVATE) + public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $cephHost, string $region = self::US_WEST_001, string $acl = self::ACL_PRIVATE) { parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); - $this->headers['host'] = $bucket.'.'.'s3'.'.'.$region.'.ceph.io'; + $this->headers['host'] = $cephHost; } - /** - * @return string - */ + public function getName(): string { return 'Ceph Storage'; } - /** - * @return string - */ public function getDescription(): string { return 'Ceph Storage'; } - + public function getType(): string { return Storage::DEVICE_CEPH; } -} \ No newline at end of file +} diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index d8aa3de3..e2fa1207 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -38,8 +38,6 @@ class Storage * Add device by name * * @param string $name - * @param Device $device - * @return void * * @throws Exception */ @@ -85,7 +83,6 @@ public static function exists($name) * * Based on: https://stackoverflow.com/a/38659168/2299554 * - * @param int $bytes * @param int $decimals * @param string $system * @return string From de7bf1cb42bd815b5cbe0c5fb99c093084dd3c85 Mon Sep 17 00:00:00 2001 From: basichacker881 Date: Tue, 31 Oct 2023 22:10:50 +0530 Subject: [PATCH 4/5] removes regions --- php-ext-brotli | 1 + src/Storage/Device/Ceph.php | 15 ++------------- 2 files changed, 3 insertions(+), 13 deletions(-) create mode 160000 php-ext-brotli diff --git a/php-ext-brotli b/php-ext-brotli new file mode 160000 index 00000000..58c0c92d --- /dev/null +++ b/php-ext-brotli @@ -0,0 +1 @@ +Subproject commit 58c0c92d416b3d7e39e442b6123bde2252a84d3d diff --git a/src/Storage/Device/Ceph.php b/src/Storage/Device/Ceph.php index 897011d9..861f8883 100644 --- a/src/Storage/Device/Ceph.php +++ b/src/Storage/Device/Ceph.php @@ -6,23 +6,12 @@ class Ceph extends S3 { - /** - * Regions constants - */ - const US_EAST_1 = 'us-east-1'; - - const US_EAST_2 = 'us-east-2'; - - const US_WEST_1 = 'us-west-1'; - - const US_WEST_2 = 'us-west-2'; - /** * Ceph Constructor */ - public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $cephHost, string $region = self::US_WEST_001, string $acl = self::ACL_PRIVATE) + public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $cephHost, string $acl = self::ACL_PRIVATE) { - parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); + parent::__construct($root, $accessKey, $secretKey, $bucket, $acl); $this->headers['host'] = $cephHost; } From ab650f830e9c03027366bd754607aae13ec941e8 Mon Sep 17 00:00:00 2001 From: mugdha273 Date: Wed, 1 Nov 2023 01:03:17 +0530 Subject: [PATCH 5/5] revert changes --- src/Storage/Storage.php | 3 +++ tests/Storage/Device/CephTest.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index e2fa1207..b4696eed 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -38,6 +38,8 @@ class Storage * Add device by name * * @param string $name + * @param Device $device + * @return void * * @throws Exception */ @@ -83,6 +85,7 @@ public static function exists($name) * * Based on: https://stackoverflow.com/a/38659168/2299554 * + * @param int $bytes * @param int $decimals * @param string $system * @return string diff --git a/tests/Storage/Device/CephTest.php b/tests/Storage/Device/CephTest.php index d87d2251..d167c68f 100644 --- a/tests/Storage/Device/CephTest.php +++ b/tests/Storage/Device/CephTest.php @@ -5,7 +5,7 @@ use Utopia\Storage\Device\Ceph; use Utopia\Tests\Storage\S3Base; -class BackblazeTest extends S3Base +class CephTest extends S3Base { protected function init(): void {