qontract-reconcile 0.10.1rc948__py3-none-any.whl → 0.10.1rc949__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.1
2
2
  Name: qontract-reconcile
3
- Version: 0.10.1rc948
3
+ Version: 0.10.1rc949
4
4
  Summary: Collection of tools to reconcile services with their desired state as defined in the app-interface DB.
5
5
  Home-page: https://github.com/app-sre/qontract-reconcile
6
6
  Author: Red Hat App-SRE Team
@@ -732,6 +732,8 @@ reconcile/utils/cloud_resource_best_practice/aws_rds.py,sha256=EvE6XKLsrZ531MJpt
732
732
  reconcile/utils/clusterhealth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
733
733
  reconcile/utils/clusterhealth/providerbase.py,sha256=DXomGYogckBLqWtXn0PXU0hWYxB6K0F7ernldrkHhVY,1140
734
734
  reconcile/utils/clusterhealth/telemeter.py,sha256=plZ2xInKJ1ZzgZGPMJzPYmPAWCG2YUxs8j_9IPsqsH8,1426
735
+ reconcile/utils/dynatrace/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
736
+ reconcile/utils/dynatrace/client.py,sha256=CsjhxyCxum2X_cl8bAe701rUvVu6PflAwIR0nBEQ2yU,1697
735
737
  reconcile/utils/glitchtip/__init__.py,sha256=FT6iBhGqoe7KExFdbgL8AYUb64iW_4snF5__Dcl7yt0,258
736
738
  reconcile/utils/glitchtip/client.py,sha256=EXJVIc0aUqkfApU4IIDoc89841XgUL7jJNyb0gLDpMI,7736
737
739
  reconcile/utils/glitchtip/models.py,sha256=i3DsGoRJkAeOVsdCEqjlMRjJcYBMXf9Qtx5VpG9xgdA,6391
@@ -844,8 +846,8 @@ tools/test/test_qontract_cli.py,sha256=_D61RFGAN5x44CY1tYbouhlGXXABwYfxKSWSQx3Jr
844
846
  tools/test/test_saas_promotion_state.py,sha256=dy4kkSSAQ7bC0Xp2CociETGN-2aABEfL6FU5D9Jl00Y,6056
845
847
  tools/test/test_sd_app_sre_alert_report.py,sha256=v363r9zM7__0kR5K6mvJoGFcM9BvE33fWAayrqkpojA,2116
846
848
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
847
- qontract_reconcile-0.10.1rc948.dist-info/METADATA,sha256=EANO3eIGME2obDm2HO01Vd2LeR5lLaf6_JBfi6ZJEew,2262
848
- qontract_reconcile-0.10.1rc948.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
849
- qontract_reconcile-0.10.1rc948.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
850
- qontract_reconcile-0.10.1rc948.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
851
- qontract_reconcile-0.10.1rc948.dist-info/RECORD,,
849
+ qontract_reconcile-0.10.1rc949.dist-info/METADATA,sha256=SaOcWUK9s8vt6wWla8KbHay5iD3vZYVIDq89zJMrRYA,2262
850
+ qontract_reconcile-0.10.1rc949.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
851
+ qontract_reconcile-0.10.1rc949.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
852
+ qontract_reconcile-0.10.1rc949.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
853
+ qontract_reconcile-0.10.1rc949.dist-info/RECORD,,
File without changes
@@ -0,0 +1,57 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Iterable
4
+
5
+ from dynatrace import Dynatrace
6
+ from pydantic import BaseModel
7
+
8
+
9
+ class DynatraceTokenCreationError(Exception):
10
+ pass
11
+
12
+
13
+ class DynatraceTokenRetrievalError(Exception):
14
+ pass
15
+
16
+
17
+ class DynatraceAPITokenCreated(BaseModel):
18
+ """
19
+ Wrap dynatrace.ApiTokenCreated for decoupling
20
+ """
21
+
22
+ token: str
23
+ id: str
24
+
25
+
26
+ class DynatraceClient:
27
+ def __init__(self, environment_url: str, api: Dynatrace) -> None:
28
+ self._environment_url = environment_url
29
+ self._api = api
30
+
31
+ def create_api_token(
32
+ self, name: str, scopes: Iterable[str]
33
+ ) -> DynatraceAPITokenCreated:
34
+ try:
35
+ token = self._api.tokens.create(name=name, scopes=scopes)
36
+ except Exception as e:
37
+ raise DynatraceTokenCreationError(
38
+ f"{self._environment_url=} Failed to create token for {name=}", e
39
+ ) from e
40
+ return DynatraceAPITokenCreated(token=token.token, id=token.id)
41
+
42
+ def get_token_ids_for_name_prefix(self, prefix: str) -> list[str]:
43
+ try:
44
+ dt_tokens = self._api.tokens.list()
45
+ except Exception as e:
46
+ raise DynatraceTokenRetrievalError(
47
+ f"{self._environment_url=} Failed to retrieve tokens for {prefix=}", e
48
+ ) from e
49
+ return [token.id for token in dt_tokens if token.name.startswith(prefix)]
50
+
51
+ @staticmethod
52
+ def create(
53
+ environment_url: str, token: str | None, api: Dynatrace | None
54
+ ) -> DynatraceClient:
55
+ if not api:
56
+ api = Dynatrace(base_url=environment_url, token=token)
57
+ return DynatraceClient(environment_url=environment_url, api=api)