qontract-reconcile 0.10.2.dev20__py3-none-any.whl → 0.10.2.dev21__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qontract-reconcile
3
- Version: 0.10.2.dev20
3
+ Version: 0.10.2.dev21
4
4
  Summary: Collection of tools to reconcile services with their desired state as defined in the app-interface DB.
5
5
  Project-URL: homepage, https://github.com/app-sre/qontract-reconcile
6
6
  Project-URL: repository, https://github.com/app-sre/qontract-reconcile
@@ -657,7 +657,7 @@ reconcile/utils/clusterhealth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
657
657
  reconcile/utils/clusterhealth/providerbase.py,sha256=DXomGYogckBLqWtXn0PXU0hWYxB6K0F7ernldrkHhVY,1140
658
658
  reconcile/utils/clusterhealth/telemeter.py,sha256=PllSLsJXvGNatmTF4mxCNPVbDrpr_MPk0m5pWj-LT6g,1534
659
659
  reconcile/utils/dynatrace/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
660
- reconcile/utils/dynatrace/client.py,sha256=H8EjqmZlB1a2ionAjV8_R1ozs9lWbmPCYKLe0J8kZAs,2838
660
+ reconcile/utils/dynatrace/client.py,sha256=RUk6KH-3CJyfJ1jolrdGQR4Hhz-tIWWJo9dsZ1IgJVw,3736
661
661
  reconcile/utils/glitchtip/__init__.py,sha256=FT6iBhGqoe7KExFdbgL8AYUb64iW_4snF5__Dcl7yt0,258
662
662
  reconcile/utils/glitchtip/client.py,sha256=ovh4tx-ajlihjvcq6nyY4chulbuMJYvzDPv9j9CuAKM,7867
663
663
  reconcile/utils/glitchtip/models.py,sha256=AJuGq4_A6G_T7asBKIw69-fOZLmT8HFrTKBEys7Tp00,6481
@@ -766,7 +766,7 @@ tools/saas_promotion_state/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
766
766
  tools/saas_promotion_state/saas_promotion_state.py,sha256=UfwwRLS5Ya4_Nh1w5n1dvoYtchQvYE9yj1VANt2IKqI,3925
767
767
  tools/sre_checkpoints/__init__.py,sha256=CDaDaywJnmRCLyl_NCcvxi-Zc0hTi_3OdwKiFOyS39I,145
768
768
  tools/sre_checkpoints/util.py,sha256=zEDbGr18ZeHNQwW8pUsr2JRjuXIPz--WAGJxZo9sv_Y,894
769
- qontract_reconcile-0.10.2.dev20.dist-info/METADATA,sha256=dMYY6LBhL21XhtZxss8dwyRBMyK2ce1Yh7UvoUBK2bM,24665
770
- qontract_reconcile-0.10.2.dev20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
771
- qontract_reconcile-0.10.2.dev20.dist-info/entry_points.txt,sha256=JniHZPadNOILPyfSl0LF2YSp3Db7K2_W2CN7i9f3Gos,540
772
- qontract_reconcile-0.10.2.dev20.dist-info/RECORD,,
769
+ qontract_reconcile-0.10.2.dev21.dist-info/METADATA,sha256=odjOqT6xlL94VSczTzQ6DNXDbhrppOG_UhaZk9wNnbg,24665
770
+ qontract_reconcile-0.10.2.dev21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
771
+ qontract_reconcile-0.10.2.dev21.dist-info/entry_points.txt,sha256=JniHZPadNOILPyfSl0LF2YSp3Db7K2_W2CN7i9f3Gos,540
772
+ qontract_reconcile-0.10.2.dev21.dist-info/RECORD,,
@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from collections.abc import Iterable
4
+ from datetime import datetime
5
+ from unittest.mock import patch
4
6
 
5
7
  from dynatrace import Dynatrace
6
8
  from dynatrace.environment_v2.tokens_api import ApiTokenUpdate
@@ -33,11 +35,32 @@ class DynatraceAPIToken(BaseModel):
33
35
  scopes: list[str]
34
36
 
35
37
 
38
+ # TODO: Remove once APPSRE-11428 is resolved #######
39
+ ISO_8601 = "%Y-%m-%dT%H:%M:%S.%fZ"
40
+ FIXED_ISO_8601 = "%Y-%m-%dT%H:%M:%SZ"
41
+
42
+
43
+ def custom_iso8601_to_datetime(timestamp: str | None) -> datetime | None:
44
+ if isinstance(timestamp, str):
45
+ try:
46
+ return datetime.strptime(timestamp, ISO_8601)
47
+ except ValueError:
48
+ return datetime.strptime(timestamp, FIXED_ISO_8601)
49
+ return timestamp
50
+
51
+
52
+ ################################################
53
+
54
+
36
55
  class DynatraceClient:
37
56
  def __init__(self, environment_url: str, api: Dynatrace) -> None:
38
57
  self._environment_url = environment_url
39
58
  self._api = api
40
59
 
60
+ @patch(
61
+ "dynatrace.environment_v2.tokens_api.iso8601_to_datetime",
62
+ custom_iso8601_to_datetime,
63
+ )
41
64
  def create_api_token(
42
65
  self, name: str, scopes: Iterable[str]
43
66
  ) -> DynatraceAPITokenCreated:
@@ -49,6 +72,10 @@ class DynatraceClient:
49
72
  ) from e
50
73
  return DynatraceAPITokenCreated(token=token.token, id=token.id)
51
74
 
75
+ @patch(
76
+ "dynatrace.environment_v2.tokens_api.iso8601_to_datetime",
77
+ custom_iso8601_to_datetime,
78
+ )
52
79
  def get_token_ids_map_for_name_prefix(self, prefix: str) -> dict[str, str]:
53
80
  try:
54
81
  dt_tokens = self._api.tokens.list()
@@ -60,6 +87,10 @@ class DynatraceClient:
60
87
  token.id: token.name for token in dt_tokens if token.name.startswith(prefix)
61
88
  }
62
89
 
90
+ @patch(
91
+ "dynatrace.environment_v2.tokens_api.iso8601_to_datetime",
92
+ custom_iso8601_to_datetime,
93
+ )
63
94
  def get_token_by_id(self, token_id: str) -> DynatraceAPIToken:
64
95
  try:
65
96
  token = self._api.tokens.get(token_id=token_id)