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

Side by Side Diff: milo/appengine/logdog/http.go

Issue 2695383002: milo: Enable Swarming LogDog log loading. (Closed)
Patch Set: Created 3 years, 10 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 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package logdog 5 package logdog
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 "strings" 9 "strings"
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if _, err := as.Load(c); err != nil { 63 if _, err := as.Load(c); err != nil {
64 return nil, err 64 return nil, err
65 } 65 }
66 66
67 // Convert the Milo Annotation protobuf to Milo objects. 67 // Convert the Milo Annotation protobuf to Milo objects.
68 return &templates.Args{ 68 return &templates.Args{
69 "Build": as.toMiloBuild(c), 69 "Build": as.toMiloBuild(c),
70 }, nil 70 }, nil
71 } 71 }
72 72
73 func resolveHost(host string) (string, error) {
74 // Resolveour our Host, and validate it against a host whitelist.
75 switch host {
76 case "":
77 return defaultLogDogHost, nil
78 case defaultLogDogHost, "luci-logdog-dev.appspot.com":
79 return host, nil
80 default:
81 return "", errors.Reason("host %(host)q is not whitelisted").
82 D("host", host).
83 Err()
84 }
85 }
86
73 // NewClient generates a new LogDog client that issues requests on behalf of the 87 // NewClient generates a new LogDog client that issues requests on behalf of the
74 // current user. 88 // current user.
75 func NewClient(c context.Context, host string) (*coordinator.Client, error) { 89 func NewClient(c context.Context, host string) (*coordinator.Client, error) {
76 » if host == "" { 90 » var err error
77 » » host = defaultLogDogHost 91 » if host, err = resolveHost(host); err != nil {
92 » » return nil, err
78 } 93 }
79 94
80 // Initialize the LogDog client authentication. 95 // Initialize the LogDog client authentication.
81 t, err := auth.GetRPCTransport(c, auth.AsUser) 96 t, err := auth.GetRPCTransport(c, auth.AsUser)
82 if err != nil { 97 if err != nil {
83 return nil, errors.New("failed to get transport for LogDog serve r") 98 return nil, errors.New("failed to get transport for LogDog serve r")
84 } 99 }
85 100
86 // Setup our LogDog client. 101 // Setup our LogDog client.
87 return coordinator.NewClient(&prpc.Client{ 102 return coordinator.NewClient(&prpc.Client{
88 C: &http.Client{ 103 C: &http.Client{
89 Transport: t, 104 Transport: t,
90 }, 105 },
91 Host: host, 106 Host: host,
92 }), nil 107 }), nil
93 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698