Alerting: Add method to provisioning API for obtaining a group and its rules (#51398)

* Generate shell for new route

* Propagate path parameters

* Implement route logic

* Add a couple simple tests

* Use NotFound error for not found, avoid returning pointer

* Regenerate
This commit is contained in:
Alexander Weaver
2022-07-05 11:53:50 -05:00
committed by GitHub
parent e64cde8727
commit b9c7eb1380
10 changed files with 220 additions and 228 deletions
@@ -24,6 +24,7 @@ type ProvisioningApiForkingService interface {
RouteDeleteMuteTiming(*models.ReqContext) response.Response
RouteDeleteTemplate(*models.ReqContext) response.Response
RouteGetAlertRule(*models.ReqContext) response.Response
RouteGetAlertRuleGroup(*models.ReqContext) response.Response
RouteGetContactpoints(*models.ReqContext) response.Response
RouteGetMuteTiming(*models.ReqContext) response.Response
RouteGetMuteTimings(*models.ReqContext) response.Response
@@ -61,6 +62,11 @@ func (f *ForkedProvisioningApi) RouteGetAlertRule(ctx *models.ReqContext) respon
uIDParam := web.Params(ctx.Req)[":UID"]
return f.forkRouteGetAlertRule(ctx, uIDParam)
}
func (f *ForkedProvisioningApi) RouteGetAlertRuleGroup(ctx *models.ReqContext) response.Response {
folderUIDParam := web.Params(ctx.Req)[":FolderUID"]
groupParam := web.Params(ctx.Req)[":Group"]
return f.forkRouteGetAlertRuleGroup(ctx, folderUIDParam, groupParam)
}
func (f *ForkedProvisioningApi) RouteGetContactpoints(ctx *models.ReqContext) response.Response {
return f.forkRouteGetContactpoints(ctx)
}
@@ -113,7 +119,7 @@ func (f *ForkedProvisioningApi) RoutePutAlertRule(ctx *models.ReqContext) respon
func (f *ForkedProvisioningApi) RoutePutAlertRuleGroup(ctx *models.ReqContext) response.Response {
folderUIDParam := web.Params(ctx.Req)[":FolderUID"]
groupParam := web.Params(ctx.Req)[":Group"]
conf := apimodels.AlertRuleGroup{}
conf := apimodels.AlertRuleGroupMetadata{}
if err := web.Bind(ctx.Req, &conf); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err)
}
@@ -203,6 +209,16 @@ func (api *API) RegisterProvisioningApiEndpoints(srv ProvisioningApiForkingServi
m,
),
)
group.Get(
toMacaronPath("/api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}"),
api.authorize(http.MethodGet, "/api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}"),
metrics.Instrument(
http.MethodGet,
"/api/v1/provisioning/folder/{FolderUID}/rule-groups/{Group}",
srv.RouteGetAlertRuleGroup,
m,
),
)
group.Get(
toMacaronPath("/api/v1/provisioning/contact-points"),
api.authorize(http.MethodGet, "/api/v1/provisioning/contact-points"),