예제 #1
0
def set(**kwargs):  # pylint:disable=redefined-builtin
    """Set the global config values.

    Example:

    \b
    ```bash
    $ polyaxon config set --host=localhost --port=80
    ```
    """
    try:
        _config = GlobalConfigManager.get_config_or_default()
    except Exception as e:
        Printer.print_error('Polyaxon load configuration.')
        Printer.print_error('Error message `{}`.'.format(e))
        Printer.print_header(
            'You can reset your config by running: polyaxon config purge')
        sys.exit(1)

    for key, value in kwargs.items():
        if value is not None:
            setattr(_config, key, value)

    GlobalConfigManager.set_config(_config)
    Printer.print_success('Config was updated.')
    # Reset cli config
    CliConfigManager.purge()
예제 #2
0
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")
예제 #3
0
    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
예제 #4
0
def set(verbose, host, http_port, ws_port, use_https):  # pylint:disable=redefined-builtin
    """Set the global config values.

    Example:

    \b
    ```bash
    $ polyaxon config set --hots=localhost http_port=80
    ```
    """
    _config = GlobalConfigManager.get_config_or_default()

    if verbose is not None:
        _config.verbose = verbose

    if host is not None:
        _config.host = host

    if http_port is not None:
        _config.http_port = http_port

    if ws_port is not None:
        _config.ws_port = ws_port

    if use_https is not None:
        _config.use_https = use_https

    GlobalConfigManager.set_config(_config)
    Printer.print_success('Config was update.')
    # Reset cli config
    CliConfigManager.purge()
예제 #5
0
def set(**kwargs):  # pylint:disable=redefined-builtin
    """Set the global config values.

    Example:

    \b
    ```bash
    $ polyaxon config set --hots=localhost http_port=80
    ```
    """
    _config = GlobalConfigManager.get_config_or_default()

    for key, value in kwargs.items():
        if value is not None:
            setattr(_config, key, value)

    GlobalConfigManager.set_config(_config)
    Printer.print_success('Config was updated.')
    # Reset cli config
    CliConfigManager.purge()
예제 #6
0
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))
예제 #7
0
    def set_raven_client():
        from polyaxon_cli.managers.cli import CliConfigManager

        cli_config = CliConfigManager.get_config()
        if cli_config and cli_config.log_handler:
            import raven

            return raven.Client(
                dsn=cli_config.log_handler.decoded_dns,
                release=cli_config.current_version,
                environment=cli_config.log_handler.environment,
                tags=cli_config.log_handler.tags,
                processors=('raven.processors.SanitizePasswordsProcessor',))
        return None
예제 #8
0
def purge(**kwargs):  # pylint:disable=redefined-builtin
    """Purge the global config values."""
    GlobalConfigManager.purge()
    Printer.print_success('Config was removed.')
    # Reset cli config
    CliConfigManager.purge()
예제 #9
0
def session_expired():
    AuthConfigManager.purge()
    CliConfigManager.purge()
    click.echo('Session has expired, please try again.')
    sys.exit(1)
예제 #10
0
    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
예제 #11
0
 def test_get_count(self):
     assert CliConfigManager._get_count() == 1
예제 #12
0
 def tearDown(self):
     path = CliConfigManager.get_config_file_path(create=False)
     if not os.path.exists(path):
         return
     os.remove(path)
예제 #13
0
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)
예제 #14
0
def logout():
    """Logout of Polyaxon."""
    AuthConfigManager.purge()
    CliConfigManager.purge()
    Printer.print_success("You are logged out")