From e3a15f77adcb7cd931a5fa5412eb53e603c749d1 Mon Sep 17 00:00:00 2001 From: Allen Reese Date: Mon, 8 Jul 2019 09:08:37 -0700 Subject: [PATCH 1/2] The password provided to configure shouldn't be echo'd. Add a --stdin option to configure, so that the password will always be read from stdin instead of stored in a file. --- databricks_cli/configure/cli.py | 18 +++++++++++++++--- databricks_cli/configure/provider.py | 13 +++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/databricks_cli/configure/cli.py b/databricks_cli/configure/cli.py index 5242b63b..6f9cdd02 100644 --- a/databricks_cli/configure/cli.py +++ b/databricks_cli/configure/cli.py @@ -32,18 +32,27 @@ PROMPT_HOST = 'Databricks Host (should begin with https://)' PROMPT_USERNAME = 'Username' -PROMPT_PASSWORD = 'Password' # NOQA +PROMPT_PASSWORD = 'Password [enter stdin to read from stdin every time]' # NOQA PROMPT_TOKEN = 'Token' # NOQA 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) + 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) +def _configure_cli_stdin(profile, insecure): + config = ProfileConfigProvider(profile).get_config() or DatabricksConfig.empty() + host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost()) + username = click.prompt(PROMPT_USERNAME, default=config.username) + password = 'stdin' + new_config = DatabricksConfig.from_password(host, username, password, insecure) + update_and_persist_config(profile, new_config) + + def _configure_cli_password(profile, insecure): config = ProfileConfigProvider(profile).get_config() or DatabricksConfig.empty() if config.password: @@ -64,9 +73,10 @@ def _configure_cli_password(profile, insecure): short_help='Configures host and authentication info for the CLI.') @click.option('--token', show_default=True, is_flag=True, default=False) @click.option('--insecure', show_default=True, is_flag=True, default=None) +@click.option('--stdin', show_default=True, is_flag=True, default=False) @debug_option @profile_option -def configure_cli(token, insecure): +def configure_cli(token, insecure, stdin): """ Configures host and authentication info for the CLI. """ @@ -74,6 +84,8 @@ def configure_cli(token, insecure): insecure_str = str(insecure) if insecure is not None else None if token: _configure_cli_token(profile, insecure_str) + elif stdin: + _configure_cli_stdin() else: _configure_cli_password(profile, insecure_str) diff --git a/databricks_cli/configure/provider.py b/databricks_cli/configure/provider.py index d8b96aae..a10d4423 100644 --- a/databricks_cli/configure/provider.py +++ b/databricks_cli/configure/provider.py @@ -20,7 +20,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +import getpass from abc import abstractmethod, ABCMeta from configparser import ConfigParser import os @@ -33,7 +33,7 @@ CONFIG_FILE_ENV_VAR = "DATABRICKS_CONFIG_FILE" HOST = 'host' USERNAME = 'username' -PASSWORD = 'password' # NOQA +PASSWORD = 'password' # NOQA TOKEN = 'token' INSECURE = 'insecure' DEFAULT_SECTION = 'DEFAULT' @@ -263,10 +263,15 @@ def get_config(self): class DatabricksConfig(object): - def __init__(self, host, username, password, token, insecure): # noqa + def __init__(self, host, username, password, token, insecure): # noqa self.host = host self.username = username - self.password = password + + if self.password == 'stdin': + self.password = getpass.getpass("Password to connect to databricks at [" + self.host + "]: ") + else: + self.password = password + self.token = token self.insecure = insecure From 44d3ba4200de0179cf0c63141007d9c10919b68a Mon Sep 17 00:00:00 2001 From: Allen Reese Date: Mon, 8 Jul 2019 12:39:38 -0700 Subject: [PATCH 2/2] Fix test failures caused by missing field --- databricks_cli/configure/cli.py | 2 +- databricks_cli/configure/provider.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/databricks_cli/configure/cli.py b/databricks_cli/configure/cli.py index 6f9cdd02..bfb41dd4 100644 --- a/databricks_cli/configure/cli.py +++ b/databricks_cli/configure/cli.py @@ -85,7 +85,7 @@ def configure_cli(token, insecure, stdin): if token: _configure_cli_token(profile, insecure_str) elif stdin: - _configure_cli_stdin() + _configure_cli_stdin(profile, insecure_str) else: _configure_cli_password(profile, insecure_str) diff --git a/databricks_cli/configure/provider.py b/databricks_cli/configure/provider.py index a10d4423..73b17cee 100644 --- a/databricks_cli/configure/provider.py +++ b/databricks_cli/configure/provider.py @@ -267,8 +267,10 @@ def __init__(self, host, username, password, token, insecure): # noqa self.host = host self.username = username + self.password = None if self.password == 'stdin': - self.password = getpass.getpass("Password to connect to databricks at [" + self.host + "]: ") + message = 'Password to connect to databricks at [{}]: '.format(self.host) + self.password = getpass.getpass(message) else: self.password = password