Browse Source

Add endpoint to GET a Service config

kegan/get-service
Kegan Dougal 8 years ago
parent
commit
d3ecdc0662
  1. 35
      src/github.com/matrix-org/go-neb/api.go
  2. 1
      src/github.com/matrix-org/go-neb/goneb.go

35
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 != "GET" {
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
}

1
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}))

Loading…
Cancel
Save