| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The LUCI Authors. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 package hierarchy | |
| 16 | |
| 17 import ( | |
| 18 log "github.com/luci/luci-go/common/logging" | |
| 19 "github.com/luci/luci-go/grpc/grpcutil" | |
| 20 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | |
| 21 "github.com/luci/luci-go/luci_config/common/cfgtypes" | |
| 22 | |
| 23 "golang.org/x/net/context" | |
| 24 ) | |
| 25 | |
| 26 func getProjects(c context.Context, r *Request) (*List, error) { | |
| 27 // None of the projects are streams. | |
| 28 var l List | |
| 29 if r.StreamOnly { | |
| 30 return &l, nil | |
| 31 } | |
| 32 | |
| 33 // Get all user-accessible active projects. | |
| 34 projects, err := config.ActiveUserProjects(c) | |
| 35 if err != nil { | |
| 36 // If there is an error, we will refrain from filtering projects
. | |
| 37 log.WithError(err).Warningf(c, "Failed to get user project list.
") | |
| 38 return nil, grpcutil.Internal | |
| 39 } | |
| 40 | |
| 41 next := cfgtypes.ProjectName(r.Next) | |
| 42 skip := r.Skip | |
| 43 for _, proj := range projects { | |
| 44 // Implement "Next" cursor. If set, don't do anything until we'v
e seen it. | |
| 45 if next != "" { | |
| 46 if proj == next { | |
| 47 next = "" | |
| 48 } | |
| 49 continue | |
| 50 } | |
| 51 | |
| 52 // Implement skip. | |
| 53 if skip > 0 { | |
| 54 skip-- | |
| 55 continue | |
| 56 } | |
| 57 | |
| 58 l.Comp = append(l.Comp, &ListComponent{ | |
| 59 Name: string(proj), | |
| 60 }) | |
| 61 | |
| 62 // Implement limit. | |
| 63 if r.Limit > 0 && len(l.Comp) >= r.Limit { | |
| 64 l.Next = string(proj) | |
| 65 break | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 return &l, nil | |
| 70 } | |
| OLD | NEW |