Skip to content

Fix S3 bucket prefix omission for custom endpoints in StorageFactory#242

Merged
ChiragAgg5k merged 4 commits into
mainfrom
fix-s3-bucket-prefix
Jul 13, 2026
Merged

Fix S3 bucket prefix omission for custom endpoints in StorageFactory#242
ChiragAgg5k merged 4 commits into
mainfrom
fix-s3-bucket-prefix

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

Fixes #239

When OPR_EXECUTOR_CONNECTION_STORAGE points to an S3-compatible backend (MinIO, Garage, etc.) via the url= DSN parameter or a custom host, StorageFactory::getDevice() created the generic S3 device without prepending the bucket from the DSN path to the storage root. Since the generic S3 device has no separate bucket parameter, requests targeted the wrong bucket/key prefix (e.g. NoSuchBucket: Bucket not found: storage with path-style access), causing builds to fail with Failed to move built code to storage.

Changes

  • StorageFactory: prepend the DSN bucket to the root for both the url= and custom host S3 branches, matching Appwrite's own getDevice() behavior. The AWS branch is untouched since it receives the bucket as a separate constructor argument, and setups without a bucket in the DSN path behave exactly as before.
  • Added unit tests for StorageFactory covering local/default fallback, invalid DSN fallback, bucket prefixing for url= and host branches, and the no-bucket cases.
  • README: clarified that a host is always required in the DSN (a placeholder works when url= is used) and documented the url= parameter for S3-compatible endpoints.

With the DSN from the issue, getDevice('/storage/builds/app-test', $dsn)->getRoot() now returns mybucket/storage/builds/app-test instead of storage/builds/app-test.

Test plan

  • composer test:unit (20 tests, 72 assertions, all passing)
  • composer format:check
  • composer analyze (phpstan, no errors)
  • composer refactor:check (rector, no changes)

Made with Cursor

ChiragAgg5k and others added 3 commits July 11, 2026 17:25
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@greptile-apps

greptile-apps Bot commented Jul 11, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug where StorageFactory::getDevice() omitted the DSN bucket when constructing the generic S3 device for custom-endpoint configurations (url= parameter or explicit host), causing path-style S3 requests to target the wrong bucket and fail with NoSuchBucket.

  • Core fix (StorageFactory.php): computes $bucketRoot by prepending the DSN bucket to $root for both the url= and host S3 branches; the AWS branch (which accepts bucket as a dedicated constructor arg) is correctly left unchanged, and empty/zero bucket values fall through to the original $root.
  • Tests (StorageFactoryTest.php): new test class covers empty/null/invalid DSN fallback, bucket-prefixing for both code paths, root-is-slash edge case, and no-bucket cases; all 20 tests pass.
  • README: replaced the single-line DSN description with a clearer table showing examples for local, AWS S3 (virtual-hosted-style), and S3-compatible backends, and documents the url= parameter.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to prepending a bucket prefix in two code paths that were previously broken for custom S3 endpoints, and all existing behaviour is preserved for the AWS branch and the no-bucket case.

The logic is straightforward: a single $bucketRoot expression guards with the same empty-value pattern already used throughout the file, the Utopia DSN library strips the leading slash from the path so the concatenation produces clean keys, and the AWS branch is explicitly left untouched. The new test class exercises every branch including edge cases (root-is-slash, no-bucket, invalid-DSN fallback).

No files require special attention.

Important Files Changed

Filename Overview
src/Executor/StorageFactory.php Adds bucket-prepending logic for generic S3 branches; AWS branch unchanged; logic is correct and consistent with DSN library behaviour.
tests/unit/Executor/StorageFactoryTest.php New unit test file covering empty/null/invalid DSN fallback, bucket-prefixing for both url= and host branches, and the no-bucket cases; good coverage of the changed logic.
README.md Documentation updated to a clearer table format with examples for each storage backend and explicit note about the url= parameter for S3-compatible endpoints.

Reviews (2): Last reviewed commit: "Clarify AWS S3 DSN example to use virtua..." | Re-trigger Greptile

Comment thread README.md Outdated
Co-authored-by: Cursor <cursoragent@cursor.com>
@ChiragAgg5k ChiragAgg5k merged commit eed20aa into main Jul 13, 2026
7 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix-s3-bucket-prefix branch July 13, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StorageFactory::getDevice() omits DSN bucket prefix for S3-compatible endpoints (url= / custom host)

2 participants