You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB

  1. package main
  2. import (
  3. log "github.com/Sirupsen/logrus"
  4. "github.com/matrix-org/dugong"
  5. "github.com/matrix-org/go-neb/clients"
  6. "github.com/matrix-org/go-neb/database"
  7. _ "github.com/matrix-org/go-neb/realms/github"
  8. _ "github.com/matrix-org/go-neb/realms/jira"
  9. "github.com/matrix-org/go-neb/server"
  10. _ "github.com/matrix-org/go-neb/services/echo"
  11. _ "github.com/matrix-org/go-neb/services/giphy"
  12. _ "github.com/matrix-org/go-neb/services/github"
  13. _ "github.com/matrix-org/go-neb/services/jira"
  14. "github.com/matrix-org/go-neb/types"
  15. _ "github.com/mattn/go-sqlite3"
  16. "net/http"
  17. _ "net/http/pprof"
  18. "os"
  19. "path/filepath"
  20. )
  21. func main() {
  22. bindAddress := os.Getenv("BIND_ADDRESS")
  23. databaseType := os.Getenv("DATABASE_TYPE")
  24. databaseURL := os.Getenv("DATABASE_URL")
  25. baseURL := os.Getenv("BASE_URL")
  26. logDir := os.Getenv("LOG_DIR")
  27. if logDir != "" {
  28. log.AddHook(dugong.NewFSHook(
  29. filepath.Join(logDir, "info.log"),
  30. filepath.Join(logDir, "warn.log"),
  31. filepath.Join(logDir, "error.log"),
  32. ))
  33. }
  34. log.Infof(
  35. "Go-NEB (BIND_ADDRESS=%s DATABASE_TYPE=%s DATABASE_URL=%s BASE_URL=%s LOG_DIR=%s)",
  36. bindAddress, databaseType, databaseURL, baseURL, logDir,
  37. )
  38. err := types.BaseURL(baseURL)
  39. if err != nil {
  40. log.Panic(err)
  41. }
  42. db, err := database.Open(databaseType, databaseURL)
  43. if err != nil {
  44. log.Panic(err)
  45. }
  46. database.SetServiceDB(db)
  47. clients := clients.New(db)
  48. if err := clients.Start(); err != nil {
  49. log.Panic(err)
  50. }
  51. http.Handle("/test", server.MakeJSONAPI(&heartbeatHandler{}))
  52. http.Handle("/admin/getService", server.MakeJSONAPI(&getServiceHandler{db: db}))
  53. http.Handle("/admin/getSession", server.MakeJSONAPI(&getSessionHandler{db: db}))
  54. http.Handle("/admin/configureClient", server.MakeJSONAPI(&configureClientHandler{db: db, clients: clients}))
  55. http.Handle("/admin/configureService", server.MakeJSONAPI(newConfigureServiceHandler(db, clients)))
  56. http.Handle("/admin/configureAuthRealm", server.MakeJSONAPI(&configureAuthRealmHandler{db: db}))
  57. http.Handle("/admin/requestAuthSession", server.MakeJSONAPI(&requestAuthSessionHandler{db: db}))
  58. wh := &webhookHandler{db: db, clients: clients}
  59. http.HandleFunc("/services/hooks/", wh.handle)
  60. rh := &realmRedirectHandler{db: db}
  61. http.HandleFunc("/realms/redirects/", rh.handle)
  62. http.ListenAndServe(bindAddress, nil)
  63. }