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

Side by Side Diff: appengine/chromium_build_stats/default/compiler_proxy_log.go

Issue 2125513002: chromium_build_stats: redirect login url if not logged in. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 5 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package chromiumbuildstats 5 package chromiumbuildstats
6 6
7 // compiler_proxy_log.go provides /compiler_proxy_log endpoints. 7 // compiler_proxy_log.go provides /compiler_proxy_log endpoints.
8 8
9 import ( 9 import (
10 "bufio" 10 "bufio"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 <tr><td>{{$i}} <td>{{$d}} 79 <tr><td>{{$i}} <td>{{$d}}
80 {{end}} 80 {{end}}
81 </table> 81 </table>
82 82
83 <h2>Compiler Proxy Histogram</h2> 83 <h2>Compiler Proxy Histogram</h2>
84 <pre>{{.CompilerProxyLog.Histogram}}</pre> 84 <pre>{{.CompilerProxyLog.Histogram}}</pre>
85 85
86 </body> 86 </body>
87 </html> 87 </html>
88 `)) 88 `))
89
90 compilerProxyAuthTmpl = template.Must(template.New("compiler_proxy_auth" ).Parse(`
91 <html>
92 <head>
93 <title>compiler_proxy log</title>
94 </head>
95 <body>
96 {{if .User}}
97 {{.User.Email}} is not alow to access this page.
98 Please <a href="{{.Logout}}">logout</a> and login with @google.com account.
99 <div align="right"><a href="{{.Logout}}">logout</a></div>
100 {{else}}
101 <div align="right"><a href="{{.Login}}">login</a></div>
102 You need to <a href="{{.Login}}">login</a> with @google.com account to access co mpiler_proxy log file.
103 {{end}}
104 </body>
105 </html>`))
89 ) 106 )
90 107
91 func init() { 108 func init() {
92 http.Handle("/compiler_proxy_log/", http.StripPrefix("/compiler_proxy_lo g/", http.HandlerFunc(compilerProxyLogHandler))) 109 http.Handle("/compiler_proxy_log/", http.StripPrefix("/compiler_proxy_lo g/", http.HandlerFunc(compilerProxyLogHandler)))
93 } 110 }
94 111
95 // compilerProxyLogHandler handles /<path> for compiler_proxy.INFO log file in g s://chrome-goma-log/<path> 112 // compilerProxyLogHandler handles /<path> for compiler_proxy.INFO log file in g s://chrome-goma-log/<path>
96 func compilerProxyLogHandler(w http.ResponseWriter, req *http.Request) { 113 func compilerProxyLogHandler(w http.ResponseWriter, req *http.Request) {
97 ctx := appengine.NewContext(req) 114 ctx := appengine.NewContext(req)
98 » user := user.Current(ctx) 115 » u := user.Current(ctx)
99 » if user == nil { 116 » if u == nil {
100 » » http.Error(w, "Login required", http.StatusUnauthorized) 117 » » authPage(w, req, http.StatusUnauthorized, compilerProxyAuthTmpl, u, path.Join("/compiler_proxy_log", req.URL.Path))
101 return 118 return
102 } 119 }
103 » if !strings.HasSuffix(user.Email, "@google.com") { 120 » if !strings.HasSuffix(u.Email, "@google.com") {
Yoshisato Yanagisawa 2016/07/05 05:00:05 maybe intended but L117 and L120 are the same?
104 » » http.Error(w, "Unauthorized to access", http.StatusUnauthorized) 121 » » authPage(w, req, http.StatusUnauthorized, compilerProxyAuthTmpl, u, path.Join("/compiler_proxy_log", req.URL.Path))
105 return 122 return
106 } 123 }
107 124
108 config := google.NewAppEngineConfig(ctx, []string{ 125 config := google.NewAppEngineConfig(ctx, []string{
109 "https://www.googleapis.com/auth/devstorage.read_only", 126 "https://www.googleapis.com/auth/devstorage.read_only",
110 }) 127 })
111 client := &http.Client{Transport: config.NewTransport()} 128 client := &http.Client{Transport: config.NewTransport()}
112 129
113 basename := path.Base(req.URL.Path) 130 basename := path.Base(req.URL.Path)
114 if !strings.HasPrefix(basename, "compiler_proxy.") { 131 if !strings.HasPrefix(basename, "compiler_proxy.") {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 255
239 var buf bytes.Buffer 256 var buf bytes.Buffer
240 err := compilerProxyLogIndexTempl.Execute(&buf, data) 257 err := compilerProxyLogIndexTempl.Execute(&buf, data)
241 if err != nil { 258 if err != nil {
242 return err 259 return err
243 } 260 }
244 w.Header().Set("Content-Type", "text/html") 261 w.Header().Set("Content-Type", "text/html")
245 _, err = w.Write(buf.Bytes()) 262 _, err = w.Write(buf.Bytes())
246 return err 263 return err
247 } 264 }
OLDNEW
« no previous file with comments | « appengine/chromium_build_stats/default/auth.go ('k') | appengine/chromium_build_stats/default/ninja_log.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698