Skip to content

enhancement: add configurable S3 storage prefix#356

Open
Antoninj wants to merge 1 commit into
Portabase:mainfrom
Antoninj:codex/configurable-s3-prefix
Open

enhancement: add configurable S3 storage prefix#356
Antoninj wants to merge 1 commit into
Portabase:mainfrom
Antoninj:codex/configurable-s3-prefix

Conversation

@Antoninj

@Antoninj Antoninj commented Jul 5, 2026

Copy link
Copy Markdown

Summary

  • Add an optional prefix field to S3 storage channel configuration
  • Normalize configured prefixes with or without leading/trailing slashes
  • Apply the prefix consistently for S3 upload, download, delete, ping, and copy keys

Note: I'm surprised there isn't any test suite in this project.

Summary by CodeRabbit

  • New Features

    • Added an optional storage path prefix for S3 channels.
    • Users can now specify a custom prefix in the S3 storage settings.
  • Bug Fixes

    • Improved S3 path handling by normalizing leading and trailing slashes.
    • Storage actions now use the configured prefix consistently across uploads, downloads, deletes, checks, and copies.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds an optional prefix configuration to S3 channel storage. The schema and form expose a new prefix field, and a buildKey helper replaces the previous BASE_DIR constant across upload, get, delete, ping, and copy S3 operations to compute object keys.

Changes

S3 Prefix Support

Layer / File(s) Summary
Config schema and form field
src/features/channel/components/storages/s3.schema.ts, src/features/channel/components/storages/s3.form.tsx
Adds an optional trimmed prefix field to S3ChannelConfigSchema and a corresponding "Prefix" input field in the S3 storage form, placed between bucket name and port.
buildKey helper and config type
src/features/channel/components/storages/s3.ts
S3Config gains an optional prefix property; a new buildKey(config, path) helper normalizes the prefix and path (trimming/stripping slashes) to compose object keys, replacing the old BASE_DIR constant.
Storage operations key computation
src/features/channel/components/storages/s3.ts
uploadS3, getS3, deleteS3, pingS3, and copyS3 now derive S3 object keys via buildKey(...) instead of ${BASE_DIR}... string interpolation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StorageS3Form
    participant S3ChannelConfigSchema
    participant S3Storage as "s3.ts operations"

    User->>StorageS3Form: Enter prefix value
    StorageS3Form->>S3ChannelConfigSchema: Validate config (with prefix)
    S3ChannelConfigSchema-->>StorageS3Form: Validated config
    StorageS3Form->>S3Storage: Save config
    S3Storage->>S3Storage: buildKey(config, path)
    S3Storage-->>S3Storage: prefix/normalizedPath or normalizedPath
Loading

Poem

A prefix hops into the key,
No more BASE_DIR fixed as can be,
Trim the slash, tidy the trail,
Upload, ping, copy — never fail,
This bunny thumps with S3 glee! 🐇📦

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a configurable S3 storage prefix.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Antoninj
Antoninj marked this pull request as ready for review July 5, 2026 10:06
@Antoninj Antoninj changed the title [codex] Add configurable S3 storage prefix enhancement: add configurable S3 storage prefix Jul 5, 2026
@RambokDev

RambokDev commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Hi @Antoninj ,

Could you describe a bit more you use case ?

Tests are in : https://github.com/Portabase/e2e-tests you can are test to it directly

This e2e tests are called in PR, like a component

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/channel/components/storages/s3.ts`:
- Around line 34-39: Add unit tests for buildKey to cover the centralized S3 key
normalization logic used by upload/get/delete/ping/copy. Focus on edge cases
around S3Config.prefix and path handling: empty or whitespace-only prefix,
prefix containing only slashes, path values with leading/trailing slashes, and
paths with multiple internal slashes. Use buildKey and S3Config as the main
symbols to locate the behavior and verify the returned key strings for each
case.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fbc8effb-dc47-40c1-bf7e-80df479d9bde

📥 Commits

Reviewing files that changed from the base of the PR and between 6952ac5 and 8646ec9.

📒 Files selected for processing (3)
  • src/features/channel/components/storages/s3.form.tsx
  • src/features/channel/components/storages/s3.schema.ts
  • src/features/channel/components/storages/s3.ts
📜 Review details
🔇 Additional comments (3)
src/features/channel/components/storages/s3.schema.ts (1)

9-9: LGTM!

src/features/channel/components/storages/s3.form.tsx (1)

87-99: LGTM!

src/features/channel/components/storages/s3.ts (1)

34-39: 🗄️ Data Integrity & Integration

No backward-compatibility issue. prefix is opt-in; existing S3 configs keep using the raw object path, so there’s no key-namespace migration here.

			> Likely an incorrect or invalid review comment.

Comment thread src/features/channel/components/storages/s3.ts
@Antoninj

Antoninj commented Jul 5, 2026

Copy link
Copy Markdown
Author

@RambokDev

-> Could you describe a bit more you use case ?

The use case is the following: I use the same S3 bucket for multiple backups (not only portabase ones). Currently, portabase hardcodes the prefix to backups but I would like to configure the name to something else

Tests are in : https://github.com/Portabase/e2e-tests you can are test to it directly
This e2e tests are called in PR, like a component

thanks I'll take a look and see if adding an E2E test makes sense for my changes. But in any case, I'd need to get those changes in first

@Antoninj

Antoninj commented Jul 5, 2026

Copy link
Copy Markdown
Author

Added E2E coverage in Portabase/e2e-tests#11. It fills the new S3 Prefix field for the existing S3/R2 storage channel flow and verifies the value persists when reopening the channel. I left it as a draft because it depends on this PR introducing the Prefix field.

@RambokDev

Copy link
Copy Markdown
Collaborator

Hi @Antoninj,

I now understand your use case.

This PR will not work as-is because uploads are handled partly on the dashboard side at some point, but mainly by the agent when dispatching backup files to storage after the backup is completed.

What I suggest is adding an environment variable on the dashboard side, for example BACKUP_FILE_PREFIX. If defined, it would override the currently hardcoded /backups prefix and then be passed down to the agent.

I think this would be more generic and would apply consistently across the whole ecosystem.

Could you open an issue so we can continue the discussion there?

I can work on it ASAP, but if you want, you can also start implementing the dashboard-side part, and I can finish the agent-side integration.

Regards,

@Antoninj

Antoninj commented Jul 6, 2026

Copy link
Copy Markdown
Author

Sounds good I'll do that thanks

@RambokDev

Copy link
Copy Markdown
Collaborator

Sounds good I'll do that thanks

Feel free to ask if you have any questions. I’d be happy to help.

@Antoninj

Antoninj commented Jul 7, 2026

Copy link
Copy Markdown
Author

Thanks. I won't have time to iterate on this before next week end though.

@RambokDev

Copy link
Copy Markdown
Collaborator

Thanks. I won't have time to iterate on this before next week end though.

No problem, ping me when you have time

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.

2 participants