From df7a547bfea99cc44535fab0d0d73bacf05777a7 Mon Sep 17 00:00:00 2001 From: Pratik Date: Sat, 14 Oct 2023 15:27:19 +0530 Subject: [PATCH 1/2] Adding support for netapp storage grid adapter which uses S3 --- src/Storage/Device/NetappStorageGrid.php | 50 ++++++++++++++++++++++ src/Storage/Storage.php | 2 + tests/Storage/Device/NetappStorageTest.php | 24 +++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/Storage/Device/NetappStorageGrid.php create mode 100644 tests/Storage/Device/NetappStorageTest.php diff --git a/src/Storage/Device/NetappStorageGrid.php b/src/Storage/Device/NetappStorageGrid.php new file mode 100644 index 00000000..5c563e80 --- /dev/null +++ b/src/Storage/Device/NetappStorageGrid.php @@ -0,0 +1,50 @@ +accessKey = $accessKey; + $this->secretKey = $secretKey; + $this->bucket = $bucket; + $this->region = $region; + $this->root = $root; + $this->acl = $acl; + $this->amzHeaders = []; + + $host = match ($region) { + self::CN_NORTH_1, self::CN_NORTH_4, self::CN_NORTHWEST_1 => $bucket.'.s3.'.$region.'.amazonaws.cn', + default => $bucket.'.s3.'.$region.'.amazonaws.com' + }; + + $this->headers['host'] = $host; + } + + public function getName(): string + { + return 'Netapp Storage Grid' + } + + public function getType(): string + { + return STORAGE::DEVICE_NETAPP_STORAGE_GRID; + } + + public function getDescription(): string + { + return 'NetApp Storage Grid using S3 Storage drive'; + } + +} diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index cabd18c8..93bbe41b 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -21,6 +21,8 @@ class Storage const DEVICE_LINODE = 'linode'; + const DEVICE_NETAPP_STORAGE_GRID = 'netappstorage' + /** * Devices. * diff --git a/tests/Storage/Device/NetappStorageTest.php b/tests/Storage/Device/NetappStorageTest.php new file mode 100644 index 00000000..1c7b6604 --- /dev/null +++ b/tests/Storage/Device/NetappStorageTest.php @@ -0,0 +1,24 @@ +storageAdapter = new NetappStorageAdapter(); + } + + protected function testGetName() + { + $this->assertEquals('Alibaba Cloud Storage', $this->storageAdapter->getName()); + } + + pubprotectedlic function testGetType() + { + $this->assertEquals(Storage::DEVICE_ALIBABA_CLOUD, $this->storageAdapter->getType()); + } + +} From e5a1f57bb0633131e04004d1068f3228db6ccd9a Mon Sep 17 00:00:00 2001 From: Pratik Date: Wed, 1 Nov 2023 20:20:03 +0530 Subject: [PATCH 2/2] formatter the files and ran composer format, all formatting passed --- src/Storage/Device/NetappStorageGrid.php | 7 +++---- src/Storage/Storage.php | 2 +- tests/Storage/Device/NetappStorageTest.php | 13 ++++++------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Storage/Device/NetappStorageGrid.php b/src/Storage/Device/NetappStorageGrid.php index 5c563e80..352eb850 100644 --- a/src/Storage/Device/NetappStorageGrid.php +++ b/src/Storage/Device/NetappStorageGrid.php @@ -2,8 +2,6 @@ namespace Utopia\Storage\Device; -use Exception; -use Utopia\Storage\Device; use Utopia\Storage\Storage; // As NetAapp Storage grid uses S3 protocol, we can extend the S3 class @@ -11,7 +9,9 @@ class NetappStorageGrid extends S3 { protected string $accessKey; + protected string $secretKey; + protected string $bucket; public function __construct(string $root, string $accessKey, string $secretKey, string $bucket) @@ -34,7 +34,7 @@ public function __construct(string $root, string $accessKey, string $secretKey, public function getName(): string { - return 'Netapp Storage Grid' + return 'Netapp Storage Grid'; } public function getType(): string @@ -46,5 +46,4 @@ public function getDescription(): string { return 'NetApp Storage Grid using S3 Storage drive'; } - } diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index 93bbe41b..d2b6f18e 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -21,7 +21,7 @@ class Storage const DEVICE_LINODE = 'linode'; - const DEVICE_NETAPP_STORAGE_GRID = 'netappstorage' + const DEVICE_NETAPP_STORAGE_GRID = 'netappstorage'; /** * Devices. diff --git a/tests/Storage/Device/NetappStorageTest.php b/tests/Storage/Device/NetappStorageTest.php index 1c7b6604..a6d53acc 100644 --- a/tests/Storage/Device/NetappStorageTest.php +++ b/tests/Storage/Device/NetappStorageTest.php @@ -2,23 +2,22 @@ namespace Utopia\Tests\Storage\Device; -use PHPUnit\Framework\TestCase; - -class NetappStorageAdapterTest extends S3Base { +class NetappStorageAdapterTest extends S3Base +{ private $storageAdapter; - protected function setUp() : void { + protected function setUp(): void + { $this->storageAdapter = new NetappStorageAdapter(); } protected function testGetName() { - $this->assertEquals('Alibaba Cloud Storage', $this->storageAdapter->getName()); + $this->assertEquals('Netapp Storage Grid', $this->storageAdapter->getName()); } - pubprotectedlic function testGetType() + protected function testGetType() { $this->assertEquals(Storage::DEVICE_ALIBABA_CLOUD, $this->storageAdapter->getType()); } - }