Compare commits

..

No commits in common. "7b49a2fde2619c8c7de6915017088440a1d33f09" and "11d2de4aef8651de432740a1a01682bff28e10a2" have entirely different histories.

4 changed files with 12 additions and 17 deletions

View file

@ -32,8 +32,3 @@ Contributing
------------ ------------
Contributions are welcome. Contributions are welcome.
Other
-----
Reference Implementation in Java: https://github.com/icann/czds-api-client-java

View file

@ -1,7 +1,7 @@
{ {
"icann.account.username": "username@example.com", "icann.account.username": "username@example.com",
"icann.account.password": "Abcdef#12345678", "icann.account.password": "Abcdef#12345678",
"authentication.base.url": "https://account-api.icann.org", "authentication.base.url": "https://account-api-test.icann.org",
"czds.base.url": "https://czds-api.icann.org", "czds.base.url": "https://czds-api-test.icann.org",
"working.directory": "/where/zonefiles/will/be/saved" "working.directory": "/where/zonefiles/will/be/saved"
} }

View file

@ -6,6 +6,6 @@ def do_get(url, access_token):
'Accept': 'application/json', 'Accept': 'application/json',
'Authorization': 'Bearer {0}'.format(access_token)} 'Authorization': 'Bearer {0}'.format(access_token)}
response = requests.get(url, params=None, headers=bearer_headers, stream=True) response = requests.get(url, params=None, headers=bearer_headers)
return response return response

View file

@ -12,13 +12,9 @@ from do_http_get import do_get
############################################################################################################## ##############################################################################################################
try: try:
if 'CZDS_CONFIG' in os.environ: config_file = open("config.json", "r")
config_data = os.environ['CZDS_CONFIG'] config = json.load(config_file)
config = json.loads(config_data) config_file.close()
else:
config_file = open("config.json", "r")
config = json.load(config_file)
config_file.close()
except: except:
sys.stderr.write("Error loading config.json file.\n") sys.stderr.write("Error loading config.json file.\n")
exit(1) exit(1)
@ -30,7 +26,7 @@ authen_base_url = config['authentication.base.url']
czds_base_url = config['czds.base.url'] czds_base_url = config['czds.base.url']
# This is optional. Default to current directory # This is optional. Default to current directory
working_directory = config.get('working.directory', '.') # Default to current directory working_directory = config['working.directory']
if not username: if not username:
sys.stderr.write("'icann.account.username' parameter not found in the config.json file\n") sys.stderr.write("'icann.account.username' parameter not found in the config.json file\n")
@ -48,6 +44,10 @@ if not czds_base_url:
sys.stderr.write("'czds.base.url' parameter not found in the config.json file\n") sys.stderr.write("'czds.base.url' parameter not found in the config.json file\n")
exit(1) exit(1)
if not working_directory:
# Default to current directory
working_directory = '.'
############################################################################################################## ##############################################################################################################
@ -109,7 +109,7 @@ def download_one_zone(url, output_directory):
if status_code == 200: if status_code == 200:
# Try to get the filename from the header # Try to get the filename from the header
_,option = cgi.parse_header(download_zone_response.headers['content-disposition']) _,option = cgi.parse_header(download_zone_response.headers['content-disposition'])
filename = option.get('filename') filename = option['filename']
# If could get a filename from the header, then makeup one like [tld].txt.gz # If could get a filename from the header, then makeup one like [tld].txt.gz
if not filename: if not filename: