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

Side by Side Diff: go/src/infra/appengine/sheriff-o-matic/main.go

Issue 2050053005: [som] Add bugqueue handler to fetch Sheriff-* issues from monorail. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: lucify Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 som implements HTTP server that handles requests to default module. 5 // Package som implements HTTP server that handles requests to default module.
6 package som 6 package som
7 7
8 import ( 8 import (
9 "crypto/sha1" 9 "crypto/sha1"
10 "encoding/json" 10 "encoding/json"
11 "fmt" 11 "fmt"
12 "html/template" 12 "html/template"
13 "infra/monorail"
13 "io/ioutil" 14 "io/ioutil"
14 "net/http" 15 "net/http"
15 "strings" 16 "strings"
16 17
17 "github.com/julienschmidt/httprouter" 18 "github.com/julienschmidt/httprouter"
18 "golang.org/x/net/context" 19 "golang.org/x/net/context"
19 "google.golang.org/appengine" 20 "google.golang.org/appengine"
20 21
21 "github.com/luci/gae/service/datastore" 22 "github.com/luci/gae/service/datastore"
23 "github.com/luci/gae/service/urlfetch"
24 "github.com/luci/luci-go/appengine/gaeauth/client"
22 "github.com/luci/luci-go/appengine/gaeauth/server" 25 "github.com/luci/luci-go/appengine/gaeauth/server"
23 "github.com/luci/luci-go/appengine/gaemiddleware" 26 "github.com/luci/luci-go/appengine/gaemiddleware"
24 "github.com/luci/luci-go/common/clock" 27 "github.com/luci/luci-go/common/clock"
25 "github.com/luci/luci-go/common/logging" 28 "github.com/luci/luci-go/common/logging"
26 "github.com/luci/luci-go/server/auth" 29 "github.com/luci/luci-go/server/auth"
27 "github.com/luci/luci-go/server/auth/identity" 30 "github.com/luci/luci-go/server/auth/identity"
28 "github.com/luci/luci-go/server/middleware" 31 "github.com/luci/luci-go/server/middleware"
29 "github.com/luci/luci-go/server/settings" 32 "github.com/luci/luci-go/server/settings"
30 ) 33 )
31 34
32 const authGroup = "sheriff-o-matic-access" 35 const authGroup = "sheriff-o-matic-access"
33 36
34 var ( 37 var (
35 mainPage = template.Must(template.ParseFiles("./index.html")) 38 mainPage = template.Must(template.ParseFiles("./index.html"))
36 accessDeniedPage = template.Must(template.ParseFiles("./access-denied.ht ml")) 39 accessDeniedPage = template.Must(template.ParseFiles("./access-denied.ht ml"))
40 monorailEndpoint = "https://monorail-prod.appspot.com/_ah/api/monorail/v 1/"
37 ) 41 )
38 42
39 var errStatus = func(w http.ResponseWriter, status int, msg string) { 43 var errStatus = func(w http.ResponseWriter, status int, msg string) {
40 w.WriteHeader(status) 44 w.WriteHeader(status)
41 w.Write([]byte(msg)) 45 w.Write([]byte(msg))
42 } 46 }
43 47
44 var requireGoogler = func(w http.ResponseWriter, c context.Context) bool { 48 var requireGoogler = func(w http.ResponseWriter, c context.Context) bool {
45 if appengine.IsDevAppServer() { 49 if appengine.IsDevAppServer() {
46 return true 50 return true
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 data, err := json.Marshal(annotation) 366 data, err := json.Marshal(annotation)
363 if err != nil { 367 if err != nil {
364 errStatus(w, http.StatusInternalServerError, err.Error()) 368 errStatus(w, http.StatusInternalServerError, err.Error())
365 return 369 return
366 } 370 }
367 371
368 w.Header().Set("Content-Type", "application/json") 372 w.Header().Set("Content-Type", "application/json")
369 w.Write(data) 373 w.Write(data)
370 } 374 }
371 375
376 func getBugQueueHandler(c context.Context, w http.ResponseWriter, r *http.Reques t, p httprouter.Params) {
377 c = client.UseServiceAccountTransport(c, nil, nil)
378 mr := monorail.NewEndpointsClient(&http.Client{Transport: urlfetch.Get(c )}, monorailEndpoint)
379 tree := p.ByName("tree")
380 req := &monorail.IssuesListRequest{
381 ProjectId: tree,
382 Can: monorail.IssuesListRequest_OPEN,
383 Q: fmt.Sprintf("label:Sheriff-%s", tree),
384 }
385
386 res, err := mr.IssuesList(c, req)
387 if err != nil {
388 errStatus(w, http.StatusInternalServerError, err.Error())
389 return
390 }
391
392 bytes, err := json.Marshal(res)
393 if err != nil {
394 errStatus(w, http.StatusInternalServerError, err.Error())
395 return
396 }
397
398 w.Header().Set("Content-Type", "application/json")
399 w.Write(bytes)
400 }
401
372 // base is the root of the middleware chain. 402 // base is the root of the middleware chain.
373 func base(h middleware.Handler) httprouter.Handle { 403 func base(h middleware.Handler) httprouter.Handle {
374 methods := auth.Authenticator{ 404 methods := auth.Authenticator{
375 &server.OAuth2Method{Scopes: []string{server.EmailScope}}, 405 &server.OAuth2Method{Scopes: []string{server.EmailScope}},
376 server.CookieAuth, 406 server.CookieAuth,
377 &server.InboundAppIDAuthMethod{}, 407 &server.InboundAppIDAuthMethod{},
378 } 408 }
379 h = auth.Use(h, methods) 409 h = auth.Use(h, methods)
380 if !appengine.IsDevAppServer() { 410 if !appengine.IsDevAppServer() {
381 h = middleware.WithPanicCatcher(h) 411 h = middleware.WithPanicCatcher(h)
382 } 412 }
383 return gaemiddleware.BaseProd(h) 413 return gaemiddleware.BaseProd(h)
384 } 414 }
385 415
386 //// Routes. 416 //// Routes.
387 func init() { 417 func init() {
388 settings.RegisterUIPage(settingsKey, settingsUIPage{}) 418 settings.RegisterUIPage(settingsKey, settingsUIPage{})
389 419
390 router := httprouter.New() 420 router := httprouter.New()
391 gaemiddleware.InstallHandlers(router, base) 421 gaemiddleware.InstallHandlers(router, base)
392 router.GET("/api/v1/trees/", base(auth.Authenticate(getTreesHandler))) 422 router.GET("/api/v1/trees/", base(auth.Authenticate(getTreesHandler)))
393 router.GET("/api/v1/alerts/:tree", base(auth.Authenticate(getAlertsHandl er))) 423 router.GET("/api/v1/alerts/:tree", base(auth.Authenticate(getAlertsHandl er)))
394 router.POST("/api/v1/alerts/:tree", base(auth.Authenticate(postAlertsHan dler))) 424 router.POST("/api/v1/alerts/:tree", base(auth.Authenticate(postAlertsHan dler)))
395 router.GET("/api/v1/annotations/", base(auth.Authenticate(getAnnotations Handler))) 425 router.GET("/api/v1/annotations/", base(auth.Authenticate(getAnnotations Handler)))
396 router.POST("/api/v1/annotations/:annKey/:action", base(auth.Authenticat e(postAnnotationsHandler))) 426 router.POST("/api/v1/annotations/:annKey/:action", base(auth.Authenticat e(postAnnotationsHandler)))
427 router.GET("/api/v1/bugqueue/:tree", base(auth.Authenticate(getBugQueueH andler)))
397 428
398 rootRouter := httprouter.New() 429 rootRouter := httprouter.New()
399 rootRouter.GET("/*path", base(auth.Authenticate(indexPage))) 430 rootRouter.GET("/*path", base(auth.Authenticate(indexPage)))
400 431
401 http.DefaultServeMux.Handle("/api/", router) 432 http.DefaultServeMux.Handle("/api/", router)
402 http.DefaultServeMux.Handle("/admin/", router) 433 http.DefaultServeMux.Handle("/admin/", router)
403 http.DefaultServeMux.Handle("/auth/", router) 434 http.DefaultServeMux.Handle("/auth/", router)
404 http.DefaultServeMux.Handle("/_ah/", router) 435 http.DefaultServeMux.Handle("/_ah/", router)
405 http.DefaultServeMux.Handle("/", rootRouter) 436 http.DefaultServeMux.Handle("/", rootRouter)
406 } 437 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698