portainer/api/http/handler/schedules/schedule_inspect.go

28 lines
991 B
Go
Raw Normal View History

feat(schedules): add the schedule API * feat(jobs): add job service interface * feat(jobs): create job execution api * style(jobs): remove comment * feat(jobs): add bindings * feat(jobs): validate payload different cases * refactor(jobs): rename endpointJob method * refactor(jobs): return original error * feat(jobs): pull image before creating container * feat(jobs): run jobs with sh * style(jobs): remove comment * refactor(jobs): change error names * feat(jobs): sync pull image * fix(jobs): close image reader after error check * style(jobs): remove comment and add docs * refactor(jobs): inline script command * fix(jobs): handle pul image error * refactor(jobs): handle image pull output * fix(docker): set http client timeout to 100s * feat(api): create schedule type * feat(agent): add basic schedule api * feat(schedules): add schedule service in bolt * feat(schedule): add schedule service to handler * feat(schedule): add and list schedules from db * feat(agent): get schedule from db * feat(schedule): update schedule in db * feat(agent): delete schedule * fix(bolt): remove sync method from scheduleService * feat(schedules): save/delete script in fs * feat(schedules): schedules cron service implementation * feat(schedule): integrate handler with cron * feat(schedules): schedules API overhaul * refactor(project): remove .idea folder * fix(schedules): fix script task execute call * refactor(schedules): refactor/fix golint issues * refactor(schedules): update SnapshotTask documentation * refactor(schedules): validate image name in ScheduleCreate operation
2018-11-05 20:58:15 +00:00
package schedules
import (
"net/http"
"github.com/portainer/libhttp/response"
"github.com/portainer/portainer"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
)
func (handler *Handler) scheduleInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
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)
}