Files
grafana/pkg/tsdb/cloudwatch/routes/dimension_values.go
T
Erik Sundell 94aa090fb0 Cloudwatch: Refactor namespaces resource request (#57590)
* add route tests

* remove not used method

* pr feedback

* change variable name
2022-10-26 15:54:23 +02:00

36 lines
1.2 KiB
Go

package routes
import (
"encoding/json"
"net/http"
"net/url"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/request"
)
func DimensionValuesHandler(pluginCtx backend.PluginContext, reqCtxFactory models.RequestContextFactoryFunc, parameters url.Values) ([]byte, *models.HttpError) {
dimensionValuesRequest, err := request.GetDimensionValuesRequest(parameters)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusBadRequest, err)
}
service, err := newListMetricsService(pluginCtx, reqCtxFactory, dimensionValuesRequest.Region)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusInternalServerError, err)
}
dimensionValues, err := service.GetDimensionValuesByDimensionFilter(dimensionValuesRequest)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusInternalServerError, err)
}
dimensionValuesResponse, err := json.Marshal(dimensionValues)
if err != nil {
return nil, models.NewHttpError("error in DimensionValuesHandler", http.StatusInternalServerError, err)
}
return dimensionValuesResponse, nil
}