| 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 logdog | 5 package logdog |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 "strings" | 9 "strings" |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 var err error | 54 var err error |
| 55 if as.Client, err = NewClient(c, ""); err != nil { | 55 if as.Client, err = NewClient(c, ""); err != nil { |
| 56 log.WithError(err).Errorf(c, "Failed to generate LogDog client."
) | 56 log.WithError(err).Errorf(c, "Failed to generate LogDog client."
) |
| 57 return nil, &miloerror.Error{ | 57 return nil, &miloerror.Error{ |
| 58 Code: http.StatusInternalServerError, | 58 Code: http.StatusInternalServerError, |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Load the Milo annotation protobuf from the annotation stream. | 62 // Load the Milo annotation protobuf from the annotation stream. |
| 63 if _, err := as.Fetch(c); err != nil { | 63 if _, err := as.Fetch(c); err != nil { |
| 64 » » return nil, err | 64 » » switch errors.Unwrap(err) { |
| 65 » » case coordinator.ErrNoSuchStream: |
| 66 » » » return nil, &miloerror.Error{ |
| 67 » » » » Message: "Stream does not exist", |
| 68 » » » » Code: http.StatusNotFound, |
| 69 » » » } |
| 70 |
| 71 » » case coordinator.ErrNoAccess: |
| 72 » » » return nil, &miloerror.Error{ |
| 73 » » » » Message: "No access to stream", |
| 74 » » » » Code: http.StatusForbidden, |
| 75 » » » } |
| 76 |
| 77 » » default: |
| 78 » » » return nil, &miloerror.Error{ |
| 79 » » » » Message: "Failed to load stream", |
| 80 » » » » Code: http.StatusInternalServerError, |
| 81 » » » } |
| 82 » » } |
| 65 } | 83 } |
| 66 | 84 |
| 67 // Convert the Milo Annotation protobuf to Milo objects. | 85 // Convert the Milo Annotation protobuf to Milo objects. |
| 68 return &templates.Args{ | 86 return &templates.Args{ |
| 69 "Build": as.toMiloBuild(c), | 87 "Build": as.toMiloBuild(c), |
| 70 }, nil | 88 }, nil |
| 71 } | 89 } |
| 72 | 90 |
| 73 func resolveHost(host string) (string, error) { | 91 func resolveHost(host string) (string, error) { |
| 74 // Resolveour our Host, and validate it against a host whitelist. | 92 // Resolveour our Host, and validate it against a host whitelist. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 99 } | 117 } |
| 100 | 118 |
| 101 // Setup our LogDog client. | 119 // Setup our LogDog client. |
| 102 return coordinator.NewClient(&prpc.Client{ | 120 return coordinator.NewClient(&prpc.Client{ |
| 103 C: &http.Client{ | 121 C: &http.Client{ |
| 104 Transport: t, | 122 Transport: t, |
| 105 }, | 123 }, |
| 106 Host: host, | 124 Host: host, |
| 107 }), nil | 125 }), nil |
| 108 } | 126 } |
| OLD | NEW |