File: bucket_context.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 (47 lines) | stat: -rw-r--r-- 1,449 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
43
44
45
46
47
package s3

import (
	"context"

	"github.com/aws/aws-sdk-go-v2/service/s3/internal/customizations"
	"github.com/aws/smithy-go/middleware"
)

// putBucketContextMiddleware stores the input bucket name within the request context (if
// present) which is required for a variety of custom S3 behaviors
type putBucketContextMiddleware struct{}

func (*putBucketContextMiddleware) ID() string {
	return "putBucketContext"
}

func (m *putBucketContextMiddleware) HandleSerialize(
	ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler,
) (
	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
) {
	if bucket, ok := m.bucketFromInput(in.Parameters); ok {
		ctx = customizations.SetBucket(ctx, bucket)
	}
	return next.HandleSerialize(ctx, in)
}

func (m *putBucketContextMiddleware) bucketFromInput(params interface{}) (string, bool) {
	v, ok := params.(bucketer)
	if !ok {
		return "", false
	}

	return v.bucket()
}

func addPutBucketContextMiddleware(stack *middleware.Stack) error {
	// This is essentially a post-Initialize task - only run it once the input
	// has received all modifications from that phase. Therefore we add it as
	// an early Serialize step.
	//
	// FUTURE: it would be nice to have explicit phases that only we as SDK
	// authors can hook into (such as between phases like this really should
	// be)
	return stack.Serialize.Add(&putBucketContextMiddleware{}, middleware.Before)
}