package api import ( "net/http" "forge.cadoles.com/Cadoles/emissary/internal/datastore" "github.com/pkg/errors" "gitlab.com/wpetit/goweb/api" "gitlab.com/wpetit/goweb/logger" ) func (m *Mount) getAgentSpecs(w http.ResponseWriter, r *http.Request) { agentID, ok := getAgentID(w, r) if !ok { return } ctx := r.Context() specs, err := m.agentRepo.GetSpecs(ctx, agentID) if err != nil { if errors.Is(err, datastore.ErrNotFound) { api.ErrorResponse(w, http.StatusNotFound, ErrCodeNotFound, nil) return } err = errors.WithStack(err) logger.Error(ctx, "could not list specs", logger.CapturedE(err)) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) return } api.DataResponse(w, http.StatusOK, struct { Specs []*datastore.Spec `json:"specs"` }{ Specs: specs, }) } type deleteSpecRequest struct { Name string `json:"name"` } func (m *Mount) deleteSpec(w http.ResponseWriter, r *http.Request) { agentID, ok := getAgentID(w, r) if !ok { return } deleteSpecReq := &deleteSpecRequest{} if ok := api.Bind(w, r, deleteSpecReq); !ok { return } ctx := r.Context() err := m.agentRepo.DeleteSpec( ctx, agentID, deleteSpecReq.Name, ) if err != nil { if errors.Is(err, datastore.ErrNotFound) { api.ErrorResponse(w, http.StatusNotFound, ErrCodeNotFound, nil) return } err = errors.WithStack(err) logger.Error(ctx, "could not delete spec", logger.CapturedE(err)) api.ErrorResponse(w, http.StatusInternalServerError, ErrCodeUnknownError, nil) return } api.DataResponse(w, http.StatusOK, struct { Name string `json:"name"` }{ Name: deleteSpecReq.Name, }) }