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