deis_client 1.5.1.dev6 → 1.5.1.dev7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/deis_client.rb +37 -31
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294b35c08130abe5681462bae18dc4cb6ec50f75
|
4
|
+
data.tar.gz: e4fd3eb53719b74fc8108b2ae005a85859c07342
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77d1663bbeee22927188a812536265f0672ff85fd77a0a9dc51af1bdad4d192ee02b7e71226a01c886268ed2d1ed74a36a4b2a4ddf3c838b5dc5c8f1f9707388
|
7
|
+
data.tar.gz: 1ee7e7c7283876966cfce733c5fefbaee2e6b5c682c14c7ab1a35a7640d6a0758bad4e3416db85774469fe06e1f86be0b496daa160ea16236bd040a42b561c67
|
data/lib/deis_client.rb
CHANGED
@@ -77,12 +77,13 @@ module Deis
|
|
77
77
|
|
78
78
|
def initialize(deis_url, username, password)
|
79
79
|
@http = Deis::ApiWrapper.new deis_url
|
80
|
-
@headers = {}
|
81
|
-
@auth = {username: username, password: password}
|
80
|
+
@headers = {'Content-Type' => 'application/json'}
|
81
|
+
@auth = { username: username, password: password }
|
82
82
|
end
|
83
83
|
|
84
84
|
def login
|
85
|
-
|
85
|
+
verb, path = @@methods[:login]
|
86
|
+
response = @http.public_send(verb, path, body: @auth)
|
86
87
|
|
87
88
|
raise AuthorizationError.new unless response.code == 200
|
88
89
|
|
@@ -95,91 +96,96 @@ module Deis
|
|
95
96
|
perform :apps
|
96
97
|
end
|
97
98
|
|
98
|
-
def create_app(id=nil)
|
99
|
+
def create_app(id = nil)
|
99
100
|
if id
|
100
|
-
perform :create_app, {id: id
|
101
|
+
perform :create_app, {}, id: id
|
101
102
|
else
|
102
103
|
perform :create_app
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
107
|
def delete_app(id)
|
107
|
-
perform :delete_app,
|
108
|
+
perform :delete_app, app: id
|
108
109
|
end
|
109
110
|
|
110
111
|
def app(id)
|
111
|
-
perform :app,
|
112
|
+
perform :app, app: id
|
112
113
|
end
|
113
114
|
|
114
115
|
def app_logs(id)
|
115
|
-
perform :app_logs,
|
116
|
+
perform :app_logs, app: id
|
116
117
|
end
|
117
118
|
|
118
119
|
def app_run(id, command)
|
119
|
-
perform :app_run, {app: id, command: command
|
120
|
+
perform :app_run, { app: id }, command: command
|
120
121
|
end
|
121
122
|
|
122
123
|
def containers(app_id)
|
123
|
-
perform :containers,
|
124
|
+
perform :containers, app: app_id
|
124
125
|
end
|
125
126
|
|
126
127
|
def scale(app_id, type_number_hash)
|
127
|
-
perform :scale,
|
128
|
+
perform :scale, { app: app_id }, type_number_hash
|
128
129
|
end
|
129
130
|
|
130
131
|
def config(app_id)
|
131
|
-
perform :config,
|
132
|
+
perform :config, app: app_id
|
132
133
|
end
|
133
134
|
|
134
135
|
def domains(app_id)
|
135
|
-
perform :domains,
|
136
|
+
perform :domains, app: app_id
|
136
137
|
end
|
137
138
|
|
138
139
|
def builds(app_id)
|
139
|
-
perform :builds,
|
140
|
+
perform :builds, app: app_id
|
140
141
|
end
|
141
142
|
|
142
143
|
def create_build(app_id, image)
|
143
|
-
perform :create_build, {app: app_id, image: image
|
144
|
+
perform :create_build, { app: app_id }, image: image
|
144
145
|
end
|
145
146
|
|
146
147
|
def releases(app_id)
|
147
|
-
perform :releases,
|
148
|
+
perform :releases, app: app_id
|
148
149
|
end
|
149
150
|
|
150
151
|
def release(app_id, release)
|
151
|
-
perform :releases,
|
152
|
+
perform :releases, app: app_id, release: release
|
152
153
|
end
|
153
154
|
|
154
155
|
def rollback_release(app_id, release)
|
155
|
-
perform :rollback_release, {app: app_id, release: release
|
156
|
+
perform :rollback_release, { app: app_id }, release: release
|
156
157
|
end
|
157
158
|
|
158
159
|
protected
|
159
160
|
|
160
|
-
def perform(method_sym, body={}, try_twice=true)
|
161
|
+
def perform(method_sym, interpolations = {}, body = {}, try_twice = true)
|
161
162
|
login unless @token
|
162
163
|
|
163
164
|
verb, path = @@methods[method_sym]
|
164
|
-
path = interpolate_path(path,
|
165
|
+
path = interpolate_path(path, interpolations)
|
165
166
|
|
166
167
|
options = {
|
167
168
|
headers: @headers,
|
168
|
-
body: body
|
169
|
+
body: body.to_json
|
169
170
|
}
|
170
|
-
|
171
|
+
|
172
|
+
begin
|
173
|
+
handle @http.public_send(verb, path, options)
|
174
|
+
rescue AuthorizationError => e
|
175
|
+
raise e unless try_twice
|
176
|
+
login
|
177
|
+
handle @http.public_send(verb, path, options)
|
178
|
+
end
|
171
179
|
end
|
172
180
|
|
173
|
-
def handle(response
|
181
|
+
def handle(response)
|
174
182
|
case response.code
|
175
183
|
when 200...300
|
176
184
|
response.parsed_response
|
177
|
-
when 401
|
178
|
-
raise AuthorizationError.new
|
179
|
-
login
|
180
|
-
perform method_sym, options, false
|
185
|
+
when 401
|
186
|
+
raise AuthorizationError.new
|
181
187
|
when 404
|
182
|
-
raise NotFound
|
188
|
+
raise NotFound.new
|
183
189
|
when 400...500
|
184
190
|
raise ClientError.new response.code, response.message, response: response
|
185
191
|
when 500...600
|
@@ -189,15 +195,15 @@ module Deis
|
|
189
195
|
end
|
190
196
|
end
|
191
197
|
|
192
|
-
def interpolate_path(path,
|
198
|
+
def interpolate_path(path, interpolations)
|
193
199
|
%r{/:(?<key>\w+)/?} =~ path
|
194
200
|
return path unless key
|
195
201
|
|
196
|
-
value =
|
202
|
+
value = interpolations[key.to_sym]
|
197
203
|
path[':' + key] = value
|
198
204
|
|
199
205
|
# this catched only one occurance of an key, so call recursively until nothing is found anymore
|
200
|
-
interpolate_path path,
|
206
|
+
interpolate_path path, interpolations
|
201
207
|
end
|
202
208
|
end
|
203
209
|
end
|