diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 43d7ca7e..0da274c0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,7 +58,7 @@ jobs: strategy: fail-fast: false matrix: - devices: [BackblazeTest, DOSpacesTest, LinodeTest, LocalTest, S3Test, WasabiTest] + devices: [BackblazeTest, DOSpacesTest, LinodeTest, LocalTest, S3Test, WasabiTest, CloudflareR2Test] steps: - name: checkout @@ -75,6 +75,8 @@ jobs: WASABI_SECRET: ${{ secrets.WASABI_SECRET }} BACKBLAZE_ACCESS_KEY: ${{ secrets.BACKBLAZE_ACCESS_KEY }} BACKBLAZE_SECRET: ${{ secrets.BACKBLAZE_SECRET }} + CLOUDFLARE_R2_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY }} + CLOUDFLARE_R2_SECRET: ${{ secrets.CLOUDFLARE_R2_SECRET }} run: | docker compose up -d sleep 10 diff --git a/docker-compose.yml b/docker-compose.yml index 4cd5e9f7..e3644ce1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,4 +20,6 @@ services: - BACKBLAZE_ACCESS_KEY - BACKBLAZE_SECRET - WASABI_ACCESS_KEY - - WASABI_SECRET \ No newline at end of file + - WASABI_SECRET + - CLOUDFLARE_R2_ACCESS_KEY + - CLOUDFLARE_R2_SECRET \ No newline at end of file diff --git a/src/Storage/Device/CloudflareR2.php b/src/Storage/Device/CloudflareR2.php new file mode 100644 index 00000000..8d7c9f19 --- /dev/null +++ b/src/Storage/Device/CloudflareR2.php @@ -0,0 +1,68 @@ +headers['host'] = $bucket.'.'.'s3'.'.'.$region.'.cloudflarestorage.com'; + } + + /** + * @return string + */ + public function getName(): string + { + return 'Cloudflare R2 Storage'; + } + + /** + * @return string + */ + public function getDescription(): string + { + return 'Cloudflare R2 Storage'; + } + + /** + * @return string + */ + public function getType(): string + { + return Storage::DEVICE_CLOUDFLARER2; + } +} diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index cabd18c8..fe759d2f 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -21,6 +21,8 @@ class Storage const DEVICE_LINODE = 'linode'; + const CLOUDFARE_R2 = 'cloudflarer2'; + /** * Devices. * diff --git a/tests/Storage/Device/CloudflareR2Test.php b/tests/Storage/Device/CloudflareR2Test.php new file mode 100644 index 00000000..c19f1db5 --- /dev/null +++ b/tests/Storage/Device/CloudflareR2Test.php @@ -0,0 +1,34 @@ +root = '/root'; + $key = $_SERVER['CLOUDFLARE_R2_ACCESS_KEY'] ?? ''; + $secret = $_SERVER['CLOUDFLARE_R2_SECRET'] ?? ''; + $bucket = 'utopia-storage-test'; + + $this->object = new CloudflareR2($this->root, $key, $secret, $bucket, CloudflareR2::AUTO, CloudflareR2::ACL_PRIVATE); + } + + protected function getAdapterName(): string + { + return 'Cloudflare R2 Storage'; + } + + protected function getAdapterType(): string + { + return $this->object->getType(); + } + + protected function getAdapterDescription(): string + { + return 'Cloudflare R2 Storage'; + } +}