This repository has been archived by the owner on May 7, 2024. It is now read-only.
forked from cloudflare/python-cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python | ||
"""Cloudflare API code - example""" | ||
|
||
import os | ||
import sys | ||
import json | ||
sys.path.insert(0, os.path.abspath('.')) | ||
sys.path.insert(0, os.path.abspath('..')) | ||
|
||
import CloudFlare | ||
|
||
def main(): | ||
"""Cloudflare API code - example""" | ||
|
||
try: | ||
zone_name = sys.argv[1] | ||
except IndexError: | ||
exit('usage: example_bot_management.py zone_name True/False') | ||
|
||
try: | ||
enable_value = sys.argv[2] | ||
except IndexError: | ||
exit('usage: example_bot_management.py zone_name True/False') | ||
|
||
enable_value = True if enable_value in ['true','True','1'] else False | ||
|
||
cf = CloudFlare.CloudFlare() | ||
|
||
# grab the zone identifier | ||
try: | ||
params = {'name': zone_name} | ||
zones = cf.zones.get(params=params) | ||
except CloudFlare.exceptions.CloudFlareAPIError as e: | ||
exit('/zone %d %s - api call failed' % (e, e)) | ||
except Exception as e: | ||
exit('/zone.get - %s - api call failed' % (e)) | ||
|
||
if len(zones) == 0: | ||
exit('/zones.get - %s - zones not found' % (zone_name)) | ||
|
||
if len(zones) != 1: | ||
exit('/zones.get - %s - api call returned %d items' % (zone_name, len(zones))) | ||
|
||
zone_id = zones[0]['id'] | ||
|
||
settings_bot = cf.zones.bot_management.get(zone_id) | ||
print(json.dumps(settings_bot, indent=4)) | ||
|
||
try: | ||
settings_bot = cf.zones.bot_management.put(zone_id, data={'enable_js': enable_value}) | ||
except Exception as e: | ||
if int(e) == 99998: | ||
pass | ||
else: | ||
exit("Exception: %d %s" % (int(e), str(e))) | ||
|
||
settings_bot = cf.zones.bot_management.get(zone_id) | ||
print(json.dumps(settings_bot, indent=4)) | ||
|
||
if __name__ == '__main__': | ||
main() |