diff --git a/go.mod b/go.mod index 64c7467dc9..1015c370de 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,12 @@ require ( github.com/ExpediaDotCom/haystack-client-go v0.0.0-20190315171017-e7edbdf53a61 github.com/Masterminds/sprig/v3 v3.2.3 github.com/abbot/go-http-auth v0.0.0-00010101000000-000000000000 + github.com/aws/aws-lambda-go v1.45.0 github.com/aws/aws-sdk-go v1.44.327 + github.com/aws/aws-sdk-go-v2 v1.24.1 + github.com/aws/aws-sdk-go-v2/config v1.18.28 + github.com/aws/aws-sdk-go-v2/credentials v1.13.27 + github.com/aws/aws-sdk-go-v2/service/lambda v1.49.7 github.com/cenkalti/backoff/v4 v4.2.1 github.com/containous/alice v0.0.0-20181107144136-d83ebdd94cbd github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf @@ -125,17 +130,12 @@ require ( github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect github.com/armon/go-metrics v0.4.1 // indirect github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c // indirect - github.com/aws/aws-lambda-go v1.45.0 // indirect - github.com/aws/aws-sdk-go-v2 v1.24.1 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.4 // indirect - github.com/aws/aws-sdk-go-v2/config v1.18.28 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.13.27 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.5 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.3.36 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.34 // indirect - github.com/aws/aws-sdk-go-v2/service/lambda v1.49.7 // indirect github.com/aws/aws-sdk-go-v2/service/lightsail v1.27.2 // indirect github.com/aws/aws-sdk-go-v2/service/route53 v1.28.4 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.12.13 // indirect diff --git a/go.sum b/go.sum index 204866e291..121d794cd5 100644 --- a/go.sum +++ b/go.sum @@ -179,7 +179,6 @@ github.com/aws/aws-sdk-go v1.44.327 h1:ZS8oO4+7MOBLhkdwIhgtVeDzCeWOlTfKJS7EgggbI github.com/aws/aws-sdk-go v1.44.327/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/aws/aws-sdk-go-v2 v1.19.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw= -github.com/aws/aws-sdk-go-v2 v1.20.3 h1:lgeKmAZhlj1JqN43bogrM75spIvYnRxqTAh1iupu1yE= github.com/aws/aws-sdk-go-v2 v1.20.3/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M= github.com/aws/aws-sdk-go-v2 v1.24.1 h1:xAojnj+ktS95YZlDf0zxWBkbFtymPeDP+rvUQIH3uAU= github.com/aws/aws-sdk-go-v2 v1.24.1/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= @@ -192,13 +191,9 @@ github.com/aws/aws-sdk-go-v2/credentials v1.13.27/go.mod h1:syOqAek45ZXZp29HlnRS github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.5 h1:kP3Me6Fy3vdi+9uHd7YLr6ewPxRL+PU6y15urfTaamU= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.5/go.mod h1:Gj7tm95r+QsDoN2Fhuz/3npQvcZbkEf5mL70n3Xfluc= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.35/go.mod h1:ipR5PvpSPqIqL5Mi82BxLnfMkHVbmco8kUwO2xrCi0M= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.40 h1:CXceCS9BrDInRc74GDCQ8Qyk/Gp9VLdK+Rlve+zELSE= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.40/go.mod h1:5kKmFhLeOVy6pwPDpDNA6/hK/d6URC98pqDDqHgdBx4= github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 h1:vF+Zgd9s+H4vOXd5BMaPWykta2a6Ih0AKLq/X6NYKn4= github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10/go.mod h1:6BkRjejp/GR4411UGqkX8+wFMbFbqsUIimfK4XjOKR4= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.29/go.mod h1:M/eUABlDbw2uVrdAn+UsI6M727qp2fxkp8K0ejcBDUY= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.34 h1:B+nZtd22cbko5+793hg7LEaTeLMiZwlgCLUrN5Y0uzg= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.34/go.mod h1:RZP0scceAyhMIQ9JvFp7HvkpcgqjL4l/4C+7RAeGbuM= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 h1:nYPe006ktcqUji8S2mqXf9c/7NdiKriOwMvWQHgYztw= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10/go.mod h1:6UV4SZkVvmODfXKql4LCbaZUpF7HO2BX38FgBf9ZOLw= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.36 h1:8r5m1BoAWkn0TDC34lUculryf7nUF25EgIMdjvGCkgo= @@ -219,7 +214,6 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.13/go.mod h1:BzqsVVFduubEmzrV github.com/aws/aws-sdk-go-v2/service/sts v1.19.3 h1:e5mnydVdCVWxP+5rPAGi2PYxC7u2OZgH1ypC114H04U= github.com/aws/aws-sdk-go-v2/service/sts v1.19.3/go.mod h1:yVGZA1CPkmUhBdA039jXNJJG7/6t+G+EBWmFq23xqnY= github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= -github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ= github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM= github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE= @@ -1261,8 +1255,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/traefik/paerser v0.2.0 h1:zqCLGSXoNlcBd+mzqSCLjon/I6phqIjeJL2xFB2ysgQ= github.com/traefik/paerser v0.2.0/go.mod h1:afzaVcgF8A+MpTnPG4wBr4whjanCSYA6vK5RwaYVtRc= -github.com/traefik/yaegi v0.15.1 h1:YA5SbaL6HZA0Exh9T/oArRHqGN2HQ+zgmCY7dkoTXu4= -github.com/traefik/yaegi v0.15.1/go.mod h1:AVRxhaI2G+nUsaM1zyktzwXn69G3t/AuTDrCiTds9p0= github.com/traefik/yaegi v0.16.0 h1:PdG291d+XKZnfgfnc9vedZ9DcIrAq4EYTy3/TyESn20= github.com/traefik/yaegi v0.16.0/go.mod h1:4eVhbPb3LnD2VigQjhYbEJ69vDRFdT2HQNrXx8eEwUY= github.com/transip/gotransip/v6 v6.20.0 h1:AuvwyOZ51f2brzMbTqlRy/wmaM3kF7Vx5Wds8xcDflY= diff --git a/pkg/config/dynamic/zz_generated.deepcopy.go b/pkg/config/dynamic/zz_generated.deepcopy.go index fee40799cf..a1a872d9a2 100644 --- a/pkg/config/dynamic/zz_generated.deepcopy.go +++ b/pkg/config/dynamic/zz_generated.deepcopy.go @@ -34,6 +34,22 @@ import ( types "github.com/traefik/traefik/v2/pkg/types" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSLambda) DeepCopyInto(out *AWSLambda) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSLambda. +func (in *AWSLambda) DeepCopy() *AWSLambda { + if in == nil { + return nil + } + out := new(AWSLambda) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AddPrefix) DeepCopyInto(out *AddPrefix) { *out = *in @@ -765,6 +781,11 @@ func (in *Middleware) DeepCopyInto(out *Middleware) { *out = new(ContentType) **out = **in } + if in.AWSLambda != nil { + in, out := &in.AWSLambda, &out.AWSLambda + *out = new(AWSLambda) + **out = **in + } if in.Plugin != nil { in, out := &in.Plugin, &out.Plugin *out = make(map[string]PluginConf, len(*in)) diff --git a/pkg/middlewares/awslambda/aws_lambda.go b/pkg/middlewares/awslambda/aws_lambda.go index 509e483e85..e5ae6e2e8b 100644 --- a/pkg/middlewares/awslambda/aws_lambda.go +++ b/pkg/middlewares/awslambda/aws_lambda.go @@ -32,7 +32,6 @@ import ( "context" "encoding/base64" "encoding/json" - _ "errors" "fmt" "io" "net/http" @@ -45,7 +44,6 @@ import ( awsconfig "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/lambda" - "github.com/opentracing/opentracing-go/ext" "github.com/traefik/traefik/v2/pkg/config/dynamic" "github.com/traefik/traefik/v2/pkg/log" @@ -58,7 +56,7 @@ const ( ) // awsLambda is a middleware that provides routing to aws lambda -// functions +// functions. type awsLambda struct { next http.Handler functionArn string @@ -66,7 +64,7 @@ type awsLambda struct { client *lambda.Client } -// New builds a new AwsLambda middleware +// New builds a new AwsLambda middleware. func New(ctx context.Context, next http.Handler, config dynamic.AWSLambda, name string) (http.Handler, error) { logger := log.FromContext(middlewares.GetLoggerCtx(ctx, name, typeName)) logger.Debug("Creating middleware") @@ -125,7 +123,7 @@ func New(ctx context.Context, next http.Handler, config dynamic.AWSLambda, name }, nil } -// GetTracingInformation +// GetTracingInformation. func (a *awsLambda) GetTracingInformation() (string, ext.SpanKindEnum) { return a.name, tracing.SpanKindNoneEnum } @@ -168,7 +166,6 @@ func (a *awsLambda) ServeHTTP(rw http.ResponseWriter, req *http.Request) { Authorizer: make(map[string]interface{}), }, }) - if err != nil { msg := fmt.Sprintf("Error invoking Lambda: %v", err) logger.Error(msg) @@ -224,7 +221,7 @@ func (a *awsLambda) ServeHTTP(rw http.ResponseWriter, req *http.Request) { } } -// bodyToBase64 ensures the request body is base64 encoded +// bodyToBase64 ensures the request body is base64 encoded. func bodyToBase64(req *http.Request) (bool, string, error) { base64Encoded := false body := "" @@ -254,7 +251,7 @@ func (a *awsLambda) invokeFunction(ctx context.Context, request events.APIGatewa payload, err := json.Marshal(request) if err != nil { - return resp, fmt.Errorf("failed to marshal request: %v", err) + return resp, fmt.Errorf("failed to marshal request: %w", err) } result, err := a.client.Invoke(ctx, &lambda.InvokeInput{ @@ -271,7 +268,7 @@ func (a *awsLambda) invokeFunction(ctx context.Context, request events.APIGatewa err = json.Unmarshal(result.Payload, &resp) if err != nil { - return resp, fmt.Errorf("failed to unmarshal response: %s, %v", result.Payload, err) + return resp, fmt.Errorf("failed to unmarshal response: %s, %w", result.Payload, err) } return resp, nil diff --git a/pkg/middlewares/awslambda/aws_lambda_test.go b/pkg/middlewares/awslambda/aws_lambda_test.go index 89d9ab2084..bd45bcf9d3 100644 --- a/pkg/middlewares/awslambda/aws_lambda_test.go +++ b/pkg/middlewares/awslambda/aws_lambda_test.go @@ -13,6 +13,7 @@ import ( "github.com/aws/aws-lambda-go/events" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/traefik/traefik/v2/pkg/config/dynamic" "github.com/traefik/traefik/v2/pkg/tracing" ) @@ -69,7 +70,8 @@ func Test_AWSLambdaMiddleware_Invoke(t *testing.T) { recorder := httptest.NewRecorder() var buf bytes.Buffer - buf.Write([]byte("This is the body")) + b := []byte("This is the body") + buf.Write(b) req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/%s", mockserver.URL, "test/example/path?a=1&b=2&c=3&c=4&d[]=5&d[]=6"), &buf) if err != nil { @@ -83,8 +85,8 @@ func Test_AWSLambdaMiddleware_Invoke(t *testing.T) { resp := recorder.Result() rBody, _ := io.ReadAll(resp.Body) - assert.Equal(t, rBody, []byte("response_body")) - assert.Equal(t, resp.StatusCode, http.StatusTeapot) + assert.Equal(t, []byte("response_body"), rBody) + assert.Equal(t, http.StatusTeapot, resp.StatusCode) } // Test_AWSLambdaMiddleware_GetTracingInformation tests that the @@ -106,12 +108,12 @@ func Test_AWSLambdaMiddleware_GetTracingInformation(t *testing.T) { // Test_AWSLambdaMiddleware_bodyToBase64_empty func Test_AWSLambdaMiddleware_bodyToBase64_empty(t *testing.T) { req, err := http.NewRequest(http.MethodGet, "/", nil) - assert.Nil(t, err) + require.NoError(t, err) isEncoded, body, err := bodyToBase64(req) - assert.Equal(t, isEncoded, false) - assert.Equal(t, body, "") - assert.Nil(t, err) + assert.False(t, isEncoded) + assert.Equal(t, "", body) + require.NoError(t, err) } // Test_AWSLambdaMiddleware_bodyToBase64_withcontent @@ -120,10 +122,10 @@ func Test_AWSLambdaMiddleware_bodyToBase64_withcontent(t *testing.T) { reqBody := `{"test": "encoded"}` req, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(reqBody)) - assert.Nil(t, err) + require.NoError(t, err) isEncoded, body, err := bodyToBase64(req) - assert.Equal(t, isEncoded, true) - assert.Equal(t, body, expected) - assert.Nil(t, err) + assert.True(t, isEncoded) + assert.Equal(t, expected, body) + require.NoError(t, err) }