From c13cd6cf9e4b0b357c576d8495072a145955c5f3 Mon Sep 17 00:00:00 2001 From: Kartik Verma Date: Tue, 2 Aug 2022 00:38:03 +0530 Subject: [PATCH 1/2] use NamespaceId instead of ns.ID --- core/bootstrap/bootstrap.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/bootstrap/bootstrap.go b/core/bootstrap/bootstrap.go index 187cded67..e8d5d84ec 100644 --- a/core/bootstrap/bootstrap.go +++ b/core/bootstrap/bootstrap.go @@ -91,9 +91,10 @@ func (s Service) onboardResource(ctx context.Context, resYAML resource.YAML) err for _, r := range rolesList { role := getResourceRole(r, ns) policy := policy.Policy{ - Action: act, - Namespace: ns, - Role: role, + Action: act, + Namespace: ns, + NamespaceID: ns.ID, + Role: role, } resourceRoles = append(resourceRoles, role) policies = append(policies, policy) @@ -161,10 +162,11 @@ func getResourceRole(r string, ns namespace.Namespace) role.Role { } role := role.Role{ - ID: roleId, - Name: roleId, - Namespace: roleNs, - Types: []string{role.UserType, role.TeamMemberType}, + ID: roleId, + Name: roleId, + Namespace: roleNs, + NamespaceID: roleNs.ID, + Types: []string{role.UserType, role.TeamMemberType}, } return role } @@ -173,9 +175,10 @@ func getResourceAction(actionStr string, ns namespace.Namespace) action.Action { actId := fmt.Sprintf("%s_%s", ns.ID, actionStr) actionName := fmt.Sprintf("%s %s", strings.Title(strings.ToLower(ns.ID)), strings.Title(strings.ToLower(actionStr))) act := action.Action{ - ID: actId, - Name: actionName, - Namespace: ns, + ID: actId, + Name: actionName, + Namespace: ns, + NamespaceID: ns.ID, } return act } From b6d872ce78ac32f8ea8cfe63f9da6f048040a35a Mon Sep 17 00:00:00 2001 From: Kartik Verma Date: Tue, 2 Aug 2022 00:44:02 +0530 Subject: [PATCH 2/2] fix tests --- core/bootstrap/bootstrap_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/bootstrap/bootstrap_test.go b/core/bootstrap/bootstrap_test.go index d92d7842c..bc7b8bcfa 100644 --- a/core/bootstrap/bootstrap_test.go +++ b/core/bootstrap/bootstrap_test.go @@ -23,10 +23,11 @@ func TestGetResourceRole(t *testing.T) { t.Run("should create role for resource", func(t *testing.T) { output := getResourceRole("admin", namespace.Namespace{ID: "kafka"}) expected := role.Role{ - ID: "kafka_admin", - Name: "kafka_admin", - Namespace: namespace.Namespace{ID: "kafka"}, - Types: []string{"user", "team#team_member"}, + ID: "kafka_admin", + Name: "kafka_admin", + Namespace: namespace.Namespace{ID: "kafka"}, + NamespaceID: "kafka", + Types: []string{"user", "team#team_member"}, } assert.EqualValues(t, expected, output) }) @@ -34,10 +35,11 @@ func TestGetResourceRole(t *testing.T) { t.Run("should assign role for other namespace for resources", func(t *testing.T) { output := getResourceRole("organization.organization_admin", namespace.Namespace{ID: "team"}) expected := role.Role{ - ID: "organization_admin", - Name: "organization_admin", - Namespace: namespace.Namespace{ID: "organization"}, - Types: []string{"user", "team#team_member"}, + ID: "organization_admin", + Name: "organization_admin", + Namespace: namespace.Namespace{ID: "organization"}, + NamespaceID: "organization", + Types: []string{"user", "team#team_member"}, } assert.EqualValues(t, expected, output) })