Skip to content

Commit 4eb3004

Browse files
authored
expose context key for checker (#126)
This will allow for easier testing to be done as a custom context handler function may be used easier. Signed-off-by: Mike Mason <[email protected]>
1 parent 64e1a86 commit 4eb3004

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pkg/permissions/permissions.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const (
2323
)
2424

2525
var (
26-
ctxKeyChecker = checkerCtxKey{}
26+
// CheckerCtxKey is the context key used to set the checker handling function
27+
CheckerCtxKey = checkerCtxKey{}
2728

2829
// DefaultAllowChecker defaults to allow when checker is disabled or skipped
2930
DefaultAllowChecker Checker = func(_ context.Context, _ gidx.PrefixedID, _ string) error {
@@ -179,7 +180,7 @@ func setCheckerContext(c echo.Context, checker Checker) {
179180
req := c.Request().WithContext(
180181
context.WithValue(
181182
c.Request().Context(),
182-
ctxKeyChecker,
183+
CheckerCtxKey,
183184
checker,
184185
),
185186
)
@@ -201,7 +202,7 @@ func ensureValidServerResponse(resp *http.Response) error {
201202

202203
// CheckAccess runs the checker function to check if the provided resource and action are supported.
203204
func CheckAccess(ctx context.Context, resource gidx.PrefixedID, action string) error {
204-
checker, ok := ctx.Value(ctxKeyChecker).(Checker)
205+
checker, ok := ctx.Value(CheckerCtxKey).(Checker)
205206
if !ok {
206207
return ErrCheckerNotFound
207208
}

0 commit comments

Comments
 (0)