ed8cfbbee4
Set Collector * set
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package queryservice
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
collectorset "queryorchestration/internal/collector/set"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/oapi-codegen/runtime/types"
|
|
)
|
|
|
|
func (s *Controllers) GetCollectorByClientId(ctx echo.Context, clientId types.UUID) error {
|
|
coll, err := s.svc.Collector.GetByClientID(ctx.Request().Context(), clientId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to get collector: %s", err))
|
|
}
|
|
|
|
fields := make([]CollectorField, len(coll.Fields))
|
|
index := 0
|
|
for name, id := range coll.Fields {
|
|
fields[index] = CollectorField{
|
|
Name: name,
|
|
QueryId: id,
|
|
}
|
|
index++
|
|
}
|
|
|
|
return ctx.JSON(http.StatusOK, Collector{
|
|
ClientId: coll.ClientID,
|
|
MinimumCleanerVersion: coll.MinCleanVersion,
|
|
MinimumTextVersion: coll.MinTextVersion,
|
|
ActiveVersion: coll.ActiveVersion,
|
|
LatestVersion: coll.LatestVersion,
|
|
Fields: fields,
|
|
})
|
|
}
|
|
|
|
func (s *Controllers) SetCollectorByClientId(ctx echo.Context, clientId types.UUID) error {
|
|
req := CollectorSet{}
|
|
if err := ctx.Bind(&req); err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, err)
|
|
}
|
|
|
|
var fields *map[string]uuid.UUID
|
|
if req.Fields != nil {
|
|
fs := map[string]uuid.UUID{}
|
|
for _, field := range *req.Fields {
|
|
fs[field.Name] = field.QueryId
|
|
}
|
|
fields = &fs
|
|
}
|
|
|
|
err := s.svc.CollectorSet.SetByClientId(ctx.Request().Context(), &collectorset.SetParams{
|
|
ClientID: clientId,
|
|
ActiveVersion: req.ActiveVersion,
|
|
MinCleanVersion: req.MinimumCleanerVersion,
|
|
MinTextVersion: req.MinimumTextVersion,
|
|
Fields: fields,
|
|
})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to update query: %s", err))
|
|
}
|
|
|
|
return ctx.NoContent(http.StatusOK)
|
|
}
|