2018-11-05 20:58:15 +00:00
|
|
|
package schedules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/portainer/libhttp/response"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api"
|
2018-11-05 20:58:15 +00:00
|
|
|
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/request"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (handler *Handler) scheduleInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
2018-12-05 22:36:25 +00:00
|
|
|
settings, err := handler.SettingsService.Settings()
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2018-11-05 20:58:15 +00:00
|
|
|
scheduleID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid schedule identifier route variable", err}
|
|
|
|
}
|
|
|
|
|
|
|
|
schedule, err := handler.ScheduleService.Schedule(portainer.ScheduleID(scheduleID))
|
|
|
|
if err == portainer.ErrObjectNotFound {
|
|
|
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a schedule with the specified identifier inside the database", err}
|
|
|
|
} else if err != nil {
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a schedule with the specified identifier inside the database", err}
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.JSON(w, schedule)
|
|
|
|
}
|