diff options
author | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-09 15:59:15 +0200 |
---|---|---|
committer | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-09 16:39:21 +0200 |
commit | 863486a6b71ed0e562a3965bed56465d007b1418 (patch) | |
tree | e93f6a687695af86d54237ec9f575d4ef104222d /vendor/github.com/aws/aws-sdk-go/private/protocol | |
parent | 49c1c7b4dc69ffb9ab52330e6dc52ccdd6351087 (diff) | |
download | terraform-provider-statuscake-863486a6b71ed0e562a3965bed56465d007b1418.tar.gz terraform-provider-statuscake-863486a6b71ed0e562a3965bed56465d007b1418.tar.zst terraform-provider-statuscake-863486a6b71ed0e562a3965bed56465d007b1418.zip |
update vendor and go.modadd_contact_groups
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/private/protocol')
9 files changed, 628 insertions, 56 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/build.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/build.go new file mode 100644 index 0000000..864fb67 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/build.go | |||
@@ -0,0 +1,296 @@ | |||
1 | // Package jsonutil provides JSON serialization of AWS requests and responses. | ||
2 | package jsonutil | ||
3 | |||
4 | import ( | ||
5 | "bytes" | ||
6 | "encoding/base64" | ||
7 | "encoding/json" | ||
8 | "fmt" | ||
9 | "math" | ||
10 | "reflect" | ||
11 | "sort" | ||
12 | "strconv" | ||
13 | "time" | ||
14 | |||
15 | "github.com/aws/aws-sdk-go/aws" | ||
16 | "github.com/aws/aws-sdk-go/private/protocol" | ||
17 | ) | ||
18 | |||
19 | var timeType = reflect.ValueOf(time.Time{}).Type() | ||
20 | var byteSliceType = reflect.ValueOf([]byte{}).Type() | ||
21 | |||
22 | // BuildJSON builds a JSON string for a given object v. | ||
23 | func BuildJSON(v interface{}) ([]byte, error) { | ||
24 | var buf bytes.Buffer | ||
25 | |||
26 | err := buildAny(reflect.ValueOf(v), &buf, "") | ||
27 | return buf.Bytes(), err | ||
28 | } | ||
29 | |||
30 | func buildAny(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error { | ||
31 | origVal := value | ||
32 | value = reflect.Indirect(value) | ||
33 | if !value.IsValid() { | ||
34 | return nil | ||
35 | } | ||
36 | |||
37 | vtype := value.Type() | ||
38 | |||
39 | t := tag.Get("type") | ||
40 | if t == "" { | ||
41 | switch vtype.Kind() { | ||
42 | case reflect.Struct: | ||
43 | // also it can't be a time object | ||
44 | if value.Type() != timeType { | ||
45 | t = "structure" | ||
46 | } | ||
47 | case reflect.Slice: | ||
48 | // also it can't be a byte slice | ||
49 | if _, ok := value.Interface().([]byte); !ok { | ||
50 | t = "list" | ||
51 | } | ||
52 | case reflect.Map: | ||
53 | // cannot be a JSONValue map | ||
54 | if _, ok := value.Interface().(aws.JSONValue); !ok { | ||
55 | t = "map" | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | |||
60 | switch t { | ||
61 | case "structure": | ||
62 | if field, ok := vtype.FieldByName("_"); ok { | ||
63 | tag = field.Tag | ||
64 | } | ||
65 | return buildStruct(value, buf, tag) | ||
66 | case "list": | ||
67 | return buildList(value, buf, tag) | ||
68 | case "map": | ||
69 | return buildMap(value, buf, tag) | ||
70 | default: | ||
71 | return buildScalar(origVal, buf, tag) | ||
72 | } | ||
73 | } | ||
74 | |||
75 | func buildStruct(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error { | ||
76 | if !value.IsValid() { | ||
77 | return nil | ||
78 | } | ||
79 | |||
80 | // unwrap payloads | ||
81 | if payload := tag.Get("payload"); payload != "" { | ||
82 | field, _ := value.Type().FieldByName(payload) | ||
83 | tag = field.Tag | ||
84 | value = elemOf(value.FieldByName(payload)) | ||
85 | |||
86 | if !value.IsValid() { | ||
87 | return nil | ||
88 | } | ||
89 | } | ||
90 | |||
91 | buf.WriteByte('{') | ||
92 | |||
93 | t := value.Type() | ||
94 | first := true | ||
95 | for i := 0; i < t.NumField(); i++ { | ||
96 | member := value.Field(i) | ||
97 | |||
98 | // This allocates the most memory. | ||
99 | // Additionally, we cannot skip nil fields due to | ||
100 | // idempotency auto filling. | ||
101 | field := t.Field(i) | ||
102 | |||
103 | if field.PkgPath != "" { | ||
104 | continue // ignore unexported fields | ||
105 | } | ||
106 | if field.Tag.Get("json") == "-" { | ||
107 | continue | ||
108 | } | ||
109 | if field.Tag.Get("location") != "" { | ||
110 | continue // ignore non-body elements | ||
111 | } | ||
112 | if field.Tag.Get("ignore") != "" { | ||
113 | continue | ||
114 | } | ||
115 | |||
116 | if protocol.CanSetIdempotencyToken(member, field) { | ||
117 | token := protocol.GetIdempotencyToken() | ||
118 | member = reflect.ValueOf(&token) | ||
119 | } | ||
120 | |||
121 | if (member.Kind() == reflect.Ptr || member.Kind() == reflect.Slice || member.Kind() == reflect.Map) && member.IsNil() { | ||
122 | continue // ignore unset fields | ||
123 | } | ||
124 | |||
125 | if first { | ||
126 | first = false | ||
127 | } else { | ||
128 | buf.WriteByte(',') | ||
129 | } | ||
130 | |||
131 | // figure out what this field is called | ||
132 | name := field.Name | ||
133 | if locName := field.Tag.Get("locationName"); locName != "" { | ||
134 | name = locName | ||
135 | } | ||
136 | |||
137 | writeString(name, buf) | ||
138 | buf.WriteString(`:`) | ||
139 | |||
140 | err := buildAny(member, buf, field.Tag) | ||
141 | if err != nil { | ||
142 | return err | ||
143 | } | ||
144 | |||
145 | } | ||
146 | |||
147 | buf.WriteString("}") | ||
148 | |||
149 | return nil | ||
150 | } | ||
151 | |||
152 | func buildList(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error { | ||
153 | buf.WriteString("[") | ||
154 | |||
155 | for i := 0; i < value.Len(); i++ { | ||
156 | buildAny(value.Index(i), buf, "") | ||
157 | |||
158 | if i < value.Len()-1 { | ||
159 | buf.WriteString(",") | ||
160 | } | ||
161 | } | ||
162 | |||
163 | buf.WriteString("]") | ||
164 | |||
165 | return nil | ||
166 | } | ||
167 | |||
168 | type sortedValues []reflect.Value | ||
169 | |||
170 | func (sv sortedValues) Len() int { return len(sv) } | ||
171 | func (sv sortedValues) Swap(i, j int) { sv[i], sv[j] = sv[j], sv[i] } | ||
172 | func (sv sortedValues) Less(i, j int) bool { return sv[i].String() < sv[j].String() } | ||
173 | |||
174 | func buildMap(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error { | ||
175 | buf.WriteString("{") | ||
176 | |||
177 | sv := sortedValues(value.MapKeys()) | ||
178 | sort.Sort(sv) | ||
179 | |||
180 | for i, k := range sv { | ||
181 | if i > 0 { | ||
182 | buf.WriteByte(',') | ||
183 | } | ||
184 | |||
185 | writeString(k.String(), buf) | ||
186 | buf.WriteString(`:`) | ||
187 | |||
188 | buildAny(value.MapIndex(k), buf, "") | ||
189 | } | ||
190 | |||
191 | buf.WriteString("}") | ||
192 | |||
193 | return nil | ||
194 | } | ||
195 | |||
196 | func buildScalar(v reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error { | ||
197 | // prevents allocation on the heap. | ||
198 | scratch := [64]byte{} | ||
199 | switch value := reflect.Indirect(v); value.Kind() { | ||
200 | case reflect.String: | ||
201 | writeString(value.String(), buf) | ||
202 | case reflect.Bool: | ||
203 | if value.Bool() { | ||
204 | buf.WriteString("true") | ||
205 | } else { | ||
206 | buf.WriteString("false") | ||
207 | } | ||
208 | case reflect.Int64: | ||
209 | buf.Write(strconv.AppendInt(scratch[:0], value.Int(), 10)) | ||
210 | case reflect.Float64: | ||
211 | f := value.Float() | ||
212 | if math.IsInf(f, 0) || math.IsNaN(f) { | ||
213 | return &json.UnsupportedValueError{Value: v, Str: strconv.FormatFloat(f, 'f', -1, 64)} | ||
214 | } | ||
215 | buf.Write(strconv.AppendFloat(scratch[:0], f, 'f', -1, 64)) | ||
216 | default: | ||
217 | switch converted := value.Interface().(type) { | ||
218 | case time.Time: | ||
219 | format := tag.Get("timestampFormat") | ||
220 | if len(format) == 0 { | ||
221 | format = protocol.UnixTimeFormatName | ||
222 | } | ||
223 | |||
224 | ts := protocol.FormatTime(format, converted) | ||
225 | if format != protocol.UnixTimeFormatName { | ||
226 | ts = `"` + ts + `"` | ||
227 | } | ||
228 | |||
229 | buf.WriteString(ts) | ||
230 | case []byte: | ||
231 | if !value.IsNil() { | ||
232 | buf.WriteByte('"') | ||
233 | if len(converted) < 1024 { | ||
234 | // for small buffers, using Encode directly is much faster. | ||
235 | dst := make([]byte, base64.StdEncoding.EncodedLen(len(converted))) | ||
236 | base64.StdEncoding.Encode(dst, converted) | ||
237 | buf.Write(dst) | ||
238 | } else { | ||
239 | // for large buffers, avoid unnecessary extra temporary | ||
240 | // buffer space. | ||
241 | enc := base64.NewEncoder(base64.StdEncoding, buf) | ||
242 | enc.Write(converted) | ||
243 | enc.Close() | ||
244 | } | ||
245 | buf.WriteByte('"') | ||
246 | } | ||
247 | case aws.JSONValue: | ||
248 | str, err := protocol.EncodeJSONValue(converted, protocol.QuotedEscape) | ||
249 | if err != nil { | ||
250 | return fmt.Errorf("unable to encode JSONValue, %v", err) | ||
251 | } | ||
252 | buf.WriteString(str) | ||
253 | default: | ||
254 | return fmt.Errorf("unsupported JSON value %v (%s)", value.Interface(), value.Type()) | ||
255 | } | ||
256 | } | ||
257 | return nil | ||
258 | } | ||
259 | |||
260 | var hex = "0123456789abcdef" | ||
261 | |||
262 | func writeString(s string, buf *bytes.Buffer) { | ||
263 | buf.WriteByte('"') | ||
264 | for i := 0; i < len(s); i++ { | ||
265 | if s[i] == '"' { | ||
266 | buf.WriteString(`\"`) | ||
267 | } else if s[i] == '\\' { | ||
268 | buf.WriteString(`\\`) | ||
269 | } else if s[i] == '\b' { | ||
270 | buf.WriteString(`\b`) | ||
271 | } else if s[i] == '\f' { | ||
272 | buf.WriteString(`\f`) | ||
273 | } else if s[i] == '\r' { | ||
274 | buf.WriteString(`\r`) | ||
275 | } else if s[i] == '\t' { | ||
276 | buf.WriteString(`\t`) | ||
277 | } else if s[i] == '\n' { | ||
278 | buf.WriteString(`\n`) | ||
279 | } else if s[i] < 32 { | ||
280 | buf.WriteString("\\u00") | ||
281 | buf.WriteByte(hex[s[i]>>4]) | ||
282 | buf.WriteByte(hex[s[i]&0xF]) | ||
283 | } else { | ||
284 | buf.WriteByte(s[i]) | ||
285 | } | ||
286 | } | ||
287 | buf.WriteByte('"') | ||
288 | } | ||
289 | |||
290 | // Returns the reflection element of a value, if it is a pointer. | ||
291 | func elemOf(value reflect.Value) reflect.Value { | ||
292 | for value.Kind() == reflect.Ptr { | ||
293 | value = value.Elem() | ||
294 | } | ||
295 | return value | ||
296 | } | ||
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/unmarshal.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/unmarshal.go new file mode 100644 index 0000000..ea0da79 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/unmarshal.go | |||
@@ -0,0 +1,250 @@ | |||
1 | package jsonutil | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "encoding/base64" | ||
6 | "encoding/json" | ||
7 | "fmt" | ||
8 | "io" | ||
9 | "reflect" | ||
10 | "time" | ||
11 | |||
12 | "github.com/aws/aws-sdk-go/aws" | ||
13 | "github.com/aws/aws-sdk-go/aws/awserr" | ||
14 | "github.com/aws/aws-sdk-go/private/protocol" | ||
15 | ) | ||
16 | |||
17 | // UnmarshalJSONError unmarshal's the reader's JSON document into the passed in | ||
18 | // type. The value to unmarshal the json document into must be a pointer to the | ||
19 | // type. | ||
20 | func UnmarshalJSONError(v interface{}, stream io.Reader) error { | ||
21 | var errBuf bytes.Buffer | ||
22 | body := io.TeeReader(stream, &errBuf) | ||
23 | |||
24 | err := json.NewDecoder(body).Decode(v) | ||
25 | if err != nil { | ||
26 | msg := "failed decoding error message" | ||
27 | if err == io.EOF { | ||
28 | msg = "error message missing" | ||
29 | err = nil | ||
30 | } | ||
31 | return awserr.NewUnmarshalError(err, msg, errBuf.Bytes()) | ||
32 | } | ||
33 | |||
34 | return nil | ||
35 | } | ||
36 | |||
37 | // UnmarshalJSON reads a stream and unmarshals the results in object v. | ||
38 | func UnmarshalJSON(v interface{}, stream io.Reader) error { | ||
39 | var out interface{} | ||
40 | |||
41 | err := json.NewDecoder(stream).Decode(&out) | ||
42 | if err == io.EOF { | ||
43 | return nil | ||
44 | } else if err != nil { | ||
45 | return err | ||
46 | } | ||
47 | |||
48 | return unmarshalAny(reflect.ValueOf(v), out, "") | ||
49 | } | ||
50 | |||
51 | func unmarshalAny(value reflect.Value, data interface{}, tag reflect.StructTag) error { | ||
52 | vtype := value.Type() | ||
53 | if vtype.Kind() == reflect.Ptr { | ||
54 | vtype = vtype.Elem() // check kind of actual element type | ||
55 | } | ||
56 | |||
57 | t := tag.Get("type") | ||
58 | if t == "" { | ||
59 | switch vtype.Kind() { | ||
60 | case reflect.Struct: | ||
61 | // also it can't be a time object | ||
62 | if _, ok := value.Interface().(*time.Time); !ok { | ||
63 | t = "structure" | ||
64 | } | ||
65 | case reflect.Slice: | ||
66 | // also it can't be a byte slice | ||
67 | if _, ok := value.Interface().([]byte); !ok { | ||
68 | t = "list" | ||
69 | } | ||
70 | case reflect.Map: | ||
71 | // cannot be a JSONValue map | ||
72 | if _, ok := value.Interface().(aws.JSONValue); !ok { | ||
73 | t = "map" | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | switch t { | ||
79 | case "structure": | ||
80 | if field, ok := vtype.FieldByName("_"); ok { | ||
81 | tag = field.Tag | ||
82 | } | ||
83 | return unmarshalStruct(value, data, tag) | ||
84 | case "list": | ||
85 | return unmarshalList(value, data, tag) | ||
86 | case "map": | ||
87 | return unmarshalMap(value, data, tag) | ||
88 | default: | ||
89 | return unmarshalScalar(value, data, tag) | ||
90 | } | ||
91 | } | ||
92 | |||
93 | func unmarshalStruct(value reflect.Value, data interface{}, tag reflect.StructTag) error { | ||
94 | if data == nil { | ||
95 | return nil | ||
96 | } | ||
97 | mapData, ok := data.(map[string]interface{}) | ||
98 | if !ok { | ||
99 | return fmt.Errorf("JSON value is not a structure (%#v)", data) | ||
100 | } | ||
101 | |||
102 | t := value.Type() | ||
103 | if value.Kind() == reflect.Ptr { | ||
104 | if value.IsNil() { // create the structure if it's nil | ||
105 | s := reflect.New(value.Type().Elem()) | ||
106 | value.Set(s) | ||
107 | value = s | ||
108 | } | ||
109 | |||
110 | value = value.Elem() | ||
111 | t = t.Elem() | ||
112 | } | ||
113 | |||
114 | // unwrap any payloads | ||
115 | if payload := tag.Get("payload"); payload != "" { | ||
116 | field, _ := t.FieldByName(payload) | ||
117 | return unmarshalAny(value.FieldByName(payload), data, field.Tag) | ||
118 | } | ||
119 | |||
120 | for i := 0; i < t.NumField(); i++ { | ||
121 | field := t.Field(i) | ||
122 | if field.PkgPath != "" { | ||
123 | continue // ignore unexported fields | ||
124 | } | ||
125 | |||
126 | // figure out what this field is called | ||
127 | name := field.Name | ||
128 | if locName := field.Tag.Get("locationName"); locName != "" { | ||
129 | name = locName | ||
130 | } | ||
131 | |||
132 | member := value.FieldByIndex(field.Index) | ||
133 | err := unmarshalAny(member, mapData[name], field.Tag) | ||
134 | if err != nil { | ||
135 | return err | ||
136 | } | ||
137 | } | ||
138 | return nil | ||
139 | } | ||
140 | |||
141 | func unmarshalList(value reflect.Value, data interface{}, tag reflect.StructTag) error { | ||
142 | if data == nil { | ||
143 | return nil | ||
144 | } | ||
145 | listData, ok := data.([]interface{}) | ||
146 | if !ok { | ||
147 | return fmt.Errorf("JSON value is not a list (%#v)", data) | ||
148 | } | ||
149 | |||
150 | if value.IsNil() { | ||
151 | l := len(listData) | ||
152 | value.Set(reflect.MakeSlice(value.Type(), l, l)) | ||
153 | } | ||
154 | |||
155 | for i, c := range listData { | ||
156 | err := unmarshalAny(value.Index(i), c, "") | ||
157 | if err != nil { | ||
158 | return err | ||
159 | } | ||
160 | } | ||
161 | |||
162 | return nil | ||
163 | } | ||
164 | |||
165 | func unmarshalMap(value reflect.Value, data interface{}, tag reflect.StructTag) error { | ||
166 | if data == nil { | ||
167 | return nil | ||
168 | } | ||
169 | mapData, ok := data.(map[string]interface{}) | ||
170 | if !ok { | ||
171 | return fmt.Errorf("JSON value is not a map (%#v)", data) | ||
172 | } | ||
173 | |||
174 | if value.IsNil() { | ||
175 | value.Set(reflect.MakeMap(value.Type())) | ||
176 | } | ||
177 | |||
178 | for k, v := range mapData { | ||
179 | kvalue := reflect.ValueOf(k) | ||
180 | vvalue := reflect.New(value.Type().Elem()).Elem() | ||
181 | |||
182 | unmarshalAny(vvalue, v, "") | ||
183 | value.SetMapIndex(kvalue, vvalue) | ||
184 | } | ||
185 | |||
186 | return nil | ||
187 | } | ||
188 | |||
189 | func unmarshalScalar(value reflect.Value, data interface{}, tag reflect.StructTag) error { | ||
190 | |||
191 | switch d := data.(type) { | ||
192 | case nil: | ||
193 | return nil // nothing to do here | ||
194 | case string: | ||
195 | switch value.Interface().(type) { | ||
196 | case *string: | ||
197 | value.Set(reflect.ValueOf(&d)) | ||
198 | case []byte: | ||
199 | b, err := base64.StdEncoding.DecodeString(d) | ||
200 | if err != nil { | ||
201 | return err | ||
202 | } | ||
203 | value.Set(reflect.ValueOf(b)) | ||
204 | case *time.Time: | ||
205 | format := tag.Get("timestampFormat") | ||
206 | if len(format) == 0 { | ||
207 | format = protocol.ISO8601TimeFormatName | ||
208 | } | ||
209 | |||
210 | t, err := protocol.ParseTime(format, d) | ||
211 | if err != nil { | ||
212 | return err | ||
213 | } | ||
214 | value.Set(reflect.ValueOf(&t)) | ||
215 | case aws.JSONValue: | ||
216 | // No need to use escaping as the value is a non-quoted string. | ||
217 | v, err := protocol.DecodeJSONValue(d, protocol.NoEscape) | ||
218 | if err != nil { | ||
219 | return err | ||
220 | } | ||
221 | value.Set(reflect.ValueOf(v)) | ||
222 | default: | ||
223 | return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type()) | ||
224 | } | ||
225 | case float64: | ||
226 | switch value.Interface().(type) { | ||
227 | case *int64: | ||
228 | di := int64(d) | ||
229 | value.Set(reflect.ValueOf(&di)) | ||
230 | case *float64: | ||
231 | value.Set(reflect.ValueOf(&d)) | ||
232 | case *time.Time: | ||
233 | // Time unmarshaled from a float64 can only be epoch seconds | ||
234 | t := time.Unix(int64(d), 0).UTC() | ||
235 | value.Set(reflect.ValueOf(&t)) | ||
236 | default: | ||
237 | return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type()) | ||
238 | } | ||
239 | case bool: | ||
240 | switch value.Interface().(type) { | ||
241 | case *bool: | ||
242 | value.Set(reflect.ValueOf(&d)) | ||
243 | default: | ||
244 | return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type()) | ||
245 | } | ||
246 | default: | ||
247 | return fmt.Errorf("unsupported JSON value (%v)", data) | ||
248 | } | ||
249 | return nil | ||
250 | } | ||
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/query/build.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/query/build.go index 60e5b09..0cb99eb 100644 --- a/vendor/github.com/aws/aws-sdk-go/private/protocol/query/build.go +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/query/build.go | |||
@@ -21,7 +21,7 @@ func Build(r *request.Request) { | |||
21 | "Version": {r.ClientInfo.APIVersion}, | 21 | "Version": {r.ClientInfo.APIVersion}, |
22 | } | 22 | } |
23 | if err := queryutil.Parse(body, r.Params, false); err != nil { | 23 | if err := queryutil.Parse(body, r.Params, false); err != nil { |
24 | r.Error = awserr.New("SerializationError", "failed encoding Query request", err) | 24 | r.Error = awserr.New(request.ErrCodeSerialization, "failed encoding Query request", err) |
25 | return | 25 | return |
26 | } | 26 | } |
27 | 27 | ||
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal.go index 3495c73..f69c1ef 100644 --- a/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal.go +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal.go | |||
@@ -24,7 +24,7 @@ func Unmarshal(r *request.Request) { | |||
24 | err := xmlutil.UnmarshalXML(r.Data, decoder, r.Operation.Name+"Result") | 24 | err := xmlutil.UnmarshalXML(r.Data, decoder, r.Operation.Name+"Result") |
25 | if err != nil { | 25 | if err != nil { |
26 | r.Error = awserr.NewRequestFailure( | 26 | r.Error = awserr.NewRequestFailure( |
27 | awserr.New("SerializationError", "failed decoding Query response", err), | 27 | awserr.New(request.ErrCodeSerialization, "failed decoding Query response", err), |
28 | r.HTTPResponse.StatusCode, | 28 | r.HTTPResponse.StatusCode, |
29 | r.RequestID, | 29 | r.RequestID, |
30 | ) | 30 | ) |
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal_error.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal_error.go index 46d354e..831b011 100644 --- a/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal_error.go +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/query/unmarshal_error.go | |||
@@ -2,73 +2,68 @@ package query | |||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/xml" | 4 | "encoding/xml" |
5 | "io/ioutil" | 5 | "fmt" |
6 | 6 | ||
7 | "github.com/aws/aws-sdk-go/aws/awserr" | 7 | "github.com/aws/aws-sdk-go/aws/awserr" |
8 | "github.com/aws/aws-sdk-go/aws/request" | 8 | "github.com/aws/aws-sdk-go/aws/request" |
9 | "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil" | ||
9 | ) | 10 | ) |
10 | 11 | ||
12 | // UnmarshalErrorHandler is a name request handler to unmarshal request errors | ||
13 | var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.query.UnmarshalError", Fn: UnmarshalError} | ||
14 | |||
11 | type xmlErrorResponse struct { | 15 | type xmlErrorResponse struct { |
12 | XMLName xml.Name `xml:"ErrorResponse"` | 16 | Code string `xml:"Error>Code"` |
13 | Code string `xml:"Error>Code"` | 17 | Message string `xml:"Error>Message"` |
14 | Message string `xml:"Error>Message"` | 18 | RequestID string `xml:"RequestId"` |
15 | RequestID string `xml:"RequestId"` | ||
16 | } | 19 | } |
17 | 20 | ||
18 | type xmlServiceUnavailableResponse struct { | 21 | type xmlResponseError struct { |
19 | XMLName xml.Name `xml:"ServiceUnavailableException"` | 22 | xmlErrorResponse |
20 | } | 23 | } |
21 | 24 | ||
22 | // UnmarshalErrorHandler is a name request handler to unmarshal request errors | 25 | func (e *xmlResponseError) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { |
23 | var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.query.UnmarshalError", Fn: UnmarshalError} | 26 | const svcUnavailableTagName = "ServiceUnavailableException" |
27 | const errorResponseTagName = "ErrorResponse" | ||
28 | |||
29 | switch start.Name.Local { | ||
30 | case svcUnavailableTagName: | ||
31 | e.Code = svcUnavailableTagName | ||
32 | e.Message = "service is unavailable" | ||
33 | return d.Skip() | ||
34 | |||
35 | case errorResponseTagName: | ||
36 | return d.DecodeElement(&e.xmlErrorResponse, &start) | ||
37 | |||
38 | default: | ||
39 | return fmt.Errorf("unknown error response tag, %v", start) | ||
40 | } | ||
41 | } | ||
24 | 42 | ||
25 | // UnmarshalError unmarshals an error response for an AWS Query service. | 43 | // UnmarshalError unmarshals an error response for an AWS Query service. |
26 | func UnmarshalError(r *request.Request) { | 44 | func UnmarshalError(r *request.Request) { |
27 | defer r.HTTPResponse.Body.Close() | 45 | defer r.HTTPResponse.Body.Close() |
28 | 46 | ||
29 | bodyBytes, err := ioutil.ReadAll(r.HTTPResponse.Body) | 47 | var respErr xmlResponseError |
48 | err := xmlutil.UnmarshalXMLError(&respErr, r.HTTPResponse.Body) | ||
30 | if err != nil { | 49 | if err != nil { |
31 | r.Error = awserr.NewRequestFailure( | 50 | r.Error = awserr.NewRequestFailure( |
32 | awserr.New("SerializationError", "failed to read from query HTTP response body", err), | 51 | awserr.New(request.ErrCodeSerialization, |
52 | "failed to unmarshal error message", err), | ||
33 | r.HTTPResponse.StatusCode, | 53 | r.HTTPResponse.StatusCode, |
34 | r.RequestID, | 54 | r.RequestID, |
35 | ) | 55 | ) |
36 | return | 56 | return |
37 | } | 57 | } |
38 | 58 | ||
39 | // First check for specific error | 59 | reqID := respErr.RequestID |
40 | resp := xmlErrorResponse{} | 60 | if len(reqID) == 0 { |
41 | decodeErr := xml.Unmarshal(bodyBytes, &resp) | 61 | reqID = r.RequestID |
42 | if decodeErr == nil { | ||
43 | reqID := resp.RequestID | ||
44 | if reqID == "" { | ||
45 | reqID = r.RequestID | ||
46 | } | ||
47 | r.Error = awserr.NewRequestFailure( | ||
48 | awserr.New(resp.Code, resp.Message, nil), | ||
49 | r.HTTPResponse.StatusCode, | ||
50 | reqID, | ||
51 | ) | ||
52 | return | ||
53 | } | ||
54 | |||
55 | // Check for unhandled error | ||
56 | servUnavailResp := xmlServiceUnavailableResponse{} | ||
57 | unavailErr := xml.Unmarshal(bodyBytes, &servUnavailResp) | ||
58 | if unavailErr == nil { | ||
59 | r.Error = awserr.NewRequestFailure( | ||
60 | awserr.New("ServiceUnavailableException", "service is unavailable", nil), | ||
61 | r.HTTPResponse.StatusCode, | ||
62 | r.RequestID, | ||
63 | ) | ||
64 | return | ||
65 | } | 62 | } |
66 | 63 | ||
67 | // Failed to retrieve any error message from the response body | ||
68 | r.Error = awserr.NewRequestFailure( | 64 | r.Error = awserr.NewRequestFailure( |
69 | awserr.New("SerializationError", | 65 | awserr.New(respErr.Code, respErr.Message, nil), |
70 | "failed to decode query XML error response", decodeErr), | ||
71 | r.HTTPResponse.StatusCode, | 66 | r.HTTPResponse.StatusCode, |
72 | r.RequestID, | 67 | reqID, |
73 | ) | 68 | ) |
74 | } | 69 | } |
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go index b80f84f..1301b14 100644 --- a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go | |||
@@ -25,6 +25,8 @@ var noEscape [256]bool | |||
25 | 25 | ||
26 | var errValueNotSet = fmt.Errorf("value not set") | 26 | var errValueNotSet = fmt.Errorf("value not set") |
27 | 27 | ||
28 | var byteSliceType = reflect.TypeOf([]byte{}) | ||
29 | |||
28 | func init() { | 30 | func init() { |
29 | for i := 0; i < len(noEscape); i++ { | 31 | for i := 0; i < len(noEscape); i++ { |
30 | // AWS expects every character except these to be escaped | 32 | // AWS expects every character except these to be escaped |
@@ -94,6 +96,14 @@ func buildLocationElements(r *request.Request, v reflect.Value, buildGETQuery bo | |||
94 | continue | 96 | continue |
95 | } | 97 | } |
96 | 98 | ||
99 | // Support the ability to customize values to be marshaled as a | ||
100 | // blob even though they were modeled as a string. Required for S3 | ||
101 | // API operations like SSECustomerKey is modeled as stirng but | ||
102 | // required to be base64 encoded in request. | ||
103 | if field.Tag.Get("marshal-as") == "blob" { | ||
104 | m = m.Convert(byteSliceType) | ||
105 | } | ||
106 | |||
97 | var err error | 107 | var err error |
98 | switch field.Tag.Get("location") { | 108 | switch field.Tag.Get("location") { |
99 | case "headers": // header maps | 109 | case "headers": // header maps |
@@ -137,7 +147,7 @@ func buildBody(r *request.Request, v reflect.Value) { | |||
137 | case string: | 147 | case string: |
138 | r.SetStringBody(reader) | 148 | r.SetStringBody(reader) |
139 | default: | 149 | default: |
140 | r.Error = awserr.New("SerializationError", | 150 | r.Error = awserr.New(request.ErrCodeSerialization, |
141 | "failed to encode REST request", | 151 | "failed to encode REST request", |
142 | fmt.Errorf("unknown payload type %s", payload.Type())) | 152 | fmt.Errorf("unknown payload type %s", payload.Type())) |
143 | } | 153 | } |
@@ -152,7 +162,7 @@ func buildHeader(header *http.Header, v reflect.Value, name string, tag reflect. | |||
152 | if err == errValueNotSet { | 162 | if err == errValueNotSet { |
153 | return nil | 163 | return nil |
154 | } else if err != nil { | 164 | } else if err != nil { |
155 | return awserr.New("SerializationError", "failed to encode REST request", err) | 165 | return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", err) |
156 | } | 166 | } |
157 | 167 | ||
158 | name = strings.TrimSpace(name) | 168 | name = strings.TrimSpace(name) |
@@ -170,7 +180,7 @@ func buildHeaderMap(header *http.Header, v reflect.Value, tag reflect.StructTag) | |||
170 | if err == errValueNotSet { | 180 | if err == errValueNotSet { |
171 | continue | 181 | continue |
172 | } else if err != nil { | 182 | } else if err != nil { |
173 | return awserr.New("SerializationError", "failed to encode REST request", err) | 183 | return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", err) |
174 | 184 | ||
175 | } | 185 | } |
176 | keyStr := strings.TrimSpace(key.String()) | 186 | keyStr := strings.TrimSpace(key.String()) |
@@ -186,7 +196,7 @@ func buildURI(u *url.URL, v reflect.Value, name string, tag reflect.StructTag) e | |||
186 | if err == errValueNotSet { | 196 | if err == errValueNotSet { |
187 | return nil | 197 | return nil |
188 | } else if err != nil { | 198 | } else if err != nil { |
189 | return awserr.New("SerializationError", "failed to encode REST request", err) | 199 | return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", err) |
190 | } | 200 | } |
191 | 201 | ||
192 | u.Path = strings.Replace(u.Path, "{"+name+"}", value, -1) | 202 | u.Path = strings.Replace(u.Path, "{"+name+"}", value, -1) |
@@ -219,7 +229,7 @@ func buildQueryString(query url.Values, v reflect.Value, name string, tag reflec | |||
219 | if err == errValueNotSet { | 229 | if err == errValueNotSet { |
220 | return nil | 230 | return nil |
221 | } else if err != nil { | 231 | } else if err != nil { |
222 | return awserr.New("SerializationError", "failed to encode REST request", err) | 232 | return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", err) |
223 | } | 233 | } |
224 | query.Set(name, str) | 234 | query.Set(name, str) |
225 | } | 235 | } |
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go index 33fd53b..de02136 100644 --- a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go | |||
@@ -57,7 +57,7 @@ func unmarshalBody(r *request.Request, v reflect.Value) { | |||
57 | defer r.HTTPResponse.Body.Close() | 57 | defer r.HTTPResponse.Body.Close() |
58 | b, err := ioutil.ReadAll(r.HTTPResponse.Body) | 58 | b, err := ioutil.ReadAll(r.HTTPResponse.Body) |
59 | if err != nil { | 59 | if err != nil { |
60 | r.Error = awserr.New("SerializationError", "failed to decode REST response", err) | 60 | r.Error = awserr.New(request.ErrCodeSerialization, "failed to decode REST response", err) |
61 | } else { | 61 | } else { |
62 | payload.Set(reflect.ValueOf(b)) | 62 | payload.Set(reflect.ValueOf(b)) |
63 | } | 63 | } |
@@ -65,7 +65,7 @@ func unmarshalBody(r *request.Request, v reflect.Value) { | |||
65 | defer r.HTTPResponse.Body.Close() | 65 | defer r.HTTPResponse.Body.Close() |
66 | b, err := ioutil.ReadAll(r.HTTPResponse.Body) | 66 | b, err := ioutil.ReadAll(r.HTTPResponse.Body) |
67 | if err != nil { | 67 | if err != nil { |
68 | r.Error = awserr.New("SerializationError", "failed to decode REST response", err) | 68 | r.Error = awserr.New(request.ErrCodeSerialization, "failed to decode REST response", err) |
69 | } else { | 69 | } else { |
70 | str := string(b) | 70 | str := string(b) |
71 | payload.Set(reflect.ValueOf(&str)) | 71 | payload.Set(reflect.ValueOf(&str)) |
@@ -77,7 +77,7 @@ func unmarshalBody(r *request.Request, v reflect.Value) { | |||
77 | case "io.ReadSeeker": | 77 | case "io.ReadSeeker": |
78 | b, err := ioutil.ReadAll(r.HTTPResponse.Body) | 78 | b, err := ioutil.ReadAll(r.HTTPResponse.Body) |
79 | if err != nil { | 79 | if err != nil { |
80 | r.Error = awserr.New("SerializationError", | 80 | r.Error = awserr.New(request.ErrCodeSerialization, |
81 | "failed to read response body", err) | 81 | "failed to read response body", err) |
82 | return | 82 | return |
83 | } | 83 | } |
@@ -85,7 +85,7 @@ func unmarshalBody(r *request.Request, v reflect.Value) { | |||
85 | default: | 85 | default: |
86 | io.Copy(ioutil.Discard, r.HTTPResponse.Body) | 86 | io.Copy(ioutil.Discard, r.HTTPResponse.Body) |
87 | defer r.HTTPResponse.Body.Close() | 87 | defer r.HTTPResponse.Body.Close() |
88 | r.Error = awserr.New("SerializationError", | 88 | r.Error = awserr.New(request.ErrCodeSerialization, |
89 | "failed to decode REST response", | 89 | "failed to decode REST response", |
90 | fmt.Errorf("unknown payload type %s", payload.Type())) | 90 | fmt.Errorf("unknown payload type %s", payload.Type())) |
91 | } | 91 | } |
@@ -115,14 +115,14 @@ func unmarshalLocationElements(r *request.Request, v reflect.Value) { | |||
115 | case "header": | 115 | case "header": |
116 | err := unmarshalHeader(m, r.HTTPResponse.Header.Get(name), field.Tag) | 116 | err := unmarshalHeader(m, r.HTTPResponse.Header.Get(name), field.Tag) |
117 | if err != nil { | 117 | if err != nil { |
118 | r.Error = awserr.New("SerializationError", "failed to decode REST response", err) | 118 | r.Error = awserr.New(request.ErrCodeSerialization, "failed to decode REST response", err) |
119 | break | 119 | break |
120 | } | 120 | } |
121 | case "headers": | 121 | case "headers": |
122 | prefix := field.Tag.Get("locationName") | 122 | prefix := field.Tag.Get("locationName") |
123 | err := unmarshalHeaderMap(m, r.HTTPResponse.Header, prefix) | 123 | err := unmarshalHeaderMap(m, r.HTTPResponse.Header, prefix) |
124 | if err != nil { | 124 | if err != nil { |
125 | r.Error = awserr.New("SerializationError", "failed to decode REST response", err) | 125 | r.Error = awserr.New(request.ErrCodeSerialization, "failed to decode REST response", err) |
126 | break | 126 | break |
127 | } | 127 | } |
128 | } | 128 | } |
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/restxml/restxml.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/restxml/restxml.go index b0f4e24..cf56964 100644 --- a/vendor/github.com/aws/aws-sdk-go/private/protocol/restxml/restxml.go +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/restxml/restxml.go | |||
@@ -37,7 +37,8 @@ func Build(r *request.Request) { | |||
37 | err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf)) | 37 | err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf)) |
38 | if err != nil { | 38 | if err != nil { |
39 | r.Error = awserr.NewRequestFailure( | 39 | r.Error = awserr.NewRequestFailure( |
40 | awserr.New("SerializationError", "failed to encode rest XML request", err), | 40 | awserr.New(request.ErrCodeSerialization, |
41 | "failed to encode rest XML request", err), | ||
41 | r.HTTPResponse.StatusCode, | 42 | r.HTTPResponse.StatusCode, |
42 | r.RequestID, | 43 | r.RequestID, |
43 | ) | 44 | ) |
@@ -55,7 +56,8 @@ func Unmarshal(r *request.Request) { | |||
55 | err := xmlutil.UnmarshalXML(r.Data, decoder, "") | 56 | err := xmlutil.UnmarshalXML(r.Data, decoder, "") |
56 | if err != nil { | 57 | if err != nil { |
57 | r.Error = awserr.NewRequestFailure( | 58 | r.Error = awserr.NewRequestFailure( |
58 | awserr.New("SerializationError", "failed to decode REST XML response", err), | 59 | awserr.New(request.ErrCodeSerialization, |
60 | "failed to decode REST XML response", err), | ||
59 | r.HTTPResponse.StatusCode, | 61 | r.HTTPResponse.StatusCode, |
60 | r.RequestID, | 62 | r.RequestID, |
61 | ) | 63 | ) |
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil/unmarshal.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil/unmarshal.go index ff1ef68..7108d38 100644 --- a/vendor/github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil/unmarshal.go +++ b/vendor/github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil/unmarshal.go | |||
@@ -1,6 +1,7 @@ | |||
1 | package xmlutil | 1 | package xmlutil |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "bytes" | ||
4 | "encoding/base64" | 5 | "encoding/base64" |
5 | "encoding/xml" | 6 | "encoding/xml" |
6 | "fmt" | 7 | "fmt" |
@@ -10,9 +11,27 @@ import ( | |||
10 | "strings" | 11 | "strings" |
11 | "time" | 12 | "time" |
12 | 13 | ||
14 | "github.com/aws/aws-sdk-go/aws/awserr" | ||
13 | "github.com/aws/aws-sdk-go/private/protocol" | 15 | "github.com/aws/aws-sdk-go/private/protocol" |
14 | ) | 16 | ) |
15 | 17 | ||
18 | // UnmarshalXMLError unmarshals the XML error from the stream into the value | ||
19 | // type specified. The value must be a pointer. If the message fails to | ||
20 | // unmarshal, the message content will be included in the returned error as a | ||
21 | // awserr.UnmarshalError. | ||
22 | func UnmarshalXMLError(v interface{}, stream io.Reader) error { | ||
23 | var errBuf bytes.Buffer | ||
24 | body := io.TeeReader(stream, &errBuf) | ||
25 | |||
26 | err := xml.NewDecoder(body).Decode(v) | ||
27 | if err != nil && err != io.EOF { | ||
28 | return awserr.NewUnmarshalError(err, | ||
29 | "failed to unmarshal error message", errBuf.Bytes()) | ||
30 | } | ||
31 | |||
32 | return nil | ||
33 | } | ||
34 | |||
16 | // UnmarshalXML deserializes an xml.Decoder into the container v. V | 35 | // UnmarshalXML deserializes an xml.Decoder into the container v. V |
17 | // needs to match the shape of the XML expected to be decoded. | 36 | // needs to match the shape of the XML expected to be decoded. |
18 | // If the shape doesn't match unmarshaling will fail. | 37 | // If the shape doesn't match unmarshaling will fail. |