| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package buildbot | 15 package buildbot |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "bytes" | 18 "bytes" |
| 19 "compress/gzip" | 19 "compress/gzip" |
| 20 "encoding/json" | 20 "encoding/json" |
| 21 "fmt" | 21 "fmt" |
| 22 "sort" | 22 "sort" |
| 23 "time" | 23 "time" |
| 24 | 24 |
| 25 ds "github.com/luci/gae/service/datastore" | 25 ds "github.com/luci/gae/service/datastore" |
| 26 "github.com/luci/luci-go/common/errors" |
| 26 "github.com/luci/luci-go/common/logging" | 27 "github.com/luci/luci-go/common/logging" |
| 27 "github.com/luci/luci-go/milo/api/resp" | 28 "github.com/luci/luci-go/milo/api/resp" |
| 28 "github.com/luci/luci-go/milo/common" | 29 "github.com/luci/luci-go/milo/common" |
| 29 "github.com/luci/luci-go/server/auth" | 30 "github.com/luci/luci-go/server/auth" |
| 30 "github.com/luci/luci-go/server/auth/identity" | 31 "github.com/luci/luci-go/server/auth/identity" |
| 31 | 32 |
| 32 "golang.org/x/net/context" | 33 "golang.org/x/net/context" |
| 33 ) | 34 ) |
| 34 | 35 |
| 35 func decodeMasterEntry( | 36 func decodeMasterEntry( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 63 | 64 |
| 64 // We're not logged in, or we can only see public stuff, so see if the m
aster | 65 // We're not logged in, or we can only see public stuff, so see if the m
aster |
| 65 // is public. | 66 // is public. |
| 66 if err := ds.Get(c, &buildbotMasterPublic{name}); err == nil { | 67 if err := ds.Get(c, &buildbotMasterPublic{name}); err == nil { |
| 67 // It exists and is public | 68 // It exists and is public |
| 68 return nil | 69 return nil |
| 69 } | 70 } |
| 70 | 71 |
| 71 if anon { | 72 if anon { |
| 72 // They need to log in before we can tell them more stuff. | 73 // They need to log in before we can tell them more stuff. |
| 73 » » return errNotAuth | 74 » » return errors.New("public master not found", common.CodeUnauthor
ized) |
| 75 |
| 74 } | 76 } |
| 75 | 77 |
| 76 // They are logged in but have no access, so tell them it's missing. | 78 // They are logged in but have no access, so tell them it's missing. |
| 77 » return errMasterNotFound | 79 » return errors.New("master not found", common.CodeNotFound) |
| 78 } | 80 } |
| 79 | 81 |
| 80 // getMasterEntry feches the named master and does an ACL check on the | 82 // getMasterEntry feches the named master and does an ACL check on the |
| 81 // current user. | 83 // current user. |
| 82 // It returns: | 84 // It returns: |
| 83 func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error
) { | 85 func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error
) { |
| 84 if err := canAccessMaster(c, name); err != nil { | 86 if err := canAccessMaster(c, name); err != nil { |
| 85 return nil, err | 87 return nil, err |
| 86 } | 88 } |
| 87 | 89 |
| 88 entry := buildbotMasterEntry{Name: name} | 90 entry := buildbotMasterEntry{Name: name} |
| 89 err := ds.Get(c, &entry) | 91 err := ds.Get(c, &entry) |
| 90 if err == ds.ErrNoSuchEntity { | 92 if err == ds.ErrNoSuchEntity { |
| 91 » » err = errMasterNotFound | 93 » » return nil, errors.New("master not found", common.CodeNotFound) |
| 92 } | 94 } |
| 93 return &entry, err | 95 return &entry, err |
| 94 } | 96 } |
| 95 | 97 |
| 96 // getMasterJSON fetches the latest known buildbot master data and returns | 98 // getMasterJSON fetches the latest known buildbot master data and returns |
| 97 // the buildbotMaster struct (if found), whether or not it is internal, | 99 // the buildbotMaster struct (if found), whether or not it is internal, |
| 98 // the last modified time, and an error if not found. | 100 // the last modified time, and an error if not found. |
| 99 func getMasterJSON(c context.Context, name string) ( | 101 func getMasterJSON(c context.Context, name string) ( |
| 100 master *buildbotMaster, internal bool, t time.Time, err error) { | 102 master *buildbotMaster, internal bool, t time.Time, err error) { |
| 101 master = &buildbotMaster{} | 103 master = &buildbotMaster{} |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 for _, bn := range sb { | 155 for _, bn := range sb { |
| 154 // Go templates escapes this for us, and also | 156 // Go templates escapes this for us, and also |
| 155 // slashes are not allowed in builder names. | 157 // slashes are not allowed in builder names. |
| 156 ml.Builders = append(ml.Builders, *resp.NewLink( | 158 ml.Builders = append(ml.Builders, *resp.NewLink( |
| 157 bn, fmt.Sprintf("/buildbot/%s/%s", entry.Name, b
n))) | 159 bn, fmt.Sprintf("/buildbot/%s/%s", entry.Name, b
n))) |
| 158 } | 160 } |
| 159 result.BuilderGroups = append(result.BuilderGroups, ml) | 161 result.BuilderGroups = append(result.BuilderGroups, ml) |
| 160 } | 162 } |
| 161 return result, nil | 163 return result, nil |
| 162 } | 164 } |
| OLD | NEW |