Skip to content

Commit e943282

Browse files
authored
Updates base Client class to more strongly enforce abstract interfaces (#93)
1 parent 1e6248a commit e943282

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

keystone_client/client.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ def __new__(cls, *args, **kwargs):
4444

4545
return new
4646

47+
@abc.abstractmethod
48+
def login(self, username: str, password: str, timeout: int) -> None:
49+
"""Authenticate a user session."""
50+
51+
@abc.abstractmethod
52+
def logout(self) -> None:
53+
"""Terminate the current user session."""
54+
55+
@abc.abstractmethod
56+
def is_authenticated(self) -> dict:
57+
"""Return metadata for the currently authenticated user."""
58+
4759
@abc.abstractmethod
4860
def _create_factory(self, endpoint: Endpoint) -> callable:
4961
"""Factory function for data creation methods."""
@@ -88,11 +100,11 @@ def _handle_identity_response(response: httpx.Response) -> dict:
88100
response: The HTTP response object.
89101
90102
Returns:
91-
The response JSON on success or `None` if the request returned HTTP 401.
103+
The response JSON on success or an empty dictionary if the request returned HTTP 401.
92104
"""
93105

94106
if response.status_code == 401:
95-
return {}
107+
return dict()
96108

97109
response.raise_for_status()
98110
return response.json()
@@ -112,7 +124,7 @@ def _handle_retrieve_response(response: httpx.Response) -> Optional[dict]:
112124
response.raise_for_status()
113125
return response.json()
114126

115-
except httpx.HTTPError:
127+
except httpx.HTTPStatusError:
116128
if response.status_code == 404:
117129
return None
118130

0 commit comments

Comments
 (0)