[9.1.x] Alerting: Remove user input from error response (#53164)

Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
Yuriy Tseretyan
2022-08-02 14:00:31 -04:00
committed by GitHub
co-authored by Alexander Weaver
parent f4aed50192
commit d330c24c89
+5 -4
View File
@@ -25,7 +25,7 @@ import (
)
var searchRegex = regexp.MustCompile(`\{(\w+)\}`)
var errInvalidRecipientFormat = errors.New("invalid recipient (datasource) identifier format. Only integer is expected")
var NotImplementedResp = ErrResp(http.StatusNotImplemented, errors.New("endpoint not implemented"), "")
func toMacaronPath(path string) string {
@@ -37,7 +37,8 @@ func toMacaronPath(path string) string {
func backendTypeByUID(ctx *models.ReqContext, cache datasources.CacheService) (apimodels.Backend, error) {
datasourceUID := web.Params(ctx.Req)[":DatasourceUID"]
if ds, err := cache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache); err == nil {
ds, err := cache.GetDatasourceByUID(ctx.Req.Context(), datasourceUID, ctx.SignedInUser, ctx.SkipCache)
if err == nil {
switch ds.Type {
case "loki", "prometheus":
return apimodels.LoTexRulerBackend, nil
@@ -47,7 +48,7 @@ func backendTypeByUID(ctx *models.ReqContext, cache datasources.CacheService) (a
return 0, fmt.Errorf("unexpected backend type (%v)", ds.Type)
}
}
return 0, fmt.Errorf("unexpected backend type (%v)", datasourceUID)
return 0, errors.New("no datasource was found matching the given UID")
}
// macaron unsafely asserts the http.ResponseWriter is an http.CloseNotifier, which will panic.
@@ -100,7 +101,7 @@ func (p *AlertingProxy) withReq(
if datasourceID != "" {
recipient, err := strconv.ParseInt(web.Params(ctx.Req)[":DatasourceID"], 10, 64)
if err != nil {
return ErrResp(http.StatusBadRequest, err, "DatasourceID is invalid")
return ErrResp(http.StatusBadRequest, errInvalidRecipientFormat, "")
}
p.DataProxy.ProxyDatasourceRequestWithID(newCtx, recipient)