mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 21:00:06 +01:00
100 lines
3.0 KiB
Go
100 lines
3.0 KiB
Go
package api
|
|
|
|
import (
|
|
httpPprof "net/http/pprof"
|
|
|
|
"github.com/glueops/autoglue/internal/config"
|
|
"github.com/glueops/autoglue/internal/handlers/authn"
|
|
"github.com/glueops/autoglue/internal/handlers/health"
|
|
"github.com/glueops/autoglue/internal/handlers/orgs"
|
|
"github.com/glueops/autoglue/internal/handlers/ssh"
|
|
"github.com/glueops/autoglue/internal/middleware"
|
|
"github.com/glueops/autoglue/internal/ui"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func RegisterRoutes(r chi.Router) {
|
|
r.Route("/api", func(api chi.Router) {
|
|
api.Get("/healthz", health.Check)
|
|
|
|
api.Route("/v1", func(v1 chi.Router) {
|
|
secret := viper.GetString("authentication.jwt_secret")
|
|
authMW := middleware.AuthMiddleware(secret)
|
|
|
|
v1.Route("/admin", func(ad chi.Router) {
|
|
ad.Use(authMW)
|
|
ad.Get("/users", authn.AdminListUsers)
|
|
ad.Post("/users", authn.AdminCreateUser)
|
|
ad.Patch("/users/{userId}", authn.AdminUpdateUser)
|
|
ad.Delete("/users/{userId}", authn.AdminDeleteUser)
|
|
})
|
|
|
|
v1.Route("/auth", func(a chi.Router) {
|
|
a.Post("/login", authn.Login)
|
|
a.Post("/register", authn.Register)
|
|
a.Post("/introspect", authn.Introspect)
|
|
a.Post("/password/forgot", authn.RequestPasswordReset)
|
|
a.Post("/password/reset", authn.ConfirmPasswordReset)
|
|
a.Get("/verify", authn.VerifyEmail)
|
|
a.Post("/verify/resend", authn.ResendVerification)
|
|
|
|
a.Group(func(pr chi.Router) {
|
|
pr.Use(authMW)
|
|
pr.Post("/refresh", authn.Refresh)
|
|
pr.Post("/logout", authn.Logout)
|
|
pr.Post("/logout_all", authn.LogoutAll)
|
|
pr.Get("/me", authn.Me)
|
|
pr.Post("/password/change", authn.ChangePassword)
|
|
pr.Post("/refresh/rotate", authn.RotateRefreshToken)
|
|
})
|
|
})
|
|
|
|
v1.Route("/orgs", func(o chi.Router) {
|
|
o.Use(authMW)
|
|
o.Post("/", orgs.CreateOrganization)
|
|
o.Get("/", orgs.ListOrganizations)
|
|
o.Post("/invite", orgs.InviteMember)
|
|
o.Get("/members", orgs.ListMembers)
|
|
o.Delete("/members/{userId}", orgs.DeleteMember)
|
|
o.Patch("/{orgId}", orgs.UpdateOrganization)
|
|
o.Delete("/{orgId}", orgs.DeleteOrganization)
|
|
})
|
|
|
|
v1.Route("/ssh", func(s chi.Router) {
|
|
s.Use(authMW)
|
|
s.Get("/", ssh.ListPublicKeys)
|
|
s.Post("/", ssh.CreateSSHKey)
|
|
s.Get("/{id}", ssh.GetSSHKey)
|
|
s.Delete("/{id}", ssh.DeleteSSHKey)
|
|
s.Get("/{id}/download", ssh.DownloadSSHKey)
|
|
})
|
|
})
|
|
})
|
|
|
|
r.Route("/debug/pprof", func(pr chi.Router) {
|
|
pr.Get("/", httpPprof.Index)
|
|
pr.Get("/cmdline", httpPprof.Cmdline)
|
|
pr.Get("/profile", httpPprof.Profile)
|
|
pr.Get("/symbol", httpPprof.Symbol)
|
|
pr.Get("/trace", httpPprof.Trace)
|
|
|
|
pr.Handle("/allocs", httpPprof.Handler("allocs"))
|
|
pr.Handle("/block", httpPprof.Handler("block"))
|
|
pr.Handle("/goroutine", httpPprof.Handler("goroutine"))
|
|
pr.Handle("/heap", httpPprof.Handler("heap"))
|
|
pr.Handle("/mutex", httpPprof.Handler("mutex"))
|
|
pr.Handle("/threadcreate", httpPprof.Handler("threadcreate"))
|
|
})
|
|
|
|
if config.IsUIDev() {
|
|
if h, err := ui.DevProxy("http://localhost:5173"); err == nil {
|
|
r.NotFound(h.ServeHTTP)
|
|
}
|
|
} else {
|
|
if h, err := ui.SPAHandler(); err == nil {
|
|
r.NotFound(h.ServeHTTP)
|
|
}
|
|
}
|
|
}
|