2018-11-05 22:58:15 +02:00
|
|
|
package schedules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/response"
|
2019-03-21 14:20:14 +13:00
|
|
|
"github.com/portainer/portainer/api"
|
2018-11-05 22:58:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// GET request on /api/schedules
|
|
|
|
func (handler *Handler) scheduleList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
2020-05-20 17:23:15 +12:00
|
|
|
settings, err := handler.DataStore.Settings().Settings()
|
2018-12-05 23:36:25 +01:00
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusServiceUnavailable, "Unable to retrieve settings", err}
|
|
|
|
}
|
|
|
|
if !settings.EnableHostManagementFeatures {
|
|
|
|
return &httperror.HandlerError{http.StatusServiceUnavailable, "Host management features are disabled", portainer.ErrHostManagementFeaturesDisabled}
|
|
|
|
}
|
|
|
|
|
2020-05-20 17:23:15 +12:00
|
|
|
schedules, err := handler.DataStore.Schedule().Schedules()
|
2018-11-05 22:58:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve schedules from the database", err}
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.JSON(w, schedules)
|
|
|
|
}
|