Skip to content

Commit 52bf6bc

Browse files
authored
Merge pull request #91 from GunnerUjjwol/Integrate-session-storage-apis-from-v27
Integrate session-storage apis from v27
2 parents 0364b36 + ea20299 commit 52bf6bc

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

privx_api/auth.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from http import HTTPStatus
2+
from typing import Optional
23

34
from privx_api.base import BasePrivXAPI
45
from privx_api.enums import UrlEnum
56
from privx_api.response import PrivXAPIResponse
7+
from privx_api.utils import get_value
68

79

810
class AuthAPI(BasePrivXAPI):
@@ -91,3 +93,105 @@ def regenerate_idp_client_config(self, idp_id: str) -> PrivXAPIResponse:
9193
UrlEnum.AUTH.REGENERATE_IDP_CLIENT, path_params={"idp_id": idp_id}
9294
)
9395
return PrivXAPIResponse(response_status, HTTPStatus.OK, data)
96+
97+
def get_user_sessions(
98+
self,
99+
user_id: str,
100+
offset: Optional[int] = None,
101+
limit: Optional[int] = None,
102+
sort_key: Optional[str] = None,
103+
sort_dir: Optional[str] = None,
104+
) -> PrivXAPIResponse:
105+
"""
106+
Fetch valid sessions for the user.
107+
108+
Returns:
109+
PrivXAPIResponse
110+
"""
111+
response_status, data = self._http_get(
112+
UrlEnum.AUTH.USER_SESSIONS,
113+
path_params={"user_id": user_id},
114+
)
115+
print(response_status, data)
116+
return PrivXAPIResponse(response_status, HTTPStatus.OK, data)
117+
118+
def get_source_sessions(
119+
self,
120+
source_id: str,
121+
offset: Optional[int] = None,
122+
limit: Optional[int] = None,
123+
sort_key: Optional[str] = None,
124+
sort_dir: Optional[str] = None,
125+
) -> PrivXAPIResponse:
126+
"""
127+
Fetch valid source sessions.
128+
129+
Returns:
130+
PrivXAPIResponse
131+
"""
132+
response_status, data = self._http_get(
133+
UrlEnum.AUTH.SOURCE_SESSIONS,
134+
path_params={"source_id": source_id},
135+
)
136+
return PrivXAPIResponse(response_status, HTTPStatus.OK, data)
137+
138+
def search_sessions(
139+
self,
140+
offset: Optional[int] = None,
141+
limit: Optional[int] = None,
142+
sort_key: Optional[str] = None,
143+
sort_dir: Optional[str] = None,
144+
search_payload: Optional[dict] = None,
145+
) -> PrivXAPIResponse:
146+
"""
147+
Search for sessions.
148+
149+
Returns:
150+
PrivXAPIResponse
151+
"""
152+
search_params = self._get_search_params(
153+
offset=offset, limit=limit, sortkey=sort_key, sortdir=sort_dir
154+
)
155+
156+
response_status, data = self._http_post(
157+
UrlEnum.AUTH.SEARCH_SESSIONS,
158+
query_params=search_params,
159+
body=get_value(search_payload, dict()),
160+
)
161+
return PrivXAPIResponse(response_status, HTTPStatus.OK, data)
162+
163+
def terminate_session(self, session_id: str) -> PrivXAPIResponse:
164+
"""
165+
Terminate single session by ID.
166+
167+
Returns:
168+
PrivXAPIResponse
169+
"""
170+
response_status, data = self._http_post(
171+
UrlEnum.AUTH.TERMINATE_SESSION,
172+
path_params={"session_id": session_id},
173+
)
174+
return PrivXAPIResponse(response_status, HTTPStatus.OK, data)
175+
176+
def terminate_user_sessions(self, user_id: str) -> PrivXAPIResponse:
177+
"""
178+
Terminate all sessions for a user.
179+
180+
Returns:
181+
PrivXAPIResponse
182+
"""
183+
response_status, data = self._http_post(
184+
UrlEnum.AUTH.TERMINATE_USER_SESSIONS,
185+
path_params={"user_id": user_id},
186+
)
187+
return PrivXAPIResponse(response_status, HTTPStatus.OK, data)
188+
189+
def logout(self) -> PrivXAPIResponse:
190+
"""
191+
User logout.
192+
193+
Returns:
194+
PrivXAPIResponse
195+
"""
196+
response_status, data = self._http_post(UrlEnum.AUTH.LOGOUT)
197+
return PrivXAPIResponse(response_status, HTTPStatus.OK, data)

privx_api/enums.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class AuthEnum:
1212
IDP_CLIENT = "AUTH.IDP_CLIENT"
1313
IDP_CLIENTS = "AUTH.IDP_CLIENTS"
1414
REGENERATE_IDP_CLIENT = "AUTH.REGENERATE_IDP_CLIENT"
15+
USER_SESSIONS = "AUTH.USER_SESSIONS"
16+
SOURCE_SESSIONS = "AUTH.SOURCE_SESSIONS"
17+
SEARCH_SESSIONS = "AUTH.SEARCH_SESSIONS"
18+
TERMINATE_SESSION = "AUTH.TERMINATE_SESSION"
19+
TERMINATE_USER_SESSIONS = "AUTH.TERMINATE_USER_SESSIONS"
20+
LOGOUT = "AUTH.LOGOUT"
1521

1622
urls = {
1723
AUTHORIZE: "/auth/api/v1/oauth/authorize",
@@ -20,6 +26,14 @@ class AuthEnum:
2026
IDP_CLIENT: "/auth/api/v1/idp/clients/{idp_id}",
2127
IDP_CLIENTS: "/auth/api/v1/idp/clients",
2228
REGENERATE_IDP_CLIENT: "/auth/api/v1/idp/clients/{idp_id}/regenerate",
29+
USER_SESSIONS: "/auth/api/v1/sessionstorage/users/{user_id}/sessions",
30+
SOURCE_SESSIONS: "/auth/api/v1/sessionstorage/sources/{source_id}/sessions",
31+
SEARCH_SESSIONS: "/auth/api/v1/sessionstorage/sessions/search",
32+
TERMINATE_SESSION: "/auth/api/v1/sessionstorage/sessions/{session_id}"
33+
"/terminate",
34+
TERMINATE_USER_SESSIONS: "/auth/api/v1/sessionstorage/users/{user_id}"
35+
"/sessions/terminate",
36+
LOGOUT: "/auth/api/v1/logout",
2337
}
2438

2539

0 commit comments

Comments
 (0)