Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save_credentials(self, service, supplied_file):
if not path.isdir(Credentials.creds_dir):
if __debug__: log('creating credentials dir: {}.', Credentials.creds_dir)
make_dir(Credentials.creds_dir)
dest_file = path.join(Credentials.creds_dir, credentials_filename(service))
copy_file(supplied_file, dest_file)
def __init__(self):
cfile = path.join(self.credentials_dir(), credentials_filename('google'))
if __debug__: log('credentials file for google is {}', cfile)
if not path.exists(cfile):
raise AuthFailure('Credentials for Google have not been installed')
elif not readable(cfile):
raise AuthFailure('Google credentials file unreadable: {}'.format(cfile))
# Haven't been able to make it work; only the environment variable
# approach has been working for me.
#
# with open(self.credentials_file, 'r') as file:
# self.credentials = json.load(file)
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = cfile
def __init__(self):
cfile = path.join(self.credentials_dir(), credentials_filename('amazon'))
if __debug__: log('credentials file for amazon is {}', cfile)
if not path.exists(cfile):
raise AuthFailure('Credentials for Amazon have not been installed')
elif not readable(cfile):
raise AuthFailure('Amazon credentials file unreadable: {}'.format(cfile))
try:
with open(cfile, 'r') as file:
self.credentials = json.load(file)
except Exception as ex:
raise AuthFailure(
'Unable to parse Amazon exceptions file: {}'.format(str(ex)))
def __init__(self):
cfile = path.join(self.credentials_dir(), credentials_filename('microsoft'))
if __debug__: log('credentials file for microsoft is {}', cfile)
if not path.exists(cfile):
raise AuthFailure('Credentials for Microsoft have not been installed')
elif not readable(cfile):
raise AuthFailure('Microsoft credentials file unreadable: {}'.format(cfile))
try:
with open(cfile, 'r') as file:
creds = json.load(file)
self.credentials = creds['subscription_key']
except Exception as ex:
raise AuthFailure(
'Unable to parse Microsoft exceptions file: {}'.format(str(ex)))