| 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 "net/http" | 8 "net/http" |
| 9 "os" | 9 "os" |
| 10 | 10 |
| 11 "google.golang.org/api/googleapi" | |
| 12 | |
| 13 "github.com/julienschmidt/httprouter" | 11 "github.com/julienschmidt/httprouter" |
| 14 "golang.org/x/net/context" | 12 "golang.org/x/net/context" |
| 13 "google.golang.org/api/googleapi" |
| 14 "google.golang.org/grpc/codes" |
| 15 | 15 |
| 16 "github.com/luci/luci-go/grpc/grpcutil" |
| 16 "github.com/luci/luci-go/milo/appengine/settings" | 17 "github.com/luci/luci-go/milo/appengine/settings" |
| 17 "github.com/luci/luci-go/milo/common/miloerror" | 18 "github.com/luci/luci-go/milo/common/miloerror" |
| 18 "github.com/luci/luci-go/server/templates" | 19 "github.com/luci/luci-go/server/templates" |
| 19 ) | 20 ) |
| 20 | 21 |
| 21 const ( | 22 const ( |
| 22 defaultSwarmingServer = "chromium-swarm.appspot.com" | 23 defaultSwarmingServer = "chromium-swarm.appspot.com" |
| 23 defaultSwarmingDevServer = "chromium-swarm-dev.appspot.com" | 24 defaultSwarmingDevServer = "chromium-swarm-dev.appspot.com" |
| 24 ) | 25 ) |
| 25 | 26 |
| 26 func getSwarmingService(c context.Context, r *http.Request) (swarmingService, er
ror) { | 27 func getSwarmingService(c context.Context, r *http.Request) (swarmingService, er
ror) { |
| 27 server := r.FormValue("server") | 28 server := r.FormValue("server") |
| 28 // TODO(hinoka): configure this mapping in luci-config | 29 // TODO(hinoka): configure this mapping in luci-config |
| 29 switch server { | 30 switch server { |
| 30 case "": | 31 case "": |
| 31 server = defaultSwarmingServer | 32 server = defaultSwarmingServer |
| 32 case "dev": | 33 case "dev": |
| 33 server = defaultSwarmingDevServer | 34 server = defaultSwarmingDevServer |
| 35 default: |
| 36 return nil, grpcutil.Errf(codes.InvalidArgument, "invalid swarmi
ng server") |
| 34 } | 37 } |
| 35 return newProdService(c, server) | 38 return newProdService(c, server) |
| 36 } | 39 } |
| 37 | 40 |
| 38 // Log is for fetching logs from swarming. | 41 // Log is for fetching logs from swarming. |
| 39 type Log struct{} | 42 type Log struct{} |
| 40 | 43 |
| 41 // Build is for deciphering recipe builds from swarming based off of logs. | 44 // Build is for deciphering recipe builds from swarming based off of logs. |
| 42 type Build struct{} | 45 type Build struct{} |
| 43 | 46 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 127 } |
| 125 | 128 |
| 126 // isAPINotFound returns true if err is a HTTP 404 API response. | 129 // isAPINotFound returns true if err is a HTTP 404 API response. |
| 127 func isAPINotFound(err error) bool { | 130 func isAPINotFound(err error) bool { |
| 128 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu
sNotFound { | 131 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu
sNotFound { |
| 129 return true | 132 return true |
| 130 } | 133 } |
| 131 | 134 |
| 132 return false | 135 return false |
| 133 } | 136 } |
| OLD | NEW |