File tree Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -100,13 +100,10 @@ def initialize(options={})
100
100
end
101
101
102
102
require 'json'
103
- credentials = Fog ::Rackspace . authenticate ( options )
104
- @auth_token = credentials [ 'X-Auth-Token' ]
105
- uri = URI . parse ( credentials [ 'X-Server-Management-Url' ] )
106
- @host = uri . host
107
- @path = uri . path
108
- @port = uri . port
109
- @scheme = uri . scheme
103
+ @rackspace_api_key = options [ :rackspace_api_key ]
104
+ @rackspace_username = options [ :rackspace_username ]
105
+ @rackspace_auth_url = options [ :rackspace_auth_url ]
106
+ authenticate
110
107
@connection = Fog ::Connection . new ( "#{ @scheme } ://#{ @host } :#{ @port } " , options [ :persistent ] )
111
108
end
112
109
@@ -124,6 +121,13 @@ def request(params)
124
121
:host => @host ,
125
122
:path => "#{ @path } /#{ params [ :path ] } "
126
123
} ) )
124
+ rescue Excon ::Errors ::Unauthorized => error
125
+ if JSON . parse ( response . body ) [ 'unauthorized' ] [ 'message' ] == 'Invalid authentication token. Please renew.'
126
+ authenticate
127
+ retry
128
+ else
129
+ raise error
130
+ end
127
131
rescue Excon ::Errors ::HTTPStatusError => error
128
132
raise case error
129
133
when Excon ::Errors ::NotFound
@@ -138,6 +142,23 @@ def request(params)
138
142
response
139
143
end
140
144
145
+ private
146
+
147
+ def authenticate
148
+ options = {
149
+ :rackspace_api_key => @rackspace_api_key ,
150
+ :rackspace_username => @rackspace_username ,
151
+ :rackspace_auth_url => @rackspace_auth_url
152
+ }
153
+ credentials = Fog ::Rackspace . authenticate ( options )
154
+ @auth_token = credentials [ 'X-Auth-Token' ]
155
+ uri = URI . parse ( credentials [ 'X-Server-Management-Url' ] )
156
+ @host = uri . host
157
+ @path = uri . path
158
+ @port = uri . port
159
+ @scheme = uri . scheme
160
+ end
161
+
141
162
end
142
163
end
143
164
end
You can’t perform that action at this time.
0 commit comments