[v8.5.x] Alerting: Provisioning message templates (#48789)

* Alerting: Provisioning message templates (#48665)

* Generate API for writing templates

* Persist templates app logic layer

* Validate templates

* Extract logic, make set and delete methods

* Drop post route for templates

* Fix response details, wire up remainder of API

* Authorize routes

* Mirror some existing tests on new APIs

* Generate mock for prov store

* Wire up prov store mock, add tests using it

* Cover cases for both storage paths

* Add happy path tests and fix bugs if file contains no template section

* Normalize template content with define statement

* Tests for deletion

* Fix linter error

* Move provenance field to DTO

* empty commit

* ID to name

* Fix in auth too

(cherry picked from commit 0f56462fbe)

* ErrorContains -> Error then Contains

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2022-05-06 09:33:33 +02:00
committed by GitHub
co-authored by Alexander Weaver
parent c375e67bf9
commit f76a5f1796
12 changed files with 880 additions and 26 deletions
+53 -3
View File
@@ -1315,7 +1315,7 @@
}
}
},
"/api/provisioning/templates/{ID}": {
"/api/provisioning/templates/{name}": {
"get": {
"tags": [
"provisioning"
@@ -1330,6 +1330,48 @@
"$ref": "#/responses/NotFound"
}
}
},
"put": {
"consumes": [
"application/json"
],
"tags": [
"provisioning"
],
"summary": "Updates an existing template.",
"operationId": "RoutePutTemplate",
"parameters": [
{
"name": "Body",
"in": "body",
"schema": {
"$ref": "#/definitions/MessageTemplateContent"
}
}
],
"responses": {
"202": {
"$ref": "#/responses/Accepted"
},
"400": {
"description": "ValidationError",
"schema": {
"$ref": "#/definitions/ValidationError"
}
}
}
},
"delete": {
"tags": [
"provisioning"
],
"summary": "Delete a template.",
"operationId": "RouteDeleteTemplate",
"responses": {
"204": {
"$ref": "#/responses/Accepted"
}
}
}
},
"/api/ruler/grafana/api/v1/rules": {
@@ -3287,6 +3329,15 @@
},
"$ref": "#/definitions/Matchers"
},
"MessageTemplateContent": {
"type": "object",
"properties": {
"Template": {
"type": "string"
}
},
"x-go-package": "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
},
"MonthRange": {
"type": "object",
"title": "A MonthRange is an inclusive range between [1, 12] where 1 = January.",
@@ -5480,6 +5531,7 @@
"$ref": "#/definitions/postableSilence"
},
"receiver": {
"description": "Receiver receiver",
"type": "object",
"required": [
"name"
@@ -5491,8 +5543,6 @@
"x-go-name": "Name"
}
},
"x-go-name": "Receiver",
"x-go-package": "github.com/prometheus/alertmanager/api/v2/models",
"$ref": "#/definitions/receiver"
},
"silence": {