harness-drone/server/handler/config.go

36 lines
803 B
Go
Raw Normal View History

2014-06-04 21:25:38 +00:00
package handler
import (
"encoding/json"
"net/http"
2014-06-13 00:17:59 +00:00
"github.com/drone/drone/server/database"
2014-06-04 21:25:38 +00:00
"github.com/drone/drone/server/session"
"github.com/gorilla/pat"
)
type ConfigHandler struct {
2014-06-13 00:17:59 +00:00
conf database.ConfigManager
2014-06-04 21:25:38 +00:00
sess session.Session
}
2014-06-13 00:17:59 +00:00
func NewConfigHandler(conf database.ConfigManager, sess session.Session) *ConfigHandler {
2014-06-04 21:25:38 +00:00
return &ConfigHandler{conf, sess}
}
// GetConfig gets the system configuration details.
// GET /api/config
func (h *ConfigHandler) GetConfig(w http.ResponseWriter, r *http.Request) error {
// get the user form the session
user := h.sess.User(r)
if user == nil || !user.Admin {
return notAuthorized{}
}
2014-06-13 00:17:59 +00:00
return json.NewEncoder(w).Encode(h.conf.Find())
2014-06-04 21:25:38 +00:00
}
func (h *ConfigHandler) Register(r *pat.Router) {
r.Get("/v1/config", errorHandler(h.GetConfig))
}