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

Side by Side Diff: milo/buildsource/rawpresentation/html.go

Issue 2977863002: [milo] Refactor all html knowledge out of backends. (Closed)
Patch Set: now with case insensitivity Created 3 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
« no previous file with comments | « milo/buildsource/rawpresentation/build.go ('k') | milo/buildsource/swarming/build.go » ('j') | 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 LUCI Authors. 1 // Copyright 2016 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package rawpresentation 15 package rawpresentation
16 16
17 import ( 17 import (
18 "net/http" 18 "net/http"
19 "strings"
20 19
21 "github.com/luci/luci-go/common/errors" 20 "github.com/luci/luci-go/common/errors"
22 log "github.com/luci/luci-go/common/logging"
23 "github.com/luci/luci-go/grpc/prpc" 21 "github.com/luci/luci-go/grpc/prpc"
24 "github.com/luci/luci-go/logdog/client/coordinator" 22 "github.com/luci/luci-go/logdog/client/coordinator"
25 "github.com/luci/luci-go/logdog/common/types"
26 "github.com/luci/luci-go/luci_config/common/cfgtypes"
27 "github.com/luci/luci-go/milo/common"
28 "github.com/luci/luci-go/server/auth" 23 "github.com/luci/luci-go/server/auth"
29 "github.com/luci/luci-go/server/router"
30 "github.com/luci/luci-go/server/templates"
31 24
32 "golang.org/x/net/context" 25 "golang.org/x/net/context"
33 ) 26 )
34 27
35 // AnnotationStreamHandler is a Handler that renders a LogDog Milo
36 // annotation protobuf stream.
37 //
38 // The protobuf stream is fetched live from LogDog and cached locally, either
39 // temporarily (if incomplete) or indefinitely (if complete).
40 type AnnotationStreamHandler struct{}
41
42 func BuildHandler(c *router.Context) {
43 (&AnnotationStreamHandler{}).Render(c)
44 return
45 }
46
47 // Render implements settings.ThemedHandler.
48 func (s *AnnotationStreamHandler) Render(c *router.Context) {
49 as := AnnotationStream{
50 Project: cfgtypes.ProjectName(c.Params.ByName("project")),
51 Path: types.StreamPath(strings.Trim(c.Params.ByName("path"), "/")),
52 }
53 if err := as.Normalize(); err != nil {
54 common.ErrorPage(c, http.StatusBadRequest, err.Error())
55 return
56 }
57
58 // Setup our LogDog client.
59 var err error
60 host := strings.TrimSpace(c.Params.ByName("logdog_host"))
61 if as.Client, err = NewClient(c.Context, host); err != nil {
62 log.WithError(err).Errorf(c.Context, "Failed to generate LogDog client.")
63 common.ErrorPage(c, http.StatusInternalServerError, "Failed to g enerate LogDog client")
64 return
65 }
66
67 // Load the Milo annotation protobuf from the annotation stream.
68 if _, err := as.Fetch(c.Context); err != nil {
69 switch errors.Unwrap(err) {
70 case coordinator.ErrNoSuchStream:
71 common.ErrorPage(c, http.StatusNotFound, "Stream does no t exist")
72
73 case coordinator.ErrNoAccess:
74 common.ErrorPage(c, http.StatusForbidden, "No access to LogDog stream")
75
76 case errNotMilo, errNotDatagram:
77 // The user requested a LogDog url that isn't a Milo ann otation.
78 common.ErrorPage(c, http.StatusBadRequest, err.Error())
79
80 default:
81 log.WithError(err).Errorf(c.Context, "Failed to load Log Dog stream.")
82 common.ErrorPage(c, http.StatusInternalServerError, "Fai led to load LogDog stream")
83 }
84 return
85 }
86
87 templates.MustRender(c.Context, c.Writer, "pages/build.html", templates. Args{
88 "Build": as.toMiloBuild(c.Context),
89 })
90 }
91
92 func resolveHost(host string) (string, error) { 28 func resolveHost(host string) (string, error) {
93 // Resolveour our Host, and validate it against a host whitelist. 29 // Resolveour our Host, and validate it against a host whitelist.
94 switch host { 30 switch host {
95 case "": 31 case "":
96 return defaultLogDogHost, nil 32 return defaultLogDogHost, nil
97 case defaultLogDogHost, "luci-logdog-dev.appspot.com": 33 case defaultLogDogHost, "luci-logdog-dev.appspot.com":
98 return host, nil 34 return host, nil
99 default: 35 default:
100 return "", errors.Reason("host %q is not whitelisted", host).Err () 36 return "", errors.Reason("host %q is not whitelisted", host).Err ()
101 } 37 }
(...skipping 14 matching lines...) Expand all
116 } 52 }
117 53
118 // Setup our LogDog client. 54 // Setup our LogDog client.
119 return coordinator.NewClient(&prpc.Client{ 55 return coordinator.NewClient(&prpc.Client{
120 C: &http.Client{ 56 C: &http.Client{
121 Transport: t, 57 Transport: t,
122 }, 58 },
123 Host: host, 59 Host: host,
124 }), nil 60 }), nil
125 } 61 }
OLDNEW
« no previous file with comments | « milo/buildsource/rawpresentation/build.go ('k') | milo/buildsource/swarming/build.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698