pydiagral 1.5.0b4__py3-none-any.whl → 1.5.0b5__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.
- pydiagral/api.py +38 -22
- pydiagral/exceptions.py +8 -0
- {pydiagral-1.5.0b4.dist-info → pydiagral-1.5.0b5.dist-info}/METADATA +1 -1
- pydiagral-1.5.0b5.dist-info/RECORD +10 -0
- pydiagral-1.5.0b4.dist-info/RECORD +0 -10
- {pydiagral-1.5.0b4.dist-info → pydiagral-1.5.0b5.dist-info}/WHEEL +0 -0
- {pydiagral-1.5.0b4.dist-info → pydiagral-1.5.0b5.dist-info}/licenses/LICENSE +0 -0
pydiagral/api.py
CHANGED
@@ -16,6 +16,8 @@ import aiohttp
|
|
16
16
|
|
17
17
|
from .constants import API_VERSION, BASE_URL
|
18
18
|
from .exceptions import (
|
19
|
+
APIKeyCreationError,
|
20
|
+
APIValidationError,
|
19
21
|
AuthenticationError,
|
20
22
|
ClientError,
|
21
23
|
ConfigurationError,
|
@@ -266,7 +268,8 @@ class DiagralAPI:
|
|
266
268
|
ApiKeyWithSecret: An instance of ApiKeyWithSecret containing the created API key and secret key.
|
267
269
|
|
268
270
|
Raises:
|
269
|
-
|
271
|
+
APIKeyCreationError: If the API key creation fails.
|
272
|
+
APIValidationError: If the API key validation fails.
|
270
273
|
|
271
274
|
"""
|
272
275
|
|
@@ -285,16 +288,16 @@ class DiagralAPI:
|
|
285
288
|
set_apikey_response: ApiKeyWithSecret = ApiKeyWithSecret.from_dict(
|
286
289
|
response_data
|
287
290
|
)
|
288
|
-
self.__apikey = set_apikey_response.api_key
|
291
|
+
self.__apikey: str = set_apikey_response.api_key
|
289
292
|
if not self.__apikey:
|
290
293
|
error_msg = "API key not found in response"
|
291
294
|
_LOGGER.error(error_msg)
|
292
|
-
raise
|
293
|
-
self.__secret_key = set_apikey_response.secret_key
|
295
|
+
raise APIKeyCreationError(error_msg)
|
296
|
+
self.__secret_key: str = set_apikey_response.secret_key
|
294
297
|
if not self.__secret_key:
|
295
298
|
error_msg = "Secret key not found in response"
|
296
299
|
_LOGGER.error(error_msg)
|
297
|
-
raise
|
300
|
+
raise APIKeyCreationError(error_msg)
|
298
301
|
|
299
302
|
_LOGGER.info("Successfully created new API key: ...%s", self.__apikey[-4:])
|
300
303
|
# Verify if the API key is valid
|
@@ -303,14 +306,14 @@ class DiagralAPI:
|
|
303
306
|
_LOGGER.info(
|
304
307
|
"Successfully verified new API key: ...%s", self.__apikey[-4:]
|
305
308
|
)
|
306
|
-
except
|
309
|
+
except APIValidationError as e:
|
307
310
|
_LOGGER.error("Created API key failed validation: %s", e)
|
308
311
|
self.__apikey = None
|
309
312
|
raise
|
310
313
|
except DiagralAPIError as e:
|
311
314
|
error_msg: str = f"Failed to create API key: {e!s}"
|
312
315
|
_LOGGER.error(error_msg)
|
313
|
-
raise
|
316
|
+
raise APIKeyCreationError(error_msg) from e
|
314
317
|
|
315
318
|
return ApiKeyWithSecret(api_key=self.__apikey, secret_key=self.__secret_key)
|
316
319
|
|
@@ -329,6 +332,7 @@ class DiagralAPI:
|
|
329
332
|
|
330
333
|
Raises:
|
331
334
|
ConfigurationError: If no API key is provided or if the API key is invalid.
|
335
|
+
APIValidationError: If the API key is invalid or not found in the list of valid keys.
|
332
336
|
|
333
337
|
"""
|
334
338
|
|
@@ -357,7 +361,7 @@ class DiagralAPI:
|
|
357
361
|
if is_valid:
|
358
362
|
_LOGGER.info("API key successfully validated")
|
359
363
|
else:
|
360
|
-
raise
|
364
|
+
raise APIValidationError(
|
361
365
|
"API key is invalid or not found in the list of valid keys"
|
362
366
|
)
|
363
367
|
|
@@ -415,7 +419,14 @@ class DiagralAPI:
|
|
415
419
|
if non-ephemeral temporary keys were generated.
|
416
420
|
|
417
421
|
Raises:
|
418
|
-
|
422
|
+
APIKeyCreationError: If creation of temporary API keys fails
|
423
|
+
APIValidationError: If API key validation fails
|
424
|
+
SessionError: If the session is not initialized.
|
425
|
+
DiagralAPIError: If the request results in a 400 status code or other API errors.
|
426
|
+
AuthenticationError: If authentication fails or request results in a 401 or 403 status code.
|
427
|
+
ValidationError: If the request results in a 422 status code.
|
428
|
+
ServerError: If the request results in a 500 or 503 status code.
|
429
|
+
ClientError: If there is a network error.
|
419
430
|
|
420
431
|
Note:
|
421
432
|
If API credentials are not provided during client initialization, temporary
|
@@ -427,20 +438,25 @@ class DiagralAPI:
|
|
427
438
|
|
428
439
|
result: TryConnectResult = TryConnectResult()
|
429
440
|
api_keys_provided = bool(self.__apikey and self.__secret_key)
|
430
|
-
try:
|
431
|
-
# If API keys are not provided, generate temporary keys
|
432
|
-
if not api_keys_provided:
|
433
|
-
api_key_response: ApiKeyWithSecret = await self.set_apikey()
|
434
441
|
|
435
|
-
|
442
|
+
# If API keys are not provided, generate temporary keys
|
443
|
+
if not api_keys_provided:
|
444
|
+
api_key_response: ApiKeyWithSecret = await self.set_apikey()
|
445
|
+
|
446
|
+
# Retrieve system status to validate connection
|
447
|
+
try:
|
436
448
|
await self.get_system_status()
|
437
|
-
|
449
|
+
except DiagralAPIError:
|
438
450
|
if ephemeral and not api_keys_provided:
|
439
451
|
await self.delete_apikey(apikey=self.__apikey)
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
452
|
+
raise
|
453
|
+
|
454
|
+
# If connection is successful, clean up temporary keys if requested (ephemeral)
|
455
|
+
if ephemeral and not api_keys_provided:
|
456
|
+
await self.delete_apikey(apikey=self.__apikey)
|
457
|
+
elif not ephemeral and not api_keys_provided:
|
458
|
+
result.keys = api_key_response
|
459
|
+
|
444
460
|
result.result = True
|
445
461
|
return result
|
446
462
|
|
@@ -602,17 +618,17 @@ class DiagralAPI:
|
|
602
618
|
SystemStatus: An instance of SystemStatus containing the retrieved system status.
|
603
619
|
|
604
620
|
Raises:
|
605
|
-
|
621
|
+
ConfigurationError: If the API key, secret key, or PIN code is not provided.
|
606
622
|
|
607
623
|
"""
|
608
624
|
|
609
625
|
if not self.__apikey or not self.__secret_key:
|
610
|
-
raise
|
626
|
+
raise ConfigurationError(
|
611
627
|
"API key and secret key required to get system details"
|
612
628
|
)
|
613
629
|
|
614
630
|
if not self.__pincode:
|
615
|
-
raise
|
631
|
+
raise ConfigurationError("PIN code required to get system details")
|
616
632
|
|
617
633
|
_TIMESTAMP = str(int(time.time()))
|
618
634
|
_HMAC: str = generate_hmac_signature(
|
pydiagral/exceptions.py
CHANGED
@@ -37,3 +37,11 @@ class ServerError(DiagralAPIError):
|
|
37
37
|
|
38
38
|
class ClientError(DiagralAPIError):
|
39
39
|
"""Raised when client returns error."""
|
40
|
+
|
41
|
+
|
42
|
+
class APIKeyCreationError(DiagralAPIError):
|
43
|
+
"""Raised when API key creation fails."""
|
44
|
+
|
45
|
+
|
46
|
+
class APIValidationError(DiagralAPIError):
|
47
|
+
"""Raised when API validation fails."""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pydiagral
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.0b5
|
4
4
|
Summary: A Python library for interacting with Diagral systems
|
5
5
|
Project-URL: Homepage, https://github.com/mguyard/pydiagral
|
6
6
|
Project-URL: Documentation, https://github.com/mguyard/pydiagral
|
@@ -0,0 +1,10 @@
|
|
1
|
+
pydiagral/__init__.py,sha256=4uM-RD2GQ6JYJkxu-D6wj3XpqfY5gN2hP8NF6WvRI9k,576
|
2
|
+
pydiagral/api.py,sha256=hF-Ol5KHqRXfpKcnxV8SLf-vnYwCTYugQzuQ5_ZG_bs,50094
|
3
|
+
pydiagral/constants.py,sha256=2B0TdKxQHA3cpIBxojo43bMW44wN9xKYsHbBRHWsaBk,119
|
4
|
+
pydiagral/exceptions.py,sha256=vMhGDQW-AhYIH9gcKHK1-4SHV3eZUXeeqXPyznUAKnU,1211
|
5
|
+
pydiagral/models.py,sha256=vUjxuApjVaMtd7H6Iw5LarwABi30O4FfdObhZRbUNuc,54931
|
6
|
+
pydiagral/utils.py,sha256=-VxI-lNaC4bU1K4DSmWDhvbsS2bXv5FAGULGKBf1UMU,449
|
7
|
+
pydiagral-1.5.0b5.dist-info/METADATA,sha256=HhOvxestYlemcBg-V3rqY88zG0ltD5X7Az4-lUDWVw0,48531
|
8
|
+
pydiagral-1.5.0b5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
+
pydiagral-1.5.0b5.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
10
|
+
pydiagral-1.5.0b5.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
pydiagral/__init__.py,sha256=4uM-RD2GQ6JYJkxu-D6wj3XpqfY5gN2hP8NF6WvRI9k,576
|
2
|
-
pydiagral/api.py,sha256=ZshZu5NTSyjK7ozPYrXO6q94yjxnHt3h_boiGzRIUzk,49410
|
3
|
-
pydiagral/constants.py,sha256=2B0TdKxQHA3cpIBxojo43bMW44wN9xKYsHbBRHWsaBk,119
|
4
|
-
pydiagral/exceptions.py,sha256=Q5wEpNtiykLs3Ck0W8r1IQAJek_omaQ3jpMOtiiwBUg,1030
|
5
|
-
pydiagral/models.py,sha256=vUjxuApjVaMtd7H6Iw5LarwABi30O4FfdObhZRbUNuc,54931
|
6
|
-
pydiagral/utils.py,sha256=-VxI-lNaC4bU1K4DSmWDhvbsS2bXv5FAGULGKBf1UMU,449
|
7
|
-
pydiagral-1.5.0b4.dist-info/METADATA,sha256=qurrNFVqrGxsuLKX9VJKPdtsW8ZhnA2A19rnC1voRPM,48531
|
8
|
-
pydiagral-1.5.0b4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
-
pydiagral-1.5.0b4.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
10
|
-
pydiagral-1.5.0b4.dist-info/RECORD,,
|
File without changes
|
File without changes
|