@@ -32,6 +32,7 @@ def _download_file(
3232 databus_key = None ,
3333 auth_url = None ,
3434 client_id = None ,
35+ verbose = False ,
3536) -> None :
3637 """
3738 Download a file from the internet with a progress bar using tqdm.
@@ -43,6 +44,7 @@ def _download_file(
4344 - databus_key: Databus API key for protected downloads
4445 - auth_url: Keycloak token endpoint URL
4546 - client_id: Client ID for token exchange
47+ - verbose: when True, print redacted HTTP request/response details
4648 """
4749 if localDir is None :
4850 _host , account , group , artifact , version , file = (
@@ -67,7 +69,15 @@ def _download_file(
6769 headers = {}
6870
6971 # --- 1a. public databus ---
72+ if verbose :
73+ from databusclient .api .utils import log_http
74+
75+ log_http ("HEAD" , url , req_headers = headers )
7076 response = requests .head (url , timeout = 30 , allow_redirects = False )
77+ if verbose :
78+ from databusclient .api .utils import log_http
79+
80+ log_http ("HEAD" , url , req_headers = headers , status = response .status_code , resp_headers = response .headers )
7181
7282 # Check for redirect and update URL if necessary
7383 if response .headers .get ("Location" ) and response .status_code in [
@@ -108,9 +118,17 @@ def _download_file(
108118 headers ["Accept-Encoding" ] = (
109119 "identity" # disable gzip to get correct content-length
110120 )
121+ if verbose :
122+ from databusclient .api .utils import log_http
123+
124+ log_http ("GET" , url , req_headers = headers )
111125 response = requests .get (
112126 url , headers = headers , stream = True , allow_redirects = True , timeout = 30
113127 )
128+ if verbose :
129+ from databusclient .api .utils import log_http
130+
131+ log_http ("GET" , url , req_headers = headers , status = response .status_code , resp_headers = response .headers )
114132 www = response .headers .get ("WWW-Authenticate" , "" ) # Check if authentication is required
115133
116134 # --- 3. Handle authentication responses ---
@@ -136,12 +154,20 @@ def _download_file(
136154 # for known hosts. __get_vault_access__ handles reading the refresh
137155 # token and exchanging it; errors are translated to DownloadAuthError
138156 # for user-friendly CLI output.
139- vault_token = __get_vault_access__ (url , vault_token_file , auth_url , client_id )
157+ vault_token = __get_vault_access__ (url , vault_token_file , auth_url , client_id , verbose = verbose )
140158 headers ["Authorization" ] = f"Bearer { vault_token } "
141159 headers .pop ("Accept-Encoding" , None )
142160
143161 # Retry with token
162+ if verbose :
163+ from databusclient .api .utils import log_http
164+
165+ log_http ("GET" , url , req_headers = headers )
144166 response = requests .get (url , headers = headers , stream = True , timeout = 30 )
167+ if verbose :
168+ from databusclient .api .utils import log_http
169+
170+ log_http ("GET" , url , req_headers = headers , status = response .status_code , resp_headers = response .headers )
145171
146172 # Map common auth failures to friendly messages
147173 if response .status_code == 401 :
@@ -191,6 +217,7 @@ def _download_files(
191217 databus_key : str = None ,
192218 auth_url : str = None ,
193219 client_id : str = None ,
220+ verbose : bool = False ,
194221) -> None :
195222 """
196223 Download multiple files from the databus.
@@ -202,6 +229,7 @@ def _download_files(
202229 - databus_key: Databus API key for protected downloads
203230 - auth_url: Keycloak token endpoint URL
204231 - client_id: Client ID for token exchange
232+ - verbose: when True, print redacted HTTP request/response details
205233 """
206234 for url in urls :
207235 _download_file (
@@ -211,6 +239,7 @@ def _download_files(
211239 databus_key = databus_key ,
212240 auth_url = auth_url ,
213241 client_id = client_id ,
242+ verbose = verbose ,
214243 )
215244
216245
@@ -294,7 +323,7 @@ def _get_file_download_urls_from_sparql_query(
294323
295324
296325def __get_vault_access__ (
297- download_url : str , token_file : str , auth_url : str , client_id : str
326+ download_url : str , token_file : str , auth_url : str , client_id : str , verbose : bool = False
298327) -> str :
299328 """
300329 Get Vault access token for a protected databus download.
@@ -320,6 +349,10 @@ def __get_vault_access__(
320349 timeout = 30 ,
321350 )
322351 resp .raise_for_status ()
352+ if verbose :
353+ from databusclient .api .utils import log_http
354+
355+ log_http ("POST" , auth_url , req_headers = {"client_id" : client_id }, status = resp .status_code , resp_headers = resp .headers )
323356 access_token = resp .json ()["access_token" ]
324357
325358 # 3. Extract host as audience
@@ -344,6 +377,10 @@ def __get_vault_access__(
344377 timeout = 30 ,
345378 )
346379 resp .raise_for_status ()
380+ if verbose :
381+ from databusclient .api .utils import log_http
382+
383+ log_http ("POST" , auth_url , req_headers = {"client_id" : client_id , "audience" : audience }, status = resp .status_code , resp_headers = resp .headers )
347384 vault_token = resp .json ()["access_token" ]
348385
349386 print (f"Using Vault access token for { download_url } " )
@@ -598,6 +635,7 @@ def download(
598635 all_versions = None ,
599636 auth_url = "https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token" ,
600637 client_id = "vault-token-exchange" ,
638+ verbose : bool = False ,
601639) -> None :
602640 """
603641 Download datasets from databus.
@@ -612,6 +650,7 @@ def download(
612650 - databus_key: Databus API key for protected downloads
613651 - auth_url: Keycloak token endpoint URL. Default is "https://auth.dbpedia.org/realms/dbpedia/protocol/openid-connect/token".
614652 - client_id: Client ID for token exchange. Default is "vault-token-exchange".
653+ - verbose: when True, print redacted HTTP request/response details
615654 """
616655 for databusURI in databusURIs :
617656 host , account , group , artifact , version , file = (
@@ -647,8 +686,7 @@ def download(
647686 vault_token_file = token ,
648687 databus_key = databus_key ,
649688 auth_url = auth_url ,
650- client_id = client_id ,
651- )
689+ client_id = client_id , verbose = verbose , )
652690 elif version is not None :
653691 print (f"Downloading version: { databusURI } " )
654692 _download_version (
@@ -709,4 +747,5 @@ def download(
709747 databus_key = databus_key ,
710748 auth_url = auth_url ,
711749 client_id = client_id ,
750+ verbose = verbose ,
712751 )
0 commit comments