From 2e16ecf602ecc8daab227b27e35d12fc0b71b0c5 Mon Sep 17 00:00:00 2001 From: hydromoll Date: Wed, 8 Nov 2023 20:52:36 +0300 Subject: [PATCH 1/5] feat: add yandex storage adapter --- src/Storage/Device/Yandex.php | 60 +++++++++++++++++++++++++++++ src/Storage/Storage.php | 6 ++- tests/Storage/Device/YandexTest.php | 36 +++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 src/Storage/Device/Yandex.php create mode 100644 tests/Storage/Device/YandexTest.php diff --git a/src/Storage/Device/Yandex.php b/src/Storage/Device/Yandex.php new file mode 100644 index 00000000..983bd063 --- /dev/null +++ b/src/Storage/Device/Yandex.php @@ -0,0 +1,60 @@ +headers['host'] = $bucket . '.storage.yandexcloud.net'; + } + + /** + * @return string + */ + public function getName(): string + { + return 'Yandex Storage'; + } + + /** + * @return string + */ + public function getDescription(): string + { + return 'Yandex Storage'; + } + + /** + * @return string + */ + public function getType(): string + { + return Storage::DEVICE_YANDEX; + } +} diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index cabd18c8..676ffd87 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -17,6 +17,8 @@ class Storage const DEVICE_WASABI = 'wasabi'; + const DEVICE_YANDEX = 'yandex'; + const DEVICE_BACKBLAZE = 'backblaze'; const DEVICE_LINODE = 'linode'; @@ -58,8 +60,8 @@ public static function setDevice($name, Device $device): void */ public static function getDevice($name) { - if (! \array_key_exists($name, self::$devices)) { - throw new Exception('The device "'.$name.'" is not listed'); + if (!\array_key_exists($name, self::$devices)) { + throw new Exception('The device "' . $name . '" is not listed'); } return self::$devices[$name]; diff --git a/tests/Storage/Device/YandexTest.php b/tests/Storage/Device/YandexTest.php new file mode 100644 index 00000000..8dbf3f55 --- /dev/null +++ b/tests/Storage/Device/YandexTest.php @@ -0,0 +1,36 @@ +root = '/root'; + $key = $_SERVER['YANDEX_ACCESS_KEY'] ?? ''; + $secret = $_SERVER['YANDEX_SECRET'] ?? ''; + $bucket = 'utopia-storage-tests'; + $region = 'ru-central1-a'; + + + $this->object = new Yandex($this->root, $key, $secret, $bucket, $region, Yandex::ACL_PRIVATE); + } + + protected function getAdapterName(): string + { + return 'Yandex Storage'; + } + + protected function getAdapterType(): string + { + return $this->object->getType(); + } + + protected function getAdapterDescription(): string + { + return 'Yandex Storage'; + } +} From 1010801b5388ef5907b22301ad7436c54871320c Mon Sep 17 00:00:00 2001 From: Hydromoll <79720944+hydromoll@users.noreply.github.com> Date: Thu, 9 Nov 2023 22:30:06 +0300 Subject: [PATCH 2/5] Update Yandex.php --- src/Storage/Device/Yandex.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Storage/Device/Yandex.php b/src/Storage/Device/Yandex.php index 983bd063..33b0d17c 100644 --- a/src/Storage/Device/Yandex.php +++ b/src/Storage/Device/Yandex.php @@ -14,10 +14,6 @@ class Yandex extends S3 const RU_CENTRAL_B = 'ru-central1-b'; const RU_CENTRAL_C = 'ru-central1-c'; - protected string $bucket; - - protected string $region = 'ru-central1-a'; - /** * YandexStorage Constructor * From 1ee732eaa29baa011ff37c256bb59d5c2a203906 Mon Sep 17 00:00:00 2001 From: hydromoll Date: Wed, 15 Nov 2023 21:56:24 +0300 Subject: [PATCH 3/5] feat: fix lint errors --- src/Storage/Device/Yandex.php | 6 +++--- src/Storage/Storage.php | 4 ++-- tests/Storage/Device/YandexTest.php | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Storage/Device/Yandex.php b/src/Storage/Device/Yandex.php index 983bd063..f3ae2dab 100644 --- a/src/Storage/Device/Yandex.php +++ b/src/Storage/Device/Yandex.php @@ -9,9 +9,10 @@ class Yandex extends S3 /** * Regions constants */ - const RU_CENTRAL_A = 'ru-central1-a'; + const RU_CENTRAL_B = 'ru-central1-b'; + const RU_CENTRAL_C = 'ru-central1-c'; protected string $bucket; @@ -27,11 +28,10 @@ class Yandex extends S3 * @param string $bucket * @param string $acl */ - public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::RU_CENTRAL_A, string $acl = self::ACL_PRIVATE) { parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); - $this->headers['host'] = $bucket . '.storage.yandexcloud.net'; + $this->headers['host'] = $bucket.'.storage.yandexcloud.net'; } /** diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index 676ffd87..2765d515 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -60,8 +60,8 @@ public static function setDevice($name, Device $device): void */ public static function getDevice($name) { - if (!\array_key_exists($name, self::$devices)) { - throw new Exception('The device "' . $name . '" is not listed'); + if (! \array_key_exists($name, self::$devices)) { + throw new Exception('The device "'.$name.'" is not listed'); } return self::$devices[$name]; diff --git a/tests/Storage/Device/YandexTest.php b/tests/Storage/Device/YandexTest.php index 8dbf3f55..89f29ec1 100644 --- a/tests/Storage/Device/YandexTest.php +++ b/tests/Storage/Device/YandexTest.php @@ -15,7 +15,6 @@ protected function init(): void $bucket = 'utopia-storage-tests'; $region = 'ru-central1-a'; - $this->object = new Yandex($this->root, $key, $secret, $bucket, $region, Yandex::ACL_PRIVATE); } From 6d5d94c3f18862e2ed47c8ec262fe5d75180dea3 Mon Sep 17 00:00:00 2001 From: hydromoll Date: Thu, 16 Nov 2023 11:02:48 +0300 Subject: [PATCH 4/5] fix php unit --- phpunit.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpunit.xml b/phpunit.xml index 1eb9dd9d..9777d2ed 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,6 +11,7 @@ ./tests/Storage/Compression ./tests/Storage/Device/LocalTest.php + ./tests/Storage/Device/YandexTest.php ./tests/Storage/Validator ./tests/Storage/StorageTest.php From 7c9e2394a9caa823d055a50a6be21b35ab5f55ae Mon Sep 17 00:00:00 2001 From: hydromoll Date: Wed, 22 Nov 2023 21:19:16 +0300 Subject: [PATCH 5/5] feat: remove yandex test --- phpunit.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 9777d2ed..1eb9dd9d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,7 +11,6 @@ ./tests/Storage/Compression ./tests/Storage/Device/LocalTest.php - ./tests/Storage/Device/YandexTest.php ./tests/Storage/Validator ./tests/Storage/StorageTest.php