2018-06-11 13:13:19 +00:00
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-09-10 10:01:38 +00:00
|
|
|
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-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handler represents an HTTP API handler for managing templates.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2020-07-06 23:18:39 +00:00
|
|
|
DataStore portainer.DataStore
|
|
|
|
GitService portainer.GitService
|
|
|
|
FileService portainer.FileService
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler returns a new instance of Handler.
|
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
|
|
h := &Handler{
|
|
|
|
Router: mux.NewRouter(),
|
|
|
|
}
|
2018-08-07 15:43:36 +00:00
|
|
|
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/templates",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.templateList))).Methods(http.MethodGet)
|
2020-07-06 23:18:39 +00:00
|
|
|
h.Handle("/templates/file",
|
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.templateFile))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|