diff --git a/src/github.com/matrix-org/go-neb/api.go b/src/github.com/matrix-org/go-neb/api.go index ff1da59..c0f22b4 100644 --- a/src/github.com/matrix-org/go-neb/api.go +++ b/src/github.com/matrix-org/go-neb/api.go @@ -1,6 +1,7 @@ package main import ( + "database/sql" "encoding/json" log "github.com/Sirupsen/logrus" "github.com/matrix-org/go-neb/clients" @@ -228,3 +229,37 @@ func (s *configureServiceHandler) OnIncomingRequest(req *http.Request) (interfac NewConfig types.Service }{body.ID, body.Type, oldService, service}, nil } + +type getServiceHandler struct { + db *database.ServiceDB +} + +func (h *getServiceHandler) OnIncomingRequest(req *http.Request) (interface{}, *errors.HTTPError) { + if req.Method != "POST" { + return nil, &errors.HTTPError{nil, "Unsupported Method", 405} + } + var body struct { + ID string + } + if err := json.NewDecoder(req.Body).Decode(&body); err != nil { + return nil, &errors.HTTPError{err, "Error parsing request JSON", 400} + } + + if body.ID == "" { + return nil, &errors.HTTPError{nil, `Must supply a "ID"`, 400} + } + + srv, err := h.db.LoadService(body.ID) + if err != nil { + if err == sql.ErrNoRows { + return nil, &errors.HTTPError{err, `Service not found`, 404} + } + return nil, &errors.HTTPError{err, `Failed to load service`, 500} + } + + return &struct { + ID string + Type string + Config types.Service + }{srv.ServiceID(), srv.ServiceType(), srv}, nil +} diff --git a/src/github.com/matrix-org/go-neb/goneb.go b/src/github.com/matrix-org/go-neb/goneb.go index 2e22ef9..2e107bd 100644 --- a/src/github.com/matrix-org/go-neb/goneb.go +++ b/src/github.com/matrix-org/go-neb/goneb.go @@ -40,6 +40,7 @@ func main() { } http.Handle("/test", server.MakeJSONAPI(&heartbeatHandler{})) + http.Handle("/admin/getService", server.MakeJSONAPI(&getServiceHandler{db: db})) http.Handle("/admin/configureClient", server.MakeJSONAPI(&configureClientHandler{db: db, clients: clients})) http.Handle("/admin/configureService", server.MakeJSONAPI(&configureServiceHandler{db: db, clients: clients})) http.Handle("/admin/configureAuthRealm", server.MakeJSONAPI(&configureAuthRealmHandler{db: db}))