def get_info(args): keyring = Keyring() print("") email = keyring.get_jumpcloud_email() password = keyring.get_jumpcloud_password() ts = keyring.get_jumpcloud_timestamp() print(f"JumpCloud email: {email or '<not stored>'}") print(f"JumpCloud password: {'******** (hidden)' if password else '<not stored>'}") print(f"Last JumpCloud authentication: {ts.astimezone().strftime('%c %Z') if ts else '<never>'}")
def _login_to_jumpcloud(profile_name): # Returns a JumpCloudSession with the user logged in. If a session already # in the current process, it uses that; otherwise it creates a new one. global _session if _session: return _session keyring = Keyring() email = keyring.get_jumpcloud_email() password = keyring.get_jumpcloud_password() if email and password: sys.stderr.write( "Using JumpCloud login details from your OS keychain.\n") elif sys.stdout.isatty(): email = _get_email() password = _get_password() keyring.store_jumpcloud_email(email) keyring.store_jumpcloud_password(password) sys.stderr.write( "JumpCloud login details saved in your OS keychain.\n") else: _print_error( "Error: JumpCloud login details not found in your OS keychain. " f'Run "{_get_program_name()} rotate {profile_name}" interactively ' "to store your credentials in the keychain, then try again.") sys.exit(1) session = JumpCloudSession(email, password) try: session.login() except JumpCloudError as e: sys.stderr.write("\n") _print_error(f"Error: {e.message}") if isinstance(e, JumpCloudAuthFailure): keyring.store_jumpcloud_email(None) keyring.store_jumpcloud_password(None) _print_error( "- You will be prompted for your username and password the next time you try." ) elif isinstance(e, JumpCloudMFARequired): _print_error( f'Run "{_get_program_name()} rotate {profile_name}" interactively to ' "refresh the temporary credentials in your OS keychain, then try again." ) elif isinstance(e, JumpCloudServerError): _print_error( f"- JumpCloud error message: {e.jumpcloud_error_message or e.response.text}" ) sys.exit(1) _session = session return _session