Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

walk and log chi routes #3610

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/walk-and-log-chi-routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Walk and log chi routes

On startup we now log all routes handled by chi

https://github.com/cs3org/reva/pull/3610
5 changes: 5 additions & 0 deletions internal/http/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error)
return nil, err
}

_ = chi.Walk(s.router, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
log.Debug().Str("service", "approvider").Str("method", method).Str("route", route).Int("middlewares", len(middlewares)).Msg("serving endpoint")
return nil
})

return s, nil
}

Expand Down
10 changes: 8 additions & 2 deletions internal/http/services/owncloud/ocs/ocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error)
router: r,
}

if err := s.routerInit(); err != nil {
if err := s.routerInit(log); err != nil {
return nil, err
}

Expand Down Expand Up @@ -94,7 +94,7 @@ func (s *svc) Unprotected() []string {
}
}

func (s *svc) routerInit() error {
func (s *svc) routerInit(log *zerolog.Logger) error {
capabilitiesHandler := new(capabilities.Handler)
userHandler := new(user.Handler)
usersHandler := new(users.Handler)
Expand Down Expand Up @@ -151,6 +151,12 @@ func (s *svc) routerInit() error {
})
})
})

_ = chi.Walk(s.router, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
log.Debug().Str("service", "ocs").Str("method", method).Str("route", route).Int("middlewares", len(middlewares)).Msg("serving endpoint")
return nil
})

return nil
}

Expand Down
10 changes: 8 additions & 2 deletions internal/http/services/preferences/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error)
router: r,
}

if err := s.routerInit(); err != nil {
if err := s.routerInit(log); err != nil {
return nil, err
}

return s, nil
}

func (s *svc) routerInit() error {
func (s *svc) routerInit(log *zerolog.Logger) error {
s.router.Get("/", s.handleGet)
s.router.Post("/", s.handlePost)

_ = chi.Walk(s.router, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
log.Debug().Str("service", "preferences").Str("method", method).Str("route", route).Int("middlewares", len(middlewares)).Msg("serving endpoint")
return nil
})

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions internal/http/services/reverseproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error)
r.Mount(rule.Endpoint, handler)
}

_ = chi.Walk(r, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
log.Debug().Str("service", "reverseproxy").Str("method", method).Str("route", route).Int("middlewares", len(middlewares)).Msg("serving endpoint")
return nil
})

return &svc{router: r}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/manager/publicshares/publicshares.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (m *manager) Authenticate(ctx context.Context, token, secret string) (*user

var owner *user.User
// FIXME use new user type SPACE_OWNER
if publicShareResponse.GetShare().GetOwner().Type == 8 {
if publicShareResponse.GetShare().GetOwner().GetType() == 8 {
owner = &user.User{Id: publicShareResponse.GetShare().GetOwner(), DisplayName: "Public", Username: "public"}
} else {
getUserResponse, err := gwConn.GetUser(ctx, &userprovider.GetUserRequest{
Expand Down
5 changes: 5 additions & 0 deletions pkg/micro/ocdav/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func Service(opts ...Option) (micro.Service, error) {
// back to using `chi.RegisterMethod`.
r.MethodNotAllowed(http.HandlerFunc(revaService.Handler().ServeHTTP))

_ = chi.Walk(r, func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error {
sopts.Logger.Debug().Str("service", "ocdav").Str("method", method).Str("route", route).Int("middlewares", len(middlewares)).Msg("serving endpoint")
return nil
})

hd := srv.NewHandler(r)
if err := srv.Handle(hd); err != nil {
return nil, err
Expand Down