def check_cli_version(): """Check if the current cli version satisfies the server requirements""" if not CliConfigManager.should_check(): return server_version = get_server_version() current_version = get_current_version() CliConfigManager.reset(current_version=current_version, min_version=server_version.min_version) if LooseVersion(current_version) < LooseVersion( server_version.min_version): click.echo( """Your version of CLI ({}) is no longer compatible with server.""" .format(current_version)) if click.confirm("Do you want to upgrade to " "version {} now?".format( server_version.latest_version)): pip_upgrade() sys.exit(0) else: clint.textui.puts("Your can manually run:") with clint.textui.indent(4): clint.textui.puts("pip install -U polyaxon-cli") clint.textui.puts("to upgrade to the latest version `{}`".format( server_version.latest_version)) sys.exit(0) elif LooseVersion(current_version) < LooseVersion( server_version.latest_version): clint.textui.puts( "New version of CLI ({}) is now available. To upgrade run:".format( server_version.latest_version)) with clint.textui.indent(4): clint.textui.puts("pip install -U polyaxon-cli")
def test_should_check(self): with patch.object(CliConfigManager, 'reset') as patch_fct: result = CliConfigManager.should_check() assert patch_fct.call_count == 1 assert result is True CliConfigManager.reset(current_version='0.0.5', min_version='0.0.4') with patch.object(CliConfigManager, 'reset') as patch_fct: result = CliConfigManager.should_check() assert patch_fct.call_count == 1 assert result is False CliConfigManager.reset(check_count=4, current_version='0.0.5', min_version='0.0.4') with patch.object(CliConfigManager, 'reset') as patch_fct: result = CliConfigManager.should_check() assert patch_fct.call_count == 1 assert result is True CliConfigManager.reset(current_version='0.0.2', min_version='0.0.4') with patch.object(CliConfigManager, 'reset') as patch_fct: result = CliConfigManager.should_check() assert patch_fct.call_count == 1 assert result is True
def check_cli_version(): """Check if the current cli version satisfies the server requirements""" if not CliConfigManager.should_check(): return from distutils.version import LooseVersion # pylint:disable=import-error server_version = get_server_version() current_version = get_current_version() CliConfigManager.reset(current_version=current_version, min_version=server_version.min_version) if LooseVersion(current_version) < LooseVersion(server_version.min_version): click.echo("""Your version of CLI ({}) is no longer compatible with server.""".format( current_version)) if click.confirm("Do you want to upgrade to " "version {} now?".format(server_version.latest_version)): pip_upgrade() sys.exit(0) else: indentation.puts("Your can manually run:") with indentation.indent(4): indentation.puts("pip install -U polyaxon-cli") indentation.puts( "to upgrade to the latest version `{}`".format(server_version.latest_version)) sys.exit(0) elif LooseVersion(current_version) < LooseVersion(server_version.latest_version): indentation.puts("New version of CLI ({}) is now available. To upgrade run:".format( server_version.latest_version )) with indentation.indent(4): indentation.puts("pip install -U polyaxon-cli") elif LooseVersion(current_version) > LooseVersion(server_version.latest_version): indentation.puts("You version of CLI ({}) is ahead of the latest version " "supported by Polyaxon Platform ({}) on your cluster, " "and might be incompatible.".format(current_version, server_version.latest_version))
def test_set_new_count(self): with patch.object(CliConfigManager, 'set_config') as patch_fct: CliConfigManager.reset(check_count=4) assert patch_fct.call_count == 1
def login(token, username, password): """Login to Polyaxon.""" auth_client = PolyaxonClient().auth if username: # Use username / password login if not password: password = click.prompt('Please enter your password', type=str, hide_input=True) password = password.strip() if not password: logger.info( 'You entered an empty string. ' 'Please make sure you enter your password correctly.') sys.exit(1) credentials = CredentialsConfig(username=username, password=password) try: access_code = auth_client.login(credentials=credentials) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error('Could not login.') Printer.print_error(e) sys.exit(1) if not access_code: Printer.print_error("Failed to login") return else: if not token: token_url = "{}/app/token".format(auth_client.config.http_host) click.confirm( 'Authentication token page will now open in your browser. Continue?', abort=True, default=True) click.launch(token_url) logger.info("Please copy and paste the authentication token.") token = click.prompt( 'This is an invisible field. Paste token and press ENTER', type=str, hide_input=True) if not token: logger.info( "Empty token received. " "Make sure your shell is handling the token appropriately.") logger.info( "See docs for help: http://docs.polyaxon.com/polyaxon_cli/commands/auth" ) return access_code = token.strip(" ") # Set user try: AuthConfigManager.purge() user = PolyaxonClient().auth.get_user(token=access_code) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error('Could not load user info.') Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) access_token = AccessTokenConfig(username=user.username, token=access_code) AuthConfigManager.set_config(access_token) Printer.print_success("Login successful") # Reset current cli server_version = get_server_version() current_version = get_current_version() log_handler = get_log_handler() CliConfigManager.reset(check_count=0, current_version=current_version, min_version=server_version.min_version, log_handler=log_handler)