Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 buildbot | 5 package buildbot |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "compress/gzip" | 9 "compress/gzip" |
| 10 "encoding/json" | 10 "encoding/json" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 return | 53 return |
| 54 } | 54 } |
| 55 | 55 |
| 56 // GetAllBuilders returns a resp.Module object containing all known masters | 56 // GetAllBuilders returns a resp.Module object containing all known masters |
| 57 // and builders. | 57 // and builders. |
| 58 func GetAllBuilders(c context.Context) (*resp.Module, error) { | 58 func GetAllBuilders(c context.Context) (*resp.Module, error) { |
| 59 result := &resp.Module{Name: "Buildbot"} | 59 result := &resp.Module{Name: "Buildbot"} |
| 60 // Fetch all Master entries from datastore | 60 // Fetch all Master entries from datastore |
| 61 ds := datastore.Get(c) | 61 ds := datastore.Get(c) |
| 62 q := datastore.NewQuery("buildbotMasterEntry") | 62 q := datastore.NewQuery("buildbotMasterEntry") |
| 63 // TODO(hinoka): Support internal queries. | |
| 64 q = q.Eq("Internal", false) | |
| 65 // TODO(hinoka): Maybe don't look past like a month or so? | 63 // TODO(hinoka): Maybe don't look past like a month or so? |
| 66 entries := []*buildbotMasterEntry{} | 64 entries := []*buildbotMasterEntry{} |
| 67 err := ds.GetAll(q, &entries) | 65 err := ds.GetAll(q, &entries) |
| 68 if err != nil { | 66 if err != nil { |
| 69 return nil, err | 67 return nil, err |
| 70 } | 68 } |
| 71 | 69 |
| 72 // Add each builder from each master entry into the result. | 70 // Add each builder from each master entry into the result. |
| 73 // TODO(hinoka): FanInOut this? | 71 // TODO(hinoka): FanInOut this? |
| 74 for _, entry := range entries { | 72 for _, entry := range entries { |
| 73 if entry.Internal { | |
| 74 // Bypass the master if it's an internal master and the user is not | |
| 75 // part of the buildbot-private project. | |
| 76 if !settings.IsAllowed(c, "buildbot-private") { | |
|
Vadim Sh.
2016/08/23 18:53:06
errors like this is why its better to deduplicate
Ryan Tseng
2016/08/23 22:00:15
doh
| |
| 77 continue | |
| 78 } | |
| 79 } | |
| 75 master := &buildbotMaster{} | 80 master := &buildbotMaster{} |
| 76 err = decodeMasterEntry(c, entry, master) | 81 err = decodeMasterEntry(c, entry, master) |
| 77 if err != nil { | 82 if err != nil { |
| 78 log.WithError(err).Errorf(c, "Could not decode %s", entr y.Name) | 83 log.WithError(err).Errorf(c, "Could not decode %s", entr y.Name) |
| 79 continue | 84 continue |
| 80 } | 85 } |
| 81 ml := resp.MasterListing{Name: entry.Name} | 86 ml := resp.MasterListing{Name: entry.Name} |
| 82 // TODO(hinoka): Sort | |
| 83 // Sort the builder listing. | 87 // Sort the builder listing. |
| 84 sb := make([]string, 0, len(master.Builders)) | 88 sb := make([]string, 0, len(master.Builders)) |
| 85 for bn := range master.Builders { | 89 for bn := range master.Builders { |
| 86 sb = append(sb, bn) | 90 sb = append(sb, bn) |
| 87 } | 91 } |
| 88 sort.Strings(sb) | 92 sort.Strings(sb) |
| 89 for _, bn := range sb { | 93 for _, bn := range sb { |
| 90 ml.Builders = append(ml.Builders, resp.Link{ | 94 ml.Builders = append(ml.Builders, resp.Link{ |
| 91 Label: bn, | 95 Label: bn, |
| 92 // Go templates escapes this for us, and also | 96 // Go templates escapes this for us, and also |
| 93 // slashes are not allowed in builder names. | 97 // slashes are not allowed in builder names. |
| 94 URL: fmt.Sprintf("/buildbot/%s/%s", entry.Name, bn), | 98 URL: fmt.Sprintf("/buildbot/%s/%s", entry.Name, bn), |
| 95 }) | 99 }) |
| 96 } | 100 } |
| 97 result.Masters = append(result.Masters, ml) | 101 result.Masters = append(result.Masters, ml) |
| 98 } | 102 } |
| 99 return result, nil | 103 return result, nil |
| 100 } | 104 } |
| OLD | NEW |