Skip to content

Commit

Permalink
pass context as argument to Config.Get (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaidliadon authored Nov 29, 2024
1 parent 724a470 commit 3a60b41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ProjectStore interface {
type Config[T any] map[string]map[string]T

// Get returns the config value for the given request.
func (c Config[T]) Get(path string) (v T, err error) {
func (c Config[T]) Get(_ context.Context, path string) (v T, err error) {
if c == nil {
return v, fmt.Errorf("config is nil")
}
Expand Down
5 changes: 3 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,14 @@ func AccessControl(acl Config[ACL], cfg Options) func(next http.Handler) http.Ha

return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
acl, err := acl.Get(r.URL.Path)
ctx := r.Context()
acl, err := acl.Get(ctx, r.URL.Path)
if err != nil {
cfg.ErrHandler(r, w, proto.ErrUnauthorized.WithCausef("get acl: %w", err))
return
}

if session, _ := GetSessionType(r.Context()); !acl.Includes(session) {
if session, _ := GetSessionType(ctx); !acl.Includes(session) {
err := proto.ErrPermissionDenied
if session == proto.SessionType_Public {
err = proto.ErrUnauthorized
Expand Down

0 comments on commit 3a60b41

Please sign in to comment.