Refactor: Use shared UploadPrefix constant across cloud drivers#1930
Refactor: Use shared UploadPrefix constant across cloud drivers#1930yuta519 wants to merge 4 commits intoDefangLabs:mainfrom
UploadPrefix constant across cloud drivers#1930Conversation
📝 WalkthroughWalkthroughCentralizes BYOC upload prefix into Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.5.0)level=warning msg="[linters_context] running gomodguard failed: unable to read module file go.mod: current working directory must have a go.mod file: if you are not using go modules it is suggested to disable this linter" Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
UploadPrefix for all cloud BYOCUploadPrefix constant across cloud drivers
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/pkg/clouds/do/appPlatform/setup.go (1)
236-266:⚠️ Potential issue | 🔴 CriticalSame sanitization bug as AWS ECS:
/inobjectKeyNamewill be replaced with_.The
s3InvalidCharsRegexpon Line 234 doesn't allow/, so when callers pass"uploads/<digest>", the sanitization on Line 249 produces"uploads_<digest>". See the detailed comment onsrc/pkg/clouds/aws/ecs/upload.go.🐛 Proposed fix: allow `/` in the regex
-var s3InvalidCharsRegexp = regexp.MustCompile(`[^a-zA-Z0-9!_.*'()-]`) +var s3InvalidCharsRegexp = regexp.MustCompile(`[^a-zA-Z0-9!_.*'()/-]`)
🤖 Fix all issues with AI agents
In `@src/pkg/cli/client/byoc/do/byoc.go`:
- Line 166: The call to b.driver.CreateUploadURL currently uses
path.Join(byoc.UploadPrefix, etag) which removes the slash and later gets
sanitized by s3InvalidCharsRegexp, producing "uploads_<etag>" instead of
"uploads/<etag>"; change the argument to construct the upload path with an
explicit slash (e.g., byoc.UploadPrefix + "/" + etag) so the resulting string
retains the separator when passed to b.driver.CreateUploadURL (update the call
site in byoc.go where b.driver.CreateUploadURL is invoked).
In `@src/pkg/clouds/aws/ecs/upload.go`:
- Around line 22-31: The sanitization currently replaces `/` in objectKeyName
which flattens S3 keys and the 64-char check is applied to the full prefixed
path; update the logic so directory separators are preserved and the length
check applies to the actual basename: either modify s3InvalidCharsRegexp to
permit `/` (so objectKeyName like "uploads/abc123" keeps its separators) or
split objectKeyName into dir and base (use path.Dir/path.Base), run
s3InvalidCharsRegexp.ReplaceAllString only on the basename, then rejoin; also
perform the 64-character validation on the sanitized basename (or adjust the
limit to exclude any upload prefix) to restore the original effective name
length constraint.
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/pkg/clouds/aws/ecs/upload.go (1)
16-37: Prefix is concatenated without ensuring a path separator.The key is built as
prefix + filename(Line 37). This works correctly whenprefixends with/(asbyoc.UploadPrefix = "uploads/"does), but if a caller passes a prefix without a trailing slash, the key will be malformed (e.g."uploadsfoo").Consider using
path.Joinor documenting/enforcing the trailing-slash convention.♻️ Suggested defensive fix
+ "path" ... - Key: ptr.String(prefix + filename), + Key: ptr.String(path.Join(prefix, filename)),src/pkg/clouds/do/appPlatform/setup.go (1)
234-258: Duplicated upload-URL logic between DO and AWS ECS implementations.
CreateUploadURLin this file is nearly identical tosrc/pkg/clouds/aws/ecs/upload.go— same regex, same UUID fallback, same 64-char limit, same sanitization, same presign flow. This is a good candidate for extracting a shared helper (e.g., asanitizeFilenamefunction) to keep the validation/sanitization logic in one place.Same trailing-slash note as the AWS implementation applies here for
prefix + filenameon Line 258.
Description
This PR introduces a shared UploadPrefix constant in the byoc package and updates all relevant cloud drivers (AWS, DigitalOcean, GCP) to use it instead of defining provider-specific upload prefixes.
Added UploadPrefix constant in pkg/cli/client/byoc/common.go and referenced it in:
Avoids duplicate hardcoded prefixes and ensures uniform upload path structure.
Linked Issues
#1904
Checklist
Summary by CodeRabbit