Skip to content
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
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