Skip to content

Commit 9313d1f

Browse files
authored
Merge branch 'main' into cw-events-doc-fix
2 parents c354cd1 + 250c0d5 commit 9313d1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+989
-137
lines changed

.github/workflows/reviewdog.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
3030

3131
- name: Upload coverage to Codecov
32-
uses: codecov/codecov-action@v1
33-
if: matrix.go == '1.16'
32+
uses: codecov/codecov-action@v2
3433
with:
3534
file: ./coverage.txt
35+
env_vars: GO
36+
env:
37+
GO: ${{ matrix.go }}

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ linters:
1212
- typecheck
1313
- unused
1414
- varcheck
15+
- stylecheck
1516

1617
run:
1718
skip-files:
1819
# These were code-generated, and cannot be changed without breaking RPC compatibility.
1920
- lambda/messages/*.go
21+
22+
linters-settings:
23+
stylecheck:
24+
go: "1.17"
25+
checks: ["all"]
26+
initialisms: ["AWS", "ARN", "IAM", "MQTT", "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"]

events/activemq_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111

1212
func TestActiveMQEventMarshaling(t *testing.T) {
1313
// 1. read JSON from file
14-
inputJson := test.ReadJSONFromFile(t, "./testdata/activemq-event.json")
14+
inputJSON := test.ReadJSONFromFile(t, "./testdata/activemq-event.json")
1515

1616
// 2. de-serialize into Go object
1717
var inputEvent ActiveMQEvent
18-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
18+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
1919
t.Errorf("could not unmarshal event. details: %v", err)
2020
}
2121

@@ -32,13 +32,13 @@ func TestActiveMQEventMarshaling(t *testing.T) {
3232
assert.Equal(t, false, message.Redelivered)
3333

3434
// 4. serialize to JSON
35-
outputJson, err := json.Marshal(inputEvent)
35+
outputJSON, err := json.Marshal(inputEvent)
3636
if err != nil {
3737
t.Errorf("could not marshal event. details: %v", err)
3838
}
3939

4040
// 5. check result
41-
assert.JSONEq(t, string(inputJson), string(outputJson))
41+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
4242
}
4343

4444
func TestActiveMQMarshalingMalformedJson(t *testing.T) {

events/alb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ALBTargetGroupRequestContext struct {
2020

2121
// ELBContext contains the information to identify the ARN invoking the lambda
2222
type ELBContext struct {
23-
TargetGroupArn string `json:"targetGroupArn"`
23+
TargetGroupArn string `json:"targetGroupArn"` //nolint: stylecheck
2424
}
2525

2626
// ALBTargetGroupResponse configures the response to be returned by the ALB Lambda target group for the request

events/apigw.go

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ type APIGatewayV2HTTPRequest struct {
6565

6666
// APIGatewayV2HTTPRequestContext contains the information to identify the AWS account and resources invoking the Lambda function.
6767
type APIGatewayV2HTTPRequestContext struct {
68-
RouteKey string `json:"routeKey"`
69-
AccountID string `json:"accountId"`
70-
Stage string `json:"stage"`
71-
RequestID string `json:"requestId"`
72-
Authorizer *APIGatewayV2HTTPRequestContextAuthorizerDescription `json:"authorizer,omitempty"`
73-
APIID string `json:"apiId"` // The API Gateway HTTP API Id
74-
DomainName string `json:"domainName"`
75-
DomainPrefix string `json:"domainPrefix"`
76-
Time string `json:"time"`
77-
TimeEpoch int64 `json:"timeEpoch"`
78-
HTTP APIGatewayV2HTTPRequestContextHTTPDescription `json:"http"`
68+
RouteKey string `json:"routeKey"`
69+
AccountID string `json:"accountId"`
70+
Stage string `json:"stage"`
71+
RequestID string `json:"requestId"`
72+
Authorizer *APIGatewayV2HTTPRequestContextAuthorizerDescription `json:"authorizer,omitempty"`
73+
APIID string `json:"apiId"` // The API Gateway HTTP API Id
74+
DomainName string `json:"domainName"`
75+
DomainPrefix string `json:"domainPrefix"`
76+
Time string `json:"time"`
77+
TimeEpoch int64 `json:"timeEpoch"`
78+
HTTP APIGatewayV2HTTPRequestContextHTTPDescription `json:"http"`
79+
Authentication APIGatewayV2HTTPRequestContextAuthentication `json:"authentication"`
7980
}
8081

8182
// APIGatewayV2HTTPRequestContextAuthorizerDescription contains authorizer information for the request context.
@@ -140,7 +141,7 @@ type APIGatewayRequestIdentity struct {
140141
SourceIP string `json:"sourceIp"`
141142
CognitoAuthenticationType string `json:"cognitoAuthenticationType"`
142143
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"`
143-
UserArn string `json:"userArn"`
144+
UserArn string `json:"userArn"` //nolint: stylecheck
144145
UserAgent string `json:"userAgent"`
145146
User string `json:"user"`
146147
}
@@ -189,10 +190,46 @@ type APIGatewayWebsocketProxyRequestContext struct {
189190
Status string `json:"status"`
190191
}
191192

192-
// APIGatewayCustomAuthorizerRequestTypeRequestIdentity contains identity information for the request caller.
193+
// APIGatewayCustomAuthorizerRequestTypeRequestIdentity contains identity information for the request caller including certificate information if using mTLS.
193194
type APIGatewayCustomAuthorizerRequestTypeRequestIdentity struct {
194-
APIKey string `json:"apiKey"`
195-
SourceIP string `json:"sourceIp"`
195+
APIKey string `json:"apiKey"`
196+
SourceIP string `json:"sourceIp"`
197+
ClientCert APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCert `json:"clientCert"`
198+
}
199+
200+
// APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCert contains certificate information for the request caller if using mTLS.
201+
type APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCert struct {
202+
ClientCertPem string `json:"clientCertPem"`
203+
IssuerDN string `json:"issuerDN"`
204+
SerialNumber string `json:"serialNumber"`
205+
SubjectDN string `json:"subjectDN"`
206+
Validity APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCertValidity `json:"validity"`
207+
}
208+
209+
// APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCertValidity contains certificate validity information for the request caller if using mTLS.
210+
type APIGatewayCustomAuthorizerRequestTypeRequestIdentityClientCertValidity struct {
211+
NotAfter string `json:"notAfter"`
212+
NotBefore string `json:"notBefore"`
213+
}
214+
215+
// APIGatewayV2HTTPRequestContextAuthentication contains authentication context information for the request caller including client certificate information if using mTLS.
216+
type APIGatewayV2HTTPRequestContextAuthentication struct {
217+
ClientCert APIGatewayV2HTTPRequestContextAuthenticationClientCert `json:"clientCert"`
218+
}
219+
220+
// APIGatewayV2HTTPRequestContextAuthenticationClientCert contains client certificate information for the request caller if using mTLS.
221+
type APIGatewayV2HTTPRequestContextAuthenticationClientCert struct {
222+
ClientCertPem string `json:"clientCertPem"`
223+
IssuerDN string `json:"issuerDN"`
224+
SerialNumber string `json:"serialNumber"`
225+
SubjectDN string `json:"subjectDN"`
226+
Validity APIGatewayV2HTTPRequestContextAuthenticationClientCertValidity `json:"validity"`
227+
}
228+
229+
// APIGatewayV2HTTPRequestContextAuthenticationClientCertValidity contains client certificate validity information for the request caller if using mTLS.
230+
type APIGatewayV2HTTPRequestContextAuthenticationClientCertValidity struct {
231+
NotAfter string `json:"notAfter"`
232+
NotBefore string `json:"notBefore"`
196233
}
197234

198235
// APIGatewayCustomAuthorizerContext represents the expected format of an API Gateway custom authorizer response.
@@ -221,13 +258,13 @@ type APIGatewayCustomAuthorizerRequestTypeRequestContext struct {
221258
type APIGatewayCustomAuthorizerRequest struct {
222259
Type string `json:"type"`
223260
AuthorizationToken string `json:"authorizationToken"`
224-
MethodArn string `json:"methodArn"`
261+
MethodArn string `json:"methodArn"` //nolint: stylecheck
225262
}
226263

227264
// APIGatewayCustomAuthorizerRequestTypeRequest contains data coming in to a custom API Gateway authorizer function.
228265
type APIGatewayCustomAuthorizerRequestTypeRequest struct {
229266
Type string `json:"type"`
230-
MethodArn string `json:"methodArn"`
267+
MethodArn string `json:"methodArn"` //nolint: stylecheck
231268
Resource string `json:"resource"`
232269
Path string `json:"path"`
233270
HTTPMethod string `json:"httpMethod"`
@@ -248,6 +285,12 @@ type APIGatewayCustomAuthorizerResponse struct {
248285
UsageIdentifierKey string `json:"usageIdentifierKey,omitempty"`
249286
}
250287

288+
// APIGatewayV2CustomAuthorizerSimpleResponse represents the simple format of an API Gateway V2 authorization response.
289+
type APIGatewayV2CustomAuthorizerSimpleResponse struct {
290+
IsAuthorized bool `json:"isAuthorized"`
291+
Context map[string]interface{} `json:"context,omitempty"`
292+
}
293+
251294
// APIGatewayCustomAuthorizerPolicy represents an IAM policy
252295
type APIGatewayCustomAuthorizerPolicy struct {
253296
Version string

events/apigw_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,67 @@ func TestApiGatewayCustomAuthorizerResponseMarshaling(t *testing.T) {
177177
assert.JSONEq(t, string(inputJSON), string(outputJSON))
178178
}
179179

180+
func TestAPIGatewayV2CustomAuthorizerSimpleResponseMarshalling(t *testing.T) {
181+
var tests = []struct {
182+
desc string
183+
in APIGatewayV2CustomAuthorizerSimpleResponse
184+
out string
185+
}{
186+
{
187+
"defaults",
188+
APIGatewayV2CustomAuthorizerSimpleResponse{},
189+
`{"isAuthorized":false}`,
190+
},
191+
{
192+
"without context",
193+
APIGatewayV2CustomAuthorizerSimpleResponse{IsAuthorized: true},
194+
`{"isAuthorized":true}`,
195+
},
196+
{
197+
"context is nil",
198+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: nil},
199+
`{"isAuthorized":false}`,
200+
},
201+
{
202+
"context is empty",
203+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{}},
204+
`{"isAuthorized":false}`,
205+
},
206+
{
207+
"context with basic types",
208+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"string": "value", "bool": true, "number": 1234}},
209+
`{"isAuthorized":false,"context":{"string":"value","bool":true,"number":1234}}`,
210+
},
211+
{
212+
"context with array",
213+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"array": []string{"value1", "value2"}}},
214+
`{"isAuthorized":false,"context":{"array":["value1","value2"]}}`,
215+
},
216+
{
217+
"context with map",
218+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"map": map[string]string{"key": "value"}}},
219+
`{"isAuthorized":false,"context":{"map":{"key":"value"}}}`,
220+
},
221+
{
222+
"context with nil value",
223+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"nil": nil}},
224+
`{"isAuthorized":false,"context":{"nil":null}}`,
225+
},
226+
}
227+
228+
for _, tt := range tests {
229+
tt := tt
230+
t.Run(tt.desc, func(t *testing.T) {
231+
outputJSON, err := json.Marshal(tt.in)
232+
if err != nil {
233+
t.Errorf("could not marshal event. details: %v", err)
234+
}
235+
236+
assert.JSONEq(t, tt.out, string(outputJSON))
237+
})
238+
}
239+
}
240+
180241
func TestApiGatewayCustomAuthorizerResponseMalformedJson(t *testing.T) {
181242
test.TestMalformedJson(t, APIGatewayCustomAuthorizerResponse{})
182243
}

events/appsync.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,28 @@ const (
3838
// OperationBatchInvoke instructs AWS AppSync to batch requests for the current GraphQL field
3939
OperationBatchInvoke AppSyncOperation = "BatchInvoke"
4040
)
41+
42+
// AppSyncLambdaAuthorizerRequest contains an authorization request from AppSync.
43+
type AppSyncLambdaAuthorizerRequest struct {
44+
AuthorizationToken string `json:"authorizationToken"`
45+
RequestContext AppSyncLambdaAuthorizerRequestContext `json:"requestContext"`
46+
}
47+
48+
// AppSyncLambdaAuthorizerRequestContext contains the parameters of the AppSync invocation which triggered
49+
// this authorization request.
50+
type AppSyncLambdaAuthorizerRequestContext struct {
51+
APIID string `json:"apiId"`
52+
AccountID string `json:"accountId"`
53+
RequestID string `json:"requestId"`
54+
QueryString string `json:"queryString"`
55+
OperationName string `json:"operationName"`
56+
Variables map[string]interface{} `json:"variables"`
57+
}
58+
59+
// AppSyncLambdaAuthorizerResponse represents the expected format of an authorization response to AppSync.
60+
type AppSyncLambdaAuthorizerResponse struct {
61+
IsAuthorized bool `json:"isAuthorized"`
62+
ResolverContext map[string]interface{} `json:"resolverContext,omitempty"`
63+
DeniedFields []string `json:"deniedFields,omitempty"`
64+
TTLOverride *int `json:"ttlOverride,omitempty"`
65+
}

events/appsync_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"testing"
77

8+
"github.com/aws/aws-lambda-go/events/test"
89
"github.com/stretchr/testify/assert"
910
)
1011

@@ -85,3 +86,49 @@ func TestAppSyncIdentity_Cognito(t *testing.T) {
8586

8687
assert.JSONEq(t, string(inputJSON), string(outputJSON))
8788
}
89+
90+
func TestAppSyncLambdaAuthorizerRequestMarshalling(t *testing.T) {
91+
inputJSON, err := ioutil.ReadFile("./testdata/appsync-lambda-auth-request.json")
92+
if err != nil {
93+
t.Errorf("could not open test file. details: %v", err)
94+
}
95+
96+
var inputEvent AppSyncLambdaAuthorizerRequest
97+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
98+
t.Errorf("could not unmarshal event. details: %v", err)
99+
}
100+
101+
outputJSON, err := json.Marshal(inputEvent)
102+
if err != nil {
103+
t.Errorf("could not marshal event. details: %v", err)
104+
}
105+
106+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
107+
}
108+
109+
func TestAppSyncLambdaAuthorizerRequestMalformedJson(t *testing.T) {
110+
test.TestMalformedJson(t, AppSyncLambdaAuthorizerRequest{})
111+
}
112+
113+
func TestAppSyncLambdaAuthorizerResponseMarshalling(t *testing.T) {
114+
inputJSON, err := ioutil.ReadFile("./testdata/appsync-lambda-auth-response.json")
115+
if err != nil {
116+
t.Errorf("could not open test file. details: %v", err)
117+
}
118+
119+
var inputEvent AppSyncLambdaAuthorizerResponse
120+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
121+
t.Errorf("could not unmarshal event. details: %v", err)
122+
}
123+
124+
outputJSON, err := json.Marshal(inputEvent)
125+
if err != nil {
126+
t.Errorf("could not marshal event. details: %v", err)
127+
}
128+
129+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
130+
}
131+
132+
func TestAppSyncLambdaAuthorizerResponseMalformedJson(t *testing.T) {
133+
test.TestMalformedJson(t, AppSyncLambdaAuthorizerResponse{})
134+
}

events/attributevalue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type DynamoDBAttributeValue struct {
2020

2121
// This struct represents DynamoDBAttributeValue which doesn't
2222
// implement fmt.Stringer interface and safely `fmt.Sprintf`able
23-
type dynamoDbAttributeValue DynamoDBAttributeValue
23+
type dynamoDbAttributeValue DynamoDBAttributeValue //nolint: stylecheck
2424

2525
// Binary provides access to an attribute of type Binary.
2626
// Method panics if the attribute is not of type Binary.

events/autoscaling_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ func TestAutoScalingEventMarshaling(t *testing.T) {
1818

1919
t.Logf("Running test for %s\n", sampleFile)
2020
// 1. read JSON from file
21-
inputJson := test.ReadJSONFromFile(t, "./testdata/"+sampleFile)
21+
inputJSON := test.ReadJSONFromFile(t, "./testdata/"+sampleFile)
2222

2323
// 2. de-serialize into Go object
2424
var inputEvent AutoScalingEvent
25-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
25+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
2626
t.Errorf("could not unmarshal event. details: %v", err)
2727
}
2828
// 3. serialize to JSON
29-
outputJson, err := json.Marshal(inputEvent)
29+
outputJSON, err := json.Marshal(inputEvent)
3030
if err != nil {
3131
t.Errorf("could not marshal event. details: %v", err)
3232
}
3333
// 4. check result
34-
assert.JSONEq(t, string(inputJson), string(outputJson))
34+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3535
}
3636

3737
}

0 commit comments

Comments
 (0)