diff --git a/databricks_cli/configure/cli.py b/databricks_cli/configure/cli.py index 5242b63b..bfb41dd4 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(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 d8b96aae..73b17cee 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,17 @@ 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 + + self.password = None + if self.password == 'stdin': + message = 'Password to connect to databricks at [{}]: '.format(self.host) + self.password = getpass.getpass(message) + else: + self.password = password + self.token = token self.insecure = insecure