Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/rapidata/service/credential_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class BridgeToken(BaseModel):


class CredentialManager:
# Per-request HTTP timeout for the bridge/identity endpoints. A
# (connect, read) pair prevents slow or hung identity servers from
# pinning the calling thread indefinitely — the outer poll_timeout
# only caps the total polling loop, not individual requests.
_HTTP_TIMEOUT: Tuple[float, float] = (10.0, 30.0)

def __init__(
self,
endpoint: str,
Expand Down Expand Up @@ -139,7 +145,11 @@ def _get_bridge_tokens(self) -> Optional[BridgeToken]:
bridge_endpoint = (
f"{self.endpoint}/identity/bridge-token?clientId=rapidata-cli"
)
response = requests.post(bridge_endpoint, verify=self.cert_path)
response = requests.post(
bridge_endpoint,
verify=self.cert_path,
timeout=self._HTTP_TIMEOUT,
)
if not response.ok:
logger.error("Failed to get bridge tokens: %s", response.status_code)
return None
Expand All @@ -158,7 +168,10 @@ def _poll_read_key(self, read_key: str) -> Optional[str]:
while time.time() - start_time < self.poll_timeout:
try:
response = requests.get(
read_endpoint, params={"readKey": read_key}, verify=self.cert_path
read_endpoint,
params={"readKey": read_key},
verify=self.cert_path,
timeout=self._HTTP_TIMEOUT,
)

if response.status_code == 200:
Expand Down Expand Up @@ -193,6 +206,7 @@ def _create_client(self, access_token: str) -> Optional[Tuple[str, str, str]]:
},
json={"displayName": display_name},
verify=self.cert_path,
timeout=self._HTTP_TIMEOUT,
)
response.raise_for_status()
data = response.json()
Expand Down
Loading