diff --git a/backend/go.mod b/backend/go.mod index 18e2a9d..0582906 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -11,7 +11,6 @@ require ( github.com/fatih/color v1.15.0 github.com/getsentry/sentry-go v0.21.0 github.com/glebarez/sqlite v1.8.0 - github.com/go-chi/chi v4.1.2+incompatible github.com/go-chi/chi/v5 v5.0.8 github.com/go-chi/cors v1.2.1 github.com/go-chi/jwtauth v4.0.4+incompatible @@ -37,6 +36,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/glebarez/go-sqlite v1.21.1 // indirect + github.com/go-chi/chi v4.1.2+incompatible // indirect github.com/go-sql-driver/mysql v1.7.1 // indirect github.com/goccy/go-json v0.9.11 // indirect github.com/google/uuid v1.3.0 // indirect diff --git a/backend/internal/api/handler/helpers.go b/backend/internal/api/handler/helpers.go index b12d7a0..e6ff9e0 100644 --- a/backend/internal/api/handler/helpers.go +++ b/backend/internal/api/handler/helpers.go @@ -8,7 +8,7 @@ import ( "npm/internal/api/context" "npm/internal/model" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v5" "github.com/rotisserie/eris" ) @@ -112,7 +112,6 @@ func getURLParamInt(r *http.Request, varName string) (uint, error) { return defaultValue, nil } - // func ParseUint(s string, base int, bitSize int) (n uint64, err error) paramUint, err := strconv.ParseUint(paramStr, 10, 32) if err != nil { return 0, eris.Wrapf(err, "%v is not a valid number", varName) diff --git a/backend/internal/api/handler/settings.go b/backend/internal/api/handler/settings.go index 2af313f..155b5a0 100644 --- a/backend/internal/api/handler/settings.go +++ b/backend/internal/api/handler/settings.go @@ -11,7 +11,7 @@ import ( "npm/internal/api/middleware" "npm/internal/entity/setting" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v5" ) // GetSettings will return a list of Settings diff --git a/backend/internal/api/handler/users.go b/backend/internal/api/handler/users.go index 9755bc2..961a0eb 100644 --- a/backend/internal/api/handler/users.go +++ b/backend/internal/api/handler/users.go @@ -14,7 +14,7 @@ import ( "npm/internal/errors" "npm/internal/logger" - "github.com/go-chi/chi" + "github.com/go-chi/chi/v5" ) // GetUsers returns all users diff --git a/backend/internal/api/router.go b/backend/internal/api/router.go index 894c957..87700dd 100644 --- a/backend/internal/api/router.go +++ b/backend/internal/api/router.go @@ -85,11 +85,11 @@ func applyRoutes(r chi.Router) chi.Router { r.With(middleware.EnforceSetup(true)).Route("/", func(r chi.Router) { // Get yourself, requires a login but no other permissions r.With(middleware.Enforce("")). - Get("/{userID:(?:me)}", handler.GetUser()) + Get("/{userID:me}", handler.GetUser()) // Update yourself, requires a login but no other permissions r.With(middleware.Enforce(""), middleware.EnforceRequestSchema(schema.UpdateUser())). - Put("/{userID:(?:me)}", handler.UpdateUser()) + Put("/{userID:me}", handler.UpdateUser()) r.With(middleware.Enforce(user.CapabilityUsersManage)).Route("/", func(r chi.Router) { // List @@ -98,19 +98,19 @@ func applyRoutes(r chi.Router) chi.Router { Get("/", handler.GetUsers()) // Specific Item - r.Get("/{userID:(?:[0-9]+)}", handler.GetUser()) - r.Delete("/{userID:(?:[0-9]+|me)}", handler.DeleteUser()) + r.Get("/{userID:[0-9]+}", handler.GetUser()) + r.Delete("/{userID:([0-9]+|me)}", handler.DeleteUser()) // Update another user r.With(middleware.EnforceRequestSchema(schema.UpdateUser())). - Put("/{userID:(?:[0-9]+)}", handler.UpdateUser()) + Put("/{userID:[0-9]+}", handler.UpdateUser()) }) // Auth - sets passwords r.With(middleware.Enforce(""), middleware.EnforceRequestSchema(schema.SetAuth())). - Post("/{userID:(?:me)}/auth", handler.SetAuth()) + Post("/{userID:me}/auth", handler.SetAuth()) r.With(middleware.Enforce(user.CapabilityUsersManage), middleware.EnforceRequestSchema(schema.SetAuth())). - Post("/{userID:(?:[0-9]+)}/auth", handler.SetAuth()) + Post("/{userID:[0-9]+}/auth", handler.SetAuth()) }) }) @@ -200,6 +200,12 @@ func applyRoutes(r chi.Router) chi.Router { r.Route("/{caID:[0-9]+}", func(r chi.Router) { r.With(middleware.Enforce(user.CapabilityCertificateAuthoritiesView)). Get("/", handler.GetCertificateAuthority()) + + r.With(middleware.EnforceRequestSchema(schema.UpdateCertificateAuthority())). + Put("/", handler.UpdateCertificateAuthority()) + r.With(middleware.Enforce(user.CapabilityCertificateAuthoritiesManage)). + Delete("/", handler.DeleteCertificateAuthority()) + r.With(middleware.Enforce(user.CapabilityCertificateAuthoritiesManage)).Route("/", func(r chi.Router) { r.Delete("/{caID:[0-9]+}", handler.DeleteCertificateAuthority()) r.With(middleware.EnforceRequestSchema(schema.UpdateCertificateAuthority())).