This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
/
ses.go
147 lines (131 loc) · 4.31 KB
/
ses.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package thundraaws
import (
"encoding/json"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/thundra-io/thundra-lambda-agent-go/application"
"github.com/thundra-io/thundra-lambda-agent-go/config"
"github.com/thundra-io/thundra-lambda-agent-go/constants"
"github.com/thundra-io/thundra-lambda-agent-go/tracer"
)
type sesIntegration struct{}
type sesData struct {
Data string
Charset string
}
type sesBody struct {
Text sesData
Html sesData
}
type sesDestination struct {
ToAddresses []string
CcAddresses []string
BccAddresses []string
}
type sesParams struct {
Source string
Destination interface{}
Subject sesData
Body sesBody
Template string
TemplateArn string
TemplateData string
}
type sesSendEmailParams struct {
Source string
Destination sesDestination
Message struct{
Body sesBody
Subject sesData
}
}
type sesSendRawEmailParams struct {
Source string
Destinations []string
RawMessage sesData
}
type sesSendTemplatedEmailParams struct {
Source string
Destination sesDestination
Template string
TemplateArn string
TemplateData string
}
func (i *sesIntegration) getSesInfo(r *request.Request) *sesParams {
fields := &sesParams{}
switch operationName := i.getOperationName(r); operationName {
case "SendEmail":
params := &sesSendEmailParams{}
m, err := json.Marshal(r.Params)
if err != nil { return &sesParams{} }
if err = json.Unmarshal(m, ¶ms); err != nil { return &sesParams{} }
fields.Source = params.Source
fields.Destination = params.Destination
fields.Subject = params.Message.Subject
fields.Body = params.Message.Body
case "SendRawEmail":
params := &sesSendRawEmailParams{}
m, err := json.Marshal(r.Params)
if err != nil { return &sesParams{} }
if err = json.Unmarshal(m, ¶ms); err != nil { return &sesParams{} }
fields.Source = params.Source
fields.Destination = params.Destinations
case "SendTemplatedEmail":
params := &sesSendTemplatedEmailParams{}
m, err := json.Marshal(r.Params)
if err != nil { return &sesParams{} }
if err = json.Unmarshal(m, ¶ms); err != nil { return &sesParams{} }
fields.Source = params.Source
fields.Destination = params.Destination
fields.Template = params.Template
fields.TemplateArn = params.TemplateArn
fields.TemplateData = params.TemplateData
}
return fields
}
func (i *sesIntegration) getOperationName(r *request.Request) string {
if r.Operation.Name != "" {
return r.Operation.Name
} else {
return constants.AWSServiceRequest
}
}
func (i *sesIntegration) beforeCall(r *request.Request, span *tracer.RawSpan) {
span.ClassName = constants.ClassNames["SES"]
span.DomainName = constants.DomainNames["MESSAGING"]
operationName := r.Operation.Name
operationType := getOperationType(operationName, constants.ClassNames["SES"])
sesInfo := i.getSesInfo(r)
tags := map[string]interface{}{
constants.SpanTags["OPERATION_TYPE"]: operationType,
constants.AwsSDKTags["REQUEST_NAME"]: operationName,
constants.SpanTags["TOPOLOGY_VERTEX"]: true,
constants.SpanTags["TRIGGER_OPERATION_NAMES"]: []string{application.FunctionName},
constants.SpanTags["TRIGGER_DOMAIN_NAME"]: constants.AwsLambdaApplicationDomain,
constants.SpanTags["TRIGGER_CLASS_NAME"]: constants.AwsLambdaApplicationClass,
}
if operationName == "SendEmail" && !config.MaskSESMail {
if sesInfo.Subject.Data != "" { tags[constants.AwsSESTags["SUBJECT"]] = sesInfo.Subject }
if sesInfo.Body.Text.Data != "" || sesInfo.Body.Html.Data != "" {
tags[constants.AwsSESTags["BODY"]] = sesInfo.Body
}
}
if operationName == "SendTemplatedEmail" {
if sesInfo.Template != "" { tags[constants.AwsSESTags["TEMPLATE_NAME"]] = sesInfo.Template }
if sesInfo.TemplateArn != "" { tags[constants.AwsSESTags["TEMPLATE_ARN"]] = sesInfo.TemplateArn }
if sesInfo.TemplateData != "" && !config.MaskSESMail {
tags[constants.AwsSESTags["TEMPLATE_DATA"]] = sesInfo.TemplateData
}
}
if sesInfo.Source != "" { tags[constants.AwsSESTags["SOURCE"]] = sesInfo.Source }
if !config.MaskSESDestination {
if _, isArr := sesInfo.Destination.([]string); (isArr && len(sesInfo.Destination.([]string)) > 0) || !isArr {
tags[constants.AwsSESTags["DESTINATION"]] = sesInfo.Destination
}
}
span.Tags = tags
}
func (i *sesIntegration) afterCall(r *request.Request, span *tracer.RawSpan) {
}
func init() {
integrations["SES"] = &sesIntegration{}
}