Skip to content

Commit f4ab076

Browse files
areeseandrewmchen
authored andcommitted
Add a debugging flag (#248)
* Add a debugging flag If --debug is used or if DATABRICKS_DEBUGGING is set in the environment the entire contents of the http requests will be printed to stdout. * 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. * Fix odd whitespace issue * Fix test failures caused by missing field * Fix whitespace error * Remove old style of setting up debug flag. Move all debug logic into ContextObject.set_debug which is called when --debug is sent to any command * Use click.echo instead of print * Remove excess logging configuration that isn't needed * Remove extra import
1 parent 4adfba9 commit f4ab076

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

databricks_cli/click_types.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# See the License for the specific language governing permissions and
2222
# limitations under the License.
2323

24+
import click
2425
from click import ParamType, Option, MissingParameter, UsageError
2526

2627

@@ -104,6 +105,22 @@ def __init__(self):
104105
def set_debug(self, debug=False):
105106
self._debug = debug
106107

108+
if not self._debug:
109+
return
110+
111+
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
112+
# You will see the REQUEST, including HEADERS and DATA,
113+
# and RESPONSE with HEADERS but without DATA.
114+
# The only thing missing will be the response.body which is not logged.
115+
try:
116+
import http.client as http_client
117+
except ImportError:
118+
# Python 2
119+
import httplib as http_client
120+
121+
click.echo("HTTP debugging enabled")
122+
http_client.HTTPConnection.debuglevel = 1
123+
107124
@property
108125
def debug_mode(self):
109126
return self._debug

0 commit comments

Comments
 (0)