Skip to content

Commit

Permalink
refactor: update of api_account_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Romazes committed Sep 20, 2024
1 parent 3453f80 commit c5d69f3
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions lean/models/json_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,37 +217,20 @@ def config_build(self,
logger.debug(f'auth: {auth_authorizations}')
configuration._value = auth_authorizations.authorization
for inner_config in self._lean_configs:
if isinstance(inner_config, AccountIdsConfiguration):
if any(condition._dependent_config_id == configuration._id for condition in
inner_config._filter._conditions):
api_account_ids = auth_authorizations.accountIds
config_dash = inner_config._id.replace('-', '_')
inner_config._choices = api_account_ids
if user_provided_options and config_dash in user_provided_options:
user_provide_account_id = user_provided_options[config_dash]
if (api_account_ids and len(api_account_ids) > 0 and
any(account_id.lower() == user_provide_account_id.lower()
for account_id in api_account_ids)):
logger.info(f'The account ID: {user_provide_account_id}')
inner_config._value = user_provide_account_id
elif not api_account_ids:
logger.warn(f"The '{self._display_name}' oauth authentication returned no account id, "
f"using provided account id: '{user_provide_account_id}'")
inner_config._value = user_provide_account_id
else:
raise ValueError(f"The provided account id '{user_provide_account_id} is not valid, "
not any(account_id.lower() == user_provide_account_id.lower()
for account_id in api_account_ids)):
raise ValueError(f"The provided account id '{user_provide_account_id}' is not valid, "
f"available: {api_account_ids}")
elif api_account_ids and len(api_account_ids) > 0:
if len(api_account_ids) == 1:
logger.info(f'The account ID: {api_account_ids[0]}')
inner_config._value = api_account_ids[0]
else:
inner_config._input_method = "choice"
inner_config._choices = api_account_ids
inner_config._value = inner_config.ask_user_for_input(inner_config._input_default,
logger,
hide_input=hide_input)
break
continue
elif isinstance(configuration, AccountIdsConfiguration):
continue

property_name = self.convert_lean_key_to_variable(configuration._id)
# Only ask for user input if the config wasn't given as an option
Expand Down

0 comments on commit c5d69f3

Please sign in to comment.