rhc 1.12.4 → 1.13.6
Sign up to get free protection for your applications and to get access to all the features.
- data/autocomplete/rhc_bash +161 -9
- data/bin/rhc +2 -2
- data/features/env.feature +0 -0
- data/features/step_definitions/env_steps.rb +1 -0
- data/features/support/platform_support.rb +5 -5
- data/lib/rhc/cartridge_helpers.rb +19 -3
- data/lib/rhc/command_runner.rb +1 -1
- data/lib/rhc/commands/app.rb +32 -17
- data/lib/rhc/commands/base.rb +15 -19
- data/lib/rhc/commands/cartridge.rb +14 -9
- data/lib/rhc/commands/env.rb +146 -0
- data/lib/rhc/commands.rb +19 -7
- data/lib/rhc/exceptions.rb +25 -1
- data/lib/rhc/help_formatter.rb +2 -2
- data/lib/rhc/helpers.rb +29 -2
- data/lib/rhc/output_helpers.rb +19 -2
- data/lib/rhc/rest/application.rb +49 -3
- data/lib/rhc/rest/cartridge.rb +4 -4
- data/lib/rhc/rest/client.rb +41 -6
- data/lib/rhc/rest/environment_variable.rb +15 -0
- data/lib/rhc/rest/mock.rb +52 -20
- data/lib/rhc/rest.rb +24 -23
- data/lib/rhc/usage_templates/help.erb +4 -4
- data/spec/rhc/assets/env_vars.txt +7 -0
- data/spec/rhc/assets/env_vars_2.txt +1 -0
- data/spec/rhc/commands/app_spec.rb +51 -10
- data/spec/rhc/commands/cartridge_spec.rb +61 -9
- data/spec/rhc/commands/env_spec.rb +493 -0
- data/spec/rhc/helpers_spec.rb +25 -5
- data/spec/rhc/rest_spec.rb +4 -3
- metadata +16 -4
@@ -17,10 +17,10 @@ module RHC::Commands
|
|
17
17
|
(like Jenkins) or provide environment variables.
|
18
18
|
|
19
19
|
Use the 'cartridges' command to see a list of all available cartridges.
|
20
|
-
Add a new cartridge to your application with 'add-cartridge'. OpenShift
|
21
|
-
also supports downloading cartridges - pass a URL in place of the cartridge
|
22
|
-
name and we'll download and install that cartridge into your app. Keep
|
23
|
-
in mind that these cartridges receive no security updates. Note that
|
20
|
+
Add a new cartridge to your application with 'add-cartridge'. OpenShift
|
21
|
+
also supports downloading cartridges - pass a URL in place of the cartridge
|
22
|
+
name and we'll download and install that cartridge into your app. Keep
|
23
|
+
in mind that these cartridges receive no security updates. Note that
|
24
24
|
not all OpenShift servers allow downloaded cartridges.
|
25
25
|
|
26
26
|
For scalable applications, use the 'cartridge-scale' command on the web
|
@@ -29,8 +29,6 @@ module RHC::Commands
|
|
29
29
|
Commands that affect a cartridge within an application will affect all
|
30
30
|
gears the cartridge is installed to.
|
31
31
|
DESC
|
32
|
-
alias_action :"app cartridge", :root_command => true, :deprecated => true
|
33
|
-
default_action :list
|
34
32
|
|
35
33
|
summary "List available cartridges"
|
36
34
|
syntax ''
|
@@ -73,6 +71,7 @@ module RHC::Commands
|
|
73
71
|
syntax "<cartridge_type> [--namespace NAME] [--app NAME]"
|
74
72
|
option ["-n", "--namespace NAME"], "Namespace of the application you are adding the cartridge to", :context => :namespace_context, :required => true
|
75
73
|
option ["-a", "--app NAME"], "Application you are adding the cartridge to", :context => :app_context, :required => true
|
74
|
+
option ["-e", "--env VARIABLE=VALUE"], "Environment variable(s) to be set on this cartridge, or path to a file containing environment variables", :option_type => :list
|
76
75
|
argument :cart_type, "The type of the cartridge you are adding (run 'rhc cartridge list' to obtain a list of available cartridges)", ["-c", "--cartridge cart_type"]
|
77
76
|
alias_action :"app cartridge add", :root_command => true, :deprecated => true
|
78
77
|
def add(cart_type)
|
@@ -83,13 +82,19 @@ module RHC::Commands
|
|
83
82
|
say format_usage_message(cart) if cart.usage_rate?
|
84
83
|
|
85
84
|
rest_app = rest_client.find_application(options.namespace, options.app, :include => :cartridges)
|
85
|
+
|
86
|
+
cart.environment_variables = collect_env_vars(options.env).map { |item| item.to_hash } if options.env
|
87
|
+
|
86
88
|
rest_cartridge = rest_app.add_cartridge(cart)
|
87
89
|
|
88
90
|
success "done"
|
89
91
|
|
92
|
+
rest_cartridge.environment_variables = cart.environment_variables if cart.environment_variables.present?
|
93
|
+
|
90
94
|
paragraph{ display_cart(rest_cartridge) }
|
95
|
+
paragraph{ say "Use 'rhc env --help' to manage environment variable(s) on this cartridge and application." }
|
91
96
|
paragraph{ rest_cartridge.messages.each { |msg| success msg } }
|
92
|
-
|
97
|
+
|
93
98
|
0
|
94
99
|
end
|
95
100
|
|
@@ -188,10 +193,10 @@ module RHC::Commands
|
|
188
193
|
|
189
194
|
summary "Set the scale range for a cartridge"
|
190
195
|
description <<-DESC
|
191
|
-
Each cartridge capable of scaling may have a minimum and a maximum set, although within that range
|
196
|
+
Each cartridge capable of scaling may have a minimum and a maximum set, although within that range
|
192
197
|
each type of cartridge may make decisions to autoscale. Web cartridges will scale based on incoming
|
193
198
|
request traffic - see https://www.openshift.com/developers/scaling for more information. Non web
|
194
|
-
cartridges such as databases may require specific increments of scaling (1, 3, 5) in order to
|
199
|
+
cartridges such as databases may require specific increments of scaling (1, 3, 5) in order to
|
195
200
|
properly function. Please consult the cartridge documentation for more on specifics of scaling.
|
196
201
|
|
197
202
|
Set both values the same to guarantee a scale value. You may pecify both values with the argument
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'rhc/commands/base'
|
2
|
+
|
3
|
+
module RHC::Commands
|
4
|
+
class Env < Base
|
5
|
+
summary "Manages user-defined environment variables set on a given application"
|
6
|
+
syntax "<action>"
|
7
|
+
description <<-DESC
|
8
|
+
Manages the user-defined environment variables set on a given
|
9
|
+
application. To see a list of all environment variables use the command
|
10
|
+
'rhc list-env <application>'. Note that some predefined
|
11
|
+
cartridge-level environment variables can also be overriden,
|
12
|
+
but most variables provided by gears are read-only.
|
13
|
+
|
14
|
+
Type 'rhc set-env --help' for more details.
|
15
|
+
|
16
|
+
DESC
|
17
|
+
default_action :help
|
18
|
+
alias_action :"app env", :root_command => true
|
19
|
+
|
20
|
+
summary "Set one or more environment variable(s) to your application"
|
21
|
+
description <<-DESC
|
22
|
+
Set one or more environment variable(s) to your application.
|
23
|
+
Operands of the form 'VARIABLE=VALUE' set the environment
|
24
|
+
variable VARIABLE to value VALUE. Example:
|
25
|
+
|
26
|
+
rhc set-env VARIABLE1=VALUE1 VARIABLE2=VALUE2 -a myapp
|
27
|
+
|
28
|
+
Environment variables can also be set from a file containing one
|
29
|
+
or more VARIABLE=VALUE pairs (one per line). Example:
|
30
|
+
|
31
|
+
rhc set-env /path/to/file -a myapp
|
32
|
+
|
33
|
+
VALUE may be empty, in that case 'VARIABLE='. Setting a
|
34
|
+
variable to an empty value is different from unsetting it.
|
35
|
+
|
36
|
+
Some default cartridge-level variables can be overriden, but
|
37
|
+
variables provided by gears are read-only.
|
38
|
+
|
39
|
+
DESC
|
40
|
+
syntax "<VARIABLE=VALUE> [... <VARIABLE=VALUE>] [--namespace NAME] [--app NAME]"
|
41
|
+
argument :env, "Environment variable name and value pair separated by an equal (=) sign, e.g. VARIABLE=VALUE", ["-e", "--env VARIABLE=VALUE"], :optional => false, :arg_type => :list
|
42
|
+
option ["-a", "--app NAME"], "Application name (required)", :context => :app_context, :required => true
|
43
|
+
option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
|
44
|
+
option ["--confirm"], "Pass to confirm setting the environment variable(s)"
|
45
|
+
alias_action :add
|
46
|
+
def set(env)
|
47
|
+
rest_app = rest_client.find_application(options.namespace, options.app)
|
48
|
+
|
49
|
+
with_file = env.index {|item| File.file? item}
|
50
|
+
|
51
|
+
env_vars = []
|
52
|
+
env.each {|item| env_vars.concat(collect_env_vars(item))}
|
53
|
+
raise RHC::EnvironmentVariableNotProvidedException.new(
|
54
|
+
(with_file ?
|
55
|
+
"Environment variable(s) not found in the provided file(s).\n" :
|
56
|
+
"Environment variable(s) not provided.\n") <<
|
57
|
+
"Please provide at least one environment variable using the syntax VARIABLE=VALUE. VARIABLE can only contain letters, digits and underscore ('_') and can't begin with a digit.") if env_vars.empty?
|
58
|
+
|
59
|
+
if with_file
|
60
|
+
env_vars.each {|item| default_display_env_var(item.name, item.value)}
|
61
|
+
confirm_action "Do you want to set these environment variables on '#{rest_app.name}?"
|
62
|
+
end
|
63
|
+
|
64
|
+
say 'Setting environment variable(s) ... '
|
65
|
+
rest_app.set_environment_variables(env_vars)
|
66
|
+
success 'done'
|
67
|
+
|
68
|
+
0
|
69
|
+
end
|
70
|
+
|
71
|
+
summary "Remove one or more environment variable(s) currently set to your application"
|
72
|
+
description <<-DESC
|
73
|
+
Remove one or more environment variable(s) currently set to your
|
74
|
+
application. Setting a variable to an empty value is
|
75
|
+
different from unsetting it. When unsetting a default cartridge-
|
76
|
+
level variable previously overriden, the variable will be set
|
77
|
+
back to its default value.
|
78
|
+
|
79
|
+
DESC
|
80
|
+
syntax "<VARIABLE> [... <VARIABLE>] [--namespace NAME] [--app NAME]"
|
81
|
+
argument :env, "Name of the environment variable(s), e.g. VARIABLE", ["-e", "--env VARIABLE"], :optional => false, :arg_type => :list
|
82
|
+
option ["-a", "--app NAME"], "Application name (required)", :context => :app_context, :required => true
|
83
|
+
option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
|
84
|
+
option ["--confirm"], "Pass to confirm removing the environment variable"
|
85
|
+
alias_action :remove
|
86
|
+
def unset(env)
|
87
|
+
rest_app = rest_client.find_application(options.namespace, options.app)
|
88
|
+
|
89
|
+
warn 'Removing environment variables is a destructive operation that may result in loss of data.'
|
90
|
+
|
91
|
+
env.each do |e|
|
92
|
+
default_display_env_var(e)
|
93
|
+
end
|
94
|
+
|
95
|
+
confirm_action "Are you sure you wish to remove the environment variable(s) above from application '#{rest_app.name}'?"
|
96
|
+
say 'Removing environment variable(s) ... '
|
97
|
+
rest_app.unset_environment_variables(env)
|
98
|
+
success 'removed'
|
99
|
+
|
100
|
+
0
|
101
|
+
end
|
102
|
+
|
103
|
+
summary "List all environment variables set on the application"
|
104
|
+
description <<-DESC
|
105
|
+
List all user-defined environment variables set on the application.
|
106
|
+
Gear-level variables overriden by the 'rhc set-env' command
|
107
|
+
will also be listed.
|
108
|
+
|
109
|
+
DESC
|
110
|
+
syntax "<app> [--namespace NAME]"
|
111
|
+
argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
|
112
|
+
option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
|
113
|
+
option ["--table"], "Format the output list as a table"
|
114
|
+
option ["--quotes"], "Format the output list with double quotes for env var values"
|
115
|
+
def list(app)
|
116
|
+
rest_app = rest_client.find_application(options.namespace, app)
|
117
|
+
rest_env_vars = rest_app.environment_variables
|
118
|
+
|
119
|
+
pager
|
120
|
+
|
121
|
+
display_env_var_list(rest_env_vars, { :table => options.table, :quotes => options.quotes })
|
122
|
+
|
123
|
+
0
|
124
|
+
end
|
125
|
+
|
126
|
+
summary "Show the value of one or more environment variable(s) currently set to your application"
|
127
|
+
syntax "<VARIABLE> [... <VARIABLE>] [--namespace NAME] [--app NAME]"
|
128
|
+
argument :env, "Name of the environment variable(s), e.g. VARIABLE", ["-e", "--env VARIABLE"], :optional => false, :arg_type => :list
|
129
|
+
option ["-a", "--app NAME"], "Application name (required)", :context => :app_context, :required => true
|
130
|
+
option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
|
131
|
+
option ["--table"], "Format the output list as a table"
|
132
|
+
option ["--quotes"], "Format the output list with double quotes for env var values"
|
133
|
+
def show(env)
|
134
|
+
rest_app = rest_client.find_application(options.namespace, options.app)
|
135
|
+
rest_env_vars = rest_app.find_environment_variables(env)
|
136
|
+
|
137
|
+
pager
|
138
|
+
|
139
|
+
display_env_var_list(rest_env_vars, { :table => options.table, :quotes => options.quotes })
|
140
|
+
|
141
|
+
0
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
data/lib/rhc/commands.rb
CHANGED
@@ -15,16 +15,24 @@ module Commander
|
|
15
15
|
|
16
16
|
#
|
17
17
|
# Force proxy_option_struct to default to nil for values,
|
18
|
-
# backported for Commander 4.0.3
|
18
|
+
# backported for Commander 4.0.3
|
19
19
|
#
|
20
20
|
def proxy_option_struct
|
21
21
|
proxy_options.inject Options.new do |options, (option, value)|
|
22
22
|
# options that are present will evaluate to true
|
23
23
|
value = true if value.nil?
|
24
|
-
|
24
|
+
if proxy_options.select{ |item| item[0] == option }.length > 1
|
25
|
+
if options[option]
|
26
|
+
options[option] << value
|
27
|
+
else
|
28
|
+
options.__send__ :"#{option}=", [value]
|
29
|
+
end
|
30
|
+
else
|
31
|
+
options.__send__ :"#{option}=", value
|
32
|
+
end
|
25
33
|
options
|
26
34
|
end
|
27
|
-
end
|
35
|
+
end
|
28
36
|
|
29
37
|
def deprecated(as_alias=nil)
|
30
38
|
return false unless info
|
@@ -234,16 +242,16 @@ module RHC
|
|
234
242
|
|
235
243
|
c.when_called do |args, options|
|
236
244
|
deprecated!
|
237
|
-
|
245
|
+
|
238
246
|
config = c.instance_variable_get(:@config)
|
239
|
-
|
247
|
+
|
240
248
|
cmd = opts[:class].new
|
241
249
|
cmd.options = options
|
242
250
|
cmd.config = config
|
243
|
-
|
251
|
+
|
244
252
|
args = fill_arguments(cmd, options, args_metadata, options_metadata, args)
|
245
253
|
needs_configuration!(cmd, options, config)
|
246
|
-
|
254
|
+
|
247
255
|
return execute(cmd, :help, args) unless opts[:method]
|
248
256
|
execute(cmd, opts[:method], args)
|
249
257
|
end
|
@@ -269,6 +277,10 @@ module RHC
|
|
269
277
|
options_metadata.each do |option_meta|
|
270
278
|
arg = option_meta[:arg]
|
271
279
|
|
280
|
+
if arg && option_meta[:option_type] != :list && options[arg].is_a?(Array)
|
281
|
+
options[arg] = options[arg].last
|
282
|
+
end
|
283
|
+
|
272
284
|
# Check to see if we've provided a value for an option tagged as deprecated
|
273
285
|
if (!(val = options.__hash__[arg]).nil? && dep_info = option_meta[:deprecated])
|
274
286
|
# Get the arg for the correct option and what the value should be
|
data/lib/rhc/exceptions.rb
CHANGED
@@ -31,6 +31,30 @@ module RHC
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
class EnvironmentVariableNotFoundException < Exception
|
35
|
+
def initialize(message="Environment variable not found")
|
36
|
+
super message, 157
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class EnvironmentVariablesNotSupportedException < Exception
|
41
|
+
def initialize(message="Server does not support environment variables")
|
42
|
+
super message, 158
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class EnvironmentVariableNotProvidedException < Exception
|
47
|
+
def initialize(message="Environment variable not provided")
|
48
|
+
super message, 159
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class JenkinsNotInstalledOnServer < Exception
|
53
|
+
def initialize(message="There is no installed cartridge that exposes Jenkins")
|
54
|
+
super message, 160
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
34
58
|
class KeyNotFoundException < Exception
|
35
59
|
def initialize(message="SSHKey not found")
|
36
60
|
super message, 118
|
@@ -144,7 +168,7 @@ module RHC
|
|
144
168
|
def initialize
|
145
169
|
super "The server does not support operations on individual gears."
|
146
170
|
end
|
147
|
-
end
|
171
|
+
end
|
148
172
|
class ServerAPINotSupportedException < UnsupportedError
|
149
173
|
def initialize(min_version, current_version)
|
150
174
|
super "The server does not support this command (requires #{min_version}, found #{current_version})."
|
data/lib/rhc/help_formatter.rb
CHANGED
@@ -33,9 +33,9 @@ module RHC
|
|
33
33
|
|
34
34
|
def initialize(command, instance_commands, runner)
|
35
35
|
@command = command
|
36
|
-
@actions =
|
36
|
+
@actions =
|
37
37
|
if command.root?
|
38
|
-
instance_commands.collect do |command_name, command_class|
|
38
|
+
instance_commands.sort_by{ |c| c[0] }.collect do |command_name, command_class|
|
39
39
|
next if command_class.summary.nil?
|
40
40
|
m = /^#{command.name}[\-]([^ ]+)/.match(command_name)
|
41
41
|
# if we have a match and it is not an alias then we can use it
|
data/lib/rhc/helpers.rb
CHANGED
@@ -49,7 +49,7 @@ module RHC
|
|
49
49
|
s /= 1000
|
50
50
|
end
|
51
51
|
((s > 9 || s.modulo(1) < 0.1 ? '%d' : '%.1f') % s) + ' ' + PREFIX[i]
|
52
|
-
end
|
52
|
+
end
|
53
53
|
|
54
54
|
def date(s)
|
55
55
|
return nil unless s.present?
|
@@ -189,6 +189,7 @@ module RHC
|
|
189
189
|
:url => openshift_rest_endpoint.to_s,
|
190
190
|
:debug => options.debug,
|
191
191
|
:timeout => options.timeout,
|
192
|
+
:warn => self.class.instance_method(:warn).bind(self),
|
192
193
|
}.merge!(ssl_options).merge!(opts))
|
193
194
|
end
|
194
195
|
|
@@ -248,7 +249,7 @@ module RHC
|
|
248
249
|
#
|
249
250
|
def agree(*args, &block)
|
250
251
|
#args.push(interactive?.presence) if args.length == 1
|
251
|
-
block = lambda do |q|
|
252
|
+
block = lambda do |q|
|
252
253
|
q.validate = /\A(?:y|yes|n|no)\Z/i
|
253
254
|
end unless block_given?
|
254
255
|
super *args, &block
|
@@ -424,5 +425,31 @@ module RHC
|
|
424
425
|
|
425
426
|
[status, stdout, stderr]
|
426
427
|
end
|
428
|
+
|
429
|
+
def collect_env_vars(item)
|
430
|
+
return nil if item.blank?
|
431
|
+
|
432
|
+
env_vars = []
|
433
|
+
|
434
|
+
[item].flatten.each do |item|
|
435
|
+
if match = item.match(env_var_regex_pattern)
|
436
|
+
name, value = match.captures
|
437
|
+
env_vars << RHC::Rest::EnvironmentVariable.new({ :name => name, :value => value })
|
438
|
+
elsif File.file? item
|
439
|
+
File.readlines(item).each do |line|
|
440
|
+
if match = line.match(env_var_regex_pattern)
|
441
|
+
name, value = match.captures
|
442
|
+
env_vars << RHC::Rest::EnvironmentVariable.new({ :name => name, :value => value })
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
447
|
+
env_vars
|
448
|
+
end
|
449
|
+
|
450
|
+
def env_var_regex_pattern
|
451
|
+
/^([a-zA-Z_][\w]*)=(.*)$/
|
452
|
+
end
|
453
|
+
|
427
454
|
end
|
428
455
|
end
|
data/lib/rhc/output_helpers.rb
CHANGED
@@ -84,9 +84,10 @@ module RHC
|
|
84
84
|
get_properties(cart, *properties).
|
85
85
|
concat([[:downloaded_cartridge_url, cart.url]]).
|
86
86
|
concat([[cart.scalable? ? :scaling : :gears, format_cart_gears(cart)]]).
|
87
|
-
concat(cart.properties.map{ |p| ["#{table_heading(p['name'])}:", p['value']] }.sort{ |a,b| a[0] <=> b[0] })
|
87
|
+
concat(cart.properties.map{ |p| ["#{table_heading(p['name'])}:", p['value']] }.sort{ |a,b| a[0] <=> b[0] }).
|
88
|
+
concat(cart.environment_variables.present? ? [[:environment_variables, cart.environment_variables.map{|item| "#{item[:name]}=#{item[:value]}" }.sort.join(', ')]] : []),
|
88
89
|
:delete => true
|
89
|
-
|
90
|
+
|
90
91
|
say format_usage_message(cart) if cart.usage_rate?
|
91
92
|
end
|
92
93
|
|
@@ -134,6 +135,22 @@ module RHC
|
|
134
135
|
"This gear costs an additional $#{cart.usage_rate} per gear after the first 3 gears."
|
135
136
|
end
|
136
137
|
|
138
|
+
def default_display_env_var(env_var_name, env_var_value=nil)
|
139
|
+
info "#{env_var_name}#{env_var_value.nil? ? '' : '=' + env_var_value}"
|
140
|
+
end
|
141
|
+
|
142
|
+
def display_env_var_list(env_vars, opts={})
|
143
|
+
if env_vars.present?
|
144
|
+
if opts[:table]
|
145
|
+
say table(env_vars.collect{ |item| [item.name, opts[:quotes] ? "\"#{item.value}\"" : item.value] }, :header => ['Name', 'Value'])
|
146
|
+
else
|
147
|
+
env_vars.sort.each do |env_var|
|
148
|
+
default_display_env_var(env_var.name, opts[:quotes] ? "\"#{env_var.value}\"" : env_var.value)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
137
154
|
private
|
138
155
|
def format_table(heading,values,opts = {})
|
139
156
|
values = values.to_a if values.is_a? Hash
|
data/lib/rhc/rest/application.rb
CHANGED
@@ -24,13 +24,17 @@ module RHC
|
|
24
24
|
def add_cartridge(cart, options={})
|
25
25
|
debug "Adding cartridge #{name}"
|
26
26
|
clear_attribute :cartridges
|
27
|
-
cart =
|
28
|
-
if cart.is_a? String
|
27
|
+
cart =
|
28
|
+
if cart.is_a? String
|
29
29
|
{:name => cart}
|
30
30
|
elsif cart.respond_to? :[]
|
31
31
|
cart
|
32
32
|
else
|
33
|
-
cart.url ? {:url => cart.url} : {:name => cart.name}
|
33
|
+
c = cart.url ? {:url => cart.url} : {:name => cart.name}
|
34
|
+
if cart.respond_to?(:environment_variables) && cart.environment_variables.present?
|
35
|
+
c[:environment_variables] = cart.environment_variables
|
36
|
+
end
|
37
|
+
cart = c
|
34
38
|
end
|
35
39
|
|
36
40
|
if cart.respond_to?(:[]) and cart[:url] and !has_param?('ADD_CARTRIDGE', 'url')
|
@@ -121,6 +125,48 @@ module RHC
|
|
121
125
|
rest_method "THREAD_DUMP", :event => "thread-dump"
|
122
126
|
end
|
123
127
|
|
128
|
+
def environment_variables
|
129
|
+
debug "Getting all environment variables for application #{name}"
|
130
|
+
if supports? "LIST_ENVIRONMENT_VARIABLES"
|
131
|
+
rest_method "LIST_ENVIRONMENT_VARIABLES"
|
132
|
+
else
|
133
|
+
raise RHC::EnvironmentVariablesNotSupportedException.new
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def find_environment_variable(env_var_name)
|
138
|
+
find_environment_variables(env_var_name).first
|
139
|
+
end
|
140
|
+
|
141
|
+
def find_environment_variables(env_var_names=nil)
|
142
|
+
return environment_variables if env_var_names.nil?
|
143
|
+
env_var_names = [env_var_names].flatten
|
144
|
+
debug "Finding environment variable(s) #{env_var_names.inspect} in app #{@name}"
|
145
|
+
env_vars = environment_variables.select { |item| env_var_names.include? item.name }
|
146
|
+
raise RHC::EnvironmentVariableNotFoundException.new("Environment variable(s) #{env_var_names.join(', ')} can't be found in application #{name}.") if env_vars.empty?
|
147
|
+
env_vars
|
148
|
+
end
|
149
|
+
|
150
|
+
# @param [Array<RHC::Rest::EnvironmentVariable>] Array of RHC::Rest::EnvironmentVariable to be set
|
151
|
+
def set_environment_variables(env_vars=[])
|
152
|
+
debug "Adding environment variable(s) #{env_vars.inspect} for #{name}"
|
153
|
+
if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
|
154
|
+
rest_method "SET_UNSET_ENVIRONMENT_VARIABLES", :environment_variables => env_vars.map{|item| item.to_hash}
|
155
|
+
else
|
156
|
+
raise RHC::EnvironmentVariablesNotSupportedException.new
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# @param [Array<String>] Array of env var names like ['FOO', 'BAR']
|
161
|
+
def unset_environment_variables(env_vars=[])
|
162
|
+
debug "Removing environment variable(s) #{env_vars.inspect} for #{name}"
|
163
|
+
if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
|
164
|
+
rest_method "SET_UNSET_ENVIRONMENT_VARIABLES", :environment_variables => env_vars.map{|item| {:name => item}}
|
165
|
+
else
|
166
|
+
raise RHC::EnvironmentVariablesNotSupportedException.new
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
124
170
|
def add_alias(app_alias)
|
125
171
|
debug "Running add_alias for #{name}"
|
126
172
|
rest_method "ADD_ALIAS", :event => "add-alias", :alias => app_alias
|
data/lib/rhc/rest/cartridge.rb
CHANGED
@@ -3,9 +3,9 @@ module RHC
|
|
3
3
|
class Cartridge < Base
|
4
4
|
HIDDEN_TAGS = [:framework, :web_framework, :cartridge].map(&:to_s)
|
5
5
|
|
6
|
-
define_attr :type, :name, :display_name, :properties, :gear_profile, :status_messages, :scales_to, :scales_from, :scales_with,
|
7
|
-
:current_scale, :supported_scales_to, :supported_scales_from, :tags, :description, :collocated_with, :base_gear_storage,
|
8
|
-
:additional_gear_storage, :url
|
6
|
+
define_attr :type, :name, :display_name, :properties, :gear_profile, :status_messages, :scales_to, :scales_from, :scales_with,
|
7
|
+
:current_scale, :supported_scales_to, :supported_scales_from, :tags, :description, :collocated_with, :base_gear_storage,
|
8
|
+
:additional_gear_storage, :url, :environment_variables
|
9
9
|
|
10
10
|
def scalable?
|
11
11
|
supported_scales_to != supported_scales_from
|
@@ -138,7 +138,7 @@ module RHC
|
|
138
138
|
name = Rack::Utils.parse_nested_query(uri.query)['name'] if name.blank? && uri.query
|
139
139
|
name = File.basename(uri.path) if name.blank? && uri.path.present? && uri.path != '/'
|
140
140
|
name.presence || url
|
141
|
-
rescue
|
141
|
+
rescue
|
142
142
|
url
|
143
143
|
end
|
144
144
|
|
data/lib/rhc/rest/client.rb
CHANGED
@@ -4,6 +4,7 @@ require 'uri'
|
|
4
4
|
require 'logger'
|
5
5
|
require 'httpclient'
|
6
6
|
require 'benchmark'
|
7
|
+
require 'set'
|
7
8
|
|
8
9
|
module RHC
|
9
10
|
module Rest
|
@@ -464,12 +465,7 @@ module RHC
|
|
464
465
|
type = result['type']
|
465
466
|
data = result['data'] || {}
|
466
467
|
|
467
|
-
|
468
|
-
messages = Array(result['messages']).map do |m|
|
469
|
-
m['text'] if (m['field'] == 'result' || m['severity'] == 'result') && (m['severity'] != 'debug' || debug?)
|
470
|
-
end.compact.map!(&:chomp)
|
471
|
-
data.each{ |d| d['messages'] = messages } if data.is_a?(Array)
|
472
|
-
data['messages'] = messages if data.is_a?(Hash)
|
468
|
+
parse_messages result, data
|
473
469
|
|
474
470
|
case type
|
475
471
|
when 'domains'
|
@@ -498,11 +494,50 @@ module RHC
|
|
498
494
|
data.map{ |json| GearGroup.new(json, self) }
|
499
495
|
when 'aliases'
|
500
496
|
data.map{ |json| Alias.new(json, self) }
|
497
|
+
when 'environment-variables'
|
498
|
+
data.map{ |json| EnvironmentVariable.new(json, self) }
|
501
499
|
else
|
502
500
|
data
|
503
501
|
end
|
504
502
|
end
|
505
503
|
|
504
|
+
def parse_messages(result, data)
|
505
|
+
warnings, messages = Array(result['messages']).inject([[],[]]) do |a, m|
|
506
|
+
severity, field, text = m.values_at('severity', 'field', 'text')
|
507
|
+
text = text.chomp
|
508
|
+
case severity
|
509
|
+
when 'warning'
|
510
|
+
a[0] << text
|
511
|
+
when 'debug'
|
512
|
+
a[1] << text if debug?
|
513
|
+
when 'info'
|
514
|
+
a[1] << text if debug? || field == 'result'
|
515
|
+
else
|
516
|
+
a[1] << text
|
517
|
+
end
|
518
|
+
a
|
519
|
+
end
|
520
|
+
|
521
|
+
if data.is_a?(Array)
|
522
|
+
data.each do |d|
|
523
|
+
d['messages'] = messages
|
524
|
+
d['warnings'] = warnings
|
525
|
+
end
|
526
|
+
elsif data.is_a?(Hash)
|
527
|
+
data['messages'] = messages
|
528
|
+
data['warnings'] = warnings
|
529
|
+
end
|
530
|
+
|
531
|
+
warnings.each do |warning|
|
532
|
+
# Prevent repeated warnings during the same client session
|
533
|
+
if !defined?(@warning_map) || !@warning_map.include?(warning)
|
534
|
+
@warning_map ||= Set.new
|
535
|
+
@warning_map << warning
|
536
|
+
warn warning
|
537
|
+
end
|
538
|
+
end if respond_to? :warn
|
539
|
+
end
|
540
|
+
|
506
541
|
def raise_generic_error(url, client)
|
507
542
|
raise ServerErrorException.new(generic_error_message(url, client), 129)
|
508
543
|
end
|