Skip to content

Commit

Permalink
Add support for trailing checksum (#1600)
Browse files Browse the repository at this point in the history
Updates the SDK adding support Amazon S3 for trailing checksums computed
with the aws-chunked content-encoding format. Adds a new internal
service module, `checksum` to the SDK that API models decorated with the
`httpChecksum` smithy trail will use.

Co-authored-by: skotambkar <kotambkarshantanu@gmail.com>
  • Loading branch information
jasdel and skotambkar authored Feb 24, 2022
1 parent 4e87627 commit 07719a1
Show file tree
Hide file tree
Showing 130 changed files with 11,433 additions and 785 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Lint rules to ignore
LINTIGNORESINGLEFIGHT='internal/sync/singleflight/singleflight.go:.+error should be the last type'
LINT_IGNORE_S3MANAGER_INPUT='feature/s3/manager/upload.go:.+struct field SSEKMSKeyId should be SSEKMSKeyID'

UNIT_TEST_TAGS=
BUILD_TAGS=-tags "example,codegen,integration,ec2env,perftest"
Expand Down Expand Up @@ -447,6 +448,7 @@ lint:
@echo "go lint SDK and vendor packages"
@lint=`golint ./...`; \
dolint=`echo "$$lint" | grep -E -v \
-e ${LINT_IGNORE_S3MANAGER_INPUT} \
-e ${LINTIGNORESINGLEFIGHT}`; \
echo "$$dolint"; \
if [ "$$dolint" != "" ]; then exit 1; fi
Expand Down
1,520 changes: 1,295 additions & 225 deletions codegen/sdk-codegen/aws-models/s3.2006-03-01.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class AwsGoDependency {
public static final GoDependency SERVICE_INTERNAL_ENDPOINT_DISCOVERY = awsModuleDep("service/internal/endpoint-discovery",
null, Versions.SERVICE_INTERNAL_ENDPOINT_DISCOVERY, "internalEndpointDiscovery");
public static final GoDependency AWS_DEFAULTS = aws("aws/defaults");
public static final GoDependency SERVICE_INTERNAL_CHECKSUM = awsModuleDep("service/internal/checksum",
null, Versions.SERVICE_INTERNAL_CHECKSUM, "internalChecksum");

public static final GoDependency REGEXP = SmithyGoDependency.stdlib("regexp");

Expand Down Expand Up @@ -99,5 +101,6 @@ private static final class Versions {
private static final String SERVICE_INTERNAL_ENDPOINT_DISCOVERY = "v0.0.0-00010101000000-000000000000";
private static final String INTERNAL_ENDPOINTS_V2 = "v2.0.0-00010101000000-000000000000";
private static final String AWS_PROTOCOL_EVENTSTREAM = "v0.0.0-00010101000000-000000000000";
private static final String SERVICE_INTERNAL_CHECKSUM = "v0.0.0-00010101000000-000000000000";
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
software.amazon.smithy.aws.go.codegen.AddProtocols
software.amazon.smithy.aws.go.codegen.ClientResolvedDefaultsMode
software.amazon.smithy.aws.go.codegen.AddAwsConfigFields
software.amazon.smithy.aws.go.codegen.AwsHttpChecksumGenerator
software.amazon.smithy.aws.go.codegen.RegisterServiceMetadataMiddleware
software.amazon.smithy.aws.go.codegen.AwsEventStreamIntegration
software.amazon.smithy.aws.go.codegen.AssembleMiddlewareStack
Expand Down
2 changes: 2 additions & 0 deletions example/service/s3/listObjects/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/

replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../../service/internal/accept-encoding/

replace github.com/aws/aws-sdk-go-v2/service/internal/checksum => ../../../../service/internal/checksum/

replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/

replace github.com/aws/aws-sdk-go-v2/service/internal/s3shared => ../../../../service/internal/s3shared/
Expand Down
2 changes: 2 additions & 0 deletions example/service/s3/usingPrivateLink/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../../internal/ini/

replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../../service/internal/accept-encoding/

replace github.com/aws/aws-sdk-go-v2/service/internal/checksum => ../../../../service/internal/checksum/

replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../../service/internal/presigned-url/

replace github.com/aws/aws-sdk-go-v2/service/internal/s3shared => ../../../../service/internal/s3shared/
Expand Down
17 changes: 9 additions & 8 deletions feature/s3/manager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,16 @@ func (d *downloader) downloadRange(rng string) {

// downloadChunk downloads the chunk from s3
func (d *downloader) downloadChunk(chunk dlchunk) error {
in := &s3.GetObjectInput{}
awsutil.Copy(in, d.in)
var params s3.GetObjectInput
awsutil.Copy(&params, d.in)

// Get the next byte range of data
in.Range = aws.String(chunk.ByteRange())
params.Range = aws.String(chunk.ByteRange())

var n int64
var err error
for retry := 0; retry <= d.partBodyMaxRetries; retry++ {
n, err = d.tryDownloadChunk(in, &chunk)
n, err = d.tryDownloadChunk(&params, &chunk)
if err == nil {
break
}
Expand All @@ -374,23 +374,24 @@ func (d *downloader) downloadChunk(chunk dlchunk) error {

chunk.cur = 0

d.cfg.Logger.Logf(logging.Debug, "object part body download interrupted %s, err, %v, retrying attempt %d",
aws.ToString(in.Key), err, retry)
d.cfg.Logger.Logf(logging.Debug,
"object part body download interrupted %s, err, %v, retrying attempt %d",
aws.ToString(params.Key), err, retry)
}

d.incrWritten(n)

return err
}

func (d *downloader) tryDownloadChunk(in *s3.GetObjectInput, w io.Writer) (int64, error) {
func (d *downloader) tryDownloadChunk(params *s3.GetObjectInput, w io.Writer) (int64, error) {
cleanup := func() {}
if d.cfg.BufferProvider != nil {
w, cleanup = d.cfg.BufferProvider.GetReadFrom(w)
}
defer cleanup()

resp, err := d.cfg.S3.GetObject(d.ctx, in, d.cfg.ClientOptions...)
resp, err := d.cfg.S3.GetObject(d.ctx, params, d.cfg.ClientOptions...)
if err != nil {
return 0, err
}
Expand Down
2 changes: 2 additions & 0 deletions feature/s3/manager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ replace github.com/aws/aws-sdk-go-v2/internal/ini => ../../../internal/ini/

replace github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding => ../../../service/internal/accept-encoding/

replace github.com/aws/aws-sdk-go-v2/service/internal/checksum => ../../../service/internal/checksum/

replace github.com/aws/aws-sdk-go-v2/service/internal/presigned-url => ../../../service/internal/presigned-url/

replace github.com/aws/aws-sdk-go-v2/service/internal/s3shared => ../../../service/internal/s3shared/
Expand Down
7 changes: 6 additions & 1 deletion feature/s3/manager/integ_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
"github.com/aws/aws-sdk-go-v2/feature/s3/manager/internal/integration"
"github.com/aws/aws-sdk-go-v2/service/s3"
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
)

var integConfig aws.Config
Expand Down Expand Up @@ -92,7 +93,11 @@ func (d dlwriter) WriteAt(p []byte, pos int64) (n int, err error) {

func validate(t *testing.T, key string, md5value string) {
mgr := manager.NewDownloader(client)
params := &s3.GetObjectInput{Bucket: bucketName, Key: &key}
params := &s3.GetObjectInput{
Bucket: bucketName,
Key: &key,
ChecksumMode: s3types.ChecksumModeEnabled,
}

w := newDLWriter(1024 * 1024 * 20)
n, err := mgr.Download(context.Background(), w, params)
Expand Down
Loading

0 comments on commit 07719a1

Please sign in to comment.