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

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

Issue 2525493002: Milo: Add themed page for errors (Closed)
Patch Set: y Created 4 years, 1 month 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
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 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "encoding/json" 10 "encoding/json"
11 "fmt" 11 "fmt"
12 "sort" 12 "sort"
13 "time" 13 "time"
14 14
15 ds "github.com/luci/gae/service/datastore" 15 ds "github.com/luci/gae/service/datastore"
16 "github.com/luci/luci-go/common/logging" 16 "github.com/luci/luci-go/common/logging"
17 "github.com/luci/luci-go/milo/api/resp" 17 "github.com/luci/luci-go/milo/api/resp"
18 "github.com/luci/luci-go/milo/appengine/settings" 18 "github.com/luci/luci-go/milo/appengine/settings"
19 "github.com/luci/luci-go/server/auth"
20 "github.com/luci/luci-go/server/auth/identity"
19 21
20 "golang.org/x/net/context" 22 "golang.org/x/net/context"
21 ) 23 )
22 24
23 func decodeMasterEntry( 25 func decodeMasterEntry(
24 c context.Context, entry *buildbotMasterEntry, master *buildbotMaster) e rror { 26 c context.Context, entry *buildbotMasterEntry, master *buildbotMaster) e rror {
25 27
26 reader, err := gzip.NewReader(bytes.NewReader(entry.Data)) 28 reader, err := gzip.NewReader(bytes.NewReader(entry.Data))
27 if err != nil { 29 if err != nil {
28 return err 30 return err
29 } 31 }
30 defer reader.Close() 32 defer reader.Close()
31 if err = json.NewDecoder(reader).Decode(master); err != nil { 33 if err = json.NewDecoder(reader).Decode(master); err != nil {
32 return err 34 return err
33 } 35 }
34 return nil 36 return nil
35 } 37 }
36 38
37 // getMasterEntry feches the named master and does an ACL check on the 39 // getMasterEntry feches the named master and does an ACL check on the
38 // current user. 40 // current user.
41 // It returns:
42 // User not logged in, master found, master public: 200
43 // User not logged in, master not found: 401
44 // User not logged in, master internal: 401
45 // User logged in, master found, master internal: 200
46 // User logged in, master not found: 404
47 // User logged in, master found, master internal: 404
48 // Other error: 500
39 func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error ) { 49 func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error ) {
40 entry := buildbotMasterEntry{Name: name} 50 entry := buildbotMasterEntry{Name: name}
41 err := ds.Get(c, &entry) 51 err := ds.Get(c, &entry)
52 cu := auth.CurrentUser(c)
53
42 switch { 54 switch {
43 case err == ds.ErrNoSuchEntity: 55 case err == ds.ErrNoSuchEntity:
44 » » return nil, errMasterNotFound 56 » » if cu.Identity == identity.AnonymousIdentity {
estaab 2016/12/01 00:04:34 It seems pretty dangerous to have the auth checkin
hinoka 2016/12/01 02:08:54 Done.
57 » » » return nil, errNotAuth
58 » » } else {
59 » » » return nil, errMasterNotFound
60 » » }
45 case err != nil: 61 case err != nil:
46 logging.WithError(err).Errorf( 62 logging.WithError(err).Errorf(
47 c, "Encountered error while fetching entry for %s:\n%s", name, err) 63 c, "Encountered error while fetching entry for %s:\n%s", name, err)
48 return nil, err 64 return nil, err
49 } 65 }
50 66
51 // Do the ACL check if the entry is internal. 67 // Do the ACL check if the entry is internal.
52 if entry.Internal { 68 if entry.Internal {
53 allowed, err := settings.IsAllowedInternal(c) 69 allowed, err := settings.IsAllowedInternal(c)
54 if err != nil { 70 if err != nil {
55 return nil, err 71 return nil, err
56 } 72 }
57 if !allowed { 73 if !allowed {
58 » » » return nil, errMasterNotFound 74 » » » if cu.Identity == identity.AnonymousIdentity {
75 » » » » return nil, errNotAuth
76 » » » } else {
77 » » » » return nil, errMasterNotFound
78 » » » }
59 } 79 }
60 } 80 }
61 81
62 return &entry, nil 82 return &entry, nil
63 } 83 }
64 84
65 // getMasterJSON fetches the latest known buildbot master data and returns 85 // getMasterJSON fetches the latest known buildbot master data and returns
66 // the buildbotMaster struct (if found), whether or not it is internal, 86 // the buildbotMaster struct (if found), whether or not it is internal,
67 // the last modified time, and an error if not found. 87 // the last modified time, and an error if not found.
68 func getMasterJSON(c context.Context, name string) ( 88 func getMasterJSON(c context.Context, name string) (
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 Label: bn, 143 Label: bn,
124 // Go templates escapes this for us, and also 144 // Go templates escapes this for us, and also
125 // slashes are not allowed in builder names. 145 // slashes are not allowed in builder names.
126 URL: fmt.Sprintf("/buildbot/%s/%s", entry.Name, bn), 146 URL: fmt.Sprintf("/buildbot/%s/%s", entry.Name, bn),
127 }) 147 })
128 } 148 }
129 result.Masters = append(result.Masters, ml) 149 result.Masters = append(result.Masters, ml)
130 } 150 }
131 return result, nil 151 return result, nil
132 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698