Skip to content

Commit ef26688

Browse files
authored
Merge pull request #72 from catchpoint/feature_synthetic
Feature synthetic to master
2 parents b9cb20d + e79a157 commit ef26688

37 files changed

+8004
-1243
lines changed

catchpoint/catchpoint_client.go

Lines changed: 1243 additions & 62 deletions
Large diffs are not rendered by default.

catchpoint/config.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
11
package catchpoint
22

33
const (
4-
catchpointTestURIProd = "https://io.catchpoint.com/api/v2/tests"
5-
catchpointTestURIStage = "https://iostage.catchpoint.com/api/v2/tests"
6-
catchpointTestURIQa = "https://ioqa.catchpoint.com/api/v2/tests"
4+
catchpointTestURIProd = "https://io.catchpoint.com/api/v3.3/tests"
5+
catchpointTestURIStage = "https://iostage.catchpoint.com/api/v3.3/tests"
6+
catchpointTestURIQa = "https://ioqa.catchpoint.com/api/v3.3/tests"
7+
catchpointProductURIProd = "https://io.catchpoint.com/api/v3.3/products"
8+
catchpointProductURIStage = "https://iostage.catchpoint.com/api/v3.3/products"
9+
catchpointProductURIQa = "https://ioqa.catchpoint.com/api/v3.3/products"
10+
catchpointFolderURIProd = "https://io.catchpoint.com/api/v3.3/folders"
11+
catchpointFolderURIStage = "https://iostage.catchpoint.com/api/v3.3/folders"
12+
catchpointFolderURIQa = "https://ioqa.catchpoint.com/api/v3.3/folders"
713
)
814

9-
var catchpointTestURI = "https://io.catchpoint.com/api/v2/tests"
15+
var catchpointTestURI = "https://io.catchpoint.com/api/v3.3/tests"
16+
var catchpointProductURI = "https://io.catchpoint.com/api/v3.3/products"
17+
var catchpointFolderURI = "https://io.catchpoint.com/api/v3.3/folders"
18+
var catchpointEnvironment string
1019

1120
func setTestUriByEnv(environment string) {
1221

1322
switch environment {
1423
case "prod", "":
1524
catchpointTestURI = catchpointTestURIProd
25+
catchpointProductURI = catchpointProductURIProd
26+
catchpointFolderURI = catchpointFolderURIProd
1627
case "stage":
1728
catchpointTestURI = catchpointTestURIStage
29+
catchpointProductURI = catchpointProductURIStage
30+
catchpointFolderURI = catchpointFolderURIStage
1831
case "qa":
1932
catchpointTestURI = catchpointTestURIQa
33+
catchpointProductURI = catchpointProductURIQa
34+
catchpointFolderURI = catchpointFolderURIQa
2035
default:
2136
catchpointTestURI = catchpointTestURIProd
37+
catchpointProductURI = catchpointProductURIProd
38+
catchpointFolderURI = catchpointFolderURIProd
2239
}
2340
}
41+
42+
func setEnvVariable(environment string) {
43+
catchpointEnvironment = environment
44+
}

