-
Notifications
You must be signed in to change notification settings - Fork 69
/
connectors.go
391 lines (351 loc) · 19.2 KB
/
connectors.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
package datastream
import (
"regexp"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
type (
// S3Connector provides details about the Amazon S3 destination in a stream
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
S3Connector struct {
DestinationType DestinationType `json:"destinationType"`
AccessKey string `json:"accessKey"`
Bucket string `json:"bucket"`
DisplayName string `json:"displayName"`
Path string `json:"path"`
Region string `json:"region"`
SecretAccessKey string `json:"secretAccessKey"`
}
// AzureConnector provides details about the Azure Storage destination configuration in a data stream
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
AzureConnector struct {
DestinationType DestinationType `json:"destinationType"`
AccessKey string `json:"accessKey"`
AccountName string `json:"accountName"`
DisplayName string `json:"displayName"`
ContainerName string `json:"containerName"`
Path string `json:"path"`
}
// DatadogConnector provides detailed information about Datadog destination
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
DatadogConnector struct {
DestinationType DestinationType `json:"destinationType"`
AuthToken string `json:"authToken"`
CompressLogs bool `json:"compressLogs"`
DisplayName string `json:"displayName"`
Service string `json:"service,omitempty"`
Source string `json:"source,omitempty"`
Tags string `json:"tags,omitempty"`
Endpoint string `json:"endpoint"`
}
// SplunkConnector provides detailed information about the Splunk destination
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
SplunkConnector struct {
DestinationType DestinationType `json:"destinationType"`
CompressLogs bool `json:"compressLogs"`
DisplayName string `json:"displayName"`
EventCollectorToken string `json:"eventCollectorToken"`
Endpoint string `json:"endpoint"`
CustomHeaderName string `json:"customHeaderName,omitempty"`
CustomHeaderValue string `json:"customHeaderValue,omitempty"`
TLSHostname string `json:"tlsHostname,omitempty"`
CACert string `json:"caCert,omitempty"`
ClientCert string `json:"clientCert,omitempty"`
ClientKey string `json:"clientKey,omitempty"`
}
// GCSConnector provides detailed information about the Google Cloud Storage destination
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
GCSConnector struct {
DestinationType DestinationType `json:"destinationType"`
Bucket string `json:"bucket"`
DisplayName string `json:"displayName"`
Path string `json:"path,omitempty"`
PrivateKey string `json:"privateKey"`
ProjectID string `json:"projectId"`
ServiceAccountName string `json:"serviceAccountName"`
}
// CustomHTTPSConnector provides detailed information about the custom HTTPS endpoint
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
CustomHTTPSConnector struct {
DestinationType DestinationType `json:"destinationType"`
AuthenticationType AuthenticationType `json:"authenticationType"`
CompressLogs bool `json:"compressLogs"`
DisplayName string `json:"displayName"`
Password string `json:"password,omitempty"`
Endpoint string `json:"endpoint"`
UserName string `json:"userName,omitempty"`
ContentType string `json:"contentType,omitempty"`
CustomHeaderName string `json:"customHeaderName,omitempty"`
CustomHeaderValue string `json:"customHeaderValue,omitempty"`
TLSHostname string `json:"tlsHostname,omitempty"`
CACert string `json:"caCert,omitempty"`
ClientCert string `json:"clientCert,omitempty"`
ClientKey string `json:"clientKey,omitempty"`
}
// SumoLogicConnector provides detailed information about the Sumo Logic destination
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
SumoLogicConnector struct {
DestinationType DestinationType `json:"destinationType"`
CollectorCode string `json:"collectorCode"`
CompressLogs bool `json:"compressLogs"`
DisplayName string `json:"displayName"`
Endpoint string `json:"endpoint"`
ContentType string `json:"contentType,omitempty"`
CustomHeaderName string `json:"customHeaderName,omitempty"`
CustomHeaderValue string `json:"customHeaderValue,omitempty"`
}
// OracleCloudStorageConnector provides details about the Oracle Cloud Storage destination
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
OracleCloudStorageConnector struct {
DestinationType DestinationType `json:"destinationType"`
AccessKey string `json:"accessKey"`
Bucket string `json:"bucket"`
DisplayName string `json:"displayName"`
Namespace string `json:"namespace"`
Path string `json:"path"`
Region string `json:"region"`
SecretAccessKey string `json:"secretAccessKey"`
}
// LogglyConnector contains details about Loggly destination.
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
LogglyConnector struct {
DestinationType DestinationType `json:"destinationType"`
DisplayName string `json:"displayName"`
Endpoint string `json:"endpoint"`
AuthToken string `json:"authToken"`
Tags string `json:"tags,omitempty"`
ContentType string `json:"contentType,omitempty"`
CustomHeaderName string `json:"customHeaderName,omitempty"`
CustomHeaderValue string `json:"customHeaderValue,omitempty"`
}
// NewRelicConnector contains details about New Relic destination.
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
NewRelicConnector struct {
DestinationType DestinationType `json:"destinationType"`
DisplayName string `json:"displayName"`
Endpoint string `json:"endpoint"`
AuthToken string `json:"authToken"`
ContentType string `json:"contentType,omitempty"`
CustomHeaderName string `json:"customHeaderName,omitempty"`
CustomHeaderValue string `json:"customHeaderValue,omitempty"`
}
// ElasticsearchConnector contains details about Elasticsearch destination.
// See: https://techdocs.akamai.com/datastream2/v2/reference/post-stream
ElasticsearchConnector struct {
DestinationType DestinationType `json:"destinationType"`
DisplayName string `json:"displayName"`
Endpoint string `json:"endpoint"`
IndexName string `json:"indexName"`
UserName string `json:"userName"`
Password string `json:"password"`
ContentType string `json:"contentType,omitempty"`
CustomHeaderName string `json:"customHeaderName,omitempty"`
CustomHeaderValue string `json:"customHeaderValue,omitempty"`
TLSHostname string `json:"tlsHostname,omitempty"`
CACert string `json:"caCert,omitempty"`
ClientCert string `json:"clientCert,omitempty"`
ClientKey string `json:"clientKey,omitempty"`
}
// DestinationType is used to create an "enum" of possible DestinationTypes
DestinationType string
// AuthenticationType is used to create an "enum" of possible AuthenticationTypes of the CustomHTTPSConnector
AuthenticationType string
)
const (
// DestinationTypeAzure const
DestinationTypeAzure DestinationType = "AZURE"
// DestinationTypeS3 const
DestinationTypeS3 DestinationType = "S3"
// DestinationTypeDataDog const
DestinationTypeDataDog DestinationType = "DATADOG"
// DestinationTypeSplunk const
DestinationTypeSplunk DestinationType = "SPLUNK"
// DestinationTypeGcs const
DestinationTypeGcs DestinationType = "GCS"
// DestinationTypeHTTPS const
DestinationTypeHTTPS DestinationType = "HTTPS"
// DestinationTypeSumoLogic const
DestinationTypeSumoLogic DestinationType = "SUMO_LOGIC"
// DestinationTypeOracle const
DestinationTypeOracle DestinationType = "Oracle_Cloud_Storage"
// DestinationTypeLoggly const
DestinationTypeLoggly DestinationType = "LOGGLY"
// DestinationTypeNewRelic const
DestinationTypeNewRelic DestinationType = "NEWRELIC"
// DestinationTypeElasticsearch const
DestinationTypeElasticsearch DestinationType = "ELASTICSEARCH"
// AuthenticationTypeNone const
AuthenticationTypeNone AuthenticationType = "NONE"
// AuthenticationTypeBasic const
AuthenticationTypeBasic AuthenticationType = "BASIC"
)
var customHeaderNameRegexp = regexp.MustCompile("^[A-Za-z0-9_-]+$")
// SetDestinationType for S3Connector
func (c *S3Connector) SetDestinationType() {
c.DestinationType = DestinationTypeS3
}
// Validate validates S3Connector
func (c *S3Connector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeS3)),
"AccessKey": validation.Validate(c.AccessKey, validation.Required),
"Bucket": validation.Validate(c.Bucket, validation.Required),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Path": validation.Validate(c.Path, validation.Required),
"Region": validation.Validate(c.Region, validation.Required),
"SecretAccessKey": validation.Validate(c.SecretAccessKey, validation.Required),
}.Filter()
}
// SetDestinationType for AzureConnector
func (c *AzureConnector) SetDestinationType() {
c.DestinationType = DestinationTypeAzure
}
// Validate validates AzureConnector
func (c *AzureConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeAzure)),
"AccessKey": validation.Validate(c.AccessKey, validation.Required),
"AccountName": validation.Validate(c.AccountName, validation.Required),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"ContainerName": validation.Validate(c.ContainerName, validation.Required),
"Path": validation.Validate(c.Path, validation.Required),
}.Filter()
}
// SetDestinationType for DatadogConnector
func (c *DatadogConnector) SetDestinationType() {
c.DestinationType = DestinationTypeDataDog
}
// Validate validates DatadogConnector
func (c *DatadogConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeDataDog)),
"AuthToken": validation.Validate(c.AuthToken, validation.Required),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
}.Filter()
}
// SetDestinationType for SplunkConnector
func (c *SplunkConnector) SetDestinationType() {
c.DestinationType = DestinationTypeSplunk
}
// Validate validates SplunkConnector
func (c *SplunkConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeSplunk)),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"EventCollectorToken": validation.Validate(c.EventCollectorToken, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
"CustomHeaderName": validation.Validate(c.CustomHeaderName, validation.Required.When(c.CustomHeaderValue != ""), validation.When(c.CustomHeaderName != "", validation.Match(customHeaderNameRegexp))),
"CustomHeaderValue": validation.Validate(c.CustomHeaderValue, validation.Required.When(c.CustomHeaderName != "")),
}.Filter()
}
// SetDestinationType for GCSConnector
func (c *GCSConnector) SetDestinationType() {
c.DestinationType = DestinationTypeGcs
}
// Validate validates GCSConnector
func (c *GCSConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeGcs)),
"Bucket": validation.Validate(c.Bucket, validation.Required),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"PrivateKey": validation.Validate(c.PrivateKey, validation.Required),
"ProjectID": validation.Validate(c.ProjectID, validation.Required),
"ServiceAccountName": validation.Validate(c.ServiceAccountName, validation.Required),
}.Filter()
}
// SetDestinationType for CustomHTTPSConnector
func (c *CustomHTTPSConnector) SetDestinationType() {
c.DestinationType = DestinationTypeHTTPS
}
// Validate validates CustomHTTPSConnector
func (c *CustomHTTPSConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeHTTPS)),
"AuthenticationType": validation.Validate(c.AuthenticationType, validation.Required, validation.In(AuthenticationTypeBasic, AuthenticationTypeNone)),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
"UserName": validation.Validate(c.UserName, validation.Required.When(c.AuthenticationType == AuthenticationTypeBasic)),
"Password": validation.Validate(c.Password, validation.Required.When(c.AuthenticationType == AuthenticationTypeBasic)),
"CustomHeaderName": validation.Validate(c.CustomHeaderName, validation.Required.When(c.CustomHeaderValue != ""), validation.When(c.CustomHeaderName != "", validation.Match(customHeaderNameRegexp))),
"CustomHeaderValue": validation.Validate(c.CustomHeaderValue, validation.Required.When(c.CustomHeaderName != "")),
}.Filter()
}
// SetDestinationType for SumoLogicConnector
func (c *SumoLogicConnector) SetDestinationType() {
c.DestinationType = DestinationTypeSumoLogic
}
// Validate validates SumoLogicConnector
func (c *SumoLogicConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeSumoLogic)),
"CollectorCode": validation.Validate(c.CollectorCode, validation.Required),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
"CustomHeaderName": validation.Validate(c.CustomHeaderName, validation.Required.When(c.CustomHeaderValue != ""), validation.When(c.CustomHeaderName != "", validation.Match(customHeaderNameRegexp))),
"CustomHeaderValue": validation.Validate(c.CustomHeaderValue, validation.Required.When(c.CustomHeaderName != "")),
}.Filter()
}
// SetDestinationType for OracleCloudStorageConnector
func (c *OracleCloudStorageConnector) SetDestinationType() {
c.DestinationType = DestinationTypeOracle
}
// Validate validates OracleCloudStorageConnector
func (c *OracleCloudStorageConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeOracle)),
"AccessKey": validation.Validate(c.AccessKey, validation.Required),
"Bucket": validation.Validate(c.Bucket, validation.Required),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Namespace": validation.Validate(c.Namespace, validation.Required),
"Path": validation.Validate(c.Path, validation.Required),
"Region": validation.Validate(c.Region, validation.Required),
"SecretAccessKey": validation.Validate(c.SecretAccessKey, validation.Required),
}.Filter()
}
// SetDestinationType for LogglyConnector
func (c *LogglyConnector) SetDestinationType() {
c.DestinationType = DestinationTypeLoggly
}
// Validate validates LogglyConnector
func (c *LogglyConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeLoggly)),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
"AuthToken": validation.Validate(c.AuthToken, validation.Required),
"CustomHeaderName": validation.Validate(c.CustomHeaderName, validation.Required.When(c.CustomHeaderValue != ""), validation.When(c.CustomHeaderName != "", validation.Match(customHeaderNameRegexp))),
"CustomHeaderValue": validation.Validate(c.CustomHeaderValue, validation.Required.When(c.CustomHeaderName != "")),
}.Filter()
}
// SetDestinationType for NewRelicConnector
func (c *NewRelicConnector) SetDestinationType() {
c.DestinationType = DestinationTypeNewRelic
}
// Validate validates NewRelicConnector
func (c *NewRelicConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeNewRelic)),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
"AuthToken": validation.Validate(c.AuthToken, validation.Required),
"CustomHeaderName": validation.Validate(c.CustomHeaderName, validation.Required.When(c.CustomHeaderValue != ""), validation.When(c.CustomHeaderName != "", validation.Match(customHeaderNameRegexp))),
"CustomHeaderValue": validation.Validate(c.CustomHeaderValue, validation.Required.When(c.CustomHeaderName != "")),
}.Filter()
}
// SetDestinationType for ElasticsearchConnector
func (c *ElasticsearchConnector) SetDestinationType() {
c.DestinationType = DestinationTypeElasticsearch
}
// Validate validates ElasticsearchConnector
func (c *ElasticsearchConnector) Validate() error {
return validation.Errors{
"DestinationType": validation.Validate(c.DestinationType, validation.Required, validation.In(DestinationTypeElasticsearch)),
"DisplayName": validation.Validate(c.DisplayName, validation.Required),
"Endpoint": validation.Validate(c.Endpoint, validation.Required),
"UserName": validation.Validate(c.UserName, validation.Required),
"Password": validation.Validate(c.Password, validation.Required),
"IndexName": validation.Validate(c.IndexName, validation.Required),
"CustomHeaderName": validation.Validate(c.CustomHeaderName, validation.Required.When(c.CustomHeaderValue != ""), validation.When(c.CustomHeaderName != "", validation.Match(customHeaderNameRegexp))),
"CustomHeaderValue": validation.Validate(c.CustomHeaderValue, validation.Required.When(c.CustomHeaderName != "")),
}.Filter()
}