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

Use CRDB instead of SpiceDB for getting role resource #280

Merged
Merged
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
29 changes: 4 additions & 25 deletions internal/query/relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,33 +1010,12 @@ func (e *engine) GetRole(ctx context.Context, roleResource types.Resource) (type

// GetRoleResource gets the role's assigned resource.
func (e *engine) GetRoleResource(ctx context.Context, roleResource types.Resource) (types.Resource, error) {
var (
resActions map[types.Resource][]string
err error
)

for _, resType := range e.schemaRoleables {
resActions, err = e.listRoleResourceActions(ctx, roleResource, resType.Name)
if err != nil {
return types.Resource{}, err
}

// roles are only ever created for a single resource, so we can break after the first one is found.
if len(resActions) != 0 {
break
}
}

if len(resActions) > 1 {
return types.Resource{}, ErrRoleHasTooManyResources
}

// returns the first resources actions.
for resource := range resActions {
return resource, nil
dbRole, err := e.store.GetRoleByID(ctx, roleResource.ID)
if err != nil {
return types.Resource{}, err
}

return types.Resource{}, ErrRoleNotFound
return e.NewResourceFromID(dbRole.ResourceID)
}

// DeleteRole removes all role actions from the assigned resource.
Expand Down
Loading