qontract-reconcile 0.10.1rc992__py3-none-any.whl → 0.10.1rc993__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.1rc992
3
+ Version: 0.10.1rc993
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
@@ -740,7 +740,7 @@ reconcile/utils/clusterhealth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
740
740
  reconcile/utils/clusterhealth/providerbase.py,sha256=DXomGYogckBLqWtXn0PXU0hWYxB6K0F7ernldrkHhVY,1140
741
741
  reconcile/utils/clusterhealth/telemeter.py,sha256=PllSLsJXvGNatmTF4mxCNPVbDrpr_MPk0m5pWj-LT6g,1534
742
742
  reconcile/utils/dynatrace/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
743
- reconcile/utils/dynatrace/client.py,sha256=CsjhxyCxum2X_cl8bAe701rUvVu6PflAwIR0nBEQ2yU,1697
743
+ reconcile/utils/dynatrace/client.py,sha256=siVDdCQeLaWm4W1T-QKnFwlotPmXmZfpyoe3pXowBt8,2760
744
744
  reconcile/utils/glitchtip/__init__.py,sha256=FT6iBhGqoe7KExFdbgL8AYUb64iW_4snF5__Dcl7yt0,258
745
745
  reconcile/utils/glitchtip/client.py,sha256=ovh4tx-ajlihjvcq6nyY4chulbuMJYvzDPv9j9CuAKM,7867
746
746
  reconcile/utils/glitchtip/models.py,sha256=uHbCK9-RWgxNYUAkEHXRAZRDDZW7jkOFFt9MdlqN4bU,6481
@@ -854,8 +854,8 @@ tools/test/test_qontract_cli.py,sha256=_D61RFGAN5x44CY1tYbouhlGXXABwYfxKSWSQx3Jr
854
854
  tools/test/test_saas_promotion_state.py,sha256=dy4kkSSAQ7bC0Xp2CociETGN-2aABEfL6FU5D9Jl00Y,6056
855
855
  tools/test/test_sd_app_sre_alert_report.py,sha256=v363r9zM7__0kR5K6mvJoGFcM9BvE33fWAayrqkpojA,2116
856
856
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
857
- qontract_reconcile-0.10.1rc992.dist-info/METADATA,sha256=DRFJMM8ZzS7zsrDv77wTXC9PngnJiNg-SphE3U7qjrQ,2262
858
- qontract_reconcile-0.10.1rc992.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
859
- qontract_reconcile-0.10.1rc992.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
860
- qontract_reconcile-0.10.1rc992.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
861
- qontract_reconcile-0.10.1rc992.dist-info/RECORD,,
857
+ qontract_reconcile-0.10.1rc993.dist-info/METADATA,sha256=D2wGMe7boygHgZavBj6P-78L2Mx4C9FZxKzi-rHUTYc,2262
858
+ qontract_reconcile-0.10.1rc993.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
859
+ qontract_reconcile-0.10.1rc993.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
860
+ qontract_reconcile-0.10.1rc993.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
861
+ qontract_reconcile-0.10.1rc993.dist-info/RECORD,,
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  from collections.abc import Iterable
4
4
 
5
5
  from dynatrace import Dynatrace
6
+ from dynatrace.environment_v2.tokens_api import ApiTokenUpdate
6
7
  from pydantic import BaseModel
7
8
 
8
9
 
@@ -10,6 +11,10 @@ class DynatraceTokenCreationError(Exception):
10
11
  pass
11
12
 
12
13
 
14
+ class DynatraceTokenUpdateError(Exception):
15
+ pass
16
+
17
+
13
18
  class DynatraceTokenRetrievalError(Exception):
14
19
  pass
15
20
 
@@ -23,6 +28,11 @@ class DynatraceAPITokenCreated(BaseModel):
23
28
  id: str
24
29
 
25
30
 
31
+ class DynatraceAPIToken(BaseModel):
32
+ id: str
33
+ scopes: list[str]
34
+
35
+
26
36
  class DynatraceClient:
27
37
  def __init__(self, environment_url: str, api: Dynatrace) -> None:
28
38
  self._environment_url = environment_url
@@ -48,6 +58,29 @@ class DynatraceClient:
48
58
  ) from e
49
59
  return [token.id for token in dt_tokens if token.name.startswith(prefix)]
50
60
 
61
+ def get_token_by_id(self, token_id: str) -> DynatraceAPIToken:
62
+ try:
63
+ token = self._api.tokens.get(token_id=token_id)
64
+ except Exception as e:
65
+ raise DynatraceTokenRetrievalError(
66
+ f"{self._environment_url=} Failed to retrieve token for {token_id=}", e
67
+ ) from e
68
+ return DynatraceAPIToken(id=token.id, scopes=token.scopes)
69
+
70
+ def update_token_scopes(self, token_id: str, scopes: list[str]) -> None:
71
+ try:
72
+ self._api.tokens.put(
73
+ token_id=token_id,
74
+ api_token=ApiTokenUpdate(
75
+ scopes=scopes,
76
+ ),
77
+ )
78
+ except Exception as e:
79
+ raise DynatraceTokenUpdateError(
80
+ f"{self._environment_url=} Failed to update token scopes for {token_id=}",
81
+ e,
82
+ ) from e
83
+
51
84
  @staticmethod
52
85
  def create(
53
86
  environment_url: str, token: str | None, api: Dynatrace | None