Skip to content

Commit

Permalink
fix: error in bootstrapping shield from fresh database (#140)
Browse files Browse the repository at this point in the history
* use NamespaceId instead of ns.ID

* fix tests
  • Loading branch information
krtkvrm authored Aug 2, 2022
1 parent 878256c commit 5b09e6d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
23 changes: 13 additions & 10 deletions core/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
18 changes: 10 additions & 8 deletions core/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ 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)
})

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)
})
Expand Down

0 comments on commit 5b09e6d

Please sign in to comment.