Skip to content

Commit

Permalink
Introduce role friendly name labels and frontend utilities. (#40260)
Browse files Browse the repository at this point in the history
Role friendly name labels and frontend utilities have been introduced.
  • Loading branch information
mdwn authored Apr 5, 2024
1 parent d8d0b50 commit 96cb398
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@ const (

// OktaGroupDescriptionLabel is the individual group description label.
OktaGroupDescriptionLabel = TeleportInternalLabelPrefix + "okta-group-description"

// OktaRoleNameLabel is the human readable name for a role sourced from Okta.
OktaRoleNameLabel = TeleportInternalLabelPrefix + "okta-role-name"
)

const (
Expand Down
2 changes: 2 additions & 0 deletions api/types/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ func FriendlyName(resource ResourceWithLabels) string {
return appName
} else if groupName, ok := resource.GetLabel(OktaGroupNameLabel); ok {
return groupName
} else if roleName, ok := resource.GetLabel(OktaRoleNameLabel); ok {
return roleName
}
return resource.GetMetadata().Description
}
Expand Down
17 changes: 17 additions & 0 deletions api/types/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,15 @@ func TestFriendlyName(t *testing.T) {
return group
}

newRole := func(t *testing.T, name string, labels map[string]string) Role {
role, err := NewRole(name, RoleSpecV6{})
require.NoError(t, err)
metadata := role.GetMetadata()
metadata.Labels = labels
role.SetMetadata(metadata)
return role
}

node, err := NewServer("node", KindNode, ServerSpecV2{
Hostname: "friendly hostname",
})
Expand Down Expand Up @@ -573,6 +582,14 @@ func TestFriendlyName(t *testing.T) {
}),
expected: "label friendly name",
},
{
name: "friendly role name (uses label)",
resource: newRole(t, "friendly", map[string]string{
OriginLabel: OriginOkta,
OktaRoleNameLabel: "label friendly name",
}),
expected: "label friendly name",
},
{
name: "friendly node name",
resource: node,
Expand Down

0 comments on commit 96cb398

Please sign in to comment.