Skip to content

Commit

Permalink
Error Handling: Added some try/except statements and exceptions to ha…
Browse files Browse the repository at this point in the history
…ndle

missing files, and missing file content.
Var Name: Edited function var name, to match everywhere else for consistancy.
  • Loading branch information
keirwhitlock authored and venth committed Apr 14, 2018
1 parent ca2ab34 commit d687a70
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions aws_adfs/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,21 @@ def _get_user_credentials(config):

return config.adfs_user, password

def _file_user_credentials(profile, credentials_file):
def _file_user_credentials(profile, authfile):
config = configparser.ConfigParser()
config.read(credentials_file)
username = config.get(profile, "username")
password = config.get(profile, "password")

try:
if len(config.read(authfile)) == 0:
raise FileNotFoundError(authfile)
except FileNotFoundError as e:
print('Auth file ({}) not found'.format(e))

try:
username = config.get(profile, "username")
password = config.get(profile, "password")
except configparser.NoSectionError:
print('Auth file section header ({}) not found.'.format(profile))


return username, password

Expand Down

0 comments on commit d687a70

Please sign in to comment.