Skip to content

Commit 8145aa1

Browse files
committed
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.
1 parent a54a7bf commit 8145aa1

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

databricks_cli/configure/cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,27 @@
3232

3333
PROMPT_HOST = 'Databricks Host (should begin with https://)'
3434
PROMPT_USERNAME = 'Username'
35-
PROMPT_PASSWORD = 'Password' # NOQA
35+
PROMPT_PASSWORD = 'Password [enter stdin to read from stdin every time]' # NOQA
3636
PROMPT_TOKEN = 'Token' # NOQA
3737

3838

3939
def _configure_cli_token(profile, insecure):
4040
config = ProfileConfigProvider(profile).get_config() or DatabricksConfig.empty()
4141
host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())
42-
token = click.prompt(PROMPT_TOKEN, default=config.token)
42+
token = click.prompt(PROMPT_TOKEN, default=config.token, hide_input=True)
4343
new_config = DatabricksConfig.from_token(host, token, insecure)
4444
update_and_persist_config(profile, new_config)
4545

4646

47+
def _configure_cli_stdin(profile, insecure):
48+
config = ProfileConfigProvider(profile).get_config() or DatabricksConfig.empty()
49+
host = click.prompt(PROMPT_HOST, default=config.host, type=_DbfsHost())
50+
username = click.prompt(PROMPT_USERNAME, default=config.username)
51+
password = 'stdin'
52+
new_config = DatabricksConfig.from_password(host, username, password, insecure)
53+
update_and_persist_config(profile, new_config)
54+
55+
4756
def _configure_cli_password(profile, insecure):
4857
config = ProfileConfigProvider(profile).get_config() or DatabricksConfig.empty()
4958
if config.password:
@@ -64,16 +73,19 @@ def _configure_cli_password(profile, insecure):
6473
short_help='Configures host and authentication info for the CLI.')
6574
@click.option('--token', show_default=True, is_flag=True, default=False)
6675
@click.option('--insecure', show_default=True, is_flag=True, default=None)
76+
@click.option('--stdin', show_default=True, is_flag=True, default=False)
6777
@debug_option
6878
@profile_option
69-
def configure_cli(token, insecure):
79+
def configure_cli(token, insecure, stdin):
7080
"""
7181
Configures host and authentication info for the CLI.
7282
"""
7383
profile = get_profile_from_context()
7484
insecure_str = str(insecure) if insecure is not None else None
7585
if token:
7686
_configure_cli_token(profile, insecure_str)
87+
elif stdin:
88+
_configure_cli_stdin()
7789
else:
7890
_configure_cli_password(profile, insecure_str)
7991

databricks_cli/configure/provider.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2121
# See the License for the specific language governing permissions and
2222
# limitations under the License.
23-
23+
import getpass
2424
from abc import abstractmethod, ABCMeta
2525
from configparser import ConfigParser
2626
import os
@@ -33,7 +33,7 @@
3333
CONFIG_FILE_ENV_VAR = "DATABRICKS_CONFIG_FILE"
3434
HOST = 'host'
3535
USERNAME = 'username'
36-
PASSWORD = 'password' # NOQA
36+
PASSWORD = 'password' # NOQA
3737
TOKEN = 'token'
3838
INSECURE = 'insecure'
3939
DEFAULT_SECTION = 'DEFAULT'
@@ -263,10 +263,15 @@ def get_config(self):
263263

264264

265265
class DatabricksConfig(object):
266-
def __init__(self, host, username, password, token, insecure): # noqa
266+
def __init__(self, host, username, password, token, insecure): # noqa
267267
self.host = host
268268
self.username = username
269-
self.password = password
269+
270+
if self.password == 'stdin':
271+
self.password = getpass.getpass("Password to connect to databricks at [" + self.host + "]: ")
272+
else:
273+
self.password = password
274+
270275
self.token = token
271276
self.insecure = insecure
272277

0 commit comments

Comments
 (0)