OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package hierarchy | 5 package hierarchy |
6 | 6 |
7 import ( | 7 import ( |
8 "github.com/luci/luci-go/appengine/logdog/coordinator" | 8 "github.com/luci/luci-go/appengine/logdog/coordinator" |
9 "github.com/luci/luci-go/appengine/logdog/coordinator/config" | |
10 luciConfig "github.com/luci/luci-go/common/config" | 9 luciConfig "github.com/luci/luci-go/common/config" |
11 log "github.com/luci/luci-go/common/logging" | 10 log "github.com/luci/luci-go/common/logging" |
12 "golang.org/x/net/context" | 11 "golang.org/x/net/context" |
13 ) | 12 ) |
14 | 13 |
15 func getProjects(c context.Context, r *Request) (*List, error) { | 14 func getProjects(c context.Context, r *Request) (*List, error) { |
16 // None of the projects are streams. | 15 // None of the projects are streams. |
17 var l List | 16 var l List |
18 if r.StreamOnly { | 17 if r.StreamOnly { |
19 return &l, nil | 18 return &l, nil |
20 } | 19 } |
21 | 20 |
22 » projects, err := config.UserProjects(c) | 21 » // Get all user-accessible active projects. |
| 22 » projects, err := coordinator.ActiveProjects(c, true) |
23 if err != nil { | 23 if err != nil { |
24 » » log.WithError(err).Errorf(c, "Failed to get user projects.") | 24 » » // If there is an error, we will refrain from filtering projects
. |
| 25 » » log.WithError(err).Warningf(c, "Failed to get project list.") |
25 return nil, err | 26 return nil, err |
26 } | 27 } |
27 | 28 |
28 // Get all current datastore namespaces. | |
29 nsProjects, err := coordinator.AllProjectsWithNamespaces(c) | |
30 if err != nil { | |
31 // If there is an error, we will refrain from filtering projects
. | |
32 log.WithError(err).Warningf(c, "Failed to get namespace project
list.") | |
33 } else { | |
34 // Only list projects that have datastore namespaces. | |
35 lookup := make(map[luciConfig.ProjectName]struct{}, len(nsProjec
ts)) | |
36 for _, proj := range nsProjects { | |
37 lookup[proj] = struct{}{} | |
38 } | |
39 | |
40 pos := 0 | |
41 for _, proj := range projects { | |
42 if _, ok := lookup[proj]; ok { | |
43 projects[pos] = proj | |
44 pos++ | |
45 } | |
46 } | |
47 projects = projects[:pos] | |
48 } | |
49 | |
50 next := luciConfig.ProjectName(r.Next) | 29 next := luciConfig.ProjectName(r.Next) |
51 skip := r.Skip | 30 skip := r.Skip |
52 for _, proj := range projects { | 31 for _, proj := range projects { |
53 // Implement "Next" cursor. If set, don't do anything until we'v
e seen it. | 32 // Implement "Next" cursor. If set, don't do anything until we'v
e seen it. |
54 if next != "" { | 33 if next != "" { |
55 if proj == next { | 34 if proj == next { |
56 next = "" | 35 next = "" |
57 } | 36 } |
58 continue | 37 continue |
59 } | 38 } |
(...skipping 10 matching lines...) Expand all Loading... |
70 | 49 |
71 // Implement limit. | 50 // Implement limit. |
72 if r.Limit > 0 && len(l.Comp) >= r.Limit { | 51 if r.Limit > 0 && len(l.Comp) >= r.Limit { |
73 l.Next = string(proj) | 52 l.Next = string(proj) |
74 break | 53 break |
75 } | 54 } |
76 } | 55 } |
77 | 56 |
78 return &l, nil | 57 return &l, nil |
79 } | 58 } |
OLD | NEW |