Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: milo/appengine/buildbot/build.go

Issue 2525493002: Milo: Add themed page for errors (Closed)
Patch Set: y Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | milo/appengine/buildbot/builder.go » ('j') | milo/appengine/buildbot/master.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 21 "github.com/luci/luci-go/milo/appengine/settings"
22 "github.com/luci/luci-go/milo/common/miloerror" 22 "github.com/luci/luci-go/milo/common/miloerror"
23 "github.com/luci/luci-go/server/auth"
24 "github.com/luci/luci-go/server/auth/identity"
23 "golang.org/x/net/context" 25 "golang.org/x/net/context"
24 ) 26 )
25 27
26 var errBuildNotFound = miloerror.Error{ 28 var errBuildNotFound = miloerror.Error{
27 Message: "Build not found", 29 Message: "Build not found",
28 Code: http.StatusNotFound, 30 Code: http.StatusNotFound,
29 } 31 }
30 32
31 // getBuild fetches a buildbot build from the datastore and checks ACLs. 33 // getBuild fetches a buildbot build from the datastore and checks ACLs.
34 // The return code matches the master responses, that is:
35 // User not logged in, master found, master public: 200
36 // User not logged in, master not found: 401
37 // User not logged in, master internal: 401
38 // User logged in, master found, master internal: 200
39 // User logged in, master not found: 404
40 // User logged in, master found, master internal: 404
41 // Other error: 500
32 func getBuild(c context.Context, master, builder string, buildNum int) (*buildbo tBuild, error) { 42 func getBuild(c context.Context, master, builder string, buildNum int) (*buildbo tBuild, error) {
33 result := &buildbotBuild{ 43 result := &buildbotBuild{
34 Master: master, 44 Master: master,
35 Buildername: builder, 45 Buildername: builder,
36 Number: buildNum, 46 Number: buildNum,
37 } 47 }
48 cu := auth.CurrentUser(c)
38 49
39 err := ds.Get(c, result) 50 err := ds.Get(c, result)
40 switch { 51 switch {
41 case err == ds.ErrNoSuchEntity: 52 case err == ds.ErrNoSuchEntity:
42 » » return nil, errBuildNotFound 53 » » if cu.Identity == identity.AnonymousIdentity {
54 » » » return nil, errNotAuth
55 » » } else {
56 » » » return nil, errBuildNotFound
57 » » }
43 case err != nil: 58 case err != nil:
44 return nil, err 59 return nil, err
45 } 60 }
46 if result.Internal { 61 if result.Internal {
47 allowed, err := settings.IsAllowedInternal(c) 62 allowed, err := settings.IsAllowedInternal(c)
48 if err != nil { 63 if err != nil {
49 return nil, err 64 return nil, err
50 } 65 }
51 if !allowed { 66 if !allowed {
52 » » » return nil, errBuildNotFound 67 » » » if cu.Identity == identity.AnonymousIdentity {
68 » » » » return nil, errNotAuth
69 » » » } else {
70 » » » » return nil, errBuildNotFound
71 » » » }
53 } 72 }
54 } 73 }
55 74
56 return result, nil 75 return result, nil
57 } 76 }
58 77
59 // result2Status translates a buildbot result integer into a resp.Status. 78 // result2Status translates a buildbot result integer into a resp.Status.
60 func result2Status(s *int) (status resp.Status) { 79 func result2Status(s *int) (status resp.Status) {
61 if s == nil { 80 if s == nil {
62 return resp.Running 81 return resp.Running
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 507
489 // TODO(hinoka): Do all fields concurrently. 508 // TODO(hinoka): Do all fields concurrently.
490 return &resp.MiloBuild{ 509 return &resp.MiloBuild{
491 SourceStamp: sourcestamp(c, b), 510 SourceStamp: sourcestamp(c, b),
492 Summary: summary(c, b), 511 Summary: summary(c, b),
493 Components: components(b), 512 Components: components(b),
494 PropertyGroup: properties(b), 513 PropertyGroup: properties(b),
495 Blame: blame(b), 514 Blame: blame(b),
496 }, nil 515 }, nil
497 } 516 }
OLDNEW
« no previous file with comments | « no previous file | milo/appengine/buildbot/builder.go » ('j') | milo/appengine/buildbot/master.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698