neris-api-client 1.3.4__tar.gz → 1.3.6__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: neris_api_client
3
- Version: 1.3.4
3
+ Version: 1.3.6
4
4
  Summary: NERIS API Client
5
5
  Author-email: Ben Coleman <ben.coleman@ul.org>, Tommy Messbauer <thomas.messbauer@ul.org>, Joseph Pagani <joseph.pagani@ul.org>
6
6
  Project-URL: Homepage, https://github.com/ulfsri/neris-api-client
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "neris_api_client"
7
- version = "1.3.4"
7
+ version = "1.3.6"
8
8
  authors = [
9
9
  { name="Ben Coleman", email="ben.coleman@ul.org" },
10
10
  { name="Tommy Messbauer", email="thomas.messbauer@ul.org" },
@@ -13,13 +13,15 @@ from .config import Config, GrantType, TokenSet
13
13
  from .models import (
14
14
  IncidentPayload,
15
15
  PatchUnitPayload,
16
+ CreateUnitPayload,
16
17
  CreateUserPayload,
17
18
  DepartmentPayload,
18
19
  UpdateUserPayload,
20
+ PatchIncidentAction,
19
21
  PatchStationPayload,
22
+ CreateStationPayload,
20
23
  PatchDepartmentPayload,
21
24
  CreateDepartmentPayload,
22
- PatchIncidentAction,
23
25
  TypeIncidentStatusValue,
24
26
  )
25
27
 
@@ -47,12 +49,14 @@ class _NerisApiClient:
47
49
  case GrantType.CLIENT_CREDENTIALS:
48
50
  assert config.client_id is not None
49
51
  assert config.client_secret is not None
50
- self.client_creds = base64.b64encode(f"{config.client_id}:{config.client_secret}".encode("utf-8")).decode("utf-8")
52
+ self.client_creds = base64.b64encode(
53
+ f"{config.client_id}:{config.client_secret}".encode("utf-8")
54
+ ).decode("utf-8")
51
55
  case GrantType.PASSWORD:
52
56
  assert config.username is not None
53
57
  assert config.password is not None
54
58
  case _:
55
- raise Exception("Bad grant type. Must be \"password\" or \"client_credentials\"")
59
+ raise Exception('Bad grant type. Must be "password" or "client_credentials"')
56
60
 
57
61
  self.config = config
58
62
 
@@ -65,7 +69,7 @@ class _NerisApiClient:
65
69
  case GrantType.PASSWORD:
66
70
  res = self._session.post(
67
71
  token_url,
68
- headers={'Content-Type': 'application/x-www-form-urlencoded'},
72
+ headers={"Content-Type": "application/x-www-form-urlencoded"},
69
73
  data={
70
74
  "grant_type": GrantType.PASSWORD,
71
75
  "username": self.config.username,
@@ -76,7 +80,10 @@ class _NerisApiClient:
76
80
  case GrantType.CLIENT_CREDENTIALS:
77
81
  res = self._session.post(
78
82
  token_url,
79
- headers={"Authorization": f"Basic {self.client_creds}", "Content-Type": "application/x-www-form-urlencoded"},
83
+ headers={
84
+ "Authorization": f"Basic {self.client_creds}",
85
+ "Content-Type": "application/x-www-form-urlencoded",
86
+ },
80
87
  data={"grant_type": GrantType.CLIENT_CREDENTIALS},
81
88
  )
82
89
 
@@ -97,7 +104,10 @@ class _NerisApiClient:
97
104
  res = self._session.post(
98
105
  token_url,
99
106
  # Basic auth required for NERIS refresh tokens
100
- headers={"Authorization": f"Basic {self.client_creds}", "Content-Type": "application/x-www-form-urlencoded"},
107
+ headers={
108
+ "Authorization": f"Basic {self.client_creds}",
109
+ "Content-Type": "application/x-www-form-urlencoded",
110
+ },
101
111
  data={
102
112
  "grant_type": "refresh_token",
103
113
  "refresh_token": self.tokens.refresh_token,
@@ -141,13 +151,13 @@ class _NerisApiClient:
141
151
 
142
152
  res = self._session.post(
143
153
  token_url,
144
- headers={'Content-Type': 'application/x-www-form-urlencoded'},
154
+ headers={"Content-Type": "application/x-www-form-urlencoded"},
145
155
  data={
146
156
  "grant_type": got["challenge_name"],
147
157
  "username": self.config.username,
148
158
  "session": got["session"],
149
159
  got["challenge_name"]: code,
150
- }
160
+ },
151
161
  )
152
162
 
153
163
  def _call(
@@ -167,8 +177,9 @@ class _NerisApiClient:
167
177
  if isinstance(data, dict):
168
178
  data = model.model_validate(data).model_dump(mode="json", by_alias=True)
169
179
 
170
-
171
- res = getattr(self._session, method)(f"{self.config.base_url}{path}", json=data, params=params)
180
+ res = getattr(self._session, method)(
181
+ f"{self.config.base_url}{path}", json=data, params=params
182
+ )
172
183
 
173
184
  if self.config.debug:
174
185
  print(
@@ -180,12 +191,11 @@ class _NerisApiClient:
180
191
  "headers": self._session.headers,
181
192
  "params": params,
182
193
  },
183
-
184
194
  "response": {
185
195
  "status_code": res.status_code,
186
196
  "headers": res.headers,
187
197
  "content": res.text,
188
- }
198
+ },
189
199
  },
190
200
  indent=4,
191
201
  cls=Encoder,
@@ -236,11 +246,17 @@ class NerisApiClient(_NerisApiClient):
236
246
  def delete_user(self, sub: str | UUID) -> None:
237
247
  self._call("delete", f"/user/{sub}")
238
248
 
239
- def create_user_role_entity_set_attachment(self, sub_user: str | UUID, nuid_role: str | UUID, nuid_entity_set: str | UUID) -> Dict[str, Any]:
249
+ def create_user_role_entity_set_attachment(
250
+ self, sub_user: str | UUID, nuid_role: str | UUID, nuid_entity_set: str | UUID
251
+ ) -> Dict[str, Any]:
240
252
  return self._call(
241
253
  "post",
242
254
  "/auth/user_role_entity_set_attachment",
243
- params={"sub_user": str(sub_user), "nuid_role": str(nuid_role), "nuid_entity_set": str(nuid_entity_set)},
255
+ params={
256
+ "sub_user": str(sub_user),
257
+ "nuid_role": str(nuid_role),
258
+ "nuid_entity_set": str(nuid_entity_set),
259
+ },
244
260
  )
245
261
 
246
262
  def create_user_entity_membership(self, sub: str | UUID, neris_id: str) -> None:
@@ -270,6 +286,11 @@ class NerisApiClient(_NerisApiClient):
270
286
  def patch_entity(self, neris_id: str, body: str | Dict[str, Any]) -> Dict[str, Any]:
271
287
  return self._call("patch", f"/entity/{neris_id}", data=body, model=PatchDepartmentPayload)
272
288
 
289
+ def create_station(self, neris_id_entity: str, body: str | Dict[str, Any]) -> Dict[str, Any]:
290
+ return self._call(
291
+ "post", f"/entity/{neris_id_entity}/station", data=body, model=CreateStationPayload
292
+ )
293
+
273
294
  def patch_station(
274
295
  self, neris_id_entity: str, neris_id_station: str, body: str | Dict[str, Any]
275
296
  ) -> Dict[str, Any]:
@@ -280,6 +301,16 @@ class NerisApiClient(_NerisApiClient):
280
301
  model=PatchStationPayload,
281
302
  )
282
303
 
304
+ def create_unit(
305
+ self, neris_id_entity: str, neris_id_station: str, body: str | Dict[str, Any]
306
+ ) -> Dict[str, Any]:
307
+ return self._call(
308
+ "post",
309
+ f"/entity/{neris_id_entity}/station/{neris_id_station}",
310
+ data=body,
311
+ model=CreateUnitPayload,
312
+ )
313
+
283
314
  def patch_unit(
284
315
  self,
285
316
  neris_id_entity: str,
@@ -309,15 +340,15 @@ class NerisApiClient(_NerisApiClient):
309
340
  ) -> Dict[str, Any]:
310
341
  return self._call(
311
342
  "put",
312
- f"/incident/{neris_id_entity}/{neris_id_incident}/status",
343
+ f"/incident/{neris_id_entity}/{neris_id_incident}/incident_status",
313
344
  data={"status": str(status)},
314
345
  )
315
346
 
316
347
  def create_api_integration(self, neris_id: str, title: str) -> Dict[str, Any]:
317
- return self._call("post", f"/account/integration/{neris_id}", data={ "title": title })
348
+ return self._call("post", f"/account/integration/{neris_id}", data={"title": title})
318
349
 
319
350
  def generate_api_secret(self, client_id: str, title: str) -> Dict[str, Any]:
320
- return self._call("post", f"/account/credential/{client_id}", data={ "title": title })
351
+ return self._call("post", f"/account/credential/{client_id}", data={"title": title})
321
352
 
322
353
  def list_integrations(self, neris_id: str) -> Dict[str, Any]:
323
354
  return self._call("get", f"/account/integration/{neris_id}/list")