Ensure authenticate never re-auths.
Other API functions will support re-auth as a matter of course.
If an auth token expires, we need to re-authenticate to acquire a new
token. If re-authentication were itself to attempt re-auth, we
would end up in an endless loop.
If after authenticating gophercloud receives a 401 Unauthorized
response, then we must assume that the provided credentials are
incorrect.
diff --git a/global_context.go b/global_context.go
index c89ac17..9977aa8 100644
--- a/global_context.go
+++ b/global_context.go
@@ -1,5 +1,9 @@
package gophercloud
+import (
+ "github.com/racker/perigee"
+)
+
// globalContext is the, well, "global context."
// Most of this SDK is written in a manner to facilitate easier testing,
// which doesn't require all the configuration a real-world application would require.
@@ -46,3 +50,13 @@
func ServersApi(acc AccessProvider, criteria ApiCriteria) (CloudServersProvider, error) {
return globalContext.ServersApi(acc, criteria)
}
+
+// ActualResponseCode inspects a returned error, and discovers the actual response actual
+// response code that caused the error to be raised.
+func ActualResponseCode(e error) (int, error) {
+ err, ok := e.(*perigee.UnexpectedResponseCodeError)
+ if !ok {
+ return 0, ErrError
+ }
+ return err.Actual, nil
+}
\ No newline at end of file