Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds FriendlyName support for IC resources #50127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion api/accessrequest/access_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func GetResourceDetails(ctx context.Context, clusterName string, lister client.L
// We're interested in hostname or friendly name details. These apply to
// nodes, app servers, and user groups.
switch resourceID.Kind {
case types.KindNode, types.KindApp, types.KindUserGroup, types.KindIdentityCenterAccount:
case types.KindIdentityCenterAccount:
resourceID.Kind = types.KindApp
resourceIDs = append(resourceIDs, resourceID)
Comment on lines +64 to +65
Copy link
Contributor

@smallinsky smallinsky Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the GetResourceDetails->GetResourcesByResourceIDs->GetResourcesByKind->mapResourceKindToListResourcesType is not better place to overwrite the kind ?


case types.KindNode, types.KindApp, types.KindUserGroup, types.KindIdentityCenterAccountAssignment:
resourceIDs = append(resourceIDs, resourceID)
}
}
Expand Down
14 changes: 14 additions & 0 deletions api/types/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/defaults"
identitycenterv1 "github.com/gravitational/teleport/api/gen/proto/go/teleport/identitycenter/v1"
"github.com/gravitational/teleport/api/types/common"
"github.com/gravitational/teleport/api/types/compare"
"github.com/gravitational/teleport/api/utils"
Expand Down Expand Up @@ -705,6 +706,19 @@ func FriendlyName(resource ResourceWithLabels) string {
}

switch rr := resource.(type) {
case Resource153Unwrapper:
// RFD-153 style resources are generally data-only and do not have any
// methods beyond the minimal [Resource153] interface. Because we can't
// rely on them being able to implement an interface in order to generate
// a friendly name, any 153-style resources that *want* a friendly name
// will have to manually generate it.
switch urr := rr.Unwrap().(type) {
case *identitycenterv1.Account:
return urr.GetSpec().GetName()

case *identitycenterv1.AccountAssignment:
return urr.GetSpec().GetDisplay()
}
case interface{ GetHostname() string }:
return rr.GetHostname()
case interface{ GetDisplayName() string }:
Expand Down
Loading