Add grant scope IDs to role list (#4893)

This adds grant_scope_ids in the output of role listing. The lookup for grant scope IDs was changed to allow taking in a set of roles instead of just a single role, and the results are collated afterwards.

---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
Jeff MitchellandJohan Brandhorst-Satzkorn authored and GitHub committed 2024-06-25 13:05:52 -04:00
1 parent d43565038f
commit 4e0c2d79ac
8 files changed
+58 -14

No files matched your search

@@ -209,7 +209,7 @@ func (s Service) ListRoles(ctx context.Context, req *pbs.ListRolesRequest) (*pbs
if !ok {
continue
}
item, err := toProto(ctx, item, nil, nil, nil, outputOpts...)
item, err := toProto(ctx, item, nil, nil, item.GrantScopes, outputOpts...)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
}
@@ -220,6 +220,7 @@ func TestList(t *testing.T) {
var totalRoles []*pb.Role
for i := 0; i < 10; i++ {
or := iam.TestRole(t, conn, oWithRoles.GetPublicId())
_ = iam.TestRoleGrantScope(t, conn, or.GetPublicId(), globals.GrantScopeChildren)
wantOrgRoles = append(wantOrgRoles, &pb.Role{
Id: or.GetPublicId(),
ScopeId: or.GetScopeId(),
@@ -228,6 +229,7 @@ func TestList(t *testing.T) {
UpdatedTime: or.GetUpdateTime().GetTimestamp(),
Version: or.GetVersion(),
AuthorizedActions: testAuthorizedActions,
GrantScopeIds: []string{"this", "children"},
})
totalRoles = append(totalRoles, wantOrgRoles[i])
pr := iam.TestRole(t, conn, pWithRoles.GetPublicId())
@@ -239,6 +241,7 @@ func TestList(t *testing.T) {
UpdatedTime: pr.GetUpdateTime().GetTimestamp(),
Version: pr.GetVersion(),
AuthorizedActions: testAuthorizedActions,
GrantScopeIds: []string{"this"},
})
totalRoles = append(totalRoles, wantProjRoles[i])
}
@@ -422,7 +425,7 @@ func TestList(t *testing.T) {
}
func roleToProto(r *iam.Role, scope *scopes.ScopeInfo, authorizedActions []string) *pb.Role {
return &pb.Role{
ret := &pb.Role{
Id: r.GetPublicId(),
ScopeId: r.GetScopeId(),
Scope: scope,
@@ -431,6 +434,10 @@ func roleToProto(r *iam.Role, scope *scopes.ScopeInfo, authorizedActions []strin
Version: r.GetVersion(),
AuthorizedActions: testAuthorizedActions,
}
for _, r := range r.GrantScopes {
ret.GrantScopeIds = append(ret.GrantScopeIds, r.ScopeIdOrSpecial)
}
return ret
}
func TestListPagination(t *testing.T) {