Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: appengine/logdog/coordinator/hierarchy/project.go

Issue 1971493003: LogDog: Project READ access for user endpoints. (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-service-config
Patch Set: Updated patchset dependency Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/logdog/coordinator/hierarchy/hierarchy_test.go ('k') | appengine/logdog/coordinator/project.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/logdog/coordinator/hierarchy/project.go
diff --git a/appengine/logdog/coordinator/hierarchy/project.go b/appengine/logdog/coordinator/hierarchy/project.go
index 70398b4c618acd0b6770c50feebbea1d0e9b4744..2193d97d143e26e48ec622e04700a808c76ab13d 100644
--- a/appengine/logdog/coordinator/hierarchy/project.go
+++ b/appengine/logdog/coordinator/hierarchy/project.go
@@ -5,9 +5,10 @@
package hierarchy
import (
+ "sort"
+
"github.com/luci/luci-go/appengine/logdog/coordinator"
- "github.com/luci/luci-go/appengine/logdog/coordinator/config"
- luciConfig "github.com/luci/luci-go/common/config"
+ "github.com/luci/luci-go/common/config"
log "github.com/luci/luci-go/common/logging"
"golang.org/x/net/context"
)
@@ -19,35 +20,21 @@ func getProjects(c context.Context, r *Request) (*List, error) {
return &l, nil
}
- projects, err := config.UserProjects(c)
+ // Get all user-accessible active projects.
+ allPcfgs, err := coordinator.ActiveUserProjects(c)
if err != nil {
- log.WithError(err).Errorf(c, "Failed to get user projects.")
+ // If there is an error, we will refrain from filtering projects.
+ log.WithError(err).Warningf(c, "Failed to get user project list.")
return nil, err
}
- // Get all current datastore namespaces.
- nsProjects, err := coordinator.AllProjectsWithNamespaces(c)
- if err != nil {
- // If there is an error, we will refrain from filtering projects.
- log.WithError(err).Warningf(c, "Failed to get namespace project list.")
- } else {
- // Only list projects that have datastore namespaces.
- lookup := make(map[luciConfig.ProjectName]struct{}, len(nsProjects))
- for _, proj := range nsProjects {
- lookup[proj] = struct{}{}
- }
-
- pos := 0
- for _, proj := range projects {
- if _, ok := lookup[proj]; ok {
- projects[pos] = proj
- pos++
- }
- }
- projects = projects[:pos]
+ projects := make(projectNameSlice, 0, len(allPcfgs))
+ for project := range allPcfgs {
+ projects = append(projects, project)
}
+ sort.Sort(projects)
- next := luciConfig.ProjectName(r.Next)
+ next := config.ProjectName(r.Next)
skip := r.Skip
for _, proj := range projects {
// Implement "Next" cursor. If set, don't do anything until we've seen it.
@@ -77,3 +64,10 @@ func getProjects(c context.Context, r *Request) (*List, error) {
return &l, nil
}
+
+// projectNameSlice is a sortable slice of config.ProjectName.
+type projectNameSlice []config.ProjectName
+
+func (s projectNameSlice) Len() int { return len(s) }
+func (s projectNameSlice) Less(i, j int) bool { return s[i] < s[j] }
+func (s projectNameSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
« no previous file with comments | « appengine/logdog/coordinator/hierarchy/hierarchy_test.go ('k') | appengine/logdog/coordinator/project.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698