-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwaf.py
274 lines (247 loc) · 10.7 KB
/
waf.py
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
#
# kt cloud SDK v1.0
#
# Copyright (c) 2020 kt corp. All rights reserved.
#
# This is a proprietary software of kt corp
# and you may not use this file except in compliance
# with license agreement with kt corp.
# Any redistribution or use of this software,
# with or without modification shall be strictly
# prohibited without prior written approval of kt corp,
# and the copyright notice above does not evidence
# any actual or intended publication of such software.
#
import common as c
def createWAF(**kargs):
""" Create a new KT Cloud WAF.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
- name(String, Required): WAF Name(max.63 length, english+(english,number,'-'))
- type(String, Required): compositon[ single | dual ]
- spec(String, Required): specification, select[ basic | standard | advanced | premiun ]
- waf1consoleport(String, Required): WAF1 VM console connection port (5950~5999)
- waf1sshport(String, Required): WAF1 VM ssh connection port (5950~5999)
- waf1dbport(String, Required): WAF1 VM DB connection port (5950~5999)
* Examples: print(waf.createWAF( zone='KR-CA', name='sdktest3', type='single', spec='standard', waf1consoleport='5997', waf1sshport='5998', waf1dbport='5999'))
"""
my_apikey, my_secretkey = c.read_config()
if not 'zone' in kargs:
return c.printZoneHelp()
if not 'name' in kargs:
return '[ktcloud] Missing required argument "name" '
if not 'type' in kargs:
return '[ktcloud] Missing required argument "type" '
if not 'spec' in kargs:
return '[ktcloud] Missing required argument "spec" '
if not 'waf1consoleport' in kargs:
return '[ktcloud] Missing required argument "waf1consoleport" '
if not 'waf1sshport' in kargs:
return '[ktcloud] Missing required argument "waf1sshport" '
if not 'waf1dbport' in kargs:
return '[ktcloud] Missing required argument "waf1dbport" '
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'createWAF'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
def listWAFs(**kargs):
""" List the KT Cloud WAFs.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
* Examples: print(waf.listWAFs(zone='KR-M'))
"""
my_apikey, my_secretkey = c.read_config()
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'listWAFs'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest_debug(kargs, baseurl, my_secretkey)
def deleteWAF(**kargs):
""" Delete a KT Cloud WAF.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
- id(String, Required): WAF ID
* Examples: print(waf.deleteWAF(zone='KR-M', id='3105'))
"""
my_apikey, my_secretkey = c.read_config()
if not 'zone' in kargs:
return c.printZoneHelp()
if not 'id' in kargs:
return '[ktcloud] Missing required argument "id" (waf id)'
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'deleteWAF'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
def addWAFWebServer(**kargs):
""" Add a WebServer to protect by KT Cloud WAF.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
- id(String, Required): WAF ID
- vmid(String, Required): virtualmachine ID
- webserverport(String, Required): web server service port
- proxyport1(String, Required): RVM to WAF VM1 connection port
- sslmode(String, Required): select[ disabled | sslthru | sslterm ]
- proxyport2(String, Optional): (Dual Product) RVM to WAF VM2 connection port
- loadbalancerid(String, Optional): (Single Product) RVM to LB connection loadbalancerID
* Examples:
- waf.addWAFWebServer(id='3046', zoneid='95e2f517-d64a-4866-8585-5177c256f7c7', virtualmachineid='4930ed0f-2967-11eb-891c-90e2bad10000', webserverport='80', proxyport1='80', proxyport2='81', sslmode='disabled')
"""
my_apikey, my_secretkey = c.read_config()
if not 'zone' in kargs:
return c.printZoneHelp()
if not 'id' in kargs:
return '[ktcloud] Missing required argument "id" '
if not 'vmid' in kargs:
return '[ktcloud] Missing required argument "vmid" '
if not 'webserverport' in kargs:
return '[ktcloud] Missing required argument "webserverport" '
if not 'proxyport1' in kargs:
return '[ktcloud] Missing required argument "proxyport1" '
if not 'sslmode' in kargs:
return '[ktcloud] Missing required argument "sslmode" (disabled | sslthru | sslterm)'
ZoneName = kargs['zone']
del kargs['zone']
kargs['virtualmachineid'] = kargs['vmid']
del kargs['vmid']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'addWAFWebServer'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
def listWAFWebServers(**kargs):
""" List the WebServers to protect by KT Cloud WAF.
* Args:
- id(String, Required): WAF ID
- zone(String, Optional) : [KR-CA, KR-CB, KR-M, KR-M2]
* Examples: print(waf.listWAFWebServers(zone='KR-M2', id='3108'))
"""
my_apikey, my_secretkey = c.read_config()
if not 'zone' in kargs:
return c.printZoneHelp()
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'listWAFWebServers'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
def removeWAFWebServer(**kargs):
""" Remove a WebServer to protect by KT Cloud WAF.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
- id(String, Required): WAF ID
- webserverid(String, Required): webserver ID. see listWAFWebServers
* Examples: print(waf.removeWAFWebServer(zone='KR-M', id='3107', webserverid='8802'))
"""
my_apikey, my_secretkey = c.read_config()
if not 'id' in kargs:
return '[ktcloud] Missing required argument "id" '
if not 'webserverid' in kargs:
return '[ktcloud] Missing required argument "webserverid '
if 'zone' in kargs:
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
else:
baseurl = c.geturl(ctype='waf', m2=False)
kargs['command'] = 'removeWAFWebServer'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
def addWAFWebSite(**kargs):
""" Add a WebSite to protect by KT Cloud WAF.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
- id(String, Required): WAF ID
- sitename(String, Required): site name or IP
- port(String, Required): service port
- policynum(String, Required): security policy, select[ 0: standard | 1: basic | 2: detection only| 3: pass ]
* Examples: print(waf.addWAFWebSite(zone='KR-M', id='3107', sitename='test.com', port='80', policynum='0'))
"""
my_apikey, my_secretkey = c.read_config()
if not 'zone' in kargs:
return c.printZoneHelp()
if not 'id' in kargs:
return '[ktcloud] Missing required argument \"id\" '
if not 'sitename' in kargs:
return '[ktcloud] Missing required argument \"sitename\" '
if not 'port' in kargs:
return '[ktcloud] Missing required argument \"port\" '
if not 'policynum' in kargs:
return '[ktcloud] Missing required argument \"policynum\" (0: standard | 1: basic | 2: detection only| 3: pass) '
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'addWAFWebSite'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
def listWAFWebSites(**kargs):
""" List the WebSites to protect by KT Cloud WAF.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
- id(String, Required): WAF ID
- websiteid(String, Required): Website ID
* Examples: print(waf.removeWAFWebSite(zone='KR-M', id='3108', websiteid='7658'))
"""
my_apikey, my_secretkey = c.read_config()
if not 'zone' in kargs:
return c.printZoneHelp()
if not 'id' in kargs:
return '[ktcloud] Missing required argument \"id\" '
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'listWAFWebSites'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
def removeWAFWebSite(**kargs):
""" Remove a WebSite to protect by KT Cloud WAF.
* Args:
- zone(String, Required) : [KR-CA, KR-CB, KR-M, KR-M2]
- id(String, Required): WAF ID
- websiteid(String, Required): website ID. see listWAFWebSites (waf_websvc_seq)
* Examples: print(waf.removeWAFWebSite(zone='KR-M', id='3107', websiteid='7657'))
"""
my_apikey, my_secretkey = c.read_config()
if not 'zone' in kargs:
return c.printZoneHelp()
if not 'id' in kargs:
return '[ktcloud] Missing required argument "id" '
if not 'websiteid' in kargs:
return '[ktcloud] Missing required argument "websiteid '
ZoneName = kargs['zone']
del kargs['zone']
kargs['zoneid'] = c.getzoneidbyhname(ZoneName)
M2Bool = c.IsM2(ZoneName)
baseurl = c.geturl(ctype = 'waf', m2 = M2Bool)
kargs['command'] = 'removeWAFWebSite'
kargs['response'] = 'json'
kargs['apikey'] = my_apikey
return c.makerequest(kargs, baseurl, my_secretkey)
# END of File