Skip to content

Commit

Permalink
Merge pull request #363 from fairdataihub/fix-soda-pennsieve-key-default
Browse files Browse the repository at this point in the history
fix: SODA-Pennsieve key in config.ini becomes default if it exists and is broken
  • Loading branch information
aaronm-2112 authored Oct 4, 2024
2 parents b0e1811 + 868121b commit dcf9502
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/pyflask/configUtils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def lowercase_account_names(config, account_name, configpath):

# add the section back with the lowercase account name
config.add_section(formatted_account_name)
config.set(formatted_account_name, "api_token", config.get(formatted_account_name, "api_token"))
config.set(formatted_account_name, "api_secret", config.get(formatted_account_name, "api_secret"))
config.set(formatted_account_name, "api_token", config.get(account_name, "api_token"))
config.set(formatted_account_name, "api_secret", config.get(account_name, "api_secret"))

# set the global default_profile option to lowercase
config.set("global", "default_profile", formatted_account_name)
Expand Down
14 changes: 8 additions & 6 deletions src/pyflask/manageDatasets/manage_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,7 @@ def bf_get_accounts():
sections = config.sections()
global namespace_logger

if SODA_SPARC_API_KEY in sections:
lowercase_account_names(config, SODA_SPARC_API_KEY, configpath)
with contextlib.suppress(Exception):
get_access_token()
return SODA_SPARC_API_KEY.lower()
elif "global" in sections:
if "global" in sections:
if "default_profile" in config["global"]:
default_profile = config["global"]["default_profile"]
if default_profile in sections:
Expand All @@ -282,6 +277,13 @@ def bf_get_accounts():
except Exception as e:
namespace_logger.info("Failed to authenticate the stored token")
abort(401, e)

elif SODA_SPARC_API_KEY in sections:
lowercase_account_names(config, SODA_SPARC_API_KEY, configpath)
with contextlib.suppress(Exception):
get_access_token()
return SODA_SPARC_API_KEY.lower()

else:
namespace_logger.info("No default account found")
for account in sections:
Expand Down

0 comments on commit dcf9502

Please sign in to comment.