Skip to content

Commit f08396f

Browse files
authored
Merge branch 'main' into feature/code-pipeline-events
2 parents 22b1ea5 + d64324e commit f08396f

Some content is hidden

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

42 files changed

+361
-117
lines changed

.github/workflows/reviewdog.yml

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

.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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type APIGatewayRequestIdentity struct {
141141
SourceIP string `json:"sourceIp"`
142142
CognitoAuthenticationType string `json:"cognitoAuthenticationType"`
143143
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"`
144-
UserArn string `json:"userArn"`
144+
UserArn string `json:"userArn"` //nolint: stylecheck
145145
UserAgent string `json:"userAgent"`
146146
User string `json:"user"`
147147
}
@@ -258,13 +258,13 @@ type APIGatewayCustomAuthorizerRequestTypeRequestContext struct {
258258
type APIGatewayCustomAuthorizerRequest struct {
259259
Type string `json:"type"`
260260
AuthorizationToken string `json:"authorizationToken"`
261-
MethodArn string `json:"methodArn"`
261+
MethodArn string `json:"methodArn"` //nolint: stylecheck
262262
}
263263

264264
// APIGatewayCustomAuthorizerRequestTypeRequest contains data coming in to a custom API Gateway authorizer function.
265265
type APIGatewayCustomAuthorizerRequestTypeRequest struct {
266266
Type string `json:"type"`
267-
MethodArn string `json:"methodArn"`
267+
MethodArn string `json:"methodArn"` //nolint: stylecheck
268268
Resource string `json:"resource"`
269269
Path string `json:"path"`
270270
HTTPMethod string `json:"httpMethod"`

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
}

events/cloudwatch_logs_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestCloudwatchLogs(t *testing.T) {
1212
for _, test := range []struct {
1313
name string
14-
eventJson string
14+
eventJSON string
1515
expectError bool
1616
expectCloudwatchEventData CloudwatchLogsEvent
1717
}{
@@ -27,10 +27,10 @@ func TestCloudwatchLogs(t *testing.T) {
2727
} {
2828
test := test
2929
t.Run(test.name, func(t *testing.T) {
30-
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
30+
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)
3131

3232
var inputEvent CloudwatchLogsEvent
33-
err := json.Unmarshal(inputJson, &inputEvent)
33+
err := json.Unmarshal(inputJSON, &inputEvent)
3434

3535
if err != nil && !test.expectError {
3636
t.Errorf("could not unmarshal event. details: %v", err)
@@ -50,7 +50,7 @@ func TestCloudwatchLogs(t *testing.T) {
5050
func TestCloudwatchLogsParse(t *testing.T) {
5151
for _, test := range []struct {
5252
name string
53-
eventJson string
53+
eventJSON string
5454
expectError bool
5555
expectCloudwatchLogsData CloudwatchLogsData
5656
}{
@@ -74,10 +74,10 @@ func TestCloudwatchLogsParse(t *testing.T) {
7474
} {
7575
test := test
7676
t.Run(test.name, func(t *testing.T) {
77-
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
77+
inputJSON := tst.ReadJSONFromFile(t, test.eventJSON)
7878

7979
var inputEvent CloudwatchLogsEvent
80-
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
80+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
8181
t.Errorf("could not unmarshal event. details: %v", err)
8282
}
8383

events/code_commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type CodeCommitRecord struct {
5252
EventPartNumber uint64 `json:"eventPartNumber"`
5353
CodeCommit CodeCommitCodeCommit `json:"codecommit"`
5454
EventName string `json:"eventName"`
55-
EventTriggerConfigId string `json:"eventTriggerConfigId"`
55+
EventTriggerConfigId string `json:"eventTriggerConfigId"` //nolint: stylecheck
5656
EventSourceARN string `json:"eventSourceARN"`
5757
UserIdentityARN string `json:"userIdentityARN"`
5858
EventSource string `json:"eventSource"`

events/config.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ package events
44

55
// ConfigEvent contains data from an event sent from AWS Config
66
type ConfigEvent struct {
7-
AccountID string `json:"accountId"` // The ID of the AWS account that owns the rule
8-
ConfigRuleArn string `json:"configRuleArn"` // The ARN that AWS Config assigned to the rule
9-
ConfigRuleID string `json:"configRuleId"`
10-
ConfigRuleName string `json:"configRuleName"` // The name that you assigned to the rule that caused AWS Config to publish the event
11-
EventLeftScope bool `json:"eventLeftScope"` // A boolean value that indicates whether the AWS resource to be evaluated has been removed from the rule's scope
12-
ExecutionRoleArn string `json:"executionRoleArn"`
13-
InvokingEvent string `json:"invokingEvent"` // If the event is published in response to a resource configuration change, this value contains a JSON configuration item
14-
ResultToken string `json:"resultToken"` // A token that the function must pass to AWS Config with the PutEvaluations call
15-
RuleParameters string `json:"ruleParameters"` // Key/value pairs that the function processes as part of its evaluation logic
16-
Version string `json:"version"`
7+
// The ID of the AWS account that owns the rule
8+
AccountID string `json:"accountId"`
9+
// The ARN that AWS Config assigned to the rule
10+
ConfigRuleArn string `json:"configRuleArn"` //nolint:stylecheck
11+
ConfigRuleID string `json:"configRuleId"` //nolint:stylecheck
12+
// The name that you assigned to the rule that caused AWS Config to publish the event
13+
ConfigRuleName string `json:"configRuleName"`
14+
// A boolean value that indicates whether the AWS resource to be evaluated has been removed from the rule's scope
15+
EventLeftScope bool `json:"eventLeftScope"`
16+
ExecutionRoleArn string `json:"executionRoleArn"` //nolint:stylecheck
17+
// If the event is published in response to a resource configuration change, this value contains a JSON configuration item
18+
InvokingEvent string `json:"invokingEvent"`
19+
// A token that the function must pass to AWS Config with the PutEvaluations call
20+
ResultToken string `json:"resultToken"`
21+
// Key/value pairs that the function processes as part of its evaluation logic
22+
RuleParameters string `json:"ruleParameters"`
23+
Version string `json:"version"`
1724
}

events/connect_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ import (
1313
func TestConnectMarshaling(t *testing.T) {
1414

1515
// 1. read JSON from file
16-
inputJson := test.ReadJSONFromFile(t, "./testdata/connect-event.json")
16+
inputJSON := test.ReadJSONFromFile(t, "./testdata/connect-event.json")
1717

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

2424
// 3. serialize to JSON
25-
outputJson, err := json.Marshal(inputEvent)
25+
outputJSON, err := json.Marshal(inputEvent)
2626
if err != nil {
2727
t.Errorf("could not marshal event. details: %v", err)
2828
}
2929

3030
// 4. check result
31-
assert.JSONEq(t, string(inputJson), string(outputJson))
31+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3232
}
3333

3434
func TestConnectMarshalingMalformedJson(t *testing.T) {

events/dynamodb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type DynamoDBEventRecord struct {
4343
EventVersion string `json:"eventVersion"`
4444

4545
// The event source ARN of DynamoDB
46-
EventSourceArn string `json:"eventSourceARN"`
46+
EventSourceArn string `json:"eventSourceARN"` //nolint: stylecheck
4747

4848
// Items that are deleted by the Time to Live process after expiration have
4949
// the following fields:

events/dynamodb_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ import (
1313
func TestDynamoDBEventMarshaling(t *testing.T) {
1414

1515
// 1. read JSON from file
16-
inputJson := test.ReadJSONFromFile(t, "./testdata/dynamodb-event.json")
16+
inputJSON := test.ReadJSONFromFile(t, "./testdata/dynamodb-event.json")
1717

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

2424
// 3. serialize to JSON
25-
outputJson, err := json.Marshal(inputEvent)
25+
outputJSON, err := json.Marshal(inputEvent)
2626
if err != nil {
2727
t.Errorf("could not marshal event. details: %v", err)
2828
}
2929

3030
// 4. check result
31-
assert.JSONEq(t, string(inputJson), string(outputJson))
31+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
3232
}
3333

3434
func TestDynamoDBEventMarshalingMalformedJson(t *testing.T) {

events/ecr_scan_test.go

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

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

1616
// 2. de-serialize into Go object
1717
var inputEvent ECRScanEvent
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

@@ -42,13 +42,13 @@ func TestECRScanEventMarshaling(t *testing.T) {
4242
assert.Equal(t, int64(0), detail.FindingSeverityCounts.Undefined)
4343

4444
// 4. serialize to JSON
45-
outputJson, err := json.Marshal(inputEvent)
45+
outputJSON, err := json.Marshal(inputEvent)
4646
if err != nil {
4747
t.Errorf("could not marshal event. details: %v", err)
4848
}
4949

5050
// 5. check result
51-
assert.JSONEq(t, string(inputJson), string(outputJson))
51+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
5252
}
5353

5454
func TestECRScanMarshalingMalformedJson(t *testing.T) {

0 commit comments

Comments
 (0)