diff --git a/cerbos/client/permission_checker.go b/cerbos/client/permission_checker.go index c1ccb8c..d86d81e 100644 --- a/cerbos/client/permission_checker.go +++ b/cerbos/client/permission_checker.go @@ -20,6 +20,10 @@ func NewPermissionChecker(service string, dashboardURL string) *PermissionChecke } func (p *PermissionChecker) CheckPermission(ctx context.Context, authInfo *appx.AuthInfo, resource string, action string) (bool, error) { + if p == nil { + return false, fmt.Errorf("permission checker not found") + } + if authInfo == nil { return false, fmt.Errorf("auth info not found") } diff --git a/cerbos/client/permission_checker_utils.go b/cerbos/client/permission_checker_utils.go deleted file mode 100644 index 33e80ae..0000000 --- a/cerbos/client/permission_checker_utils.go +++ /dev/null @@ -1,38 +0,0 @@ -package client - -import ( - "context" - - "github.com/reearth/reearthx/appx" - "github.com/reearth/reearthx/i18n" - "github.com/reearth/reearthx/rerror" -) - -var ( - errOperationDenied error = rerror.NewE(i18n.T("operation denied")) -) - -type PermissionService interface { - CheckPermission(ctx context.Context, authInfo *appx.AuthInfo, resource string, action string) (bool, error) -} - -func checkPermissionClient(client any) (PermissionService, bool) { - if client == nil { - return nil, false - } - - adapter, ok := client.(PermissionService) - if !ok || adapter == nil { - return nil, false - } - return adapter, true -} - -func CheckPermission(ctx context.Context, authInfo *appx.AuthInfo, client any, resource string, action string) (bool, error) { - checkPermissionAdapter, ok := checkPermissionClient(client) - if !ok { - return false, errOperationDenied - } - - return checkPermissionAdapter.CheckPermission(ctx, authInfo, resource, action) -}