oncall-engine/engine/apps/webhooks/presets/preset.py
Michael Derynck 60ef4348f5
Allow OnCall API to use Grafana Service Accounts (#3189)
# What this PR does
Allows public OnCall API to use Grafana service accounts for
authorization. In cloud requests using a Grafana service account token
also needs to provide headers for `X-Grafana-Org-Slug` and
`X-Grafana-Instance-Slug`

This is **alpha** functionality, it may break or be removed in the
future. Going to use this on one endpoint (resolution notes) before we
consider the implications across all of public API.

## Which issue(s) this PR fixes

## 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)
2023-11-23 16:42:27 +00:00

42 lines
1.1 KiB
Python

import typing
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import List
from django.utils.functional import cached_property
from apps.webhooks.models import Webhook
@dataclass
class WebhookPresetMetadata:
id: str
name: str
logo: str
description: str
controlled_fields: List[str]
class WebhookPreset(ABC):
@cached_property
def metadata(self) -> WebhookPresetMetadata:
return self._metadata()
@abstractmethod
def _metadata(self) -> WebhookPresetMetadata:
raise NotImplementedError
@abstractmethod
def override_parameters_before_save(self, webhook: Webhook):
"""Implement this to write parameters before the webhook is saved to the database"""
pass
@abstractmethod
def override_parameters_at_runtime(self, webhook: Webhook):
"""Implement this to write parameters before the webhook is executed (These will not be persisted)"""
pass
@abstractmethod
def get_masked_headers(self) -> typing.List[str]:
"""Implement this to write sensitive header data as ******** when writing to logs"""
return []