Skip to content

Commit

Permalink
Merge pull request #22 from ConductorOne/ggreer/grant-parent-check
Browse files Browse the repository at this point in the history
Avoid a nil pointer exception by checking for parent resource before using it.
  • Loading branch information
ggreer authored Apr 18, 2024
2 parents b3af4af + d7ca734 commit 6d423a3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/connector/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ func (o *workspaceRoleType) Grant(ctx context.Context, principal *v2.Resource, e
return nil, fmt.Errorf("baton-slack: only users can be assigned a role")
}

// TODO: put the team ID in the entitlement or user ID, not the parent resource
if principal.ParentResourceId == nil {
l.Warn(
"baton-slack: user does not have a parent resource",
zap.String("principal_id", principal.Id.Resource),
)
return nil, fmt.Errorf("baton-slack: user does not have a parent resource")
}

err := o.enterpriseClient.SetWorkspaceRole(ctx, principal.ParentResourceId.Resource, principal.Id.Resource, entitlement.Resource.Id.Resource)
if err != nil {
return nil, fmt.Errorf("baton-slack: failed to assign user role: %w", err)
Expand All @@ -157,6 +166,7 @@ func (o *workspaceRoleType) Revoke(ctx context.Context, grant *v2.Grant) (annota
return nil, fmt.Errorf("baton-slack: only users can have role revoked")
}

// TODO: put the team ID in the entitlement or user ID, not the parent resource
if principal.ParentResourceId == nil {
l.Warn(
"baton-slack: user does not have a parent resource",
Expand Down

0 comments on commit 6d423a3

Please sign in to comment.