Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions pybatfish/client/restv2helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ def _delete(session: Session, url_tail: str, params: dict[str, Any] | None = Non
headers=_get_headers(session),
params=params,
verify=session.verify_ssl_certs,
timeout=session.timeout,
proxies=session.proxies,
)
_check_response_status(response)

Expand All @@ -461,6 +463,8 @@ def _get(
params=params,
stream=stream,
verify=session.verify_ssl_certs,
timeout=session.timeout,
proxies=session.proxies,
)
_check_response_status(response)
return response
Expand Down Expand Up @@ -521,6 +525,8 @@ def _post(
headers=headers,
params=params,
verify=session.verify_ssl_certs,
timeout=session.timeout,
proxies=session.proxies,
)
_check_response_status(response)
return None
Expand All @@ -544,6 +550,8 @@ def _put(session, url_tail, params=None, json=None, stream=None):
headers=headers,
verify=session.verify_ssl_certs,
params=params,
timeout=session.timeout,
proxies=session.proxies,
)
_check_response_status(response)
return None
Expand Down
6 changes: 6 additions & 0 deletions pybatfish/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ class Session:
:ivar port_v2: Legacy alias for port
:ivar ssl: Whether to use SSL when connecting to Batfish (False by default)
:ivar api_key: Your API key
:ivar proxies: A dictionary of proxies to use for the session. See `requests` documentation for details.
:ivar timeout: Timeout for requests in seconds (default is 30 seconds)
"""

def __init__(
Expand All @@ -333,6 +335,8 @@ def __init__(
verify_ssl_certs: bool = Options.verify_ssl_certs,
api_key: str = CoordConsts.DEFAULT_API_KEY,
load_questions: bool = True,
proxies: dict[str, str] | None = None,
timeout: int = 30,
):
# Coordinator args
self.host: str = host
Expand Down Expand Up @@ -360,6 +364,8 @@ def __init__(

self.elapsed_delay: int = 5
self.stale_timeout: int = 5
self.proxies = proxies
self.timeout = timeout

# Auto-load question templates
if load_questions:
Expand Down
14 changes: 14 additions & 0 deletions tests/client/test_restv2helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def session() -> Session:
s.get_base_url2.return_value = BASE_URL
s.api_key = "0000"
s.verify_ssl_certs = True
s.timeout = 30
s.proxies = None
return s


Expand Down Expand Up @@ -92,6 +94,8 @@ def test_delete(session: Session, request_session: Mock) -> None:
headers=_get_headers(session),
params=None,
verify=session.verify_ssl_certs,
proxies=session.proxies,
timeout=session.timeout,
)


Expand All @@ -111,6 +115,8 @@ def test_get(session: Session, request_session: Mock) -> None:
params=None,
stream=False,
verify=session.verify_ssl_certs,
proxies=session.proxies,
timeout=session.timeout,
)

# Fast-failing session
Expand All @@ -124,6 +130,8 @@ def test_get(session: Session, request_session: Mock) -> None:
params=None,
stream=False,
verify=session.verify_ssl_certs,
proxies=session.proxies,
timeout=session.timeout,
)


Expand All @@ -144,6 +152,8 @@ def test_post_json(session, request_session):
headers=_get_headers(session),
params=None,
verify=session.verify_ssl_certs,
proxies=session.proxies,
timeout=session.timeout,
)


Expand All @@ -165,6 +175,8 @@ def test_post_stream(session, request_session):
headers=expected_headers,
params=None,
verify=session.verify_ssl_certs,
proxies=session.proxies,
timeout=session.timeout,
)


Expand All @@ -184,6 +196,8 @@ def test_put(session, request_session):
headers=_get_headers(session),
verify=session.verify_ssl_certs,
params=None,
proxies=session.proxies,
timeout=session.timeout,
)


Expand Down