rhc 1.24.4 → 1.25.2
Sign up to get free protection for your applications and to get access to all the features.
- data/features/core_feature.rb +1 -0
- data/lib/rhc/rest/base.rb +5 -3
- data/lib/rhc/rest/client.rb +9 -6
- data/lib/rhc/rest/mock.rb +5 -5
- data/spec/direct_execution_helper.rb +26 -0
- data/spec/rhc/rest_client_spec.rb +6 -0
- metadata +5 -5
data/features/core_feature.rb
CHANGED
data/lib/rhc/rest/base.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'uri'
|
2
2
|
|
3
3
|
module RHC
|
4
4
|
module Rest
|
@@ -8,6 +8,8 @@ module RHC
|
|
8
8
|
|
9
9
|
define_attr :messages
|
10
10
|
|
11
|
+
URI_ESCAPE_REGEX = Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")
|
12
|
+
|
11
13
|
def initialize(attrs=nil, client=nil)
|
12
14
|
@attributes = (attrs || {}).stringify_keys!
|
13
15
|
@attributes['messages'] ||= []
|
@@ -22,7 +24,7 @@ module RHC
|
|
22
24
|
link = link(link_name)
|
23
25
|
raise "No link defined for #{link_name}" unless link
|
24
26
|
url = link['href']
|
25
|
-
url = url.gsub(/:\w+/) { |s|
|
27
|
+
url = url.gsub(/:\w+/) { |s| URI.escape(options[:params][s], URI_ESCAPE_REGEX) || s } if options[:params]
|
26
28
|
method = options[:method] || link['method']
|
27
29
|
|
28
30
|
result = client.request(options.merge({
|
@@ -53,7 +55,7 @@ module RHC
|
|
53
55
|
|
54
56
|
def link_href(sym, params=nil, resource=nil, &block)
|
55
57
|
if (l = link(sym)) && (h = l['href'])
|
56
|
-
h = h.gsub(/:\w+/){ |s| params[s].nil? ? s :
|
58
|
+
h = h.gsub(/:\w+/){ |s| params[s].nil? ? s : URI.escape(params[s], URI_ESCAPE_REGEX) } if params
|
57
59
|
h = "#{h}/#{resource}" if resource
|
58
60
|
return h
|
59
61
|
end
|
data/lib/rhc/rest/client.rb
CHANGED
@@ -199,12 +199,15 @@ module RHC
|
|
199
199
|
end
|
200
200
|
|
201
201
|
def link_show_application_by_domain_name(domain, application, *args)
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
202
|
+
if link = api.link_href(:SHOW_APPLICATION_BY_DOMAIN, {':domain_name' => domain, ':name' => application}, *args)
|
203
|
+
link
|
204
|
+
else
|
205
|
+
# Pre-1.5 API
|
206
|
+
(
|
207
|
+
[api.links['LIST_DOMAINS']['href']] +
|
208
|
+
([domain, "applications", application] + args).map{|s| URI.escape(s, RHC::Rest::Base::URI_ESCAPE_REGEX) }
|
209
|
+
).join("/")
|
210
|
+
end
|
208
211
|
end
|
209
212
|
|
210
213
|
def link_show_application_by_id(id, *args)
|
data/lib/rhc/rest/mock.rb
CHANGED
@@ -422,10 +422,10 @@ module RHC::Rest::Mock
|
|
422
422
|
|
423
423
|
def mock_client_links
|
424
424
|
mock_teams_links.concat([
|
425
|
-
['GET_USER', 'user
|
425
|
+
['GET_USER', 'user', 'get' ],
|
426
426
|
['ADD_DOMAIN', 'domains/add', 'post'],
|
427
|
-
['LIST_DOMAINS', 'domains
|
428
|
-
['LIST_CARTRIDGES', 'cartridges
|
427
|
+
['LIST_DOMAINS', 'domains', 'get' ],
|
428
|
+
['LIST_CARTRIDGES', 'cartridges', 'get' ]
|
429
429
|
])
|
430
430
|
end
|
431
431
|
|
@@ -454,7 +454,7 @@ module RHC::Rest::Mock
|
|
454
454
|
|
455
455
|
def mock_team_links(team_id='test_team')
|
456
456
|
[['GET', "team/#{team_id}", 'get' ],
|
457
|
-
['ADD_MEMBER', "team/#{team_id}/members
|
457
|
+
['ADD_MEMBER', "team/#{team_id}/members", 'post', {'optional_params' => [{'name' => 'id'}, {'name' => 'login'}], 'required_params' => [{'name' => 'role'}]} ],
|
458
458
|
['LIST_MEMBERS', "team/#{team_id}/update", 'get' ],
|
459
459
|
['UPDATE_MEMBERS', "team/#{team_id}/delete", 'patch', {'optional_params' => [{'name' => 'id'}, {'name' => 'login'}, {'name' => 'members'}] } ],
|
460
460
|
['LEAVE', "team/#{team_id}/delete", 'delete' ],
|
@@ -463,7 +463,7 @@ module RHC::Rest::Mock
|
|
463
463
|
|
464
464
|
def mock_domain_links(domain_id='test_domain')
|
465
465
|
[['ADD_APPLICATION', "domains/#{domain_id}/apps/add", 'post', {'optional_params' => [{'name' => 'environment_variables'}, {'name' => 'cartridges[][name]'}, {'name' => 'cartridges[][url]'}]} ],
|
466
|
-
['LIST_APPLICATIONS', "domains/#{domain_id}/apps
|
466
|
+
['LIST_APPLICATIONS', "domains/#{domain_id}/apps", 'get' ],
|
467
467
|
['UPDATE', "domains/#{domain_id}/update", 'put'],
|
468
468
|
['DELETE', "domains/#{domain_id}/delete", 'post']]
|
469
469
|
end
|
@@ -141,6 +141,32 @@ module RhcExecutionHelper
|
|
141
141
|
object.members.length.should == 1
|
142
142
|
end
|
143
143
|
|
144
|
+
def has_gears_available(gear_count=1, for_user=nil)
|
145
|
+
debug.puts "Ensuring user has at least #{gear_count} gears free" if debug?
|
146
|
+
|
147
|
+
c = for_user ? for_user.client : client
|
148
|
+
|
149
|
+
max_gears = c.user.max_gears
|
150
|
+
consumed_gears = c.user.consumed_gears
|
151
|
+
raise "User has max_gears=#{max_gears}, cannot make #{gear_count} gears available" if max_gears < gear_count
|
152
|
+
|
153
|
+
max_consumed = max_gears - gear_count
|
154
|
+
if consumed_gears <= max_consumed
|
155
|
+
debug.puts " user can use up to #{max_consumed} gears and is only using #{consumed_gears}" if debug?
|
156
|
+
return
|
157
|
+
end
|
158
|
+
|
159
|
+
delete_count = 0
|
160
|
+
c.owned_applications.sort_by(&:gear_count).reverse.each do |app|
|
161
|
+
if (consumed_gears - delete_count) > max_consumed
|
162
|
+
debug.puts " deleting app to free #{app.gear_count} gears" if debug?
|
163
|
+
delete_count += app.gear_count
|
164
|
+
debug.puts " user is now using #{consumed_gears - delete_count} gears" if debug?
|
165
|
+
app.destroy
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
144
170
|
def has_an_application(for_user=nil)
|
145
171
|
c = for_user ? for_user.client : client
|
146
172
|
debug.puts "Creating or reusing an app" if debug?
|
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
require 'stringio'
|
4
4
|
require 'rest_spec_helper'
|
5
5
|
require 'rhc/rest'
|
6
|
+
require 'uri'
|
6
7
|
|
7
8
|
module RHC
|
8
9
|
module Rest
|
@@ -368,6 +369,11 @@ module RHC
|
|
368
369
|
:status => 'not_found'
|
369
370
|
}, 404)
|
370
371
|
end
|
372
|
+
it "encodes application id correctly" do
|
373
|
+
url = client.link_show_application_by_domain_name("~[", "~]")
|
374
|
+
URI.parse(url)
|
375
|
+
url.should == "https://test.domain.com/domains/~%5B/applications/~%5D"
|
376
|
+
end
|
371
377
|
it "returns application object for nested application IDs" do
|
372
378
|
match = client.find_application(mock_domain, mock_app)
|
373
379
|
match.class.should == RHC::Rest::Application
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 119
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 25
|
9
|
+
- 2
|
10
|
+
version: 1.25.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Red Hat
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2014-05-
|
18
|
+
date: 2014-05-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: net-ssh
|