Skip to content

Commit 6c896a0

Browse files
authored
Merge pull request #470 from TheHive-Project/445-review-profile-endpoints
#445 - Review profile endpoints
2 parents 3d08fa0 + 4a2ba9d commit 6c896a0

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

thehive4py/endpoints/profile.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,48 @@
1010

1111
class ProfileEndpoint(EndpointBase):
1212
def create(self, profile: InputProfile) -> OutputProfile:
13+
"""Create a profile.
14+
15+
Args:
16+
profile: The body of the profile.
17+
18+
Returns:
19+
The created profile.
20+
"""
1321
return self._session.make_request("POST", path="/api/v1/profile", json=profile)
1422

1523
def get(self, profile_id: str) -> OutputProfile:
24+
"""Get a profile by id.
25+
26+
Args:
27+
profile_id: The id of the profile.
28+
29+
Returns:
30+
The profile specified by the id.
31+
"""
1632
return self._session.make_request("GET", path=f"/api/v1/profile/{profile_id}")
1733

1834
def delete(self, profile_id: str) -> None:
35+
"""Delete a profile.
36+
37+
Args:
38+
profile_id: The id of the profile.
39+
40+
Returns:
41+
N/A
42+
"""
1943
return self._session.make_request("DELETE", f"/api/v1/profile/{profile_id}")
2044

2145
def update(self, profile_id: str, fields: InputUpdateProfile) -> None:
46+
"""Update a profile.
47+
48+
Args:
49+
profile_id: The id of the profile.
50+
fields: The fields of the profile to update.
51+
52+
Returns:
53+
N/A
54+
"""
2255
return self._session.make_request(
2356
"PATCH", f"/api/v1/profile/{profile_id}", json=fields
2457
)
@@ -29,6 +62,16 @@ def find(
2962
sortby: Optional[SortExpr] = None,
3063
paginate: Optional[Paginate] = None,
3164
) -> List[OutputProfile]:
65+
"""Find multiple profiles.
66+
67+
Args:
68+
filters: The filter expressions to apply in the query.
69+
sortby: The sort expressions to apply in the query.
70+
paginate: The pagination expression to apply in the query.
71+
72+
Returns:
73+
The list of profiles matched by the query or an empty list.
74+
"""
3275
query: QueryExpr = [
3376
{"_name": "listProfile"},
3477
*self._build_subquery(filters=filters, sortby=sortby, paginate=paginate),
@@ -42,6 +85,14 @@ def find(
4285
)
4386

4487
def count(self, filters: Optional[FilterExpr] = None) -> int:
88+
"""Count profiles.
89+
90+
Args:
91+
filters: The filter expressions to apply in the query.
92+
93+
Returns:
94+
The count of profiles matched by the query.
95+
"""
4596
query: QueryExpr = [
4697
{"_name": "listProfile"},
4798
*self._build_subquery(filters=filters),

thehive4py/types/profile.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
from typing import List, TypedDict
22

3-
4-
class InputProfileRequired(TypedDict):
5-
name: str
3+
from typing_extensions import NotRequired
64

75

8-
class InputProfile(InputProfileRequired, total=False):
9-
permissions: List[str]
6+
class InputProfile(TypedDict):
7+
name: str
8+
permissions: NotRequired[List[str]]
109

1110

12-
class OutputProfileRequired(TypedDict):
11+
class OutputProfile(TypedDict):
1312
_id: str
1413
_type: str
1514
_createdBy: str
15+
_updatedBy: NotRequired[str]
1616
_createdAt: int
17+
_updatedAt: NotRequired[int]
1718
name: str
19+
permissions: NotRequired[List[str]]
1820
editable: bool
19-
isAdmin: bool
20-
21-
22-
class OutputProfile(OutputProfileRequired, total=False):
23-
_updatedBy: str
24-
_updatedAt: int
25-
permissions: List[str]
21+
forAdmin: bool
22+
forOrg: bool
23+
consumesLicense: bool
2624

2725

2826
class InputUpdateProfile(TypedDict, total=False):

0 commit comments

Comments
 (0)