|
|
|
@ -30,6 +30,7 @@ func (payload *DeleteMultiplePayload) Validate(r *http.Request) error {
|
|
|
|
|
if payload == nil || len(payload.Endpoints) == 0 {
|
|
|
|
|
return fmt.Errorf("invalid request payload; you must provide a list of nodes to delete")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -53,6 +54,7 @@ type DeleteMultipleResp struct {
|
|
|
|
|
// @failure 500 "Server error"
|
|
|
|
|
// @router /endpoints/{id} [delete]
|
|
|
|
|
// @deprecated
|
|
|
|
|
// Deprecated: use endpointDeleteMultiple instead.
|
|
|
|
|
func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
|
|
|
endpointID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
|
|
|
|
if err != nil {
|
|
|
|
@ -102,12 +104,13 @@ func (handler *Handler) endpointDelete(w http.ResponseWriter, r *http.Request) *
|
|
|
|
|
// @router /endpoints/remove [post]
|
|
|
|
|
func (handler *Handler) endpointDeleteMultiple(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
|
|
|
var p DeleteMultiplePayload
|
|
|
|
|
err := request.DecodeAndValidateJSONPayload(r, &p)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err := request.DecodeAndValidateJSONPayload(r, &p); err != nil {
|
|
|
|
|
return httperror.BadRequest("Invalid request payload", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resps []DeleteMultipleResp
|
|
|
|
|
|
|
|
|
|
err := handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
|
|
|
|
for _, e := range p.Endpoints {
|
|
|
|
|
// Demo endpoints cannot be deleted.
|
|
|
|
|
if handler.demoService.IsDemoEnvironment(portainer.EndpointID(e.ID)) {
|
|
|
|
@ -119,15 +122,21 @@ func (handler *Handler) endpointDeleteMultiple(w http.ResponseWriter, r *http.Re
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attempt deletion.
|
|
|
|
|
err = handler.DataStore.UpdateTx(func(tx dataservices.DataStoreTx) error {
|
|
|
|
|
return handler.deleteEndpoint(
|
|
|
|
|
err := handler.deleteEndpoint(
|
|
|
|
|
tx,
|
|
|
|
|
portainer.EndpointID(e.ID),
|
|
|
|
|
e.DeleteCluster,
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
resps = append(resps, DeleteMultipleResp{Name: e.Name, Err: err})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return httperror.InternalServerError("Unable to delete environments", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response.JSON(w, resps)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|