Skip to content

Commit

Permalink
fix CheckPermission
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyatomohiro committed Nov 6, 2024
1 parent 44c50f7 commit c7840c0
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions cerbos/client/permission_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
"github.com/reearth/reearthx/appx"
)

type ContextKey string

const (
contextAuthInfo ContextKey = "authinfo"
)

type PermissionChecker struct {
Service string
DashboardURL string
Expand All @@ -25,8 +19,7 @@ func NewPermissionChecker(service string, dashboardURL string) *PermissionChecke
}
}

func (p *PermissionChecker) CheckPermission(ctx context.Context, resource string, action string) (bool, error) {
authInfo := getAuthInfo(ctx)
func (p *PermissionChecker) CheckPermission(ctx context.Context, authInfo *appx.AuthInfo, resource string, action string) (bool, error) {
if authInfo == nil {
return false, fmt.Errorf("auth info not found")
}
Expand All @@ -40,12 +33,3 @@ func (p *PermissionChecker) CheckPermission(ctx context.Context, resource string
client := NewClient(p.DashboardURL)
return client.CheckPermission(ctx, authInfo, input)
}

func getAuthInfo(ctx context.Context) *appx.AuthInfo {
if v := ctx.Value(contextAuthInfo); v != nil {
if v2, ok := v.(appx.AuthInfo); ok {
return &v2
}
}
return nil
}

0 comments on commit c7840c0

Please sign in to comment.