Skip to content

Add PinnedResources to ListUnifiedResources Request#32077

Merged
avatus merged 3 commits intomasterfrom
avatus/get_unified_resources_by_id
Oct 10, 2023
Merged

Add PinnedResources to ListUnifiedResources Request#32077
avatus merged 3 commits intomasterfrom
avatus/get_unified_resources_by_id

Conversation

@avatus
Copy link
Copy Markdown
Contributor

@avatus avatus commented Sep 18, 2023

Relies on #32009
Part of #32075

This is the backend portion to fetch unified resources per the user's pinned resources.

If the pinnedResources param is present in the request, we will populate the unified resources only from the IDs present in their pinned resources preferences rather than all the resources. Afterwards, all the same filters apply such as rbac, search/query, etc.

Comment thread lib/auth/auth_with_roles.go Outdated
Comment on lines +1631 to +1545
ids := make([]string, 0)
clusterName, err := a.authServer.GetClusterName()
if err != nil {
return nil, trace.Wrap(err, "getting cluster name")
}

prefs, err := a.authServer.GetUserPreferences(ctx, a.context.User.GetName())
if err != nil {
return nil, trace.Wrap(err, "getting user preferences")
}
clusters := prefs.PinnedResources.GetPinnedResources()
clusterIds, ok := clusters[clusterName.GetClusterName()]
if ok {
ids = clusterIds.ResourceIds
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this whole song and dance of getting userprefs and clustername and all that seems really messy but i couldn't find a simpler way to do it. Open to suggestions

@avatus
Copy link
Copy Markdown
Contributor Author

avatus commented Sep 18, 2023

This is sort of temporary because we will be updating how we get these IDs when we move towards the indexes/map of resources in the upcoming performance updates. But for now, this is my idea for the current implementation.

@avatus
Copy link
Copy Markdown
Contributor Author

avatus commented Sep 18, 2023

Looking into this crazy amount of unit test errors.
edit: oh yeah. i keep forgetting that opPut sends a ResourceHeader. will fix this shortly. i think im going to have to add that map of resources

Comment on lines +1784 to +1786
// PinnedResources indicates that the request will pull only the pinned resources
// of the requesting user
bool PinnedResources = 11 [(gogoproto.jsontag) = "pinned_resources,omitempty"];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Weird that the linter says this field isn't present

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about PinnedResourcesOnly for a name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I was trying to think of a name like "include pinned resources" or "use pinned resources" but every name sounded inclusive instead of exclusive so I gave up. I like Only. Will update.

Comment thread lib/auth/auth_with_roles.go Outdated
Comment thread lib/auth/auth_with_roles.go Outdated
Comment thread lib/auth/auth_with_roles_test.go Outdated
Comment thread lib/auth/auth_with_roles_test.go Outdated
Comment thread lib/auth/auth_with_roles_test.go Outdated
Comment thread lib/auth/auth_with_roles.go Outdated
Comment thread lib/auth/auth_with_roles.go Outdated
Comment thread lib/auth/auth_with_roles.go Outdated
Comment thread lib/auth/auth_with_roles.go Outdated
Comment thread lib/auth/auth_with_roles_test.go Outdated
Comment thread lib/services/unified_resource.go Outdated
Comment on lines +238 to +268
var name, kind string
// set the kind to the appropriate "contained" type, rather than
// the container type. This better represents what resource is
// being sent to the ui
switch r := resource.(type) {
case types.AppServer:
app := r.GetApp()
if app != nil {
name = app.GetName()
kind = types.KindApp
}
case types.SAMLIdPServiceProvider:
name = r.GetName()
kind = types.KindApp
case types.KubeServer:
cluster := r.GetCluster()
if cluster != nil {
name = r.GetCluster().GetName()
kind = types.KindKubernetesCluster
}
case types.DatabaseServer:
db := r.GetDatabase()
if db != nil {
name = db.GetName()
kind = types.KindDatabase
}
default:
name = resource.GetName()
kind = resource.GetKind()
}
return backend.Key(prefix, name, kind)
Copy link
Copy Markdown
Contributor Author

@avatus avatus Sep 27, 2023

Choose a reason for hiding this comment

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

This is currently broke and I'm trying to fix it. When a resource is added, it's "contained resource" exists, but if something gets updated (or deleted), like AppServer, then the event is sent without its contained resource which means I can't generate the resource key again. The frontend only receives the contained resource and uses it as the ID for pinning.

So, backend updates don't know about the 'contained' resource, and the frontend doesn't know about the 'container' resource. I have to figure out a way to connect them again.

You can ignore this PR until I fix it. Thanks! (Or check out other parts)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Once #32709 is in, I can refactor to use the resourceSortKey.ByName to fetch the correct resource by the pinned resource ID.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored using resourceSortKey and added the matcher.

@avatus
Copy link
Copy Markdown
Contributor Author

avatus commented Oct 5, 2023

This is ready to be reviewed again

Comment thread lib/services/unified_resource.go Outdated
Comment thread lib/services/unified_resource.go Outdated
Comment thread lib/auth/auth_with_roles.go Outdated
if trace.IsAccessDenied(err) {
return false
}
return false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is the if trace.isAccessDenied necessary? we return false regardless

@avatus avatus force-pushed the avatus/pinned_user_prefs branch from d2d0b55 to dceb604 Compare October 10, 2023 15:30
Base automatically changed from avatus/pinned_user_prefs to master October 10, 2023 18:30
@avatus avatus force-pushed the avatus/get_unified_resources_by_id branch from 887e3ab to 3ee5435 Compare October 10, 2023 19:13
@avatus avatus force-pushed the avatus/get_unified_resources_by_id branch from d43d08c to 06af5ca Compare October 10, 2023 22:17
@avatus avatus enabled auto-merge October 10, 2023 22:17
@avatus avatus added this pull request to the merge queue Oct 10, 2023
Merged via the queue into master with commit b905eaf Oct 10, 2023
@avatus avatus deleted the avatus/get_unified_resources_by_id branch October 10, 2023 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants