Include Principals and Grants on Roles When Updating the Role. (#203)
This commit is contained in:
1 parent
99653727bb
commit
5bb13e71fe
6 files changed
+182
-38
No files matched your search
+4
-4
@@ -122,7 +122,7 @@ func (s Role) AddGrants(ctx context.Context, grants []string) (*Role, *api.Error
|
||||
"version": s.Version,
|
||||
}
|
||||
if len(grants) > 0 {
|
||||
body["grants"] = grants
|
||||
body["grant_strings"] = grants
|
||||
}
|
||||
|
||||
req, err := s.Client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:add-grants", s.Id), body)
|
||||
@@ -156,9 +156,9 @@ func (s Role) SetGrants(ctx context.Context, grants []string) (*Role, *api.Error
|
||||
"version": s.Version,
|
||||
}
|
||||
if len(grants) > 0 {
|
||||
body["grants"] = grants
|
||||
body["grant_strings"] = grants
|
||||
} else if grants != nil {
|
||||
body["grants"] = nil
|
||||
body["grant_strings"] = nil
|
||||
}
|
||||
|
||||
req, err := s.Client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:set-grants", s.Id), body)
|
||||
@@ -192,7 +192,7 @@ func (s Role) RemoveGrants(ctx context.Context, grants []string) (*Role, *api.Er
|
||||
"version": s.Version,
|
||||
}
|
||||
if len(grants) > 0 {
|
||||
body["grants"] = grants
|
||||
body["grant_strings"] = grants
|
||||
}
|
||||
|
||||
req, err := s.Client.NewRequest(ctx, "POST", fmt.Sprintf("roles/%s:remove-grants", s.Id), body)
|
||||
|
||||
@@ -112,14 +112,14 @@ func TestCustom(t *testing.T) {
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr, "Got error ", apiErr)
|
||||
assert.Equal(t, updatedRole.Version, r.Version+1)
|
||||
assert.Contains(t, updatedRole.Grants, "id=*;actions=read")
|
||||
assert.Contains(t, updatedRole.GrantStrings, "id=*;actions=read")
|
||||
|
||||
r = updatedRole
|
||||
updatedRole, apiErr, err = r.SetGrants(ctx, []string{"id=*;actions=*"})
|
||||
require.NoError(err)
|
||||
require.Nil(apiErr, "Got error ", apiErr)
|
||||
assert.Equal(t, updatedRole.Version, r.Version+1)
|
||||
assert.Contains(t, updatedRole.Grants, "id=*;actions=*")
|
||||
assert.Contains(t, updatedRole.GrantStrings, "id=*;actions=*")
|
||||
|
||||
r = updatedRole
|
||||
updatedRole, apiErr, err = r.RemoveGrants(ctx, []string{"id=*;actions=*"})
|
||||
|
||||
Reference in new issue
Block a user