pangea-sdk 6.0.0__py3-none-any.whl → 6.2.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,17 @@
2
2
  # Author: Pangea Cyber Corporation
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Dict, List, Optional, Union
5
+ from typing import Dict, List, Literal, Optional, Union
6
6
 
7
7
  import pangea.services.authn.models as m
8
8
  from pangea.asyncio.services.base import ServiceBaseAsync
9
9
  from pangea.config import PangeaConfig
10
10
  from pangea.response import PangeaResponse, PangeaResponseResult
11
11
 
12
- SERVICE_NAME = "authn"
12
+ __all__ = ["AuthNAsync"]
13
+
14
+
15
+ _SERVICE_NAME = "authn"
13
16
 
14
17
 
15
18
  class AuthNAsync(ServiceBaseAsync):
@@ -35,7 +38,7 @@ class AuthNAsync(ServiceBaseAsync):
35
38
  authn = AuthNAsync(token=PANGEA_TOKEN, config=authn_config)
36
39
  """
37
40
 
38
- service_name = SERVICE_NAME
41
+ service_name = _SERVICE_NAME
39
42
 
40
43
  def __init__(
41
44
  self,
@@ -65,7 +68,7 @@ class AuthNAsync(ServiceBaseAsync):
65
68
  self.agreements = AuthNAsync.AgreementsAsync(token, config, logger_name=logger_name)
66
69
 
67
70
  class SessionAsync(ServiceBaseAsync):
68
- service_name = SERVICE_NAME
71
+ service_name = _SERVICE_NAME
69
72
 
70
73
  def __init__(
71
74
  self,
@@ -162,7 +165,7 @@ class AuthNAsync(ServiceBaseAsync):
162
165
  )
163
166
 
164
167
  class ClientAsync(ServiceBaseAsync):
165
- service_name = SERVICE_NAME
168
+ service_name = _SERVICE_NAME
166
169
 
167
170
  def __init__(
168
171
  self,
@@ -222,7 +225,7 @@ class AuthNAsync(ServiceBaseAsync):
222
225
  return await self.request.post("v2/client/jwks", m.ClientJWKSResult, {})
223
226
 
224
227
  class SessionAsync(ServiceBaseAsync):
225
- service_name = SERVICE_NAME
228
+ service_name = _SERVICE_NAME
226
229
 
227
230
  def __init__(
228
231
  self,
@@ -359,7 +362,7 @@ class AuthNAsync(ServiceBaseAsync):
359
362
  )
360
363
 
361
364
  class PasswordAsync(ServiceBaseAsync):
362
- service_name = SERVICE_NAME
365
+ service_name = _SERVICE_NAME
363
366
 
364
367
  def __init__(
365
368
  self,
@@ -419,7 +422,7 @@ class AuthNAsync(ServiceBaseAsync):
419
422
  return await self.request.post("v2/user/password/expire", PangeaResponseResult, {"id": user_id})
420
423
 
421
424
  class TokenAsync(ServiceBaseAsync):
422
- service_name = SERVICE_NAME
425
+ service_name = _SERVICE_NAME
423
426
 
424
427
  def __init__(
425
428
  self,
@@ -456,7 +459,7 @@ class AuthNAsync(ServiceBaseAsync):
456
459
  )
457
460
 
458
461
  class UserAsync(ServiceBaseAsync):
459
- service_name = SERVICE_NAME
462
+ service_name = _SERVICE_NAME
460
463
 
461
464
  def __init__(
462
465
  self,
@@ -667,7 +670,7 @@ class AuthNAsync(ServiceBaseAsync):
667
670
  return await self.request.post("v2/user/list", m.UserListResult, data=input.model_dump(exclude_none=True))
668
671
 
669
672
  class InvitesAsync(ServiceBaseAsync):
670
- service_name = SERVICE_NAME
673
+ service_name = _SERVICE_NAME
671
674
 
672
675
  def __init__(
673
676
  self,
@@ -739,7 +742,7 @@ class AuthNAsync(ServiceBaseAsync):
739
742
  )
740
743
 
741
744
  class AuthenticatorsAsync(ServiceBaseAsync):
742
- service_name = SERVICE_NAME
745
+ service_name = _SERVICE_NAME
743
746
 
744
747
  def __init__(
745
748
  self,
@@ -821,7 +824,7 @@ class AuthNAsync(ServiceBaseAsync):
821
824
  )
822
825
 
823
826
  class ProfileAsync(ServiceBaseAsync):
824
- service_name = SERVICE_NAME
827
+ service_name = _SERVICE_NAME
825
828
 
826
829
  def __init__(
827
830
  self,
@@ -905,8 +908,57 @@ class AuthNAsync(ServiceBaseAsync):
905
908
  "v2/user/profile/update", m.UserProfileUpdateResult, data=input.model_dump(exclude_none=True)
906
909
  )
907
910
 
911
+ class GroupAsync(ServiceBaseAsync):
912
+ service_name = _SERVICE_NAME
913
+
914
+ def __init__(
915
+ self,
916
+ token: str,
917
+ config: PangeaConfig | None = None,
918
+ logger_name: str = "pangea",
919
+ ) -> None:
920
+ super().__init__(token, config, logger_name=logger_name)
921
+
922
+ async def assign(self, user_id: str, group_ids: list[str]) -> PangeaResponse[PangeaResponseResult]:
923
+ """
924
+ Assign groups to a user
925
+
926
+ Add a list of groups to a specified user
927
+
928
+ OperationId: authn_post_v2_user_group_assign
929
+ """
930
+ return await self.request.post(
931
+ "v2/user/group/assign",
932
+ data={"id": user_id, "group_ids": group_ids},
933
+ result_class=m.PangeaResponseResult,
934
+ )
935
+
936
+ async def remove(self, user_id: str, group_id: str) -> PangeaResponse[PangeaResponseResult]:
937
+ """
938
+ Remove a group assigned to a user
939
+
940
+ Remove a group assigned to a user
941
+
942
+ OperationId: authn_post_v2_user_group_remove
943
+ """
944
+ return await self.request.post(
945
+ "v2/user/group/remove",
946
+ data={"id": user_id, "group_id": group_id},
947
+ result_class=m.PangeaResponseResult,
948
+ )
949
+
950
+ async def list(self, user_id: str) -> PangeaResponse[m.GroupList]:
951
+ """
952
+ List of groups assigned to a user
953
+
954
+ Return a list of ids for groups assigned to a user
955
+
956
+ OperationId: authn_post_v2_user_group_list
957
+ """
958
+ return await self.request.post("v2/user/group/list", data={"id": user_id}, result_class=m.GroupList)
959
+
908
960
  class FlowAsync(ServiceBaseAsync):
909
- service_name = SERVICE_NAME
961
+ service_name = _SERVICE_NAME
910
962
 
911
963
  def __init__(
912
964
  self,
@@ -1052,7 +1104,7 @@ class AuthNAsync(ServiceBaseAsync):
1052
1104
  )
1053
1105
 
1054
1106
  class AgreementsAsync(ServiceBaseAsync):
1055
- service_name = SERVICE_NAME
1107
+ service_name = _SERVICE_NAME
1056
1108
 
1057
1109
  def __init__(
1058
1110
  self,
@@ -1201,3 +1253,108 @@ class AuthNAsync(ServiceBaseAsync):
1201
1253
  return await self.request.post(
1202
1254
  "v2/agreements/update", m.AgreementUpdateResult, data=input.model_dump(exclude_none=True)
1203
1255
  )
1256
+
1257
+ class GroupAsync(ServiceBaseAsync):
1258
+ service_name = _SERVICE_NAME
1259
+
1260
+ def __init__(
1261
+ self,
1262
+ token: str,
1263
+ config: PangeaConfig | None = None,
1264
+ logger_name: str = "pangea",
1265
+ ) -> None:
1266
+ super().__init__(token, config, logger_name=logger_name)
1267
+
1268
+ async def create(
1269
+ self, name: str, type: str, *, description: str | None = None, attributes: dict[str, str] | None = None
1270
+ ) -> PangeaResponse[m.GroupInfo]:
1271
+ """
1272
+ Create a new group
1273
+
1274
+ Create a new group
1275
+
1276
+ OperationId: authn_post_v2_group_create
1277
+ """
1278
+ return await self.request.post(
1279
+ "v2/group/create",
1280
+ data={"name": name, "type": type, "description": description, "attributes": attributes},
1281
+ result_class=m.GroupInfo,
1282
+ )
1283
+
1284
+ async def delete(self, id: str) -> PangeaResponse[PangeaResponseResult]:
1285
+ """
1286
+ Delete a group
1287
+
1288
+ Delete a group
1289
+
1290
+ OperationId: authn_post_v2_group_delete
1291
+ """
1292
+ return await self.request.post("v2/group/delete", data={"id": id}, result_class=PangeaResponseResult)
1293
+
1294
+ async def get(self, id: str) -> PangeaResponse[m.GroupInfo]:
1295
+ """
1296
+ Get group information
1297
+
1298
+ Look up a group by ID and return its information.
1299
+
1300
+ OperationId: authn_post_v2_group_get
1301
+ """
1302
+ return await self.request.post("v2/group/get", data={"id": id}, result_class=m.GroupInfo)
1303
+
1304
+ async def list(
1305
+ self,
1306
+ *,
1307
+ filter: m.GroupsFilter | None = None,
1308
+ last: str | None = None,
1309
+ order: Literal["asc", "desc"] | None = None,
1310
+ order_by: Literal["id", "created_at", "updated_at", "name", "type"] | None = None,
1311
+ size: int | None = None,
1312
+ ) -> PangeaResponse[m.GroupList]:
1313
+ """
1314
+ List groups
1315
+
1316
+ Look up groups by name, type, or attributes.
1317
+ """
1318
+ return await self.request.post(
1319
+ "v2/group/list",
1320
+ data={"filter": filter, "last": last, "order": order, "order_by": order_by, "size": size},
1321
+ result_class=m.GroupList,
1322
+ )
1323
+
1324
+ async def list_users(
1325
+ self, id: str, *, last: str | None = None, size: int | None = None
1326
+ ) -> PangeaResponse[m.GroupUserList]:
1327
+ """
1328
+ List of users assigned to a group
1329
+
1330
+ Return a list of ids for users assigned to a group
1331
+
1332
+ OperationId: authn_post_v2_group_user_list
1333
+ """
1334
+ return await self.request.post(
1335
+ "v2/group/user/list",
1336
+ data={"id": id, "last": last, "size": size},
1337
+ result_class=m.GroupUserList,
1338
+ )
1339
+
1340
+ async def update(
1341
+ self,
1342
+ id: str,
1343
+ *,
1344
+ name: str | None = None,
1345
+ description: str | None = None,
1346
+ type: str | None = None,
1347
+ attributes: dict[str, str] | None = None,
1348
+ ) -> PangeaResponse[m.GroupInfo]:
1349
+ """
1350
+ Update group information
1351
+
1352
+ Update group information
1353
+
1354
+ OperationId: authn_post_v2_group_update
1355
+ """
1356
+ return await self.request.post(
1357
+ "v2/group/update",
1358
+ data={"id": id, "name": name, "description": description, "type": type, "attributes": attributes},
1359
+ result_class=m.GroupInfo,
1360
+ )
@@ -3,7 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
- from typing import Any, Dict, List, Optional
6
+ from typing import Any
7
7
 
8
8
  from pangea.asyncio.services.base import ServiceBaseAsync
9
9
  from pangea.config import PangeaConfig
@@ -73,14 +73,14 @@ class AuthZAsync(ServiceBaseAsync):
73
73
 
74
74
  super().__init__(token, config, logger_name, config_id=config_id)
75
75
 
76
- async def tuple_create(self, tuples: List[Tuple]) -> PangeaResponse[TupleCreateResult]:
76
+ async def tuple_create(self, tuples: list[Tuple]) -> PangeaResponse[TupleCreateResult]:
77
77
  """Create tuples.
