Skip to content

Commit

Permalink
cloudtests: move client_cert from AuthConfig to WebRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
nrainer-materialize committed Aug 28, 2023
1 parent 7706d8a commit 8a67cf2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 0 additions & 2 deletions misc/python/materialize/cloudtest/util/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class AuthConfig:

refresh_fn: Callable[[AuthConfig], None]

client_cert: Optional[tuple[str, str]] = None

def refresh(self) -> None:
self.refresh_fn(self)

Expand Down
6 changes: 4 additions & 2 deletions misc/python/materialize/cloudtest/util/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def configured_base_url(self) -> str:

return self.endpoint.base_url

def requests(self, auth: Optional[AuthConfig]) -> WebRequests:
return WebRequests(auth, self.configured_base_url())
def requests(
self, auth: Optional[AuthConfig], client_cert: Optional[tuple[str, str]] = None
) -> WebRequests:
return WebRequests(auth, self.configured_base_url(), client_cert)


def wait_for_connectable(
Expand Down
19 changes: 11 additions & 8 deletions misc/python/materialize/cloudtest/util/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ def verbose_http_errors() -> Generator[None, None, None]:


class WebRequests:
def __init__(self, auth: Optional[AuthConfig], base_url: str):
def __init__(
self,
auth: Optional[AuthConfig],
base_url: str,
client_cert: Optional[tuple[str, str]] = None,
):
self.auth = auth
self.base_url = base_url
self.client_cert = client_cert

def get(
self,
Expand All @@ -50,7 +56,7 @@ def try_get() -> requests.Response:
f"{self.base_url}{path}",
headers=headers,
timeout=timeout,
cert=self._get_cert(self.auth),
cert=self.client_cert,
)
response.raise_for_status()
return response
Expand Down Expand Up @@ -82,7 +88,7 @@ def try_post() -> requests.Response:
headers=headers,
json=json,
timeout=timeout,
cert=self._get_cert(self.auth),
cert=self.client_cert,
)
response.raise_for_status()
return response
Expand Down Expand Up @@ -114,7 +120,7 @@ def try_patch() -> requests.Response:
headers=headers,
json=json,
timeout=timeout,
cert=self._get_cert(self.auth),
cert=self.client_cert,
)
response.raise_for_status()
return response
Expand Down Expand Up @@ -145,7 +151,7 @@ def try_delete() -> requests.Response:
f"{self.base_url}{path}",
headers=headers,
timeout=timeout,
cert=self._get_cert(self.auth),
cert=self.client_cert,
**(
{
"params": params,
Expand Down Expand Up @@ -174,6 +180,3 @@ def _create_headers(self, auth: Optional[AuthConfig]) -> dict[str, Any]:
headers["Authorization"] = f"Bearer {auth.token}"

return headers

def _get_cert(self, auth: Optional[AuthConfig]) -> Optional[tuple[str, str]]:
return auth.client_cert if auth is not None else None

0 comments on commit 8a67cf2

Please sign in to comment.