Пример #1
0
def _configure_cli_token(profile, insecure):
    config = ProfileConfigProvider(
        profile).get_config() or DatabricksConfig.empty()
    host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())
    token = click.prompt(PROMPT_TOKEN, default=config.token)
    new_config = DatabricksConfig.from_token(host, token, insecure)
    update_and_persist_config(profile, new_config)
Пример #2
0
def _configure_cli_aad_token(profile, insecure, host, jobs_api_version):
    config = ProfileConfigProvider(
        profile).get_config() or DatabricksConfig.empty()

    if ENV_AAD_TOKEN not in os.environ:
        click.echo('[ERROR] Set Environment Variable \'%s\' with your '
                   'AAD Token and run again.\n' % ENV_AAD_TOKEN)
        click.echo(
            'Commands to run to get your AAD token:\n'
            '\t az login\n'
            '\t token_response=$(az account get-access-token '
            '--resource 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d)\n'
            '\t export %s=$(jq .accessToken -r <<< "$token_response")\n' %
            ENV_AAD_TOKEN)
        return

    if not host:
        host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())

    aad_token = os.environ.get(ENV_AAD_TOKEN)
    new_config = DatabricksConfig.from_token(host=host,
                                             token=aad_token,
                                             refresh_token=None,
                                             insecure=insecure,
                                             jobs_api_version=jobs_api_version)
    update_and_persist_config(profile, new_config)
Пример #3
0
def configure(version):
    profile = get_profile_from_context()
    config = ProfileConfigProvider(
        profile).get_config() if profile else get_config()
    new_config = config or DatabricksConfig.empty()
    new_config.jobs_api_version = version
    update_and_persist_config(profile, new_config)
Пример #4
0
def _configure_cli_token(profile, insecure):
    PROMPT_HOST = "Databricks Host (should begin with https://)"
    PROMPT_TOKEN = "Token"  #  NOQA
    config = ProfileConfigProvider(
        profile).get_config() or DatabricksConfig.empty()
    host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())
    token = click.prompt(PROMPT_TOKEN, default=config.token, hide_input=True)
    new_config = DatabricksConfig.from_token(host, token, insecure)
    update_and_persist_config(profile, new_config)
Пример #5
0
def _configure_cli_token(profile, insecure, host, jobs_api_version):
    config = ProfileConfigProvider(
        profile).get_config() or DatabricksConfig.empty()

    if not host:
        host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())

    token = click.prompt(PROMPT_TOKEN, default=config.token, hide_input=True)
    new_config = DatabricksConfig.from_token(host, token, insecure,
                                             jobs_api_version)
    update_and_persist_config(profile, new_config)
Пример #6
0
def _configure_cli_token_file(profile, token_file, host, insecure):
    if not path.exists(token_file):
        raise RuntimeError('Unable to read token from "{}"'.format(token_file))

    with io.open(token_file, encoding='utf-8') as f:
        token = f.readline().strip()

    config = ProfileConfigProvider(profile).get_config() or DatabricksConfig.empty()
    if not host:
        host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())

    new_config = DatabricksConfig.from_token(host, token, insecure)
    update_and_persist_config(profile, new_config)
Пример #7
0
def _configure_cli_password(profile, insecure, host):
    config = ProfileConfigProvider(profile).get_config() or DatabricksConfig.empty()
    if config.password:
        default_password = '******' * len(config.password)
    else:
        default_password = None

    if not host:
        host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())

    username = click.prompt(PROMPT_USERNAME, default=config.username)
    password = click.prompt(PROMPT_PASSWORD, default=default_password, hide_input=True,
                            confirmation_prompt=True)
    if password == default_password:
        password = config.password
    new_config = DatabricksConfig.from_password(host, username, password, insecure)
    update_and_persist_config(profile, new_config)
Пример #8
0
def _configure_cli_oauth(profile, insecure, host, scope, jobs_api_version):
    config = ProfileConfigProvider(
        profile).get_config() or DatabricksConfig.empty()

    if not host:
        host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())
    if not scope:
        scope = click.prompt(
            "Pick one or more comma-separated scopes from {scopes}".format(
                scopes=DEFAULT_SCOPES),
            value_proc=scope_format,
            type=click.Choice(DEFAULT_SCOPES),
            default=None)
    access_token, refresh_token = get_tokens(host, scope)
    new_config = DatabricksConfig.from_token(host=host,
                                             token=access_token,
                                             refresh_token=refresh_token,
                                             insecure=insecure,
                                             jobs_api_version=jobs_api_version)
    update_and_persist_config(profile, new_config)