[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:
co-authored by
Alexander Weaver
parent
c375e67bf9
commit
f76a5f1796
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
type ProvisioningApiForkingService interface {
|
||||
RouteDeleteContactpoints(*models.ReqContext) response.Response
|
||||
RouteDeleteTemplate(*models.ReqContext) response.Response
|
||||
RouteGetContactpoints(*models.ReqContext) response.Response
|
||||
RouteGetPolicyTree(*models.ReqContext) response.Response
|
||||
RouteGetTemplate(*models.ReqContext) response.Response
|
||||
@@ -28,12 +29,17 @@ type ProvisioningApiForkingService interface {
|
||||
RoutePostContactpoints(*models.ReqContext) response.Response
|
||||
RoutePostPolicyTree(*models.ReqContext) response.Response
|
||||
RoutePutContactpoints(*models.ReqContext) response.Response
|
||||
RoutePutTemplate(*models.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (f *ForkedProvisioningApi) RouteDeleteContactpoints(ctx *models.ReqContext) response.Response {
|
||||
return f.forkRouteDeleteContactpoints(ctx)
|
||||
}
|
||||
|
||||
func (f *ForkedProvisioningApi) RouteDeleteTemplate(ctx *models.ReqContext) response.Response {
|
||||
return f.forkRouteDeleteTemplate(ctx)
|
||||
}
|
||||
|
||||
func (f *ForkedProvisioningApi) RouteGetContactpoints(ctx *models.ReqContext) response.Response {
|
||||
return f.forkRouteGetContactpoints(ctx)
|
||||
}
|
||||
@@ -74,6 +80,14 @@ func (f *ForkedProvisioningApi) RoutePutContactpoints(ctx *models.ReqContext) re
|
||||
return f.forkRoutePutContactpoints(ctx, conf)
|
||||
}
|
||||
|
||||
func (f *ForkedProvisioningApi) RoutePutTemplate(ctx *models.ReqContext) response.Response {
|
||||
conf := apimodels.MessageTemplateContent{}
|
||||
if err := web.Bind(ctx.Req, &conf); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
return f.forkRoutePutTemplate(ctx, conf)
|
||||
}
|
||||
|
||||
func (api *API) RegisterProvisioningApiEndpoints(srv ProvisioningApiForkingService, m *metrics.API) {
|
||||
api.RouteRegister.Group("", func(group routing.RouteRegister) {
|
||||
group.Delete(
|
||||
@@ -86,6 +100,16 @@ func (api *API) RegisterProvisioningApiEndpoints(srv ProvisioningApiForkingServi
|
||||
m,
|
||||
),
|
||||
)
|
||||
group.Delete(
|
||||
toMacaronPath("/api/provisioning/templates/{name}"),
|
||||
api.authorize(http.MethodDelete, "/api/provisioning/templates/{name}"),
|
||||
metrics.Instrument(
|
||||
http.MethodDelete,
|
||||
"/api/provisioning/templates/{name}",
|
||||
srv.RouteDeleteTemplate,
|
||||
m,
|
||||
),
|
||||
)
|
||||
group.Get(
|
||||
toMacaronPath("/api/provisioning/contact-points"),
|
||||
api.authorize(http.MethodGet, "/api/provisioning/contact-points"),
|
||||
@@ -107,11 +131,11 @@ func (api *API) RegisterProvisioningApiEndpoints(srv ProvisioningApiForkingServi
|
||||
),
|
||||
)
|
||||
group.Get(
|
||||
toMacaronPath("/api/provisioning/templates/{ID}"),
|
||||
api.authorize(http.MethodGet, "/api/provisioning/templates/{ID}"),
|
||||
toMacaronPath("/api/provisioning/templates/{name}"),
|
||||
api.authorize(http.MethodGet, "/api/provisioning/templates/{name}"),
|
||||
metrics.Instrument(
|
||||
http.MethodGet,
|
||||
"/api/provisioning/templates/{ID}",
|
||||
"/api/provisioning/templates/{name}",
|
||||
srv.RouteGetTemplate,
|
||||
m,
|
||||
),
|
||||
@@ -156,5 +180,15 @@ func (api *API) RegisterProvisioningApiEndpoints(srv ProvisioningApiForkingServi
|
||||
m,
|
||||
),
|
||||
)
|
||||
group.Put(
|
||||
toMacaronPath("/api/provisioning/templates/{name}"),
|
||||
api.authorize(http.MethodPut, "/api/provisioning/templates/{name}"),
|
||||
metrics.Instrument(
|
||||
http.MethodPut,
|
||||
"/api/provisioning/templates/{name}",
|
||||
srv.RoutePutTemplate,
|
||||
m,
|
||||
),
|
||||
)
|
||||
}, middleware.ReqSignedIn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user