rhc 1.2.7 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/rhc +6 -8
- data/bin/rhc-chk +23 -10
- data/features/domain.feature +1 -1
- data/features/lib/rhc_helper.rb +3 -2
- data/features/lib/rhc_helper/api.rb +7 -0
- data/features/lib/rhc_helper/app.rb +8 -10
- data/features/lib/rhc_helper/domain.rb +2 -1
- data/features/lib/rhc_helper/runnable.rb +2 -24
- data/features/sshkey.feature +3 -3
- data/features/step_definitions/cartridge_steps.rb +6 -6
- data/features/step_definitions/client_steps.rb +0 -1
- data/features/step_definitions/sshkey_steps.rb +2 -2
- data/features/support/before_hooks.rb +0 -1
- data/features/support/env.rb +5 -3
- data/lib/rhc-common.rb +1 -1
- data/lib/rhc.rb +9 -8
- data/lib/rhc/auth.rb +3 -0
- data/lib/rhc/auth/basic.rb +54 -0
- data/lib/rhc/cartridge_helpers.rb +11 -5
- data/lib/rhc/cli.rb +4 -2
- data/lib/rhc/command_runner.rb +35 -30
- data/lib/rhc/commands.rb +127 -18
- data/lib/rhc/commands/account.rb +24 -0
- data/lib/rhc/commands/alias.rb +1 -1
- data/lib/rhc/commands/app.rb +210 -209
- data/lib/rhc/commands/apps.rb +22 -0
- data/lib/rhc/commands/base.rb +10 -77
- data/lib/rhc/commands/cartridge.rb +35 -35
- data/lib/rhc/commands/domain.rb +20 -13
- data/lib/rhc/commands/git_clone.rb +30 -0
- data/lib/rhc/commands/{port-forward.rb → port_forward.rb} +3 -3
- data/lib/rhc/commands/server.rb +28 -16
- data/lib/rhc/commands/setup.rb +18 -1
- data/lib/rhc/commands/snapshot.rb +4 -4
- data/lib/rhc/commands/sshkey.rb +4 -18
- data/lib/rhc/commands/tail.rb +32 -9
- data/lib/rhc/config.rb +168 -99
- data/lib/rhc/context_helper.rb +22 -9
- data/lib/rhc/core_ext.rb +41 -1
- data/lib/rhc/exceptions.rb +21 -5
- data/lib/rhc/git_helpers.rb +81 -0
- data/lib/rhc/help_formatter.rb +21 -1
- data/lib/rhc/helpers.rb +222 -87
- data/lib/rhc/output_helpers.rb +94 -110
- data/lib/rhc/rest.rb +15 -198
- data/lib/rhc/rest/api.rb +88 -0
- data/lib/rhc/rest/application.rb +29 -30
- data/lib/rhc/rest/attributes.rb +27 -0
- data/lib/rhc/rest/base.rb +29 -33
- data/lib/rhc/rest/cartridge.rb +42 -20
- data/lib/rhc/rest/client.rb +351 -89
- data/lib/rhc/rest/domain.rb +7 -13
- data/lib/rhc/rest/gear_group.rb +1 -1
- data/lib/rhc/rest/key.rb +7 -2
- data/lib/rhc/rest/mock.rb +609 -0
- data/lib/rhc/rest/user.rb +6 -2
- data/lib/rhc/{ssh_key_helpers.rb → ssh_helpers.rb} +58 -28
- data/lib/rhc/{targz.rb → tar_gz.rb} +0 -0
- data/lib/rhc/usage_templates/command_help.erb +4 -1
- data/lib/rhc/usage_templates/help.erb +24 -11
- data/lib/rhc/usage_templates/options_help.erb +14 -0
- data/lib/rhc/wizard.rb +283 -213
- data/spec/keys/example.pem +23 -0
- data/spec/keys/example_private.pem +27 -0
- data/spec/keys/server.pem +19 -0
- data/spec/rest_spec_helper.rb +3 -371
- data/spec/rhc/auth_spec.rb +226 -0
- data/spec/rhc/cli_spec.rb +41 -14
- data/spec/rhc/command_spec.rb +44 -15
- data/spec/rhc/commands/account_spec.rb +41 -0
- data/spec/rhc/commands/alias_spec.rb +16 -15
- data/spec/rhc/commands/app_spec.rb +115 -92
- data/spec/rhc/commands/apps_spec.rb +39 -0
- data/spec/rhc/commands/cartridge_spec.rb +134 -112
- data/spec/rhc/commands/domain_spec.rb +31 -86
- data/spec/rhc/commands/git_clone_spec.rb +56 -0
- data/spec/rhc/commands/{port-forward_spec.rb → port_forward_spec.rb} +27 -32
- data/spec/rhc/commands/server_spec.rb +28 -3
- data/spec/rhc/commands/setup_spec.rb +29 -11
- data/spec/rhc/commands/snapshot_spec.rb +4 -3
- data/spec/rhc/commands/sshkey_spec.rb +24 -56
- data/spec/rhc/commands/tail_spec.rb +26 -9
- data/spec/rhc/commands/threaddump_spec.rb +12 -11
- data/spec/rhc/config_spec.rb +211 -164
- data/spec/rhc/context_spec.rb +2 -0
- data/spec/rhc/helpers_spec.rb +242 -46
- data/spec/rhc/rest_application_spec.rb +42 -28
- data/spec/rhc/rest_client_spec.rb +110 -93
- data/spec/rhc/rest_spec.rb +220 -131
- data/spec/rhc/targz_spec.rb +1 -1
- data/spec/rhc/wizard_spec.rb +435 -624
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +140 -6
- data/spec/wizard_spec_helper.rb +326 -0
- metadata +163 -143
- data/lib/rhc/client.rb +0 -17
- data/lib/rhc/git_helper.rb +0 -59
data/lib/rhc/output_helpers.rb
CHANGED
@@ -30,98 +30,101 @@ module RHC
|
|
30
30
|
not @issues.nil?
|
31
31
|
end
|
32
32
|
|
33
|
-
#---------------------------
|
34
|
-
# Domain information
|
35
|
-
#---------------------------
|
36
|
-
|
37
|
-
# This is a little different because we don't want to recreate the display_app function
|
38
|
-
def display_domain(domain)
|
39
|
-
say "No domain exists. You can use 'rhc domain create' to create a namespace for applications." and return unless domain
|
40
|
-
header "Applications in %s" % domain.id do
|
41
|
-
domain.applications.each do |a|
|
42
|
-
display_app(a,a.cartridges,a.scalable_carts.first)
|
43
|
-
end.blank? and say "No applications. You can use 'rhc app create' to create new applications."
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
33
|
#---------------------------
|
48
34
|
# Application information
|
49
35
|
#---------------------------
|
50
|
-
def display_app(app,cartridges = nil
|
51
|
-
heading = "%s @ %s" % [app.name, app.app_url]
|
36
|
+
def display_app(app,cartridges = nil)
|
37
|
+
heading = "%s @ %s (uuid: %s)" % [app.name, app.app_url, app.uuid]
|
52
38
|
paragraph do
|
53
39
|
header heading do
|
54
|
-
|
40
|
+
section(:bottom => 1) do
|
41
|
+
display_app_properties(
|
42
|
+
app,
|
43
|
+
:creation_time,
|
44
|
+
:gear_info,
|
45
|
+
:git_url,
|
46
|
+
:initial_git_url,
|
47
|
+
:ssh_string,
|
48
|
+
:aliases)
|
49
|
+
end
|
55
50
|
display_included_carts(cartridges) if cartridges
|
56
|
-
display_scaling_info(app,scalable_cart) if scalable_cart
|
57
51
|
end
|
58
52
|
end
|
59
53
|
end
|
60
54
|
|
61
55
|
def display_app_properties(app,*properties)
|
62
56
|
say_table \
|
63
|
-
|
57
|
+
nil,
|
64
58
|
get_properties(app,*properties),
|
65
59
|
:delete => true
|
66
60
|
end
|
67
61
|
|
68
62
|
def display_included_carts(carts)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
say_table \
|
76
|
-
"Cartridges",
|
77
|
-
properties,
|
78
|
-
:preserve_keys => true
|
63
|
+
carts.each do |c|
|
64
|
+
section(:bottom => 1) do
|
65
|
+
display_cart(c)
|
66
|
+
end
|
67
|
+
end
|
79
68
|
end
|
80
69
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
properties = "Scaled x%d (minimum: %s, maximum: %s) with %s on %s gears" %
|
88
|
-
[properties.values_at(*values), app.gear_profile].flatten
|
70
|
+
def format_cart_header(cart)
|
71
|
+
[
|
72
|
+
cart.name,
|
73
|
+
cart.name != cart.display_name ? "(#{cart.display_name})" : nil,
|
74
|
+
].compact.join(' ')
|
75
|
+
end
|
89
76
|
|
90
|
-
|
91
|
-
|
92
|
-
|
77
|
+
def format_scaling_info(scaling)
|
78
|
+
"x%d (minimum: %s, maximum: %s) on %s gears" %
|
79
|
+
[:current_scale, :scales_from, :scales_to, :gear_profile].map{ |key| format_value(key, scaling[key]) } if scaling
|
80
|
+
end
|
81
|
+
def format_cart_gears(cart)
|
82
|
+
if cart.scalable?
|
83
|
+
format_scaling_info(cart.scaling)
|
84
|
+
elsif cart.shares_gears?
|
85
|
+
"Located with #{cart.collocated_with.join(", ")}"
|
86
|
+
else
|
87
|
+
"%d %s" % [format_value(:current_scale, cart.current_scale), format_value(:gear_profile, cart.gear_profile)]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
def format_gear_info(info)
|
91
|
+
"%d (defaults to %s)" %
|
92
|
+
[:gear_count, :gear_profile].map{ |key| format_value(key, info[key]) } if info
|
93
93
|
end
|
94
94
|
|
95
95
|
#---------------------------
|
96
96
|
# Cartridge information
|
97
97
|
#---------------------------
|
98
98
|
|
99
|
-
def display_cart(cart,properties
|
99
|
+
def display_cart(cart, *properties)
|
100
100
|
@table_displayed = false
|
101
|
-
header cart.name do
|
102
|
-
display_cart_properties(cart,properties) if properties
|
103
|
-
display_cart_scaling_info(cart) if cart.scalable?
|
104
|
-
# Commenting this out for US2438
|
105
|
-
# display_cart_storage_info(cart) if cart.additional_gear_storage > 0
|
106
|
-
display_no_info("cartridge") unless @table_displayed
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def display_cart_properties(cart,properties)
|
111
|
-
# We need to actually access the cart because it's not a simple hash
|
112
|
-
properties = get_properties(cart,*properties.keys) do |prop|
|
113
|
-
cart.property(:cart_data,prop)["value"]
|
114
|
-
end
|
115
101
|
|
116
102
|
say_table \
|
117
|
-
|
118
|
-
properties
|
103
|
+
format_cart_header(cart),
|
104
|
+
get_properties(cart, *properties).
|
105
|
+
concat([[cart.scalable? ? :scaling : :gears, format_cart_gears(cart)]]).
|
106
|
+
concat(cart.properties.map{ |p| ["#{table_heading(p['name'])}:", p['value']] }.sort{ |a,b| a[0] <=> b[0] }),
|
107
|
+
:delete => true
|
108
|
+
display_no_info("cartridge") unless @table_displayed
|
119
109
|
end
|
120
110
|
|
121
|
-
def
|
122
|
-
|
123
|
-
|
124
|
-
|
111
|
+
def display_key(key, *properties)
|
112
|
+
properties = [:fingerprint, :visible_to_ssh?] if properties.empty?
|
113
|
+
say_table(
|
114
|
+
properties.include?(:name) ? nil : format_key_header(key),
|
115
|
+
get_properties(key, *properties),
|
116
|
+
{
|
117
|
+
:delete => true,
|
118
|
+
:color => (:green if properties.include?(:visible_to_ssh?) && key.visible_to_ssh?),
|
119
|
+
}
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
def format_key_header(key)
|
124
|
+
[
|
125
|
+
key.name,
|
126
|
+
"(type: #{key.type})",
|
127
|
+
].compact.join(' ')
|
125
128
|
end
|
126
129
|
|
127
130
|
=begin
|
@@ -147,91 +150,72 @@ module RHC
|
|
147
150
|
def display_no_info(type)
|
148
151
|
say_table \
|
149
152
|
nil,
|
150
|
-
["This #{type} has no information to show"]
|
153
|
+
[["This #{type} has no information to show"]]
|
151
154
|
end
|
152
155
|
|
153
156
|
private
|
154
157
|
def say_table(heading,values,opts = {})
|
155
158
|
@table_displayed = true
|
156
|
-
table = make_table(values,opts)
|
157
159
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
160
|
+
values = values.to_a if values.is_a? Hash
|
161
|
+
values.delete_if do |arr|
|
162
|
+
arr[0] = "#{table_heading(arr.first)}:" if arr[0].is_a? Symbol
|
163
|
+
opts[:delete] and arr.last.blank?
|
164
|
+
end
|
165
|
+
|
166
|
+
table = self.table(values)
|
167
|
+
table = table.map{ |s| color(s, opts[:color]) } if opts[:color]
|
165
168
|
|
166
169
|
# Make sure we nest properly
|
167
170
|
if heading
|
168
|
-
header
|
169
|
-
|
171
|
+
header(heading, opts) do
|
172
|
+
say table
|
170
173
|
end
|
171
174
|
else
|
172
|
-
|
175
|
+
say table
|
173
176
|
end
|
174
177
|
end
|
175
178
|
|
176
179
|
# This uses the array of properties to retrieve them from an object
|
177
180
|
def get_properties(object,*properties)
|
178
|
-
|
181
|
+
properties.map do |prop|
|
179
182
|
# Either send the property to the object or yield it
|
180
183
|
value = block_given? ? yield(prop) : object.send(prop)
|
181
184
|
# Some values (like date) need some special handling
|
182
|
-
value = format_value(prop,value)
|
183
185
|
|
184
|
-
[prop,value]
|
185
|
-
end
|
186
|
+
[prop, format_value(prop,value)]
|
187
|
+
end
|
186
188
|
end
|
187
189
|
|
188
190
|
# Format some special values
|
189
191
|
def format_value(prop,value)
|
190
192
|
case prop
|
193
|
+
when :plan_id
|
194
|
+
case value
|
195
|
+
when 'freeshift' then 'FreeShift'
|
196
|
+
when 'megashift' then 'MegaShift'
|
197
|
+
else value && value.capitalize || nil
|
198
|
+
end
|
199
|
+
when :visible_to_ssh?
|
200
|
+
value || nil
|
191
201
|
when :creation_time
|
192
202
|
date(value)
|
193
203
|
when :scales_from,:scales_to
|
194
|
-
(value == -1 ? "available
|
204
|
+
(value == -1 ? "available" : value)
|
205
|
+
when :gear_info
|
206
|
+
format_gear_info(value)
|
195
207
|
=begin
|
196
208
|
# Commenting this out for US2438
|
197
209
|
when :base_gear_storage,:additional_gear_storage
|
198
210
|
((value.nil? or value == 0) ? "None" : "#{value}GB")
|
199
211
|
=end
|
200
212
|
when :aliases
|
201
|
-
value.join ' '
|
213
|
+
value.join ', '
|
202
214
|
else
|
203
|
-
value
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
# Make the rows for the table
|
208
|
-
# If we pass a hash, it will manipulate it into a nice table
|
209
|
-
# Arrays and single vars will just be passed back as arrays
|
210
|
-
def make_table(values,opts = {})
|
211
|
-
case values
|
212
|
-
when Hash
|
213
|
-
# Loop through the values in case we need to fix them
|
214
|
-
_values = values.inject({}) do |h,(k,v)|
|
215
|
-
# Format the keys based on the table_heading function
|
216
|
-
# If we pass :preserve_keys, we leave them alone (like for cart names)
|
217
|
-
key = opts[:preserve_keys] ? k : table_heading(k)
|
218
|
-
|
219
|
-
# Replace empty or nil values with spaces
|
220
|
-
# If we pass :delete, we assume those are not needed
|
221
|
-
if v.blank?
|
222
|
-
h[key] = "" unless opts[:delete]
|
223
|
-
else
|
224
|
-
h[key] = v.to_s
|
225
|
-
end
|
226
|
-
h
|
215
|
+
case value
|
216
|
+
when Array then value.join(', ')
|
217
|
+
else value
|
227
218
|
end
|
228
|
-
# Join the values into rows
|
229
|
-
table _values, :join => " = "
|
230
|
-
# Create a simple array
|
231
|
-
when Array
|
232
|
-
values
|
233
|
-
else
|
234
|
-
[values]
|
235
219
|
end
|
236
220
|
end
|
237
221
|
end
|
data/lib/rhc/rest.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'rest-client'
|
3
|
-
|
4
1
|
module RHC
|
5
2
|
module Rest
|
6
3
|
|
4
|
+
autoload :Base, 'rhc/rest/base'
|
5
|
+
autoload :Attributes, 'rhc/rest/attributes'
|
6
|
+
|
7
|
+
autoload :Api, 'rhc/rest/api'
|
7
8
|
autoload :Application, 'rhc/rest/application'
|
8
9
|
autoload :Cartridge, 'rhc/rest/cartridge'
|
9
10
|
autoload :Client, 'rhc/rest/client'
|
@@ -14,7 +15,7 @@ module RHC
|
|
14
15
|
|
15
16
|
class Exception < RuntimeError
|
16
17
|
attr_reader :code
|
17
|
-
def initialize(message=nil, code=
|
18
|
+
def initialize(message=nil, code=1)
|
18
19
|
super(message)
|
19
20
|
@code = (Integer(code) rescue code)
|
20
21
|
end
|
@@ -48,6 +49,7 @@ module RHC
|
|
48
49
|
#The server has not found anything matching the Request-URI or the
|
49
50
|
#requested resource does not exist
|
50
51
|
class ResourceNotFoundException < ClientErrorException; end
|
52
|
+
class ApiEndpointNotFound < ResourceNotFoundException; end
|
51
53
|
|
52
54
|
#Exceptions thrown in case of an HTTP 422 is received.
|
53
55
|
class ValidationException < ClientErrorException
|
@@ -75,208 +77,23 @@ module RHC
|
|
75
77
|
#that authorization has been refused for those credentials.
|
76
78
|
class UnAuthorizedException < ClientErrorException; end
|
77
79
|
|
78
|
-
# Unreachable host, SSL Exception
|
80
|
+
# DEPRECATED Unreachable host, SSL Exception
|
79
81
|
class ResourceAccessException < Exception; end
|
80
82
|
|
81
83
|
#I/O Exceptions Connection timeouts, etc
|
82
84
|
class ConnectionException < Exception; end
|
83
85
|
class TimeoutException < ConnectionException; end
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
module Rest
|
88
|
-
#API_VERSION = '1.1'
|
89
|
-
@@headers = {:accept => :json}
|
90
|
-
#@@headers = {:accept => "application/json;version=#{RHC::Rest::VERSION}"}
|
91
|
-
|
92
|
-
def logger
|
93
|
-
Logger.new(STDOUT)
|
94
|
-
end
|
95
86
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
when 'domains'
|
102
|
-
domains = Array.new
|
103
|
-
data.each do |domain_json|
|
104
|
-
domains.push(Domain.new(domain_json, debug?))
|
105
|
-
end
|
106
|
-
return domains
|
107
|
-
when 'domain'
|
108
|
-
return Domain.new(data, debug?)
|
109
|
-
when 'applications'
|
110
|
-
apps = Array.new
|
111
|
-
data.each do |app_json|
|
112
|
-
apps.push(Application.new(app_json, debug?))
|
113
|
-
end
|
114
|
-
return apps
|
115
|
-
when 'application'
|
116
|
-
app = Application.new(data, debug?)
|
117
|
-
result['messages'].each do |message|
|
118
|
-
app.add_message(message['text']) if message['field'].nil? or message['field'] == 'result'
|
119
|
-
end
|
120
|
-
return app
|
121
|
-
when 'cartridges'
|
122
|
-
carts = Array.new
|
123
|
-
data.each do |cart_json|
|
124
|
-
carts.push(Cartridge.new(cart_json, debug?))
|
125
|
-
end
|
126
|
-
return carts
|
127
|
-
when 'cartridge'
|
128
|
-
return Cartridge.new(data, debug?)
|
129
|
-
when 'user'
|
130
|
-
return User.new(data, debug?)
|
131
|
-
when 'keys'
|
132
|
-
keys = Array.new
|
133
|
-
data.each do |key_json|
|
134
|
-
keys.push(Key.new(key_json, debug?))
|
135
|
-
end
|
136
|
-
return keys
|
137
|
-
when 'key'
|
138
|
-
return Key.new(data, debug?)
|
139
|
-
when 'gear_groups'
|
140
|
-
gears = Array.new
|
141
|
-
data.each do |gear_json|
|
142
|
-
gears.push(GearGroup.new(gear_json, debug?))
|
143
|
-
end
|
144
|
-
return gears
|
145
|
-
else
|
146
|
-
data
|
87
|
+
class SSLConnectionFailed < ConnectionException
|
88
|
+
attr_reader :reason
|
89
|
+
def initialize(reason, message)
|
90
|
+
super message
|
91
|
+
@reason = reason
|
147
92
|
end
|
148
93
|
end
|
94
|
+
class CertificateVerificationFailed < SSLConnectionFailed; end
|
95
|
+
class SelfSignedCertificate < CertificateVerificationFailed; end
|
149
96
|
|
150
|
-
|
151
|
-
# user specified timeout takes presidence
|
152
|
-
options[:timeout] = $rest_timeout || options[:timeout]
|
153
|
-
options[:open_timeout] ||= (options[:timeout] || 4)
|
154
|
-
|
155
|
-
RestClient::Request.new options
|
156
|
-
end
|
157
|
-
|
158
|
-
def request(request, &block)
|
159
|
-
tried = 0
|
160
|
-
begin
|
161
|
-
debug "Request: #{request.inspect}" if debug?
|
162
|
-
begin
|
163
|
-
response = request.execute
|
164
|
-
ensure
|
165
|
-
debug "Response: #{response.inspect}" rescue nil if debug?
|
166
|
-
end
|
167
|
-
#set cookie
|
168
|
-
rh_sso = response.cookies['rh_sso']
|
169
|
-
if not rh_sso.nil?
|
170
|
-
@@headers["cookie"] = "rh_sso=#{rh_sso}"
|
171
|
-
end
|
172
|
-
if block_given?
|
173
|
-
yield response
|
174
|
-
else
|
175
|
-
parse_response(response) unless response.nil? or response.code == 204
|
176
|
-
end
|
177
|
-
rescue RestClient::RequestTimeout => e
|
178
|
-
raise TimeoutException.new(
|
179
|
-
"Connection to server timed out. "\
|
180
|
-
"It is possible the operation finished without being able "\
|
181
|
-
"to report success. Use 'rhc domain show' or 'rhc app show' "\
|
182
|
-
"to see the status of your applications.")
|
183
|
-
rescue RestClient::ServerBrokeConnection => e
|
184
|
-
raise ConnectionException.new(
|
185
|
-
"Connection to server got interrupted: #{e.message}")
|
186
|
-
rescue RestClient::BadGateway => e
|
187
|
-
debug "ERROR: Received bad gateway from server, will retry once if this is a GET" if debug?
|
188
|
-
retry if (tried += 1) < 2 && request.method.to_s.upcase == "GET"
|
189
|
-
raise ConnectionException.new(
|
190
|
-
"An error occurred while communicating with the server (#{e.message}). This problem may only be temporary."\
|
191
|
-
"#{RestClient.proxy.present? ? " Check that you have correctly specified your proxy server '#{RestClient.proxy}' as well as your OpenShift server '#{request.url}'." : " Check that you have correctly specified your OpenShift server '#{request.url}'."}")
|
192
|
-
rescue RestClient::ExceptionWithResponse => e
|
193
|
-
process_error_response(e.response, request.url)
|
194
|
-
rescue SocketError => e
|
195
|
-
raise ConnectionException.new(
|
196
|
-
"Unable to connect to the server (#{e.message})."\
|
197
|
-
"#{RestClient.proxy.present? ? " Check that you have correctly specified your proxy server '#{RestClient.proxy}' as well as your OpenShift server '#{request.url}'." : " Check that you have correctly specified your OpenShift server '#{request.url}'."}")
|
198
|
-
rescue => e
|
199
|
-
logger.debug e.backtrace.join("\n ") if debug?
|
200
|
-
raise ResourceAccessException.new(
|
201
|
-
"Failed to access resource: #{e.message}")
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def generic_error(url)
|
206
|
-
ServerErrorException.new(
|
207
|
-
"The server did not respond correctly. This may be an issue "\
|
208
|
-
"with the server configuration or with your connection to the "\
|
209
|
-
"server (such as a Web proxy or firewall)."\
|
210
|
-
"#{RestClient.proxy.present? ? " Please verify that your proxy server is working correctly (#{RestClient.proxy}) and that you can access the OpenShift server #{url}" : "Please verify that you can access the OpenShift server #{url}"}",
|
211
|
-
129)
|
212
|
-
end
|
213
|
-
|
214
|
-
def process_error_response(response, url=nil)
|
215
|
-
messages = []
|
216
|
-
parse_error = nil
|
217
|
-
begin
|
218
|
-
result = RHC::Json.decode(response)
|
219
|
-
messages = Array(result['messages'])
|
220
|
-
rescue => e
|
221
|
-
logger.debug "Response did not include a message from server: #{e.message}" if debug?
|
222
|
-
parse_error = generic_error(url)
|
223
|
-
end
|
224
|
-
case response.code
|
225
|
-
when 401
|
226
|
-
raise UnAuthorizedException, "Not authenticated"
|
227
|
-
when 403
|
228
|
-
messages.each do |message|
|
229
|
-
if message['severity'].upcase == "ERROR"
|
230
|
-
raise RequestDeniedException, message['text']
|
231
|
-
end
|
232
|
-
end
|
233
|
-
raise RequestDeniedException.new("Forbidden")
|
234
|
-
when 404
|
235
|
-
messages.each do |message|
|
236
|
-
if message['severity'].upcase == "ERROR"
|
237
|
-
raise ResourceNotFoundException, message['text']
|
238
|
-
end
|
239
|
-
end
|
240
|
-
raise ResourceNotFoundException.new(url)
|
241
|
-
when 409
|
242
|
-
messages.each do |message|
|
243
|
-
if message['severity'] and message['severity'].upcase == "ERROR"
|
244
|
-
raise ValidationException.new(message['text'], message['field'], message['exit_code'])
|
245
|
-
end
|
246
|
-
end
|
247
|
-
when 422
|
248
|
-
e = nil
|
249
|
-
messages.each do |message|
|
250
|
-
if e and e.field == message["field"]
|
251
|
-
e.message << " #{message["text"]}"
|
252
|
-
else
|
253
|
-
e = ValidationException.new(message["text"], message["field"], message["exit_code"])
|
254
|
-
end
|
255
|
-
end
|
256
|
-
raise e || parse_error || ValidationException.new('Not valid')
|
257
|
-
when 400
|
258
|
-
messages.each do |message|
|
259
|
-
if message['severity'].upcase == "ERROR"
|
260
|
-
raise ClientErrorException, message['text']
|
261
|
-
end
|
262
|
-
end
|
263
|
-
when 500
|
264
|
-
messages.each do |message|
|
265
|
-
if message['severity'].upcase == "ERROR"
|
266
|
-
raise ServerErrorException.new(message['text'], message["exit_code"] ? message["exit_code"].to_i : nil)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
when 503
|
270
|
-
messages.each do |message|
|
271
|
-
if message['severity'].upcase == "ERROR"
|
272
|
-
raise ServiceUnavailableException, message['text']
|
273
|
-
end
|
274
|
-
end
|
275
|
-
raise ServiceUnavailableException
|
276
|
-
else
|
277
|
-
raise ServerErrorException, "Server returned an unexpected error code: #{response.code}"
|
278
|
-
end
|
279
|
-
raise parse_error || generic_error(url)
|
280
|
-
end
|
97
|
+
class SSLVersionRejected < SSLConnectionFailed; end
|
281
98
|
end
|
282
99
|
end
|