Skip to content

Replacing deprecated code in s3 aws sdk#803

Merged
javuto merged 1 commit intomainfrom
deprecated-s3-uploader
Apr 21, 2026
Merged

Replacing deprecated code in s3 aws sdk#803
javuto merged 1 commit intomainfrom
deprecated-s3-uploader

Conversation

@javuto
Copy link
Copy Markdown
Collaborator

@javuto javuto commented Apr 21, 2026

Replacing deprecated code in s3 aws SDK: aws/aws-sdk-go-v2#3306

@javuto javuto requested a review from Copilot April 21, 2026 09:20
@javuto javuto added refactor Refactorization of code osctrl-tls osctrl-tls related changes 🗄️ logging Logging related issues labels Apr 21, 2026
@javuto javuto merged commit 509c39c into main Apr 21, 2026
11 checks passed
@javuto javuto deleted the deprecated-s3-uploader branch April 21, 2026 09:25
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 replaces usage of the AWS SDK Go v2 feature/s3/manager helpers with direct S3 client calls, aligning the codebase with newer/non-deprecated S3 usage patterns.

Changes:

  • Removed manager.Uploader usage and switched uploads to s3.Client.PutObject for S3 logging and carve block uploads.
  • Replaced S3 downloads from manager.Downloader with s3.Client.GetObject + in-memory buffering.
  • Added a small in-memory io.WriterAt implementation (bytesWriterAt) to support the updated download path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
pkg/logging/s3.go Removes S3 manager uploader and uses PutObject directly for log uploads.
pkg/carves/s3.go Removes S3 manager uploader/downloader, uses PutObject for carve blocks, and GetObject for downloads with a new in-memory buffer type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/carves/s3.go
Comment on lines +81 to 85
uploadOutput, err := carveS3.Client.PutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String(carveS3.S3Config.Bucket),
Key: aws.String(GenerateS3Key(block.Environment, uuid, block.SessionID, block.BlockID)),
Body: bytes.NewBuffer(toUpload),
Body: bytes.NewReader(toUpload),
ContentLength: &ptrContentLength,
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Switching from manager.Uploader.Upload to s3.Client.PutObject changes behavior: PutObject is a single-request upload (no multipart) and has the 5GB object size limit, while the uploader would automatically use multipart uploads and provide additional resiliency for larger payloads. If carve blocks can be large or you relied on multipart semantics, consider using the multipart upload APIs (or an equivalent uploader helper) instead of PutObject.

Copilot uses AI. Check for mistakes.
Comment thread pkg/carves/s3.go
Comment on lines +184 to +188
data, err := io.ReadAll(output.Body)
if err != nil {
return nil, fmt.Errorf("Download - reading object body - %w", err)
}
fileReader := newBytesWriterAt(len(data))
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Download reads the entire S3 object into memory via io.ReadAll and then copies it into a second buffer (bytesWriterAt), which can double peak memory usage and risk OOM for large carves. Consider streaming the response to a file/io.Writer, or reading directly into a single preallocated buffer, instead of ReadAll + copy.

Copilot uses AI. Check for mistakes.
Comment thread pkg/carves/s3.go
Comment on lines +188 to 192
fileReader := newBytesWriterAt(len(data))
if _, err := fileReader.WriteAt(data, 0); err != nil {
return nil, fmt.Errorf("Download - buffering object body - %w", err)
}
if carveS3.Debug {
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

After buffering the object in memory, Download still returns io.WriterAt, which doesn’t let callers read the downloaded content back. Consider changing the return type to something readable (e.g., io.ReadCloser, []byte, or io.ReaderAt) so callers can actually consume the downloaded data.

Copilot uses AI. Check for mistakes.
Comment thread pkg/carves/s3.go
Comment on lines +215 to +219
type bytesWriterAt struct {
data []byte
}

func newBytesWriterAt(size int) *bytesWriterAt {
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

bytesWriterAt is an in-memory buffer type, but it only supports WriteAt and doesn’t expose any method to read/extract the buffered bytes (and the type is unexported). If this is meant to be returned from Download, consider implementing a readable interface (e.g., io.ReaderAt) and/or adding an accessor like Bytes().

Copilot uses AI. Check for mistakes.
Comment thread pkg/logging/s3.go
Comment on lines +63 to 67
result, err := logS3.Client.PutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String(logS3.S3Config.Bucket),
Key: aws.String(environment + "/" + logType + "/" + uuid + ":" + strconv.FormatInt(time.Now().UnixMilli(), 10) + ".json"),
Body: bytes.NewBuffer(data),
Body: bytes.NewReader(data),
ContentLength: &ptrContentLength,
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Replacing manager.Uploader.Upload with s3.Client.PutObject removes automatic multipart upload behavior and associated handling for large payloads; PutObject is limited to 5GB per object and performs a single request. If log payloads could be large or you previously depended on multipart semantics, consider using multipart upload APIs (or an equivalent uploader helper) here.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🗄️ logging Logging related issues osctrl-tls osctrl-tls related changes refactor Refactorization of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants