Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / github.com / gophercloud / gophercloud / errors.go
1 package gophercloud
2
3 import (
4         "fmt"
5         "strings"
6 )
7
8 // BaseError is an error type that all other error types embed.
9 type BaseError struct {
10         DefaultErrString string
11         Info             string
12 }
13
14 func (e BaseError) Error() string {
15         e.DefaultErrString = "An error occurred while executing a Gophercloud request."
16         return e.choseErrString()
17 }
18
19 func (e BaseError) choseErrString() string {
20         if e.Info != "" {
21                 return e.Info
22         }
23         return e.DefaultErrString
24 }
25
26 // ErrMissingInput is the error when input is required in a particular
27 // situation but not provided by the user
28 type ErrMissingInput struct {
29         BaseError
30         Argument string
31 }
32
33 func (e ErrMissingInput) Error() string {
34         e.DefaultErrString = fmt.Sprintf("Missing input for argument [%s]", e.Argument)
35         return e.choseErrString()
36 }
37
38 // ErrInvalidInput is an error type used for most non-HTTP Gophercloud errors.
39 type ErrInvalidInput struct {
40         ErrMissingInput
41         Value interface{}
42 }
43
44 func (e ErrInvalidInput) Error() string {
45         e.DefaultErrString = fmt.Sprintf("Invalid input provided for argument [%s]: [%+v]", e.Argument, e.Value)
46         return e.choseErrString()
47 }
48
49 // ErrMissingEnvironmentVariable is the error when environment variable is required
50 // in a particular situation but not provided by the user
51 type ErrMissingEnvironmentVariable struct {
52         BaseError
53         EnvironmentVariable string
54 }
55
56 func (e ErrMissingEnvironmentVariable) Error() string {
57         e.DefaultErrString = fmt.Sprintf("Missing environment variable [%s]", e.EnvironmentVariable)
58         return e.choseErrString()
59 }
60
61 // ErrMissingAnyoneOfEnvironmentVariables is the error when anyone of the environment variables
62 // is required in a particular situation but not provided by the user
63 type ErrMissingAnyoneOfEnvironmentVariables struct {
64         BaseError
65         EnvironmentVariables []string
66 }
67
68 func (e ErrMissingAnyoneOfEnvironmentVariables) Error() string {
69         e.DefaultErrString = fmt.Sprintf(
70                 "Missing one of the following environment variables [%s]",
71                 strings.Join(e.EnvironmentVariables, ", "),
72         )
73         return e.choseErrString()
74 }
75
76 // ErrUnexpectedResponseCode is returned by the Request method when a response code other than
77 // those listed in OkCodes is encountered.
78 type ErrUnexpectedResponseCode struct {
79         BaseError
80         URL      string
81         Method   string
82         Expected []int
83         Actual   int
84         Body     []byte
85 }
86
87 func (e ErrUnexpectedResponseCode) Error() string {
88         e.DefaultErrString = fmt.Sprintf(
89                 "Expected HTTP response code %v when accessing [%s %s], but got %d instead\n%s",
90                 e.Expected, e.Method, e.URL, e.Actual, e.Body,
91         )
92         return e.choseErrString()
93 }
94
95 // ErrDefault400 is the default error type returned on a 400 HTTP response code.
96 type ErrDefault400 struct {
97         ErrUnexpectedResponseCode
98 }
99
100 // ErrDefault401 is the default error type returned on a 401 HTTP response code.
101 type ErrDefault401 struct {
102         ErrUnexpectedResponseCode
103 }
104
105 // ErrDefault403 is the default error type returned on a 403 HTTP response code.
106 type ErrDefault403 struct {
107         ErrUnexpectedResponseCode
108 }
109
110 // ErrDefault404 is the default error type returned on a 404 HTTP response code.
111 type ErrDefault404 struct {
112         ErrUnexpectedResponseCode
113 }
114
115 // ErrDefault405 is the default error type returned on a 405 HTTP response code.
116 type ErrDefault405 struct {
117         ErrUnexpectedResponseCode
118 }
119
120 // ErrDefault408 is the default error type returned on a 408 HTTP response code.
121 type ErrDefault408 struct {
122         ErrUnexpectedResponseCode
123 }
124
125 // ErrDefault409 is the default error type returned on a 409 HTTP response code.
126 type ErrDefault409 struct {
127         ErrUnexpectedResponseCode
128 }
129
130 // ErrDefault429 is the default error type returned on a 429 HTTP response code.
131 type ErrDefault429 struct {
132         ErrUnexpectedResponseCode
133 }
134
135 // ErrDefault500 is the default error type returned on a 500 HTTP response code.
136 type ErrDefault500 struct {
137         ErrUnexpectedResponseCode
138 }
139
140 // ErrDefault503 is the default error type returned on a 503 HTTP response code.
141 type ErrDefault503 struct {
142         ErrUnexpectedResponseCode
143 }
144
145 func (e ErrDefault400) Error() string {
146         e.DefaultErrString = fmt.Sprintf(
147                 "Bad request with: [%s %s], error message: %s",
148                 e.Method, e.URL, e.Body,
149         )
150         return e.choseErrString()
151 }
152 func (e ErrDefault401) Error() string {
153         return "Authentication failed"
154 }
155 func (e ErrDefault403) Error() string {
156         e.DefaultErrString = fmt.Sprintf(
157                 "Request forbidden: [%s %s], error message: %s",
158                 e.Method, e.URL, e.Body,
159         )
160         return e.choseErrString()
161 }
162 func (e ErrDefault404) Error() string {
163         return "Resource not found"
164 }
165 func (e ErrDefault405) Error() string {
166         return "Method not allowed"
167 }
168 func (e ErrDefault408) Error() string {
169         return "The server timed out waiting for the request"
170 }
171 func (e ErrDefault429) Error() string {
172         return "Too many requests have been sent in a given amount of time. Pause" +
173                 " requests, wait up to one minute, and try again."
174 }
175 func (e ErrDefault500) Error() string {
176         return "Internal Server Error"
177 }
178 func (e ErrDefault503) Error() string {
179         return "The service is currently unable to handle the request due to a temporary" +
180                 " overloading or maintenance. This is a temporary condition. Try again later."
181 }
182
183 // Err400er is the interface resource error types implement to override the error message
184 // from a 400 error.
185 type Err400er interface {
186         Error400(ErrUnexpectedResponseCode) error
187 }
188
189 // Err401er is the interface resource error types implement to override the error message
190 // from a 401 error.
191 type Err401er interface {
192         Error401(ErrUnexpectedResponseCode) error
193 }
194
195 // Err403er is the interface resource error types implement to override the error message
196 // from a 403 error.
197 type Err403er interface {
198         Error403(ErrUnexpectedResponseCode) error
199 }
200
201 // Err404er is the interface resource error types implement to override the error message
202 // from a 404 error.
203 type Err404er interface {
204         Error404(ErrUnexpectedResponseCode) error
205 }
206
207 // Err405er is the interface resource error types implement to override the error message
208 // from a 405 error.
209 type Err405er interface {
210         Error405(ErrUnexpectedResponseCode) error
211 }
212
213 // Err408er is the interface resource error types implement to override the error message
214 // from a 408 error.
215 type Err408er interface {
216         Error408(ErrUnexpectedResponseCode) error
217 }
218
219 // Err409er is the interface resource error types implement to override the error message
220 // from a 409 error.
221 type Err409er interface {
222         Error409(ErrUnexpectedResponseCode) error
223 }
224
225 // Err429er is the interface resource error types implement to override the error message
226 // from a 429 error.
227 type Err429er interface {
228         Error429(ErrUnexpectedResponseCode) error
229 }
230
231 // Err500er is the interface resource error types implement to override the error message
232 // from a 500 error.
233 type Err500er interface {
234         Error500(ErrUnexpectedResponseCode) error
235 }
236
237 // Err503er is the interface resource error types implement to override the error message
238 // from a 503 error.
239 type Err503er interface {
240         Error503(ErrUnexpectedResponseCode) error
241 }
242
243 // ErrTimeOut is the error type returned when an operations times out.
244 type ErrTimeOut struct {
245         BaseError
246 }
247
248 func (e ErrTimeOut) Error() string {
249         e.DefaultErrString = "A time out occurred"
250         return e.choseErrString()
251 }
252
253 // ErrUnableToReauthenticate is the error type returned when reauthentication fails.
254 type ErrUnableToReauthenticate struct {
255         BaseError
256         ErrOriginal error
257 }
258
259 func (e ErrUnableToReauthenticate) Error() string {
260         e.DefaultErrString = fmt.Sprintf("Unable to re-authenticate: %s", e.ErrOriginal)
261         return e.choseErrString()
262 }
263
264 // ErrErrorAfterReauthentication is the error type returned when reauthentication
265 // succeeds, but an error occurs afterword (usually an HTTP error).
266 type ErrErrorAfterReauthentication struct {
267         BaseError
268         ErrOriginal error
269 }
270
271 func (e ErrErrorAfterReauthentication) Error() string {
272         e.DefaultErrString = fmt.Sprintf("Successfully re-authenticated, but got error executing request: %s", e.ErrOriginal)
273         return e.choseErrString()
274 }
275
276 // ErrServiceNotFound is returned when no service in a service catalog matches
277 // the provided EndpointOpts. This is generally returned by provider service
278 // factory methods like "NewComputeV2()" and can mean that a service is not
279 // enabled for your account.
280 type ErrServiceNotFound struct {
281         BaseError
282 }
283
284 func (e ErrServiceNotFound) Error() string {
285         e.DefaultErrString = "No suitable service could be found in the service catalog."
286         return e.choseErrString()
287 }
288
289 // ErrEndpointNotFound is returned when no available endpoints match the
290 // provided EndpointOpts. This is also generally returned by provider service
291 // factory methods, and usually indicates that a region was specified
292 // incorrectly.
293 type ErrEndpointNotFound struct {
294         BaseError
295 }
296
297 func (e ErrEndpointNotFound) Error() string {
298         e.DefaultErrString = "No suitable endpoint could be found in the service catalog."
299         return e.choseErrString()
300 }
301
302 // ErrResourceNotFound is the error when trying to retrieve a resource's
303 // ID by name and the resource doesn't exist.
304 type ErrResourceNotFound struct {
305         BaseError
306         Name         string
307         ResourceType string
308 }
309
310 func (e ErrResourceNotFound) Error() string {
311         e.DefaultErrString = fmt.Sprintf("Unable to find %s with name %s", e.ResourceType, e.Name)
312         return e.choseErrString()
313 }
314
315 // ErrMultipleResourcesFound is the error when trying to retrieve a resource's
316 // ID by name and multiple resources have the user-provided name.
317 type ErrMultipleResourcesFound struct {
318         BaseError
319         Name         string
320         Count        int
321         ResourceType string
322 }
323
324 func (e ErrMultipleResourcesFound) Error() string {
325         e.DefaultErrString = fmt.Sprintf("Found %d %ss matching %s", e.Count, e.ResourceType, e.Name)
326         return e.choseErrString()
327 }
328
329 // ErrUnexpectedType is the error when an unexpected type is encountered
330 type ErrUnexpectedType struct {
331         BaseError
332         Expected string
333         Actual   string
334 }
335
336 func (e ErrUnexpectedType) Error() string {
337         e.DefaultErrString = fmt.Sprintf("Expected %s but got %s", e.Expected, e.Actual)
338         return e.choseErrString()
339 }
340
341 func unacceptedAttributeErr(attribute string) string {
342         return fmt.Sprintf("The base Identity V3 API does not accept authentication by %s", attribute)
343 }
344
345 func redundantWithTokenErr(attribute string) string {
346         return fmt.Sprintf("%s may not be provided when authenticating with a TokenID", attribute)
347 }
348
349 func redundantWithUserID(attribute string) string {
350         return fmt.Sprintf("%s may not be provided when authenticating with a UserID", attribute)
351 }
352
353 // ErrAPIKeyProvided indicates that an APIKey was provided but can't be used.
354 type ErrAPIKeyProvided struct{ BaseError }
355
356 func (e ErrAPIKeyProvided) Error() string {
357         return unacceptedAttributeErr("APIKey")
358 }
359
360 // ErrTenantIDProvided indicates that a TenantID was provided but can't be used.
361 type ErrTenantIDProvided struct{ BaseError }
362
363 func (e ErrTenantIDProvided) Error() string {
364         return unacceptedAttributeErr("TenantID")
365 }
366
367 // ErrTenantNameProvided indicates that a TenantName was provided but can't be used.
368 type ErrTenantNameProvided struct{ BaseError }
369
370 func (e ErrTenantNameProvided) Error() string {
371         return unacceptedAttributeErr("TenantName")
372 }
373
374 // ErrUsernameWithToken indicates that a Username was provided, but token authentication is being used instead.
375 type ErrUsernameWithToken struct{ BaseError }
376
377 func (e ErrUsernameWithToken) Error() string {
378         return redundantWithTokenErr("Username")
379 }
380
381 // ErrUserIDWithToken indicates that a UserID was provided, but token authentication is being used instead.
382 type ErrUserIDWithToken struct{ BaseError }
383
384 func (e ErrUserIDWithToken) Error() string {
385         return redundantWithTokenErr("UserID")
386 }
387
388 // ErrDomainIDWithToken indicates that a DomainID was provided, but token authentication is being used instead.
389 type ErrDomainIDWithToken struct{ BaseError }
390
391 func (e ErrDomainIDWithToken) Error() string {
392         return redundantWithTokenErr("DomainID")
393 }
394
395 // ErrDomainNameWithToken indicates that a DomainName was provided, but token authentication is being used instead.s
396 type ErrDomainNameWithToken struct{ BaseError }
397
398 func (e ErrDomainNameWithToken) Error() string {
399         return redundantWithTokenErr("DomainName")
400 }
401
402 // ErrUsernameOrUserID indicates that neither username nor userID are specified, or both are at once.
403 type ErrUsernameOrUserID struct{ BaseError }
404
405 func (e ErrUsernameOrUserID) Error() string {
406         return "Exactly one of Username and UserID must be provided for password authentication"
407 }
408
409 // ErrDomainIDWithUserID indicates that a DomainID was provided, but unnecessary because a UserID is being used.
410 type ErrDomainIDWithUserID struct{ BaseError }
411
412 func (e ErrDomainIDWithUserID) Error() string {
413         return redundantWithUserID("DomainID")
414 }
415
416 // ErrDomainNameWithUserID indicates that a DomainName was provided, but unnecessary because a UserID is being used.
417 type ErrDomainNameWithUserID struct{ BaseError }
418
419 func (e ErrDomainNameWithUserID) Error() string {
420         return redundantWithUserID("DomainName")
421 }
422
423 // ErrDomainIDOrDomainName indicates that a username was provided, but no domain to scope it.
424 // It may also indicate that both a DomainID and a DomainName were provided at once.
425 type ErrDomainIDOrDomainName struct{ BaseError }
426
427 func (e ErrDomainIDOrDomainName) Error() string {
428         return "You must provide exactly one of DomainID or DomainName to authenticate by Username"
429 }
430
431 // ErrMissingPassword indicates that no password was provided and no token is available.
432 type ErrMissingPassword struct{ BaseError }
433
434 func (e ErrMissingPassword) Error() string {
435         return "You must provide a password to authenticate"
436 }
437
438 // ErrScopeDomainIDOrDomainName indicates that a domain ID or Name was required in a Scope, but not present.
439 type ErrScopeDomainIDOrDomainName struct{ BaseError }
440
441 func (e ErrScopeDomainIDOrDomainName) Error() string {
442         return "You must provide exactly one of DomainID or DomainName in a Scope with ProjectName"
443 }
444
445 // ErrScopeProjectIDOrProjectName indicates that both a ProjectID and a ProjectName were provided in a Scope.
446 type ErrScopeProjectIDOrProjectName struct{ BaseError }
447
448 func (e ErrScopeProjectIDOrProjectName) Error() string {
449         return "You must provide at most one of ProjectID or ProjectName in a Scope"
450 }
451
452 // ErrScopeProjectIDAlone indicates that a ProjectID was provided with other constraints in a Scope.
453 type ErrScopeProjectIDAlone struct{ BaseError }
454
455 func (e ErrScopeProjectIDAlone) Error() string {
456         return "ProjectID must be supplied alone in a Scope"
457 }
458
459 // ErrScopeEmpty indicates that no credentials were provided in a Scope.
460 type ErrScopeEmpty struct{ BaseError }
461
462 func (e ErrScopeEmpty) Error() string {
463         return "You must provide either a Project or Domain in a Scope"
464 }
465
466 // ErrAppCredMissingSecret indicates that no Application Credential Secret was provided with Application Credential ID or Name
467 type ErrAppCredMissingSecret struct{ BaseError }
468
469 func (e ErrAppCredMissingSecret) Error() string {
470         return "You must provide an Application Credential Secret"
471 }