def _get_user(self, prompt: bool) -> str: """ Get the user either from cache, or prompt the user. Returns: str -> username """ defaults = self._defaults if defaults is not None and not prompt: return defaults.user else: return Input.get_user(provider=self._defaults.provider.name)
def configure_auth(self, current_defaults: CLIDefaults, configure_provider=True) -> CLIDefaults: updated_defaults = current_defaults if configure_provider or current_defaults.provider is Provider.UNSELECTED: provider: Provider = Input.select_provider() updated_defaults.provider = provider else: provider: Provider = current_defaults.provider if provider in Provider.sso_providers(): user: str = Input.get_user(provider=provider.name) password: str = Input.get_password(provider=provider.name) self._secrets_mgr.set_password(user, password) updated_defaults.user = user try: mfa_enabled = Utils.parse_bool(self._config_mgr.get_or_prompt(Config.Section.Figgy.MFA_ENABLED, Input.select_mfa_enabled, desc=MFA_DESC)) if mfa_enabled: auto_mfa = Utils.parse_bool(self._config_mgr.get_or_prompt(Config.Section.Figgy.AUTO_MFA, Input.select_auto_mfa, desc=AUTO_MFA_DESC)) else: auto_mfa = False except ValueError as e: Utils.stc_error_exit(f"Invalid value found in figgy defaults file under " f"{Config.Section.Figgy.MFA_ENABLED.value}. It must be either 'true' or 'false'") else: updated_defaults.mfa_enabled = mfa_enabled updated_defaults.auto_mfa = auto_mfa if updated_defaults.auto_mfa: mfa_secret = Input.get_mfa_secret() self._secrets_mgr.set_mfa_secret(updated_defaults.user, mfa_secret) if configure_provider: provider_config = ProviderConfigFactory().instance(provider, mfa_enabled=updated_defaults.mfa_enabled) updated_defaults.provider_config = provider_config return updated_defaults