Skip to content

Commit be19c4e

Browse files
hummelm10hummelm10
authored andcommitted
fixed modify WAF rule
1 parent 3aacb9c commit be19c4e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

FastlyPythonCLI/scripts/WAF/getWAFRuleset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import scripts
33
import pprint
44
import pandas
5+
import json
56
from pandas.io.json import json_normalize
67
from .listWAFIDs import listWAFIDs
78
from .listWAFIDs import listWAFIDsNoPrompt
@@ -88,11 +89,14 @@ def getWAFRuleset():
8889
#print(json.dumps(data))
8990
header={"Accept":"application/vnd.api+json"}
9091
header.update({"Fastly-Key":scripts.getKeyFromConfig()})
92+
9193
#r=requests.get("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(rid) + "/rule_status",headers=header)
9294
#pprint.pprint(r.json()['data'])
9395
header.update({"Content-Type":"application/vnd.api+json"})
94-
#print("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(rid) + "/rule_status")
95-
r=requests.patch("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(row['ID']) + "/rule_status", data=body ,headers=header)
96+
#print(json.dumps(header))
97+
#print(json.dumps(body))
98+
#print("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(row['Num ID']) + "/rule_status")
99+
r=requests.patch("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(row['Num ID']) + "/rule_status", data=str(json.dumps(body)) ,headers=header)
96100
if r.status_code == 200:
97101
pprint.pprint(r.json()['data'])
98102
else:

FastlyPythonCLI/scripts/WAF/modifyRules.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,31 @@ def modifyRules():
2121
ruleids = str(input("Enter rule ID's to modify (Example: 1010010,931100,931110): ")).lower().strip()
2222
action = str(input("Enter action to perform on rules (disabled, log, block):")).lower().strip()
2323
ruleList = ruleids.split(",")
24-
data = {}
24+
body = {}
2525
datatemp = {}
2626
attributes = {}
2727
for rid in ruleList:
28+
print(str(rid))
2829
wrid=str(dfObj['WAF ID'].iloc[inVar]) + "-" + str(rid)
2930
datatemp.update({"id":wrid})
3031
datatemp.update({"type":"rule_status"})
3132
attributes.update({"status":action})
3233
datatemp.update({"attributes":attributes})
33-
data.update({"data":datatemp})
34+
body.update({"data":datatemp})
3435
#print(json.dumps(data))
3536
header={"Accept":"application/vnd.api+json"}
3637
header.update({"Fastly-Key":scripts.getKeyFromConfig()})
3738
#r=requests.get("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(rid) + "/rule_status",headers=header)
3839
#pprint.pprint(r.json()['data'])
3940
header.update({"Content-Type":"application/vnd.api+json"})
40-
#print("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(rid) + "/rule_status")
41-
r=requests.patch("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(rid) + "/rule_status", data=data ,headers=header)
41+
#print(json.dumps(header))
42+
#print(json.dumps(body))
43+
#print("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(row['Num ID']) + "/rule_status")
44+
r=requests.patch("https://api.fastly.com/service/" + str(dfObj['Service ID'].iloc[inVar]) + "/wafs/" + str(dfObj['WAF ID'].iloc[inVar]) + "/rules/" + str(rid) + "/rule_status", data=str(json.dumps(body)) ,headers=header)
4245
if r.status_code == 200:
4346
pprint.pprint(r.json()['data'])
4447
else:
4548
print(scripts.bcolors.WARNING + "Error with services request.\nStatus: " + str(r.status_code) + scripts.bcolors.ENDC)
46-
break
4749
while "Not a valid response.":
4850
reply = str(input("Modify another set [Y/n]: ")).lower().strip()
4951
if reply == 'y':

0 commit comments

Comments
 (0)