| 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 "encoding/json" | 8 "encoding/json" |
| 9 "fmt" | 9 "fmt" |
| 10 "io/ioutil" | 10 "io/ioutil" |
| 11 "net/http" | 11 "net/http" |
| 12 "path/filepath" | 12 "path/filepath" |
| 13 "sort" | 13 "sort" |
| 14 "strings" | 14 "strings" |
| 15 "time" | 15 "time" |
| 16 | 16 |
| 17 ds "github.com/luci/gae/service/datastore" | 17 ds "github.com/luci/gae/service/datastore" |
| 18 "github.com/luci/luci-go/common/data/stringset" | 18 "github.com/luci/luci-go/common/data/stringset" |
| 19 "github.com/luci/luci-go/common/logging" | 19 "github.com/luci/luci-go/common/logging" |
| 20 "github.com/luci/luci-go/milo/api/resp" | 20 "github.com/luci/luci-go/milo/api/resp" |
| 21 "github.com/luci/luci-go/milo/appengine/settings" | |
| 22 "github.com/luci/luci-go/milo/common/miloerror" | 21 "github.com/luci/luci-go/milo/common/miloerror" |
| 23 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 24 ) | 23 ) |
| 25 | 24 |
| 26 var errBuildNotFound = miloerror.Error{ | 25 var errBuildNotFound = miloerror.Error{ |
| 27 Message: "Build not found", | 26 Message: "Build not found", |
| 28 Code: http.StatusNotFound, | 27 Code: http.StatusNotFound, |
| 29 } | 28 } |
| 30 | 29 |
| 31 // getBuild fetches a buildbot build from the datastore and checks ACLs. | 30 // getBuild fetches a buildbot build from the datastore and checks ACLs. |
| 31 // The return code matches the master responses. |
| 32 func getBuild(c context.Context, master, builder string, buildNum int) (*buildbo
tBuild, error) { | 32 func getBuild(c context.Context, master, builder string, buildNum int) (*buildbo
tBuild, error) { |
| 33 result := &buildbotBuild{ | 33 result := &buildbotBuild{ |
| 34 Master: master, | 34 Master: master, |
| 35 Buildername: builder, | 35 Buildername: builder, |
| 36 Number: buildNum, | 36 Number: buildNum, |
| 37 } | 37 } |
| 38 | 38 |
| 39 err := ds.Get(c, result) | 39 err := ds.Get(c, result) |
| 40 » switch { | 40 » err = checkAccess(c, err, result.Internal) |
| 41 » case err == ds.ErrNoSuchEntity: | 41 » if err == errMasterNotFound { |
| 42 » » return nil, errBuildNotFound | 42 » » err = errBuildNotFound |
| 43 » case err != nil: | |
| 44 » » return nil, err | |
| 45 } | 43 } |
| 46 » if result.Internal { | 44 » return result, err |
| 47 » » allowed, err := settings.IsAllowedInternal(c) | |
| 48 » » if err != nil { | |
| 49 » » » return nil, err | |
| 50 » » } | |
| 51 » » if !allowed { | |
| 52 » » » return nil, errBuildNotFound | |
| 53 » » } | |
| 54 » } | |
| 55 | |
| 56 » return result, nil | |
| 57 } | 45 } |
| 58 | 46 |
| 59 // result2Status translates a buildbot result integer into a resp.Status. | 47 // result2Status translates a buildbot result integer into a resp.Status. |
| 60 func result2Status(s *int) (status resp.Status) { | 48 func result2Status(s *int) (status resp.Status) { |
| 61 if s == nil { | 49 if s == nil { |
| 62 return resp.Running | 50 return resp.Running |
| 63 } | 51 } |
| 64 switch *s { | 52 switch *s { |
| 65 case 0: | 53 case 0: |
| 66 status = resp.Success | 54 status = resp.Success |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 476 |
| 489 // TODO(hinoka): Do all fields concurrently. | 477 // TODO(hinoka): Do all fields concurrently. |
| 490 return &resp.MiloBuild{ | 478 return &resp.MiloBuild{ |
| 491 SourceStamp: sourcestamp(c, b), | 479 SourceStamp: sourcestamp(c, b), |
| 492 Summary: summary(c, b), | 480 Summary: summary(c, b), |
| 493 Components: components(b), | 481 Components: components(b), |
| 494 PropertyGroup: properties(b), | 482 PropertyGroup: properties(b), |
| 495 Blame: blame(b), | 483 Blame: blame(b), |
| 496 }, nil | 484 }, nil |
| 497 } | 485 } |
| OLD | NEW |