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
2424from abc import abstractmethod , ABCMeta
2525from configparser import ConfigParser
2626import os
3333CONFIG_FILE_ENV_VAR = "DATABRICKS_CONFIG_FILE"
3434HOST = 'host'
3535USERNAME = 'username'
36- PASSWORD = 'password' # NOQA
36+ PASSWORD = 'password' # NOQA
3737TOKEN = 'token'
3838INSECURE = 'insecure'
3939DEFAULT_SECTION = 'DEFAULT'
40+ DEBUG = 'debug'
4041
4142# User-provided override for the DatabricksConfigProvider
4243_config_provider = None
@@ -238,7 +239,11 @@ def get_config(self):
238239 password = os .environ .get ('DATABRICKS_PASSWORD' )
239240 token = os .environ .get ('DATABRICKS_TOKEN' )
240241 insecure = os .environ .get ('DATABRICKS_INSECURE' )
241- config = DatabricksConfig (host , username , password , token , insecure )
242+ debugging = os .environ .get ('DATABRICKS_DEBUGGING' )
243+ if debugging is None :
244+ debugging = 0
245+
246+ config = DatabricksConfig (host , username , password , token , insecure , debugging = debugging )
242247 if config .is_valid :
243248 return config
244249 return None
@@ -256,19 +261,30 @@ def get_config(self):
256261 password = _get_option_if_exists (raw_config , self .profile , PASSWORD )
257262 token = _get_option_if_exists (raw_config , self .profile , TOKEN )
258263 insecure = _get_option_if_exists (raw_config , self .profile , INSECURE )
259- config = DatabricksConfig (host , username , password , token , insecure )
264+ debugging = _get_option_if_exists (raw_config , self .profile , DEBUG )
265+ if debugging is None :
266+ debugging = 0
267+
268+ config = DatabricksConfig (host , username , password , token , insecure , debugging = debugging )
260269 if config .is_valid :
261270 return config
262271 return None
263272
264273
265274class DatabricksConfig (object ):
266- def __init__ (self , host , username , password , token , insecure ): # noqa
275+ def __init__ (self , host , username , password , token , insecure , debugging = 0 ): # noqa
267276 self .host = host
268277 self .username = username
269- self .password = password
278+
279+ if self .password == 'stdin' :
280+ self .password = getpass .getpass ("Password to connect to databricks at [" + self .host + "]: " )
281+ else :
282+ self .password = password
283+
270284 self .token = token
271285 self .insecure = insecure
286+ self .debugging = debugging
287+
272288
273289 @classmethod
274290 def from_token (cls , host , token , insecure = None ):
@@ -293,3 +309,7 @@ def is_valid_with_password(self):
293309 @property
294310 def is_valid (self ):
295311 return self .is_valid_with_token or self .is_valid_with_password
312+
313+ @property
314+ def is_debugging (self ):
315+ return self .debugging
0 commit comments