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

Add num_member_entities and num_parent_groups to key_info in group listing #4648

Merged
merged 3 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion vault/identity_store_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (i *IdentityStore) handleGroupReadCommon(group *identity.Group) (*logical.R
respData["name"] = group.Name
respData["policies"] = group.Policies
respData["member_entity_ids"] = group.MemberEntityIDs
respData["parent_group_ids"] = group.ParentGroupIDs
respData["metadata"] = group.Metadata
respData["creation_time"] = ptypes.TimestampString(group.CreationTime)
respData["last_update_time"] = ptypes.TimestampString(group.LastUpdateTime)
Expand Down Expand Up @@ -347,7 +348,9 @@ func (i *IdentityStore) pathGroupIDList() framework.OperationFunc {
group := raw.(*identity.Group)
groupIDs = append(groupIDs, group.ID)
groupInfoEntry := map[string]interface{}{
"name": group.Name,
"name": group.Name,
"num_member_entities": len(group.MemberEntityIDs),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about s/num_member_entities/num_member_entity_ids and s/num_member_groups/num_parent_group_ids?

Copy link
Member Author

@jefferai jefferai May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IDs aren't members, the entities are members. :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean :-) But my thought was to be consistent with the input parameters of the group creation API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When doing group creation, you have to provide the IDs because that's how you're referencing the entities. But the entities themselves become members, not the entity IDs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 👍

"num_parent_groups": len(group.ParentGroupIDs),
}
if group.Alias != nil {
entry := map[string]interface{}{
Expand Down
11 changes: 7 additions & 4 deletions vault/identity_store_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sort"
"testing"

"github.com/go-test/deep"
"github.com/hashicorp/vault/helper/identity"
"github.com/hashicorp/vault/logical"
)
Expand Down Expand Up @@ -290,6 +291,7 @@ func TestIdentityStore_GroupsCreateUpdate(t *testing.T) {
"testkey1": "testvalue1",
"testkey2": "testvalue2",
},
"parent_group_ids": []string(nil),
}
expectedData["id"] = resp.Data["id"]
expectedData["type"] = resp.Data["type"]
Expand All @@ -301,8 +303,8 @@ func TestIdentityStore_GroupsCreateUpdate(t *testing.T) {
expectedData["modify_index"] = resp.Data["modify_index"]
expectedData["alias"] = resp.Data["alias"]

if !reflect.DeepEqual(expectedData, resp.Data) {
t.Fatalf("bad: group data;\nexpected: %#v\n actual: %#v\n", expectedData, resp.Data)
if diff := deep.Equal(expectedData, resp.Data); diff != nil {
t.Fatal(diff)
}

// Update the policies and metadata in the group
Expand Down Expand Up @@ -410,6 +412,7 @@ func TestIdentityStore_GroupsCRUD_ByID(t *testing.T) {
"testkey1": "testvalue1",
"testkey2": "testvalue2",
},
"parent_group_ids": []string(nil),
}
expectedData["id"] = resp.Data["id"]
expectedData["type"] = resp.Data["type"]
Expand All @@ -421,8 +424,8 @@ func TestIdentityStore_GroupsCRUD_ByID(t *testing.T) {
expectedData["modify_index"] = resp.Data["modify_index"]
expectedData["alias"] = resp.Data["alias"]

if !reflect.DeepEqual(expectedData, resp.Data) {
t.Fatalf("bad: group data;\nexpected: %#v\n actual: %#v\n", expectedData, resp.Data)
if diff := deep.Equal(expectedData, resp.Data); diff != nil {
t.Fatal(diff)
}

// Update the policies and metadata in the group
Expand Down