| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 swarming | 5 package swarming |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "net/http" | 10 "net/http" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 defaultSwarmingServer = "chromium-swarm.appspot.com" | 23 defaultSwarmingServer = "chromium-swarm.appspot.com" |
| 24 defaultSwarmingDevServer = "chromium-swarm-dev.appspot.com" | 24 defaultSwarmingDevServer = "chromium-swarm-dev.appspot.com" |
| 25 ) | 25 ) |
| 26 | 26 |
| 27 var errUnrecognizedHost = errors.New("Unregistered Swarming Host") | 27 var errUnrecognizedHost = errors.New("Unregistered Swarming Host") |
| 28 | 28 |
| 29 // getSwarmingHost parses the swarming hostname out of the context. If | 29 // getSwarmingHost parses the swarming hostname out of the context. If |
| 30 // none is specified, get the default swarming host out of the global | 30 // none is specified, get the default swarming host out of the global |
| 31 // configs. | 31 // configs. |
| 32 func getSwarmingHost(c context.Context, r *http.Request) (string, error) { | 32 func getSwarmingHost(c context.Context, r *http.Request) (string, error) { |
| 33 » settings, err := common.GetSettings(c) | 33 » settings := common.GetSettings(c) |
| 34 » if err != nil { | |
| 35 » » logging.WithError(err).Errorf(c, "could not get settings") | |
| 36 » » return "", err | |
| 37 » } | |
| 38 if settings.Swarming == nil { | 34 if settings.Swarming == nil { |
| 39 » » err = errors.New("swarming not in settings") | 35 » » err := errors.New("swarming not in settings") |
| 40 logging.Errorf(c, err.Error()) | 36 logging.Errorf(c, err.Error()) |
| 41 return "", err | 37 return "", err |
| 42 } | 38 } |
| 43 server := r.FormValue("server") | 39 server := r.FormValue("server") |
| 44 // If server isn't specified, return the default host. | 40 // If server isn't specified, return the default host. |
| 45 if server == "" { | 41 if server == "" { |
| 46 return settings.Swarming.DefaultHost, nil | 42 return settings.Swarming.DefaultHost, nil |
| 47 } | 43 } |
| 48 // If it is specified, validate the hostname. | 44 // If it is specified, validate the hostname. |
| 49 for _, hostname := range settings.Swarming.AllowedHosts { | 45 for _, hostname := range settings.Swarming.AllowedHosts { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return http.StatusInternalServerError | 141 return http.StatusInternalServerError |
| 146 } | 142 } |
| 147 | 143 |
| 148 // isAPINotFound returns true if err is a HTTP 404 API response. | 144 // isAPINotFound returns true if err is a HTTP 404 API response. |
| 149 func isAPINotFound(err error) bool { | 145 func isAPINotFound(err error) bool { |
| 150 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu
sNotFound { | 146 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu
sNotFound { |
| 151 return true | 147 return true |
| 152 } | 148 } |
| 153 return false | 149 return false |
| 154 } | 150 } |
| OLD | NEW |