@@ -33,11 +33,11 @@ const contentType = "application/cloudevents+json"
33
33
type ceBinaryStructure struct {
34
34
ID string `json:"id"`
35
35
Type string `json:"type"`
36
- Time string `json:"time"`
37
36
Source string `json:"source"`
38
37
Specversion string `json:"specversion"`
39
- Contenttype string `json:"datacontenttype"`
40
- Data interface {} `json:"data"`
38
+ Time string `json:"time,omitempty"`
39
+ Contenttype string `json:"datacontenttype,omitempty"`
40
+ Data interface {} `json:"data,omitempty"`
41
41
}
42
42
43
43
// CloudEvent is a data structure required to map KLR responses to cloudevents
@@ -46,6 +46,10 @@ type CloudEvent struct {
46
46
// only data payload or full event in binary format
47
47
FunctionResponseMode string `envconfig:"function_response_mode" default:"data"`
48
48
49
+ Overrides Overrides `envconfig:"overrides"`
50
+ }
51
+
52
+ type Overrides struct {
49
53
EventType string `envconfig:"type" default:"ce.klr.triggermesh.io"`
50
54
Source string `envconfig:"source" default:"knative-lambda-runtime"`
51
55
Subject string `envconfig:"subject" default:"klr-response"`
@@ -67,7 +71,7 @@ func (ce *CloudEvent) Response(data []byte) ([]byte, error) {
67
71
// If response format is set to CloudEvents
68
72
// and CE_TYPE is empty,
69
73
// then reply with the empty response
70
- if ce .EventType == "" {
74
+ if ce .Overrides . EventType == "" {
71
75
return nil , nil
72
76
}
73
77
@@ -88,9 +92,9 @@ func (ce *CloudEvent) Response(data []byte) ([]byte, error) {
88
92
89
93
b := ceBinaryStructure {
90
94
ID : uuid .NewString (),
91
- Type : ce .EventType ,
95
+ Type : ce .Overrides . EventType ,
92
96
Time : time .Now ().Format (time .RFC3339 ),
93
- Source : ce .Source ,
97
+ Source : ce .Overrides . Source ,
94
98
Specversion : "1.0" ,
95
99
Contenttype : contentType ,
96
100
Data : body ,
@@ -104,14 +108,16 @@ func (ce *CloudEvent) fillInContext(data []byte) ([]byte, error) {
104
108
return nil , fmt .Errorf ("cannot unmarshal function response into binary CE: %w" , err )
105
109
}
106
110
107
- switch {
108
- case response .ID == "" :
111
+ if response .ID == "" {
109
112
response .ID = uuid .NewString ()
110
- case response .Type == "" :
111
- response .Type = ce .EventType
112
- case response .Source == "" :
113
- response .Source = ce .Source
114
- case response .Specversion == "" :
113
+ }
114
+ if response .Type == "" {
115
+ response .Type = ce .Overrides .EventType
116
+ }
117
+ if response .Source == "" {
118
+ response .Source = ce .Overrides .Source
119
+ }
120
+ if response .Specversion == "" {
115
121
response .Specversion = "1.0"
116
122
}
117
123
0 commit comments