-
Notifications
You must be signed in to change notification settings - Fork 2
/
profiles_waf.go
195 lines (155 loc) · 5.39 KB
/
profiles_waf.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
package main
import (
"encoding/json"
"fmt"
"github.com/EdgeCast/ec-sdk-go/edgecast"
"github.com/EdgeCast/ec-sdk-go/edgecast/rtld"
"github.com/EdgeCast/ec-sdk-go/edgecast/rtld/profiles_waf"
"github.com/EdgeCast/ec-sdk-go/edgecast/rtldmodels"
"github.com/fatih/color"
)
func main() {
// Setup
apiToken := "MY_API_TOKEN"
idsCredentials := edgecast.IDSCredentials{
ClientID: "CLIENT_ID",
ClientSecret: "CLIENT_SECRET",
Scope: "SCOPE",
}
sdkConfig := edgecast.NewSDKConfig()
sdkConfig.APIToken = apiToken
sdkConfig.IDSCredentials = idsCredentials
rtldService, err := rtld.New(sdkConfig)
if err != nil {
color.Red("error creating rtld Service: %v\n", err)
return
}
fmt.Println("")
color.Green("**** GET WAF CUSTOMER PROFILE ****")
fmt.Println("")
profileGetParam :=
profiles_waf.NewProfilesWafGetCustomerSettingsParams()
profileWafGetCustomerSettingsResp, err :=
rtldService.
ProfilesWaf.
ProfilesWafGetCustomerSettings(profileGetParam)
if err != nil {
color.Red("failed to get waf customer profile: %v\n", err)
return
}
color.Blue("successfully retrieved waf customer profile")
fmt.Printf(ShowAsJson("response:", profileWafGetCustomerSettingsResp))
fmt.Println("")
color.Green("**** GET WAF CUSTOMER PROFILE BY ID****")
fmt.Println("")
color.Blue("customerSettingsByIdParam")
customerSettingsByIdParam :=
profiles_waf.
NewProfilesWafGetCustomerSettingsByIDParams()
customerSettingsByIdParam.ID = 10869
color.Blue("ProfilesWafGetCustomerSettingsByID")
customerSettingsByIdResp, err :=
rtldService.
ProfilesWaf.
ProfilesWafGetCustomerSettingsByID(customerSettingsByIdParam)
if err != nil {
color.Red("failed to get waf customer profile: %v\n", err)
return
}
color.Blue("successfully retrieved waf customer profile")
fmt.Print(ShowAsJson("customerSettingsByIdResp", customerSettingsByIdResp))
fmt.Println("")
color.Green("**** ADD CUSTOMER SETTINGS ****")
fmt.Println("")
customerSettingsParam :=
profiles_waf.
NewProfilesWafAddCustomerSettingParams()
var settingDto rtldmodels.WafProfileDto
settingDto.DeliveryMethod = "http_post"
settingDto.Enabled = true
settingDto.LogFormat = "json"
settingDto.ProfileName = "testcname"
settingDto.Description = "waf rtld testing"
settingDto.Fields = []string{"account_number"}
var filters rtldmodels.RtldWafFiltersDto
filters.Cnames = []string{"somethig.com"}
filters.CnamesCondition = "in"
settingDto.Filters = &filters
var httpPost rtldmodels.RtldHTTPPostSettingDto
httpPost.AuthenticationType = "http_basic"
httpPost.DestinationEndpoint = "https://cnametest.com"
httpPost.Username = "testUser1"
httpPost.Password = "test123"
settingDto.HTTPPost = &httpPost
customerSettingsParam.SettingDto = &settingDto
color.Blue("Calling ProfilesWafAddCustomerSetting()")
customerSettingsAddResp, err :=
rtldService.
ProfilesWaf.
ProfilesWafAddCustomerSetting(customerSettingsParam)
if err != nil {
color.Red("failed to add waf customer profile: %v\n", err)
return
}
color.Blue("successfully added waf customer profile")
fmt.Printf(ShowAsJson("customerSettingsAddResp", customerSettingsAddResp))
fmt.Printf("new ID:%d", customerSettingsAddResp.ID)
fmt.Println("")
color.Green("**** UPDATE CUSTOMER SETTINGS ****")
fmt.Println("")
customerSettingsUpdateParam :=
profiles_waf.NewProfilesWafUpdateCustomerSettingParams()
var updateDto rtldmodels.BaseProfileDto
updateDto.DeliveryMethod = "http_post"
updateDto.Enabled = true
updateDto.LogFormat = "json"
updateDto.ProfileName = "testcname"
updateDto.Description = "waf rtld testing"
updateDto.Fields = []string{"account_number"}
var updfilters rtldmodels.RtldWafFiltersDto
updfilters.Cnames = []string{"something.com"}
updfilters.CnamesCondition = "in"
var updHttpPost rtldmodels.RtldHTTPPostSettingDto
updHttpPost.AuthenticationType = "http_basic"
updHttpPost.DestinationEndpoint = "https://cnametest.com"
updHttpPost.Username = "testUser2"
updHttpPost.Password = "test12345"
updateDto.HTTPPost = &httpPost
customerSettingsParam.SettingDto = &settingDto
customerSettingsUpdateParam.ID = customerSettingsAddResp.ID
customerSettingsUpdateParam.Body.BaseProfileDto = updateDto
color.Blue("Calling ProfilesWafAddCustomerSetting()")
customerSettingsUpdateResp, err :=
rtldService.
ProfilesWaf.
ProfilesWafUpdateCustomerSetting(customerSettingsUpdateParam)
if err != nil {
color.Red("failed to update waf customer profile: %v\n", err)
return
}
color.Blue("successfully updated waf customer profile")
fmt.Printf(ShowAsJson("customerSettingsUpdateResp", customerSettingsUpdateResp))
fmt.Println("")
color.Green("**** DELETE CUSTOMER SETTINGS ****")
fmt.Println("")
customerSettingsDelParam :=
profiles_waf.NewProfilesWafDeleteCustomerSettingsByIDParams()
customerSettingsDelParam.ID = customerSettingsAddResp.ID
color.Blue("Calling ProfilesWafAddCustomerSetting()")
customerSettingsDelResp, err :=
rtldService.
ProfilesWaf.
ProfilesWafDeleteCustomerSettingsByID(customerSettingsDelParam)
if err != nil {
color.Red("failed to delete waf customer profile: %v\n", err)
return
}
color.Blue("successfully deleted waf customer profile")
fmt.Printf(ShowAsJson("customerSettingsDelResp", customerSettingsDelResp))
}
func ShowAsJson(objName string, body interface{}) string {
fb, _ := json.MarshalIndent(body, "", " ")
s := fmt.Sprintf("Object: %s\n", objName)
s += fmt.Sprintf("Marshall as JSON:%s\n", fb)
return s
}