From a4fa4d363a4c23e6eb73048688fb5be933a81c10 Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Thu, 11 Apr 2024 16:40:40 +0100 Subject: [PATCH] lxd/project: Simplify `FilterUsedBy` function. We no longer need to enforce that the project query parameter is set in the URLs that are passed into Authorizer methods, nor do we need to strip the project query parameter from the URL. Signed-off-by: Mark Laing --- lxd/project/permissions.go | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/lxd/project/permissions.go b/lxd/project/permissions.go index 63b8a15ae876..465b45ad0243 100644 --- a/lxd/project/permissions.go +++ b/lxd/project/permissions.go @@ -1478,35 +1478,18 @@ func FilterUsedBy(authorizer auth.Authorizer, r *http.Request, entries []string) continue } - entityType, projectName, location, pathArguments, err := entity.ParseURL(*u) + entityType, _, _, _, err := entity.ParseURL(*u) if err != nil { logger.Warn("Failed to parse project used-by entity URL", logger.Ctx{"url": entry, "error": err}) continue } - entityURL, err := entity.URL(entityType, projectName, location, pathArguments...) - if err != nil { - logger.Warn("Failed to create canonical entity URL for project used-by filtering", logger.Ctx{"url": entry, "error": err}) - continue - } - - urlsByEntityType[entityType] = append(urlsByEntityType[entityType], entityURL) + urlsByEntityType[entityType] = append(urlsByEntityType[entityType], &api.URL{URL: *u}) } // Filter the entries. usedBy := make([]string, 0, len(entries)) - // Used-by lists do not include the project query parameter if it is the default project. - appendUsedBy := func(u *api.URL) { - if u.Query().Get("project") == api.ProjectDefaultName { - q := u.Query() - q.Del("project") - u.RawQuery = q.Encode() - } - - usedBy = append(usedBy, u.String()) - } - for entityType, urls := range urlsByEntityType { // If only one entry of this type, check directly. if len(urls) == 1 { @@ -1515,7 +1498,7 @@ func FilterUsedBy(authorizer auth.Authorizer, r *http.Request, entries []string) continue } - appendUsedBy(urls[0]) + usedBy = append(usedBy, urls[0].String()) continue } @@ -1528,7 +1511,7 @@ func FilterUsedBy(authorizer auth.Authorizer, r *http.Request, entries []string) // Check each url and append. for _, u := range urls { if canViewEntity(u) { - appendUsedBy(u) + usedBy = append(usedBy, u.String()) } } }