catchpoint/flatten_all_test_type.go

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func flattenThresholds(thresholds Thresholds) []interface{} {
3030
}
3131
return []interface{}{thresholdsMap}
3232
}
33+
3334
func flattenHttpHeaderRequests(requestSetting RequestSetting) []interface{} {
3435
httpHeaderRequests := make([]interface{}, 0, len(requestSetting.HttpHeaderRequests))
3536
for _, header := range requestSetting.HttpHeaderRequests {
@@ -39,12 +40,20 @@ func flattenHttpHeaderRequests(requestSetting RequestSetting) []interface{} {
3940
"value": header.RequestValue,
4041
"child_host_pattern": header.ChildHostPattern,
4142
}
43+
if header.HeaderName == "Sni-Override" {
44+
key = "sni_override"
45+
userAgentHeader["header_name"] = header.HeaderName
46+
} else if header.RequestHeaderType.Name == "Custom" {
47+
key = "custom"
48+
userAgentHeader["header_name"] = header.HeaderName
49+
}
4250
httpHeaderRequests = append(httpHeaderRequests, map[string]interface{}{
4351
key: []interface{}{userAgentHeader},
4452
})
4553
}
4654
return httpHeaderRequests
4755
}
56+
4857
func flattenRequestSetting(requestSetting RequestSetting) []interface{} {
4958
requestSettingMap := map[string]interface{}{
5059
"authentication": flattenAuthenticationStruct(requestSetting.Authentication),
@@ -106,6 +115,9 @@ func flattenScheduleSetting(scheduleSetting ScheduleSetting) []interface{} {
106115
nodeGroups := make([]int, len(scheduleSetting.NodeGroups))
107116
for i, group := range scheduleSetting.NodeGroups {
108117
nodeGroups[i] = group.Id
118+
if group.NodeGroupId != 0 {
119+
nodeGroups[i] = group.NodeGroupId
120+
}
109121
}
110122

111123
if len(nodeGroups) > 0 {
@@ -203,21 +215,18 @@ func flattenNotificationGroup(notificationGroup NotificationGroupStruct, include
203215
}
204216

205217
var recipients []string
206-
var contactGroups []string
207218
for _, recipient := range notificationGroup.Recipients {
208219
recipientFlattened := flattenRecipient(recipient)
209220
var value = recipientFlattened["email"].(string)
210221
if isValidEmail(value) {
211222
recipients = append(recipients, value)
212-
} else {
213-
contactGroups = append(contactGroups, value)
214223
}
215224
}
216225

217226
notifGroupMap := map[string]interface{}{
218227
"recipient_email_ids": recipients,
219228
"subject": notificationGroup.Subject,
220-
"contact_groups": contactGroups,
229+
"contact_groups": flattenContactGroup(notificationGroup.Recipients),
221230
}
222231

223232
if includeNotify {
@@ -232,6 +241,28 @@ func flattenNotificationGroup(notificationGroup NotificationGroupStruct, include
232241
return []interface{}{notifGroupMap}
233242
}
234243

244+
func flattenContactGroup(recipients []Recipient) []interface{} {
245+
var contactGroups []interface{}
246+
247+
for _, recipient := range recipients {
248+
recipientFlattened := flattenRecipient(recipient)
249+
recipientType, ok := recipientFlattened["recipientType"].(string)
250+
if ok && strings.Contains(recipientType, "ContactGroup") {
251+
252+
contactGroupMap := map[string]interface{}{}
253+
if contactGroupID, ok := recipientFlattened["id"].(int); ok {
254+
contactGroupMap["contact_group_id"] = contactGroupID
255+
}
256+
if contactGroupName, ok := recipientFlattened["name"].(string); ok {
257+
contactGroupMap["contact_group_name"] = contactGroupName
258+
}
259+
260+
contactGroups = append(contactGroups, contactGroupMap)
261+
}
262+
}
263+
return contactGroups
264+
}
265+
235266
func flattenAlertRuleNotificationGroup(notificationGroups []NotificationGroupStruct, includeNotify bool) []interface{} {
236267
var flattenedGroups []interface{}
237268

@@ -328,6 +359,7 @@ func flattenAlertGroupStruct(alertGroup AlertGroupStruct) []interface{} {
328359
alertGroupMap := map[string]interface{}{
329360
"notification_group": flattenNotificationGroup(alertGroup.NotificationGroup, false),
330361
"alert_rule": alertGroupItems,
362+
"alert_setting_type": getAlertSettingTypeName(alertGroup.AlertSettingType.Id),
331363
}
332364
return []interface{}{alertGroupMap}
333365
}
@@ -342,8 +374,12 @@ func flattenTest(test *Test) map[string]interface{} {
342374
if test.UserAgentType != nil {
343375
userAgentType = getUserAgentTypeName(test.UserAgentType.Id)
344376
}
377+
chromeVersion = test.ApplicationVersion
345378
if test.ChromeMonitorVersion != nil {
346-
chromeVersion = strings.ToLower(test.ChromeMonitorVersion.ApplicationVersionType.Name)
379+
name := test.ChromeMonitorVersion.ApplicationVersionType.Name
380+
if name == "Stable" || name == "Preview" {
381+
chromeVersion = strings.ToLower(name)
382+
}
347383
}
348384
testMap := map[string]interface{}{
349385
"id": test.Id,
@@ -384,5 +420,47 @@ func flattenTest(test *Test) map[string]interface{} {
384420
testMap["test_script_type"] = strings.ToLower(test.TestRequestData.TransactionScriptType.Name)
385421
}
386422
}
423+
if test.CertificateName != "" {
424+
testMap["certificate_name"] = test.CertificateName
425+
}
426+
if test.CertificateThumbprintValue != "" {
427+
testMap["certificate_thumbprint_value"] = test.CertificateThumbprintValue
428+
}
429+
if test.PublicKeyThumbprintValue != "" {
430+
testMap["public_key_thumbprint_value"] = test.PublicKeyThumbprintValue
431+
}
387432
return testMap
388433
}
434+
435+
func flattenProduct(product *Product) map[string]interface{} {
436+
productMap := map[string]interface{}{
437+
"id": product.Id,
438+
"division_id": product.DivisionId,
439+
"product_name": product.Name,
440+
"status": strings.ToLower(product.Status.Name),
441+
"alert_group_id": product.AlertGroupId,
442+
"test_data_webhook_id": product.TestDataWebhookId,
443+
"request_settings": flattenRequestSetting(product.RequestSettings),
444+
"alert_settings": flattenAlertGroupStruct(product.AlertGroup),
445+
"insights": flattenInsightDataStruct(product.InsightData),
446+
"schedule_settings": flattenScheduleSetting(product.ScheduleSettings),
447+
"advanced_settings": flattenAdvancedSetting(product.AdvancedSettings),
448+
}
449+
return productMap
450+
}
451+
452+
func flattenFolder(folder *Folder) map[string]interface{} {
453+
folderMap := map[string]interface{}{
454+
"id": folder.Id,
455+
"division_id": folder.DivisionId,
456+
"product_id": folder.ProductId,
457+
"parent_id": folder.ParentId,
458+
"folder_name": folder.Name,
459+
"request_settings": flattenRequestSetting(folder.RequestSettings),
460+
"alert_settings": flattenAlertGroupStruct(folder.AlertGroup),
461+
"insights": flattenInsightDataStruct(folder.InsightData),
462+
"schedule_settings": flattenScheduleSetting(folder.ScheduleSettings),
463+
"advanced_settings": flattenAdvancedSetting(folder.AdvancedSettings),
464+
}
465+
return folderMap
466+
}

0 commit comments

Comments
 (0)