| OLD | NEW |
| 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 raw_presentation | 5 package raw_presentation |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 "strings" | 9 "strings" |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 func resolveHost(host string) (string, error) { | 82 func resolveHost(host string) (string, error) { |
| 83 // Resolveour our Host, and validate it against a host whitelist. | 83 // Resolveour our Host, and validate it against a host whitelist. |
| 84 switch host { | 84 switch host { |
| 85 case "": | 85 case "": |
| 86 return defaultLogDogHost, nil | 86 return defaultLogDogHost, nil |
| 87 case defaultLogDogHost, "luci-logdog-dev.appspot.com": | 87 case defaultLogDogHost, "luci-logdog-dev.appspot.com": |
| 88 return host, nil | 88 return host, nil |
| 89 default: | 89 default: |
| 90 » » return "", errors.Reason("host %(host)q is not whitelisted"). | 90 » » return "", errors.Reason("host %q is not whitelisted", host).Err
() |
| 91 » » » D("host", host). | |
| 92 » » » Err() | |
| 93 } | 91 } |
| 94 } | 92 } |
| 95 | 93 |
| 96 // NewClient generates a new LogDog client that issues requests on behalf of the | 94 // NewClient generates a new LogDog client that issues requests on behalf of the |
| 97 // current user. | 95 // current user. |
| 98 func NewClient(c context.Context, host string) (*coordinator.Client, error) { | 96 func NewClient(c context.Context, host string) (*coordinator.Client, error) { |
| 99 var err error | 97 var err error |
| 100 if host, err = resolveHost(host); err != nil { | 98 if host, err = resolveHost(host); err != nil { |
| 101 return nil, err | 99 return nil, err |
| 102 } | 100 } |
| 103 | 101 |
| 104 // Initialize the LogDog client authentication. | 102 // Initialize the LogDog client authentication. |
| 105 t, err := auth.GetRPCTransport(c, auth.AsUser) | 103 t, err := auth.GetRPCTransport(c, auth.AsUser) |
| 106 if err != nil { | 104 if err != nil { |
| 107 return nil, errors.New("failed to get transport for LogDog serve
r") | 105 return nil, errors.New("failed to get transport for LogDog serve
r") |
| 108 } | 106 } |
| 109 | 107 |
| 110 // Setup our LogDog client. | 108 // Setup our LogDog client. |
| 111 return coordinator.NewClient(&prpc.Client{ | 109 return coordinator.NewClient(&prpc.Client{ |
| 112 C: &http.Client{ | 110 C: &http.Client{ |
| 113 Transport: t, | 111 Transport: t, |
| 114 }, | 112 }, |
| 115 Host: host, | 113 Host: host, |
| 116 }), nil | 114 }), nil |
| 117 } | 115 } |
| OLD | NEW |