| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package hierarchy | 5 package hierarchy |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "sort" | |
| 9 | |
| 10 log "github.com/luci/luci-go/common/logging" | 8 log "github.com/luci/luci-go/common/logging" |
| 11 "github.com/luci/luci-go/grpc/grpcutil" | 9 "github.com/luci/luci-go/grpc/grpcutil" |
| 12 » "github.com/luci/luci-go/logdog/appengine/coordinator" | 10 » "github.com/luci/luci-go/logdog/appengine/coordinator/config" |
| 13 "github.com/luci/luci-go/luci_config/common/cfgtypes" | 11 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 14 | 12 |
| 15 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 16 ) | 14 ) |
| 17 | 15 |
| 18 func getProjects(c context.Context, r *Request) (*List, error) { | 16 func getProjects(c context.Context, r *Request) (*List, error) { |
| 19 // None of the projects are streams. | 17 // None of the projects are streams. |
| 20 var l List | 18 var l List |
| 21 if r.StreamOnly { | 19 if r.StreamOnly { |
| 22 return &l, nil | 20 return &l, nil |
| 23 } | 21 } |
| 24 | 22 |
| 25 // Get all user-accessible active projects. | 23 // Get all user-accessible active projects. |
| 26 » allPcfgs, err := coordinator.ActiveUserProjects(c) | 24 » projects, err := config.ActiveUserProjects(c) |
| 27 if err != nil { | 25 if err != nil { |
| 28 // If there is an error, we will refrain from filtering projects
. | 26 // If there is an error, we will refrain from filtering projects
. |
| 29 log.WithError(err).Warningf(c, "Failed to get user project list.
") | 27 log.WithError(err).Warningf(c, "Failed to get user project list.
") |
| 30 return nil, grpcutil.Internal | 28 return nil, grpcutil.Internal |
| 31 } | 29 } |
| 32 | 30 |
| 33 projects := make(projectNameSlice, 0, len(allPcfgs)) | |
| 34 for project := range allPcfgs { | |
| 35 projects = append(projects, project) | |
| 36 } | |
| 37 sort.Sort(projects) | |
| 38 | |
| 39 next := cfgtypes.ProjectName(r.Next) | 31 next := cfgtypes.ProjectName(r.Next) |
| 40 skip := r.Skip | 32 skip := r.Skip |
| 41 for _, proj := range projects { | 33 for _, proj := range projects { |
| 42 // Implement "Next" cursor. If set, don't do anything until we'v
e seen it. | 34 // Implement "Next" cursor. If set, don't do anything until we'v
e seen it. |
| 43 if next != "" { | 35 if next != "" { |
| 44 if proj == next { | 36 if proj == next { |
| 45 next = "" | 37 next = "" |
| 46 } | 38 } |
| 47 continue | 39 continue |
| 48 } | 40 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 | 51 |
| 60 // Implement limit. | 52 // Implement limit. |
| 61 if r.Limit > 0 && len(l.Comp) >= r.Limit { | 53 if r.Limit > 0 && len(l.Comp) >= r.Limit { |
| 62 l.Next = string(proj) | 54 l.Next = string(proj) |
| 63 break | 55 break |
| 64 } | 56 } |
| 65 } | 57 } |
| 66 | 58 |
| 67 return &l, nil | 59 return &l, nil |
| 68 } | 60 } |
| 69 | |
| 70 // projectNameSlice is a sortable slice of cfgtypes.ProjectName. | |
| 71 type projectNameSlice []cfgtypes.ProjectName | |
| 72 | |
| 73 func (s projectNameSlice) Len() int { return len(s) } | |
| 74 func (s projectNameSlice) Less(i, j int) bool { return s[i] < s[j] } | |
| 75 func (s projectNameSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | |
| OLD | NEW |