|
2 | 2 |
|
3 | 3 | import httpx |
4 | 4 |
|
5 | | -from devhelm._generated import ServiceSubscriptionDto |
6 | | -from devhelm._http import api_delete, api_get, api_post, path_param |
| 5 | +from devhelm._generated import ( |
| 6 | + ServiceSubscribeRequest, |
| 7 | + ServiceSubscriptionDto, |
| 8 | + UpdateAlertSensitivityRequest, |
| 9 | +) |
| 10 | +from devhelm._http import api_delete, api_get, api_patch, api_post, path_param |
7 | 11 | from devhelm._pagination import Page, fetch_all_pages, fetch_page |
8 | | -from devhelm._validation import parse_single |
| 12 | +from devhelm._validation import parse_single, validate_request |
9 | 13 |
|
10 | 14 |
|
11 | 15 | class Dependencies: |
@@ -38,14 +42,59 @@ def get(self, id: int | str) -> ServiceSubscriptionDto: |
38 | 42 | f"GET /api/v1/service-subscriptions/{id}", |
39 | 43 | ) |
40 | 44 |
|
41 | | - def track(self, slug: str) -> ServiceSubscriptionDto: |
42 | | - """Track a new service dependency by slug.""" |
| 45 | + def track( |
| 46 | + self, |
| 47 | + slug: str, |
| 48 | + *, |
| 49 | + component_id: str | None = None, |
| 50 | + alert_sensitivity: str | None = None, |
| 51 | + ) -> ServiceSubscriptionDto: |
| 52 | + """Track a new service dependency by slug. |
| 53 | +
|
| 54 | + ``component_id`` subscribes to one component instead of the whole |
| 55 | + service. ``alert_sensitivity`` is one of ``ALL``, |
| 56 | + ``INCIDENTS_ONLY``, ``MAJOR_ONLY``, or ``AWARENESS`` (the API |
| 57 | + default — silent tracking with no alert fan-out). The request body |
| 58 | + is omitted entirely when neither kwarg is provided. |
| 59 | + """ |
| 60 | + body: ServiceSubscribeRequest | None = None |
| 61 | + if component_id is not None or alert_sensitivity is not None: |
| 62 | + fields: dict[str, str] = {} |
| 63 | + if component_id is not None: |
| 64 | + fields["componentId"] = component_id |
| 65 | + if alert_sensitivity is not None: |
| 66 | + fields["alertSensitivity"] = alert_sensitivity |
| 67 | + body = validate_request( |
| 68 | + ServiceSubscribeRequest, fields, "dependencies.track" |
| 69 | + ) |
43 | 70 | return parse_single( |
44 | 71 | ServiceSubscriptionDto, |
45 | | - api_post(self._client, f"/api/v1/service-subscriptions/{path_param(slug)}"), |
| 72 | + api_post( |
| 73 | + self._client, f"/api/v1/service-subscriptions/{path_param(slug)}", body |
| 74 | + ), |
46 | 75 | f"POST /api/v1/service-subscriptions/{slug}", |
47 | 76 | ) |
48 | 77 |
|
| 78 | + def update_alert_sensitivity( |
| 79 | + self, subscription_id: int | str, alert_sensitivity: str |
| 80 | + ) -> ServiceSubscriptionDto: |
| 81 | + """Update the alert sensitivity on a tracked dependency. |
| 82 | +
|
| 83 | + ``alert_sensitivity`` is one of ``ALL``, ``INCIDENTS_ONLY``, |
| 84 | + ``MAJOR_ONLY``, or ``AWARENESS``. |
| 85 | + """ |
| 86 | + body = validate_request( |
| 87 | + UpdateAlertSensitivityRequest, |
| 88 | + {"alertSensitivity": alert_sensitivity}, |
| 89 | + "dependencies.update_alert_sensitivity", |
| 90 | + ) |
| 91 | + path = f"/api/v1/service-subscriptions/{path_param(subscription_id)}" |
| 92 | + return parse_single( |
| 93 | + ServiceSubscriptionDto, |
| 94 | + api_patch(self._client, f"{path}/alert-sensitivity", body), |
| 95 | + f"PATCH /api/v1/service-subscriptions/{subscription_id}/alert-sensitivity", |
| 96 | + ) |
| 97 | + |
49 | 98 | def delete(self, id: int | str) -> None: |
50 | 99 | """Remove a tracked dependency.""" |
51 | 100 | api_delete(self._client, f"/api/v1/service-subscriptions/{path_param(id)}") |
0 commit comments