File: express_default_checksum.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.24.1-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 554,032 kB
  • sloc: java: 15,941; makefile: 419; sh: 175
file content (42 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package customizations

import (
	"context"
	"fmt"

	ictx "github.com/aws/aws-sdk-go-v2/internal/context"
	"github.com/aws/aws-sdk-go-v2/service/internal/checksum"
	"github.com/aws/smithy-go/middleware"
)

type expressDefaultChecksumMiddleware struct{}

func (*expressDefaultChecksumMiddleware) ID() string {
	return "expressDefaultChecksum"
}

func (*expressDefaultChecksumMiddleware) HandleFinalize(
	ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler,
) (
	out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
	if ictx.GetS3Backend(ctx) == ictx.S3BackendS3Express && ictx.GetChecksumInputAlgorithm(ctx) == "" {
		ctx = ictx.SetChecksumInputAlgorithm(ctx, string(checksum.AlgorithmCRC32))
	}
	return next.HandleFinalize(ctx, in)
}

// AddExpressDefaultChecksumMiddleware appends a step to default to CRC32 for
// S3Express requests. This should only be applied to operations where a
// checksum is required (e.g. DeleteObject).
func AddExpressDefaultChecksumMiddleware(s *middleware.Stack) error {
	err := s.Finalize.Insert(
		&expressDefaultChecksumMiddleware{},
		"AWSChecksum:ComputeInputPayloadChecksum",
		middleware.Before,
	)
	if err != nil {
		return fmt.Errorf("add expressDefaultChecksum: %v", err)
	}
	return nil
}