2018-11-05 20:58:15 +00:00
|
|
|
package schedules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-11-05 20:58:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to handle schedule operations.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2019-07-25 22:38:07 +00:00
|
|
|
ScheduleService portainer.ScheduleService
|
|
|
|
EndpointService portainer.EndpointService
|
|
|
|
SettingsService portainer.SettingsService
|
|
|
|
FileService portainer.FileService
|
|
|
|
JobService portainer.JobService
|
|
|
|
JobScheduler portainer.JobScheduler
|
|
|
|
ReverseTunnelService portainer.ReverseTunnelService
|
2018-11-05 20:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to manage schedule operations.
|
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
|
|
h := &Handler{
|
|
|
|
Router: mux.NewRouter(),
|
|
|
|
}
|
|
|
|
|
|
|
|
h.Handle("/schedules",
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.AuthorizedAccess(httperror.LoggerHandler(h.scheduleList))).Methods(http.MethodGet)
|
2018-11-05 20:58:15 +00:00
|
|
|
h.Handle("/schedules",
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.AuthorizedAccess(httperror.LoggerHandler(h.scheduleCreate))).Methods(http.MethodPost)
|
2018-11-05 20:58:15 +00:00
|
|
|
h.Handle("/schedules/{id}",
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.AuthorizedAccess(httperror.LoggerHandler(h.scheduleInspect))).Methods(http.MethodGet)
|
2018-11-05 20:58:15 +00:00
|
|
|
h.Handle("/schedules/{id}",
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.AuthorizedAccess(httperror.LoggerHandler(h.scheduleUpdate))).Methods(http.MethodPut)
|
2018-11-05 20:58:15 +00:00
|
|
|
h.Handle("/schedules/{id}",
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.AuthorizedAccess(httperror.LoggerHandler(h.scheduleDelete))).Methods(http.MethodDelete)
|
2018-11-07 04:19:10 +00:00
|
|
|
h.Handle("/schedules/{id}/file",
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.AuthorizedAccess(httperror.LoggerHandler(h.scheduleFile))).Methods(http.MethodGet)
|
2018-11-13 01:39:26 +00:00
|
|
|
h.Handle("/schedules/{id}/tasks",
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.AuthorizedAccess(httperror.LoggerHandler(h.scheduleTasks))).Methods(http.MethodGet)
|
2018-11-05 20:58:15 +00:00
|
|
|
return h
|
|
|
|
}
|