@@ -16,11 +16,15 @@ def listWAFIDs():
1616 r = requests .get ("https://api.fastly.com/service/" + str (services ['ID' ].iloc [x ]) + "/version/" + str (services ['Version' ].iloc [x ]) + "/wafs" ,headers = header )
1717 if r .status_code == 401 :
1818 input (scripts .bcolors .WARNING + "Error with request. Press ENTER to continue..." + scripts .bcolors .ENDC )
19+ elif r .status_code == 404 :
20+ # * no waf for that service
21+ pass
1922 elif r .status_code == 200 :
2023 with scripts .utils .DataFrameFromDict (r .json ()['data' ]) as df :
2124 if df .empty != True :
2225 df .insert (0 , 'Name' , str (services ['Name' ].iloc [x ]))
2326 df .insert (1 , 'Service ID' , str (services ['ID' ].iloc [x ]))
27+ df .insert (2 , 'Domain(s)' , str (services ['Domain(s)' ].iloc [x ]))
2428 df ['WAF ID' ] = df ['id' ]
2529 df ['Version' ] = df ['attributes.version' ]
2630 df ['Last Push' ] = df ['attributes.last_push' ]
@@ -30,12 +34,12 @@ def listWAFIDs():
3034 if df .empty != True :
3135 dfObj = dfObj .append (df )
3236 else :
33- input (scripts .bcolors .WARNING + "Error with request. Press ENTER to continue..." + scripts .bcolors .ENDC )
37+ input (scripts .bcolors .WARNING + "Error with services request.\n Status: " + str ( r . status_code ) + " \n Press ENTER to continue..." + scripts .bcolors .ENDC )
3438 print (dfObj )
3539 input ("Press ENTER to continue..." )
3640 return dfObj
3741 else :
38- input (scripts .bcolors .WARNING + "Error with request. Press ENTER to continue..." + scripts .bcolors .ENDC )
42+ input (scripts .bcolors .WARNING + "Error with services request.\n Status: " + str ( r . status_code ) + " \n Press ENTER to continue..." + scripts .bcolors .ENDC )
3943 else :
4044 input (scripts .bcolors .WARNING + "Error with API Key, generate a new one. Press ENTER to continue..." + scripts .bcolors .ENDC )
4145 return None
@@ -47,27 +51,32 @@ def listWAFIDsNoPrompt():
4751 if services is not None :
4852 dfObj = pandas .DataFrame ()
4953 for x in range (len (services .index )):
50- header = {"Accept" :"application/vnd.api+json" }
51- header .update ({"Fastly-Key" :scripts .getKeyFromConfig ()})
52- # print("https://api.fastly.com/service/" + str(services['ID'].iloc[x]) + "/version/" + str(services['Version'].iloc[x]) + "/wafs")
53- r = requests .get ("https://api.fastly.com/service/" + str (services ['ID' ].iloc [x ]) + "/version/" + str (services ['Version' ].iloc [x ]) + "/wafs" ,headers = header )
54- if r .status_code == 401 :
55- input (scripts .bcolors .WARNING + "Error with request. Press ENTER to continue..." + scripts .bcolors .ENDC )
56- elif r .status_code == 200 :
57- with scripts .utils .DataFrameFromDict (r .json ()['data' ]) as df :
54+ if not services ['Version' ].isnull ().iloc [x ]:
55+ header = {"Accept" :"application/vnd.api+json" }
56+ header .update ({"Fastly-Key" :scripts .getKeyFromConfig ()})
57+ # print("https://api.fastly.com/service/" + str(services['ID'].iloc[x]) + "/version/" + str(services['Version'].iloc[x]) + "/wafs")
58+ r = requests .get ("https://api.fastly.com/service/" + str (services ['ID' ].iloc [x ]) + "/version/" + str (services ['Version' ].iloc [x ]) + "/wafs" ,headers = header )
59+ if r .status_code == 401 :
60+ input (scripts .bcolors .WARNING + "Error with services request.\n Status: " + str (r .status_code ) + "\n Press ENTER to continue..." + scripts .bcolors .ENDC )
61+ elif r .status_code == 404 :
62+ # * no waf for that service
63+ pass
64+ elif r .status_code == 200 :
65+ with scripts .utils .DataFrameFromDict (r .json ()['data' ]) as df :
66+ if df .empty != True :
67+ df .insert (0 , 'Name' , str (services ['Name' ].iloc [x ]))
68+ df .insert (1 , 'Service ID' , str (services ['ID' ].iloc [x ]))
69+ df .insert (2 , 'Domain(s)' , str (services ['Domain(s)' ].iloc [x ]))
70+ df ['WAF ID' ] = df ['id' ]
71+ df ['Version' ] = df ['attributes.version' ]
72+ df ['Last Push' ] = df ['attributes.last_push' ]
73+ df ['Logged Rules' ] = df ['attributes.rule_statuses_log_count' ]
74+ df ['Blocked Rules' ] = df ['attributes.rule_statuses_block_count' ]
75+ df ['Disabled Rules' ] = df ['attributes.rule_statuses_disabled_count' ]
5876 if df .empty != True :
59- df .insert (0 , 'Name' , str (services ['Name' ].iloc [x ]))
60- df .insert (1 , 'Service ID' , str (services ['ID' ].iloc [x ]))
61- df ['WAF ID' ] = df ['id' ]
62- df ['Version' ] = df ['attributes.version' ]
63- df ['Last Push' ] = df ['attributes.last_push' ]
64- df ['Logged Rules' ] = df ['attributes.rule_statuses_log_count' ]
65- df ['Blocked Rules' ] = df ['attributes.rule_statuses_block_count' ]
66- df ['Disabled Rules' ] = df ['attributes.rule_statuses_disabled_count' ]
67- if df .empty != True :
68- dfObj = dfObj .append (df )
69- else :
70- input (scripts .bcolors .WARNING + "Error with request. Press ENTER to continue..." + scripts .bcolors .ENDC )
77+ dfObj = dfObj .append (df )
78+ else :
79+ input (scripts .bcolors .WARNING + "Error with services request.\n Status: " + str (r .status_code ) + "\n Press ENTER to continue..." + scripts .bcolors .ENDC )
7180 print (dfObj )
7281 return dfObj
7382 else :
0 commit comments