78
78
 
79
79
  Create tuples in the AuthZ Service. The request will fail if there is no schema
80
80
  or the tuples do not validate against the schema.
81
81
 
82
82
  Args:
83
- tuples (List[Tuple]): List of tuples to be created.
83
+ tuples: Tuples to be created.
84
84
 
85
85
  Raises:
86
86
  PangeaAPIException: If an API Error happens.
@@ -110,10 +110,10 @@ class AuthZAsync(ServiceBaseAsync):
110
110
  async def tuple_list(
111
111
  self,
112
112
  filter: TupleListFilter,
113
- size: Optional[int] = None,
114
- last: Optional[str] = None,
115
- order: Optional[ItemOrder] = None,
116
- order_by: Optional[TupleOrderBy] = None,
113
+ size: int | None = None,
114
+ last: str | None = None,
115
+ order: ItemOrder | None = None,
116
+ order_by: TupleOrderBy | None = None,
117
117
  ) -> PangeaResponse[TupleListResult]:
118
118
  """List tuples.
119
119
 
@@ -122,11 +122,11 @@ class AuthZAsync(ServiceBaseAsync):
122
122
  is empty it will return all the tuples.
123
123
 
124
124
  Args:
125
- filter (TupleListFilter): The filter for listing tuples.
126
- size (Optional[int]): The size of the result set. Default is None.
127
- last (Optional[str]): The last token from a previous response. Default is None.
128
- order (Optional[ItemOrder]): Order results asc(ending) or desc(ending).
129
- order_by (Optional[TupleOrderBy]): Which field to order results by.
125
+ filter: The filter for listing tuples.
126
+ size: The size of the result set. Default is None.
127
+ last: The last token from a previous response. Default is None.
128
+ order: Order results asc(ending) or desc(ending).
129
+ order_by: Which field to order results by.
130
130
 
131
131
  Raises:
132
132
  PangeaAPIException: If an API Error happens.
@@ -144,13 +144,13 @@ class AuthZAsync(ServiceBaseAsync):
144
144
  )
145
145
  return await self.request.post("v1/tuple/list", TupleListResult, data=input_data.model_dump(exclude_none=True))
146
146
 
147
- async def tuple_delete(self, tuples: List[Tuple]) -> PangeaResponse[TupleDeleteResult]:
147
+ async def tuple_delete(self, tuples: list[Tuple]) -> PangeaResponse[TupleDeleteResult]:
148
148
  """Delete tuples.
