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

Unified Diff: milo/appengine/buildbot/master.go

Issue 2525493002: Milo: Add themed page for errors (Closed)
Patch Set: Review 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 side-by-side diff with in-line comments
Download patch
Index: milo/appengine/buildbot/master.go
diff --git a/milo/appengine/buildbot/master.go b/milo/appengine/buildbot/master.go
index 6fcef9219291e4fa81ae5969f850fc238d3dc4a9..fdde75f10fe1f8bf7946524e3512b763dc8e9151 100644
--- a/milo/appengine/buildbot/master.go
+++ b/milo/appengine/buildbot/master.go
@@ -16,6 +16,8 @@ import (
"github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/milo/api/resp"
"github.com/luci/luci-go/milo/appengine/settings"
+ "github.com/luci/luci-go/server/auth"
+ "github.com/luci/luci-go/server/auth/identity"
"golang.org/x/net/context"
)
@@ -34,32 +36,52 @@ func decodeMasterEntry(
return nil
}
-// getMasterEntry feches the named master and does an ACL check on the
-// current user.
-func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error) {
- entry := buildbotMasterEntry{Name: name}
- err := ds.Get(c, &entry)
+// User not logged in, master found, master public: nil
+// User not logged in, master not found: 401
+// User not logged in, master internal: 401
+// User logged in, master found, master internal: nil
+// User logged in, master not found: 404
+// User logged in, master found, master internal: 404
+// Other error: 500
+func checkAccess(c context.Context, err error, internal bool) error {
+ cu := auth.CurrentUser(c)
switch {
case err == ds.ErrNoSuchEntity:
- return nil, errMasterNotFound
+ if cu.Identity == identity.AnonymousIdentity {
+ return errNotAuth
+ } else {
+ return errMasterNotFound
+ }
case err != nil:
- logging.WithError(err).Errorf(
- c, "Encountered error while fetching entry for %s:\n%s", name, err)
- return nil, err
+ return err
}
// Do the ACL check if the entry is internal.
- if entry.Internal {
+ if internal {
allowed, err := settings.IsAllowedInternal(c)
if err != nil {
- return nil, err
+ return err
}
if !allowed {
- return nil, errMasterNotFound
+ if cu.Identity == identity.AnonymousIdentity {
+ return errNotAuth
+ } else {
+ return errMasterNotFound
+ }
}
}
- return &entry, nil
+ return nil
+}
+
+// getMasterEntry feches the named master and does an ACL check on the
+// current user.
+// It returns:
+func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error) {
+ entry := buildbotMasterEntry{Name: name}
+ err := ds.Get(c, &entry)
+ err = checkAccess(c, err, entry.Internal)
+ return &entry, err
}
// getMasterJSON fetches the latest known buildbot master data and returns

Powered by Google App Engine
This is Rietveld 408576698