2016-12-18 05:21:29 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/portainer/portainer"
|
|
|
|
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2016-12-25 20:34:02 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2016-12-18 05:21:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SettingsHandler represents an HTTP API handler for managing settings.
|
|
|
|
type SettingsHandler struct {
|
|
|
|
*mux.Router
|
2017-03-12 16:24:15 +00:00
|
|
|
Logger *log.Logger
|
|
|
|
settings *portainer.Settings
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSettingsHandler returns a new instance of SettingsHandler.
|
2017-03-12 16:24:15 +00:00
|
|
|
func NewSettingsHandler(mw *middleWareService) *SettingsHandler {
|
2016-12-18 05:21:29 +00:00
|
|
|
h := &SettingsHandler{
|
2017-03-12 16:24:15 +00:00
|
|
|
Router: mux.NewRouter(),
|
|
|
|
Logger: log.New(os.Stderr, "", log.LstdFlags),
|
2016-12-18 05:21:29 +00:00
|
|
|
}
|
2017-03-12 16:24:15 +00:00
|
|
|
h.Handle("/settings",
|
|
|
|
mw.public(http.HandlerFunc(h.handleGetSettings)))
|
|
|
|
|
2016-12-18 05:21:29 +00:00
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleGetSettings handles GET requests on /settings
|
|
|
|
func (handler *SettingsHandler) handleGetSettings(w http.ResponseWriter, r *http.Request) {
|
2016-12-25 20:34:02 +00:00
|
|
|
if r.Method != http.MethodGet {
|
|
|
|
handleNotAllowed(w, []string{http.MethodGet})
|
2016-12-18 05:21:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
encodeJSON(w, handler.settings, handler.Logger)
|
|
|
|
}
|