Skip to content

Commit 55626ad

Browse files
authored
fix: Avoids runtime error: invalid memory address or nil pointer dereference when type!=DatabaseTrigger (#1218)
1 parent d3d88a3 commit 55626ad

File tree

5 files changed

+32
-58
lines changed

5 files changed

+32
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ update.json
2727
**/functions/packages
2828
**/taskcat_outputs/
2929
**/inputs/**
30+
**/samples/**
3031
pytestdebug.log
3132
!/cdk/**/.*
3233
*.DS_Store

cfn-resources/trigger/cmd/resource/resource.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,28 +230,26 @@ func newEventTrigger(model *Model) (*appservices.EventTriggerRequest, error) {
230230
conf.Database = *model.DatabaseTrigger.Database
231231
}
232232
dTrigger := model.DatabaseTrigger
233-
234-
if dTrigger.Match != nil {
235-
jsonData := []byte(*dTrigger.Match)
236-
// convert the JSON string to a map
237-
var m interface{}
238-
if err := json.Unmarshal(jsonData, &m); err != nil {
239-
return nil, errors.New("error unmarshalling Match field - " + err.Error())
233+
if dTrigger != nil {
234+
if dTrigger.Match != nil {
235+
jsonData := []byte(*dTrigger.Match)
236+
// convert the JSON string to a map
237+
var m interface{}
238+
if err := json.Unmarshal(jsonData, &m); err != nil {
239+
return nil, errors.New("error unmarshalling Match field - " + err.Error())
240+
}
241+
conf.Match = m
240242
}
241-
conf.Match = m
242-
}
243243

244-
if dTrigger.Project != nil {
245-
jsonData := []byte(*dTrigger.Project)
246-
// convert the JSON string to a map
247-
var m interface{}
248-
if err := json.Unmarshal(jsonData, &m); err != nil {
249-
return nil, errors.New("error unmarshalling Project field - " + err.Error())
244+
if dTrigger.Project != nil {
245+
jsonData := []byte(*dTrigger.Project)
246+
// convert the JSON string to a map
247+
var m interface{}
248+
if err := json.Unmarshal(jsonData, &m); err != nil {
249+
return nil, errors.New("error unmarshalling Project field - " + err.Error())
250+
}
251+
conf.Project = m
250252
}
251-
conf.Project = m
252-
}
253-
254-
if dTrigger != nil {
255253
conf.Collection = aws.StringValue(dTrigger.Collection)
256254
conf.ServiceID = aws.StringValue(dTrigger.ServiceId)
257255
conf.OperationTypes = dTrigger.OperationTypes

cfn-resources/trigger/index.html

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"Name": "materializeMonthlyProductSales46",
2+
"Name": "cfn-test-trigger-${RANDOM_INT_100K}",
33
"Type": "DATABASE",
4-
"Profile": "default",
4+
"Profile": "${MONGODB_ATLAS_PROFILE}",
55
"DatabaseTrigger": {
66
"OperationTypes": [
77
"INSERT"
88
],
99
"Database": "store",
1010
"Collection": "sales",
11-
"ServiceId": "6387aee08659af5254b0a51e",
11+
"ServiceId": "${MONGODB_REALM_SERVICE_ID}",
1212
"FullDocument": "true",
1313
"FullDocumentBeforeChange": "false",
1414
"Unordered": "false",
@@ -20,14 +20,14 @@
2020
"EventProcessors": {
2121
"FUNCTION": {
2222
"FuncConfig": {
23-
"FunctionName": "cfn_func",
24-
"FunctionId": "63862553ac0702272aa701ba"
23+
"FunctionName": "${MONGODB_REALM_FUNCTION_NAME}",
24+
"FunctionId": "${MONGODB_REALM_FUNCTION_ID}"
2525
}
2626
},
2727
"AWSEVENTBRIDGE": {
2828
"AWSConfig": {}
2929
}
3030
},
31-
"AppId": "638624a5167f5659feb75971",
32-
"ProjectId": "625454459c4e6108393d650d"
31+
"AppId": "${MONGODB_REALM_APP_ID}",
32+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}"
3333
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"Name": "materializeMonthlyProductSales46",
2+
"Name": "cfn-test-trigger-${RANDOM_INT_100K}",
33
"Type": "DATABASE",
4-
"Profile": "default",
4+
"Profile": "${MONGODB_ATLAS_PROFILE}",
55
"DatabaseTrigger": {
66
"OperationTypes": [
77
"INSERT"
88
],
99
"Database": "store",
1010
"Collection": "sales",
11-
"ServiceId": "6387aee08659af5254b0a51e",
11+
"ServiceId": "${MONGODB_REALM_SERVICE_ID}",
1212
"FullDocument": "true",
1313
"FullDocumentBeforeChange": "false",
1414
"Unordered": "false",
@@ -20,14 +20,14 @@
2020
"EventProcessors": {
2121
"FUNCTION": {
2222
"FuncConfig": {
23-
"FunctionName": "cfn_func",
24-
"FunctionId": "63862553ac0702272aa701ba"
23+
"FunctionName": "${MONGODB_REALM_FUNCTION_NAME}",
24+
"FunctionId": "${MONGODB_REALM_FUNCTION_ID}"
2525
}
2626
},
2727
"AWSEVENTBRIDGE": {
2828
"AWSConfig": {}
2929
}
3030
},
31-
"AppId": "638624a5167f5659feb75971",
32-
"ProjectId": "625454459c4e6108393d650d"
31+
"AppId": "${MONGODB_REALM_APP_ID}",
32+
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}"
3333
}

0 commit comments

Comments
 (0)