issue#85 initial commit

This commit is contained in:
Davis Thames
2018-05-09 22:26:18 -05:00
parent 1869f34c8a
commit e3f26f609b
4 changed files with 148 additions and 7 deletions

View File

@@ -6,35 +6,46 @@ import re
import argparse
fixtures_directory = 'tests/fixtures/'
# restclient api header configuration
zero_api_regex = r'(\[Token )0{40}(\])'
real_api_regex = r'(\[Token ).{40}(\])'
zero_token_string = '[Token ' + 40 * '0' + ']'
# pandas json api call configuration
pd_real_api_regex = r'&token=.{40}'
pd_zero_api_regex = r'&token=0{40}'
pd_zero_token_string = '&token=' + 40 * '0'
def has_api_key(file):
def has_api_key(file_name):
"""
Detect whether the file contains an api key in the Token object that is not 40*'0'.
See issue #86.
:param file: path-to-file to check
:return: boolean
"""
f = open(file, 'r')
f = open(file_name, 'r')
text = f.read()
if re.search(real_api_regex, text) is not None and \
re.search(zero_api_regex, text) is None:
return True
elif re.search(pd_real_api_regex, text) is not None and \
re.search(pd_zero_api_regex, text) is None:
return True
return False
def remove_api_key(file):
def remove_api_key(file_name):
"""
Change the api key in the Token object to 40*'0'. See issue #86.
:param file: path-to-file to change
"""
with open(file, 'r') as fp:
with open(file_name, 'r') as fp:
text = fp.read()
text = re.sub(real_api_regex, zero_token_string, text)
with open(file, 'w') as fp:
text = re.sub(pd_real_api_regex, pd_zero_token_string, text)
with open(file_name, 'w') as fp:
fp.write(text)
return