-
-
Notifications
You must be signed in to change notification settings - Fork 10
refactor: move S3 configuration to its own package #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the S3 storage configuration by extracting the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the S3 configuration into its own pkg/s3 package, which is a good step for modularity. However, I've found a few issues that need to be addressed:
- The refactoring breaks existing tests in
pkg/storage/s3/s3_test.gobecause the tested functions have been moved or removed. The tests need to be updated or moved to the new package. - The new
GetEndpointWithoutSchemefunction inpkg/s3/config.gois buggy as it doesn't handle URL paths correctly. - The endpoint validation can be made more robust by using the
net/urlpackage.
Please see my detailed comments for suggestions on how to address these points.
I am having trouble creating individual review comments. Click here to see my feedback.
pkg/storage/s3/s3.go (558-582)
By removing ValidateConfig and the logic for GetEndpointWithoutScheme and IsHTTPS from this package, you are breaking the existing tests in pkg/storage/s3/s3_test.go. The tests for this functionality should be moved to a new test file in the pkg/s3 package (e.g., pkg/s3/config_test.go) and the existing tests in s3_test.go should be updated to call the new pkg/s3 functions or removed if they are now redundant.
References
- Risky behavioral changes should not be included in a refactoring pull request and should be addressed separately. Breaking existing tests during a refactoring indicates a potential risky change or an incomplete refactoring that needs careful attention.
pkg/s3/config.go (75-80)
The current implementation of GetEndpointWithoutScheme only removes the scheme prefix. If the endpoint URL contains a path (e.g., https://my-s3.com/some/path), the path will be incorrectly included in the returned endpoint string. The MinIO client expects only the host and port for the endpoint. Using net/url.Parse and returning u.Host would be more robust and correct. You'll need to add "net/url" to your imports.
func GetEndpointWithoutScheme(endpoint string) string {
// This function assumes a valid URL with a scheme, as validated by ValidateConfig.
// We can ignore the error from url.Parse.
u, _ := url.Parse(endpoint)
return u.Host
}
pkg/s3/config.go (58)
The current validation for the endpoint scheme using strings.HasPrefix is not fully robust as it can allow malformed URLs (e.g., http:foo). Using net/url.Parse provides more reliable validation of the URL structure and its scheme. This also makes the code's intent clearer. You'll need to add "net/url" to your imports.
if u, err := url.Parse(cfg.Endpoint); err != nil || (u.Scheme != "http" && u.Scheme != "https") {
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request is a nice refactoring that moves the S3 configuration into its own dedicated package pkg/s3. This improves modularity and makes the S3 configuration logic more reusable and robust. The new ValidateConfig function with specific error variables and the improved GetEndpointWithoutScheme and IsHTTPS helpers are great additions. The tests have also been correctly moved and updated.
I've found one minor issue regarding some redundant wrapper functions left over after the refactoring. Please see my comment below.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #675 +/- ##
==========================================
- Coverage 69.51% 67.98% -1.54%
==========================================
Files 2 2
Lines 479 456 -23
==========================================
- Hits 333 310 -23
Misses 129 129
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|

No description provided.