Skip to content

Commit

Permalink
chore: update storage to use new generic S3 class
Browse files Browse the repository at this point in the history
  • Loading branch information
basert committed Feb 26, 2025
1 parent ba96a61 commit 0c913eb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"utopia-php/framework": "0.34.*",
"utopia-php/logger": "0.6.*",
"utopia-php/cli": "0.16.*",
"utopia-php/storage": "0.18.*",
"utopia-php/storage": "dev-generic-s3-device as 0.18.0",
"utopia-php/dsn": "0.1.*",
"utopia-php/registry": "0.5.*",
"utopia-php/preloader": "0.2.*",
Expand Down
69 changes: 40 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/Executor/Runner/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Utopia\Http\Response;
use Utopia\Logger\Log;
use Utopia\Storage\Device;
use Utopia\Storage\Device\AWS;
use Utopia\Storage\Device\Backblaze;
use Utopia\Storage\Device\DOSpaces;
use Utopia\Storage\Device\Linode;
Expand Down Expand Up @@ -111,6 +112,7 @@ protected function getStorageDevice(string $root): Device
$device = Storage::DEVICE_LOCAL;
$accessKey = '';
$accessSecret = '';
$host = '';
$bucket = '';
$region = '';

Expand All @@ -119,6 +121,7 @@ protected function getStorageDevice(string $root): Device
$device = $dsn->getScheme();
$accessKey = $dsn->getUser() ?? '';
$accessSecret = $dsn->getPassword() ?? '';
$host = $dsn->getHost() ?? '';
$bucket = $dsn->getPath() ?? '';
$region = $dsn->getParam('region');
} catch (\Exception $e) {
Expand All @@ -127,7 +130,11 @@ protected function getStorageDevice(string $root): Device

switch ($device) {
case Storage::DEVICE_S3:
return new S3($root, $accessKey, $accessSecret, $bucket, $region, $acl);
if (!empty($host)) {
return new S3(root: $root, accessKey: $accessKey, secretKey: $accessSecret, host: $host, region: $region, acl: $acl);
} else {
return new AWS(root: $root, accessKey: $accessKey, secretKey: $accessSecret, bucket: $bucket, region: $region, acl: $acl);
}
case STORAGE::DEVICE_DO_SPACES:
return new DOSpaces($root, $accessKey, $accessSecret, $bucket, $region, $acl);
case Storage::DEVICE_BACKBLAZE:
Expand All @@ -148,10 +155,15 @@ protected function getStorageDevice(string $root): Device
case Storage::DEVICE_S3:
$s3AccessKey = Http::getEnv('OPR_EXECUTOR_STORAGE_S3_ACCESS_KEY', '') ?? '';
$s3SecretKey = Http::getEnv('OPR_EXECUTOR_STORAGE_S3_SECRET', '') ?? '';
$s3Host = Http::getEnv('OPR_EXECUTOR_STORAGE_S3_HOST', '') ?? '';
$s3Region = Http::getEnv('OPR_EXECUTOR_STORAGE_S3_REGION', '') ?? '';
$s3Bucket = Http::getEnv('OPR_EXECUTOR_STORAGE_S3_BUCKET', '') ?? '';
$s3Acl = 'private';
return new S3($root, $s3AccessKey, $s3SecretKey, $s3Bucket, $s3Region, $s3Acl);
if (!empty($s3Host)) {
return new S3(root: $root, accessKey: $s3AccessKey, secretKey: $s3SecretKey, host: $s3Host, region: $s3Region, acl: $s3Acl);
} else {
return new AWS(root: $root, accessKey: $s3AccessKey, secretKey: $s3SecretKey, bucket: $s3Bucket, region: $s3Region, acl: $s3Acl);
}
case Storage::DEVICE_DO_SPACES:
$doSpacesAccessKey = Http::getEnv('OPR_EXECUTOR_STORAGE_DO_SPACES_ACCESS_KEY', '') ?? '';
$doSpacesSecretKey = Http::getEnv('OPR_EXECUTOR_STORAGE_DO_SPACES_SECRET', '') ?? '';
Expand Down

0 comments on commit 0c913eb

Please sign in to comment.