From 5b09e6dbb70c5a57f03e44dd42af6cf2105d4eb7 Mon Sep 17 00:00:00 2001 From: Kartik Verma Date: Tue, 2 Aug 2022 08:18:52 +0530 Subject: [PATCH] fix: error in bootstrapping shield from fresh database (#140) * use NamespaceId instead of ns.ID * fix tests --- core/bootstrap/bootstrap.go | 23 +++++++++++++---------- core/bootstrap/bootstrap_test.go | 18 ++++++++++-------- 2 files changed, 23 insertions(+), 18 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 } 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) })