149
149
 
150
150
  Delete tuples in the AuthZ Service.
151
151
 
152
152
  Args:
153
- tuples (List[Tuple]): List of tuples to be deleted.
153
+ tuples: Tuples to be deleted.
154
154
 
155
155
  Raises:
156
156
  PangeaAPIException: If an API Error happens.
@@ -182,8 +182,8 @@ class AuthZAsync(ServiceBaseAsync):
182
182
  resource: Resource,
183
183
  action: str,
184
184
  subject: Subject,
185
- debug: Optional[bool] = None,
186
- attributes: Optional[Dict[str, Any]] = None,
185
+ debug: bool | None = None,
186
+ attributes: dict[str, Any] | None = None,
187
187
  ) -> PangeaResponse[CheckResult]:
188
188
  """Perform a check request.
189
189
 
@@ -192,9 +192,9 @@ class AuthZAsync(ServiceBaseAsync):
192
192
  Args:
193
193
  resource (Resource): The resource to check.
194
194
  action (str): The action to check.
195
- subject (Subject): The subject to check.
196
- debug (Optional[bool]): Setting this value to True will provide a detailed analysis of the check.
197
- attributes (Optional[Dict[str, Any]]): Additional attributes for the check.
195
+ subject: The subject to check.
196
+ debug: Setting this value to True will provide a detailed analysis of the check.
197
+ attributes: Additional attributes for the check.
198
198
 
199
199
  Raises:
200
200
  PangeaAPIException: If an API Error happens.
@@ -217,7 +217,7 @@ class AuthZAsync(ServiceBaseAsync):
217
217
  return await self.request.post("v1/check", CheckResult, data=input_data.model_dump(exclude_none=True))
218
218
 
219
219
  async def list_resources(
220
- self, type: str, action: str, subject: Subject, attributes: Optional[Dict[str, Any]] = None
220
+ self, type: str, action: str, subject: Subject, attributes: dict[str, Any] | None = None
221
221
  ) -> PangeaResponse[ListResourcesResult]:
222
222
  """List resources.
