oncall-engine/engine/apps/labels/client.py
Yulya Artyukhina 24f4969f61
Add labels implementation for integration (#3014)
# What this PR does
Adds labels implementation for integrations:
- ability to create/update labels on creating/updating integration
- ability to associate labels to integrations
- cache for label reprs on OnCall side
- feature flag to enable/disable labels

## Which issue(s) this PR fixes
https://github.com/grafana/oncall-private/issues/2157

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)

---------

Co-authored-by: Maxim <maxim.mordasov@grafana.com>
Co-authored-by: Rares Mardare <rares.mardare@grafana.com>
2023-10-20 07:30:11 +00:00

42 lines
1.7 KiB
Python

import typing
from urllib.parse import urljoin
from apps.grafana_plugin.helpers.client import APIClient
if typing.TYPE_CHECKING:
from apps.labels.utils import LabelKeyData, LabelsKeysData, LabelUpdateParam
class LabelsAPIClient(APIClient):
LABELS_API_URL = "/api/plugins/grafana-labels/resources/v1/labels/"
def __init__(self, api_url: str, api_token: str) -> None:
super().__init__(api_url, api_token)
self.api_url = urljoin(api_url, self.LABELS_API_URL)
def create_label(self, label_data: "LabelUpdateParam") -> typing.Tuple[typing.Optional["LabelKeyData"], dict]:
return self.api_post("", label_data)
def get_keys(self) -> typing.Tuple[typing.Optional["LabelsKeysData"], dict]:
return self.api_get("keys")
def get_values(self, key_id: str) -> typing.Tuple[typing.Optional["LabelKeyData"], dict]:
return self.api_get(f"id/{key_id}")
def get_value(self, key_id: str, value_id: str) -> typing.Tuple[typing.Optional["LabelKeyData"], dict]:
return self.api_get(f"id/{key_id}/values/{value_id}")
def add_value(
self, key_id: str, label_data: "LabelUpdateParam"
) -> typing.Tuple[typing.Optional["LabelKeyData"], dict]:
return self.api_post(f"id/{key_id}/values", label_data)
def rename_key(
self, key_id: str, label_data: "LabelUpdateParam"
) -> typing.Tuple[typing.Optional["LabelKeyData"], dict]:
return self.api_put(f"id/{key_id}", label_data)
def rename_value(
self, key_id: str, value_id: str, label_data: "LabelUpdateParam"
) -> typing.Tuple[typing.Optional["LabelKeyData"], dict]:
return self.api_put(f"id/{key_id}/values/{value_id}", label_data)