File: s3_object_lambda.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 (88 lines) | stat: -rw-r--r-- 2,365 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package customizations

import (
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/aws"
	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
	"github.com/aws/smithy-go/middleware"
	"github.com/aws/smithy-go/transport/http"
	"net/url"
)

type s3ObjectLambdaEndpoint struct {
	// whether the operation should use the s3-object-lambda endpoint
	UseEndpoint bool

	// use transfer acceleration
	UseAccelerate bool

	EndpointResolver        EndpointResolver
	EndpointResolverOptions EndpointResolverOptions
}

func (t *s3ObjectLambdaEndpoint) ID() string {
	return "S3:ObjectLambdaEndpoint"
}

func (t *s3ObjectLambdaEndpoint) HandleSerialize(
	ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler,
) (
	out middleware.SerializeOutput, metadata middleware.Metadata, err error,
) {
	if !awsmiddleware.GetRequiresLegacyEndpoints(ctx) {
		return next.HandleSerialize(ctx, in)
	}

	if !t.UseEndpoint {
		return next.HandleSerialize(ctx, in)
	}

	req, ok := in.Request.(*http.Request)
	if !ok {
		return out, metadata, fmt.Errorf("unknown transport type: %T", in.Request)
	}

	if t.EndpointResolverOptions.UseDualStackEndpoint == aws.DualStackEndpointStateEnabled {
		return out, metadata, fmt.Errorf("client configured for dualstack but not supported for operation")
	}

	if t.UseAccelerate {
		return out, metadata, fmt.Errorf("client configured for accelerate but not supported for operation")
	}

	region := awsmiddleware.GetRegion(ctx)

	ero := t.EndpointResolverOptions

	endpoint, err := t.EndpointResolver.ResolveEndpoint(region, ero)
	if err != nil {
		return out, metadata, err
	}

	// Set the ServiceID and SigningName
	ctx = awsmiddleware.SetServiceID(ctx, s3ObjectLambda)

	if len(endpoint.SigningName) > 0 && endpoint.Source == aws.EndpointSourceCustom {
		ctx = awsmiddleware.SetSigningName(ctx, endpoint.SigningName)
	} else {
		ctx = awsmiddleware.SetSigningName(ctx, s3ObjectLambda)
	}

	req.URL, err = url.Parse(endpoint.URL)
	if err != nil {
		return out, metadata, err
	}

	if len(endpoint.SigningRegion) > 0 {
		ctx = awsmiddleware.SetSigningRegion(ctx, endpoint.SigningRegion)
	} else {
		ctx = awsmiddleware.SetSigningRegion(ctx, region)
	}

	if endpoint.Source == aws.EndpointSourceServiceMetadata || !endpoint.HostnameImmutable {
		updateS3HostForS3ObjectLambda(req)
	}

	return next.HandleSerialize(ctx, in)
}