223
223
 
@@ -225,10 +225,10 @@ class AuthZAsync(ServiceBaseAsync):
225
225
  type that the subject has access to the action with.
226
226
 
227
227
  Args:
228
- type (str): The type to filter resources.
229
- action (str): The action to filter resources.
230
- subject (Subject): The subject to filter resources.
231
- attributes (Optional[Dict[str, Any]]): A JSON object of attribute data.
228
+ type: The type to filter resources.
229
+ action: The action to filter resources.
230
+ subject: The subject to filter resources.
231
+ attributes: A JSON object of attribute data.
232
232
 
233
233
  Raises:
234
234
  PangeaAPIException: If an API Error happens.
@@ -252,7 +252,7 @@ class AuthZAsync(ServiceBaseAsync):
252
252
  )
253
253
 
254
254
  async def list_subjects(
255
- self, resource: Resource, action: str, attributes: Optional[Dict[str, Any]] = None
255
+ self, resource: Resource, action: str, attributes: dict[str, Any] | None = None
256
256
  ) -> PangeaResponse[ListSubjectsResult]:
257
257
  """List subjects.
258
258
 
@@ -260,9 +260,9 @@ class AuthZAsync(ServiceBaseAsync):
260
260
  access to the action for the given resource.
261
261
 
262
262
  Args:
263
- resource (Resource): The resource to filter subjects.
264
- action (str): The action to filter subjects.
265
- attributes (Optional[Dict[str, Any]]): A JSON object of attribute data.
263
+ resource: The resource to filter subjects.
264
+ action: The action to filter subjects.
265
+ attributes: A JSON object of attribute data.
266
266
 
267
267
  Raises:
268
268
  PangeaAPIException: If an API Error happens.