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

Unified Diff: milo/appengine/logdog/html.go

Issue 2944983003: [milo] {buildbucket,buildbot,swarming,logdog} -> backends/*. (Closed)
Patch Set: fix the tests Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/appengine/logdog/build.go ('k') | milo/appengine/logdog/internal/gen.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/logdog/html.go
diff --git a/milo/appengine/logdog/html.go b/milo/appengine/logdog/html.go
deleted file mode 100644
index fa547fd778112e80a3288e38c8931bd64b05f523..0000000000000000000000000000000000000000
--- a/milo/appengine/logdog/html.go
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2016 The LUCI Authors. All rights reserved.
-// Use of this source code is governed under the Apache License, Version 2.0
-// that can be found in the LICENSE file.
-
-package logdog
-
-import (
- "net/http"
- "strings"
-
- "github.com/luci/luci-go/common/errors"
- log "github.com/luci/luci-go/common/logging"
- "github.com/luci/luci-go/grpc/prpc"
- "github.com/luci/luci-go/logdog/client/coordinator"
- "github.com/luci/luci-go/logdog/common/types"
- "github.com/luci/luci-go/luci_config/common/cfgtypes"
- "github.com/luci/luci-go/milo/appengine/common"
- "github.com/luci/luci-go/server/auth"
- "github.com/luci/luci-go/server/router"
- "github.com/luci/luci-go/server/templates"
-
- "golang.org/x/net/context"
-)
-
-// AnnotationStreamHandler is a Handler that renders a LogDog Milo
-// annotation protobuf stream.
-//
-// The protobuf stream is fetched live from LogDog and cached locally, either
-// temporarily (if incomplete) or indefinitely (if complete).
-type AnnotationStreamHandler struct{}
-
-func BuildHandler(c *router.Context) {
- (&AnnotationStreamHandler{}).Render(c)
- return
-}
-
-// Render implements settings.ThemedHandler.
-func (s *AnnotationStreamHandler) Render(c *router.Context) {
- as := AnnotationStream{
- Project: cfgtypes.ProjectName(c.Params.ByName("project")),
- Path: types.StreamPath(strings.Trim(c.Params.ByName("path"), "/")),
- }
- if err := as.Normalize(); err != nil {
- common.ErrorPage(c, http.StatusBadRequest, err.Error())
- return
- }
-
- // Setup our LogDog client.
- var err error
- host := strings.TrimSpace(c.Params.ByName("logdog_host"))
- if as.Client, err = NewClient(c.Context, host); err != nil {
- log.WithError(err).Errorf(c.Context, "Failed to generate LogDog client.")
- common.ErrorPage(c, http.StatusInternalServerError, "Failed to generate LogDog client")
- return
- }
-
- // Load the Milo annotation protobuf from the annotation stream.
- if _, err := as.Fetch(c.Context); err != nil {
- switch errors.Unwrap(err) {
- case coordinator.ErrNoSuchStream:
- common.ErrorPage(c, http.StatusNotFound, "Stream does not exist")
-
- case coordinator.ErrNoAccess:
- common.ErrorPage(c, http.StatusForbidden, "No access to LogDog stream")
-
- case errNotMilo, errNotDatagram:
- // The user requested a LogDog url that isn't a Milo annotation.
- common.ErrorPage(c, http.StatusBadRequest, err.Error())
-
- default:
- log.WithError(err).Errorf(c.Context, "Failed to load LogDog stream.")
- common.ErrorPage(c, http.StatusInternalServerError, "Failed to load LogDog stream")
- }
- return
- }
-
- templates.MustRender(c.Context, c.Writer, "pages/build.html", templates.Args{
- "Build": as.toMiloBuild(c.Context),
- })
-}
-
-func resolveHost(host string) (string, error) {
- // Resolveour our Host, and validate it against a host whitelist.
- switch host {
- case "":
- return defaultLogDogHost, nil
- case defaultLogDogHost, "luci-logdog-dev.appspot.com":
- return host, nil
- default:
- return "", errors.Reason("host %(host)q is not whitelisted").
- D("host", host).
- Err()
- }
-}
-
-// NewClient generates a new LogDog client that issues requests on behalf of the
-// current user.
-func NewClient(c context.Context, host string) (*coordinator.Client, error) {
- var err error
- if host, err = resolveHost(host); err != nil {
- return nil, err
- }
-
- // Initialize the LogDog client authentication.
- t, err := auth.GetRPCTransport(c, auth.AsUser)
- if err != nil {
- return nil, errors.New("failed to get transport for LogDog server")
- }
-
- // Setup our LogDog client.
- return coordinator.NewClient(&prpc.Client{
- C: &http.Client{
- Transport: t,
- },
- Host: host,
- }), nil
-}
« no previous file with comments | « milo/appengine/logdog/build.go ('k') | milo/appengine/logdog/internal/gen.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698