| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package logdog |
| 6 |
| 7 import ( |
| 8 "net/http" |
| 9 "strings" |
| 10 |
| 11 "github.com/julienschmidt/httprouter" |
| 12 "github.com/luci/luci-go/appengine/cmd/milo/miloerror" |
| 13 "github.com/luci/luci-go/appengine/cmd/milo/settings" |
| 14 authClient "github.com/luci/luci-go/appengine/gaeauth/client" |
| 15 "github.com/luci/luci-go/common/config" |
| 16 log "github.com/luci/luci-go/common/logging" |
| 17 "github.com/luci/luci-go/logdog/common/types" |
| 18 "github.com/luci/luci-go/server/templates" |
| 19 |
| 20 "golang.org/x/net/context" |
| 21 ) |
| 22 |
| 23 // AnnotationStream is a ThemedHandler that renders a LogDog Milo annotation |
| 24 // protobuf stream. |
| 25 // |
| 26 // The protobuf stream is fetched live from LogDog and cached locally, either |
| 27 // temporarily (if incomplete) or indefinitely (if complete). |
| 28 type AnnotationStream struct { |
| 29 // logDogClient is a reusable HTTP client to use for LogDog. |
| 30 logDogClient *http.Client |
| 31 } |
| 32 |
| 33 // GetTemplateName implements settings.ThemedHandler. |
| 34 func (s *AnnotationStream) GetTemplateName(t settings.Theme) string { |
| 35 return "build.html" |
| 36 } |
| 37 |
| 38 // Render implements settings.ThemedHandler. |
| 39 func (s *AnnotationStream) Render(c context.Context, req *http.Request, p httpro
uter.Params) (*templates.Args, error) { |
| 40 // Initialize the LogDog client authentication. |
| 41 a, err := authClient.Transport(c, nil, nil) |
| 42 if err != nil { |
| 43 log.WithError(err).Errorf(c, "Failed to get transport for LogDog
server.") |
| 44 return nil, &miloerror.Error{ |
| 45 Code: http.StatusInternalServerError, |
| 46 } |
| 47 } |
| 48 |
| 49 as := annotationStreamRequest{ |
| 50 AnnotationStream: s, |
| 51 |
| 52 project: config.ProjectName(p.ByName("project")), |
| 53 path: types.StreamPath(strings.Trim(p.ByName("path"), "/")), |
| 54 host: req.FormValue("host"), |
| 55 |
| 56 logDogClient: http.Client{ |
| 57 Transport: a, |
| 58 }, |
| 59 } |
| 60 if err := as.normalize(); err != nil { |
| 61 return nil, err |
| 62 } |
| 63 |
| 64 // Load the Milo annotation protobuf from the annotation stream. |
| 65 if err := as.load(c); err != nil { |
| 66 return nil, err |
| 67 } |
| 68 |
| 69 // Convert the Milo Annotation protobuf to Milo objects. |
| 70 return &templates.Args{ |
| 71 "Build": as.toMiloBuild(c), |
| 72 }, nil |
| 73 } |
| OLD | NEW |