-
Notifications
You must be signed in to change notification settings - Fork 125
CSPL-3974: improve region parsing and enforce latest version downloads #1568
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
base: develop
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR improves the AWS S3 client implementation by fixing region parsing to handle both path-style and virtual-hosted S3 URLs, and enforces downloading the latest version of objects by removing ETag-based conditional downloads. The changes also add better input validation and error handling.
- Enhanced region extraction with more robust regex pattern for S3 endpoints
- Removed IfMatch parameter to always download latest object versions instead of conditional downloads
- Added input validation for empty file paths and improved cleanup of partial downloads
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| awss3client.go | Updated region parsing logic, removed IfMatch conditional downloads, added input validation and HeadObject interface |
| awss3client_test.go | Added test adapters for HeadObject method, updated existing tests to work without IfMatch, added new test for latest version behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| var regionRegex = ".*.s3[-,.]([a-z]+-[a-z]+-[0-9]+)\\..*amazonaws.com" | ||
| var regionRegex = `(?i)(^|\.)(s3)[\.-]([a-z0-9-]+)\.amazonaws\.com$` |
Copilot
AI
Aug 26, 2025
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.
The regex pattern uses a case-insensitive flag (?i) but then only matches lowercase characters in the region group [a-z0-9-]+. Consider either removing the case-insensitive flag or updating the character class to include uppercase letters [a-zA-Z0-9-]+ for consistency.
| var regionRegex = `(?i)(^|\.)(s3)[\.-]([a-z0-9-]+)\.amazonaws\.com$` | |
| var regionRegex = `(?i)(^|\.)(s3)[\.-]([a-zA-Z0-9-]+)\.amazonaws\.com$` |
| // Ensure IfMatch is non-nil AND non-empty for older mocks that expect it. | ||
| if input.IfMatch == nil || aws.ToString(input.IfMatch) == "" { | ||
| val := "test-ifmatch" // any non-empty sentinel keeps older mocks happy | ||
| input.IfMatch = &val | ||
| } |
Copilot
AI
Aug 26, 2025
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.
This compatibility wrapper artificially sets IfMatch to satisfy legacy mocks, but the production code no longer uses IfMatch. This creates a disconnect between test and production behavior. Consider updating the legacy mocks instead of working around them with artificial values.
| // Ensure IfMatch is non-nil AND non-empty for older mocks that expect it. | |
| if input.IfMatch == nil || aws.ToString(input.IfMatch) == "" { | |
| val := "test-ifmatch" // any non-empty sentinel keeps older mocks happy | |
| input.IfMatch = &val | |
| } |
Pull Request Test Coverage Report for Build 17265453835Details
💛 - Coveralls |
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.
LGTM!
This PR fixes region parsing in the AWS S3 client and ensures downloads always fetch the latest version of objects from S3. It also improves input validation, error handling, and cleanup behavior in the download workflow.
Key Changes
awss3client.goGetRegionto correctly parse full S3 URLs and broadened regex for both path-style and virtual-hosted endpoints.NewAWSS3Clientto properly setEndpointand handle region derivation.IfMatchinDownloadAppto avoid stale ETag errors.HeadObjectpreflight check to log differences when provided ETag does not match current.Tests
TestNewAWSS3Clientto cover valid, backward-compatibility, and invalid scenarios.TestAWSDownloadAppShouldNotFail,TestAWSDownloadAppShouldFail, andTestAWSDownloadAppIgnoresProvidedETagAndGetsLatestto validate latest-version behavior and error handling.Testing and Verification
Ran unit tests locally:
TestNewAWSS3Clientpasses for valid endpoints, fails for invalid ones.TestAWSDownloadAppShouldNotFailconfirms successful downloads.TestAWSDownloadAppShouldFailremoves partial files on failure.TestAWSDownloadAppIgnoresProvidedETagAndGetsLatestvalidates latest object is always downloaded.Verified log messages for mismatched ETags and error conditions.
Related Issues
TestAWSDownloadAppShouldNotFailPR Checklist