88import json
99from datetime import datetime
1010
11+
1112class DatabunkerproAPI :
1213 """Main client class for interacting with the DatabunkerPro API."""
1314
14- def __init__ (self , base_url : str , x_bunker_token : str = "" , x_bunker_tenant : str = "" ):
15+ def __init__ (
16+ self , base_url : str , x_bunker_token : str = "" , x_bunker_tenant : str = ""
17+ ):
1518 """
1619 Initialize the DatabunkerPro API client.
1720
@@ -20,12 +23,17 @@ def __init__(self, base_url: str, x_bunker_token: str = "", x_bunker_tenant: str
2023 x_bunker_token (str, optional): The X-Bunker-Token for authentication
2124 x_bunker_tenant (str, optional): The X-Bunker-Tenant identifier
2225 """
23- self .base_url = base_url .rstrip ('/' )
26+ self .base_url = base_url .rstrip ("/" )
2427 self .x_bunker_token = x_bunker_token
2528 self .x_bunker_tenant = x_bunker_tenant
2629
27- def _make_request (self , endpoint : str , method : str = "POST" , data : Optional [Dict [str , Any ]] = None ,
28- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
30+ def _make_request (
31+ self ,
32+ endpoint : str ,
33+ method : str = "POST" ,
34+ data : Optional [Dict [str , Any ]] = None ,
35+ request_metadata : Optional [Dict [str , Any ]] = None ,
36+ ) -> Dict [str , Any ]:
2937 """
3038 Make a request to the DatabunkerPro API.
3139
@@ -41,9 +49,7 @@ def _make_request(self, endpoint: str, method: str = "POST", data: Optional[Dict
4149 Raises:
4250 Exception: If the API request fails
4351 """
44- headers = {
45- "Content-Type" : "application/json"
46- }
52+ headers = {"Content-Type" : "application/json" }
4753
4854 if self .x_bunker_token :
4955 headers ["X-Bunker-Token" ] = self .x_bunker_token
@@ -75,8 +81,12 @@ def _make_request(self, endpoint: str, method: str = "POST", data: Optional[Dict
7581 except requests .exceptions .RequestException as e :
7682 raise Exception (f"Error making request: { str (e )} " )
7783
78- def create_user (self , profile : Dict [str , Any ], options : Optional [Dict [str , Any ]] = None ,
79- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
84+ def create_user (
85+ self ,
86+ profile : Dict [str , Any ],
87+ options : Optional [Dict [str , Any ]] = None ,
88+ request_metadata : Optional [Dict [str , Any ]] = None ,
89+ ) -> Dict [str , Any ]:
8090 """
8191 Create a new user in DatabunkerPro.
8292
@@ -93,8 +103,12 @@ def create_user(self, profile: Dict[str, Any], options: Optional[Dict[str, Any]]
93103 data .update (options )
94104 return self ._make_request ("UserCreate" , "POST" , data , request_metadata )
95105
96- def get_user (self , mode : str , identity : str ,
97- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
106+ def get_user (
107+ self ,
108+ mode : str ,
109+ identity : str ,
110+ request_metadata : Optional [Dict [str , Any ]] = None ,
111+ ) -> Dict [str , Any ]:
98112 """
99113 Get user information from DatabunkerPro.
100114
@@ -106,10 +120,17 @@ def get_user(self, mode: str, identity: str,
106120 Returns:
107121 Dict[str, Any]: The API response
108122 """
109- return self ._make_request ("UserGet" , "POST" , {"mode" : mode , "identity" : identity }, request_metadata )
123+ return self ._make_request (
124+ "UserGet" , "POST" , {"mode" : mode , "identity" : identity }, request_metadata
125+ )
110126
111- def update_user (self , mode : str , identity : str , profile : Dict [str , Any ],
112- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
127+ def update_user (
128+ self ,
129+ mode : str ,
130+ identity : str ,
131+ profile : Dict [str , Any ],
132+ request_metadata : Optional [Dict [str , Any ]] = None ,
133+ ) -> Dict [str , Any ]:
113134 """
114135 Update user information in DatabunkerPro.
115136
@@ -122,12 +143,19 @@ def update_user(self, mode: str, identity: str, profile: Dict[str, Any],
122143 Returns:
123144 Dict[str, Any]: The API response
124145 """
125- return self ._make_request ("UserUpdate" , "POST" ,
126- {"mode" : mode , "identity" : identity , "profile" : profile },
127- request_metadata )
146+ return self ._make_request (
147+ "UserUpdate" ,
148+ "POST" ,
149+ {"mode" : mode , "identity" : identity , "profile" : profile },
150+ request_metadata ,
151+ )
128152
129- def delete_user (self , mode : str , identity : str ,
130- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
153+ def delete_user (
154+ self ,
155+ mode : str ,
156+ identity : str ,
157+ request_metadata : Optional [Dict [str , Any ]] = None ,
158+ ) -> Dict [str , Any ]:
131159 """
132160 Delete a user from DatabunkerPro.
133161
@@ -139,9 +167,13 @@ def delete_user(self, mode: str, identity: str,
139167 Returns:
140168 Dict[str, Any]: The API response
141169 """
142- return self ._make_request ("UserDelete" , "POST" , {"mode" : mode , "identity" : identity }, request_metadata )
170+ return self ._make_request (
171+ "UserDelete" , "POST" , {"mode" : mode , "identity" : identity }, request_metadata
172+ )
143173
144- def get_system_stats (self , request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
174+ def get_system_stats (
175+ self , request_metadata : Optional [Dict [str , Any ]] = None
176+ ) -> Dict [str , Any ]:
145177 """
146178 Get system statistics from DatabunkerPro.
147179
@@ -151,11 +183,17 @@ def get_system_stats(self, request_metadata: Optional[Dict[str, Any]] = None) ->
151183 Returns:
152184 Dict[str, Any]: The API response containing system statistics
153185 """
154- return self ._make_request ("SystemGetSystemStats" , "POST" , None , request_metadata )
186+ return self ._make_request (
187+ "SystemGetSystemStats" , "POST" , None , request_metadata
188+ )
155189
156- def create_token (self , token_type : str , record : str ,
157- options : Optional [Dict [str , Any ]] = None ,
158- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
190+ def create_token (
191+ self ,
192+ token_type : str ,
193+ record : str ,
194+ options : Optional [Dict [str , Any ]] = None ,
195+ request_metadata : Optional [Dict [str , Any ]] = None ,
196+ ) -> Dict [str , Any ]:
159197 """
160198 Create a token for sensitive data.
161199
@@ -173,8 +211,9 @@ def create_token(self, token_type: str, record: str,
173211 data .update (options )
174212 return self ._make_request ("TokenCreate" , "POST" , data , request_metadata )
175213
176- def get_token (self , token : str ,
177- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
214+ def get_token (
215+ self , token : str , request_metadata : Optional [Dict [str , Any ]] = None
216+ ) -> Dict [str , Any ]:
178217 """
179218 Get token information from DatabunkerPro.
180219
@@ -185,10 +224,13 @@ def get_token(self, token: str,
185224 Returns:
186225 Dict[str, Any]: The API response
187226 """
188- return self ._make_request ("TokenGet" , "POST" , {"token" : token }, request_metadata )
227+ return self ._make_request (
228+ "TokenGet" , "POST" , {"token" : token }, request_metadata
229+ )
189230
190- def delete_token (self , token : str ,
191- request_metadata : Optional [Dict [str , Any ]] = None ) -> Dict [str , Any ]:
231+ def delete_token (
232+ self , token : str , request_metadata : Optional [Dict [str , Any ]] = None
233+ ) -> Dict [str , Any ]:
192234 """
193235 Delete a token from DatabunkerPro.
194236
@@ -199,4 +241,6 @@ def delete_token(self, token: str,
199241 Returns:
200242 Dict[str, Any]: The API response
201243 """
202- return self ._make_request ("TokenDelete" , "POST" , {"token" : token }, request_metadata )
244+ return self ._make_request (
245+ "TokenDelete" , "POST" , {"token" : token }, request_metadata
246+ )
0 commit comments