rhc 1.2.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/bin/rhc +6 -8
  2. data/bin/rhc-chk +23 -10
  3. data/features/domain.feature +1 -1
  4. data/features/lib/rhc_helper.rb +3 -2
  5. data/features/lib/rhc_helper/api.rb +7 -0
  6. data/features/lib/rhc_helper/app.rb +8 -10
  7. data/features/lib/rhc_helper/domain.rb +2 -1
  8. data/features/lib/rhc_helper/runnable.rb +2 -24
  9. data/features/sshkey.feature +3 -3
  10. data/features/step_definitions/cartridge_steps.rb +6 -6
  11. data/features/step_definitions/client_steps.rb +0 -1
  12. data/features/step_definitions/sshkey_steps.rb +2 -2
  13. data/features/support/before_hooks.rb +0 -1
  14. data/features/support/env.rb +5 -3
  15. data/lib/rhc-common.rb +1 -1
  16. data/lib/rhc.rb +9 -8
  17. data/lib/rhc/auth.rb +3 -0
  18. data/lib/rhc/auth/basic.rb +54 -0
  19. data/lib/rhc/cartridge_helpers.rb +11 -5
  20. data/lib/rhc/cli.rb +4 -2
  21. data/lib/rhc/command_runner.rb +35 -30
  22. data/lib/rhc/commands.rb +127 -18
  23. data/lib/rhc/commands/account.rb +24 -0
  24. data/lib/rhc/commands/alias.rb +1 -1
  25. data/lib/rhc/commands/app.rb +210 -209
  26. data/lib/rhc/commands/apps.rb +22 -0
  27. data/lib/rhc/commands/base.rb +10 -77
  28. data/lib/rhc/commands/cartridge.rb +35 -35
  29. data/lib/rhc/commands/domain.rb +20 -13
  30. data/lib/rhc/commands/git_clone.rb +30 -0
  31. data/lib/rhc/commands/{port-forward.rb → port_forward.rb} +3 -3
  32. data/lib/rhc/commands/server.rb +28 -16
  33. data/lib/rhc/commands/setup.rb +18 -1
  34. data/lib/rhc/commands/snapshot.rb +4 -4
  35. data/lib/rhc/commands/sshkey.rb +4 -18
  36. data/lib/rhc/commands/tail.rb +32 -9
  37. data/lib/rhc/config.rb +168 -99
  38. data/lib/rhc/context_helper.rb +22 -9
  39. data/lib/rhc/core_ext.rb +41 -1
  40. data/lib/rhc/exceptions.rb +21 -5
  41. data/lib/rhc/git_helpers.rb +81 -0
  42. data/lib/rhc/help_formatter.rb +21 -1
  43. data/lib/rhc/helpers.rb +222 -87
  44. data/lib/rhc/output_helpers.rb +94 -110
  45. data/lib/rhc/rest.rb +15 -198
  46. data/lib/rhc/rest/api.rb +88 -0
  47. data/lib/rhc/rest/application.rb +29 -30
  48. data/lib/rhc/rest/attributes.rb +27 -0
  49. data/lib/rhc/rest/base.rb +29 -33
  50. data/lib/rhc/rest/cartridge.rb +42 -20
  51. data/lib/rhc/rest/client.rb +351 -89
  52. data/lib/rhc/rest/domain.rb +7 -13
  53. data/lib/rhc/rest/gear_group.rb +1 -1
  54. data/lib/rhc/rest/key.rb +7 -2
  55. data/lib/rhc/rest/mock.rb +609 -0
  56. data/lib/rhc/rest/user.rb +6 -2
  57. data/lib/rhc/{ssh_key_helpers.rb → ssh_helpers.rb} +58 -28
  58. data/lib/rhc/{targz.rb → tar_gz.rb} +0 -0
  59. data/lib/rhc/usage_templates/command_help.erb +4 -1
  60. data/lib/rhc/usage_templates/help.erb +24 -11
  61. data/lib/rhc/usage_templates/options_help.erb +14 -0
  62. data/lib/rhc/wizard.rb +283 -213
  63. data/spec/keys/example.pem +23 -0
  64. data/spec/keys/example_private.pem +27 -0
  65. data/spec/keys/server.pem +19 -0
  66. data/spec/rest_spec_helper.rb +3 -371
  67. data/spec/rhc/auth_spec.rb +226 -0
  68. data/spec/rhc/cli_spec.rb +41 -14
  69. data/spec/rhc/command_spec.rb +44 -15
  70. data/spec/rhc/commands/account_spec.rb +41 -0
  71. data/spec/rhc/commands/alias_spec.rb +16 -15
  72. data/spec/rhc/commands/app_spec.rb +115 -92
  73. data/spec/rhc/commands/apps_spec.rb +39 -0
  74. data/spec/rhc/commands/cartridge_spec.rb +134 -112
  75. data/spec/rhc/commands/domain_spec.rb +31 -86
  76. data/spec/rhc/commands/git_clone_spec.rb +56 -0
  77. data/spec/rhc/commands/{port-forward_spec.rb → port_forward_spec.rb} +27 -32
  78. data/spec/rhc/commands/server_spec.rb +28 -3
  79. data/spec/rhc/commands/setup_spec.rb +29 -11
  80. data/spec/rhc/commands/snapshot_spec.rb +4 -3
  81. data/spec/rhc/commands/sshkey_spec.rb +24 -56
  82. data/spec/rhc/commands/tail_spec.rb +26 -9
  83. data/spec/rhc/commands/threaddump_spec.rb +12 -11
  84. data/spec/rhc/config_spec.rb +211 -164
  85. data/spec/rhc/context_spec.rb +2 -0
  86. data/spec/rhc/helpers_spec.rb +242 -46
  87. data/spec/rhc/rest_application_spec.rb +42 -28
  88. data/spec/rhc/rest_client_spec.rb +110 -93
  89. data/spec/rhc/rest_spec.rb +220 -131
  90. data/spec/rhc/targz_spec.rb +1 -1
  91. data/spec/rhc/wizard_spec.rb +435 -624
  92. data/spec/spec.opts +1 -1
  93. data/spec/spec_helper.rb +140 -6
  94. data/spec/wizard_spec_helper.rb +326 -0
  95. metadata +163 -143
  96. data/lib/rhc/client.rb +0 -17
  97. data/lib/rhc/git_helper.rb +0 -59
@@ -2,7 +2,7 @@ require 'rhc/commands/base'
2
2
 
3
3
  module RHC::Commands
4
4
  class Snapshot < Base
5
- summary "Pull down application snapshot for a user."
5
+ summary "Save the current state of your application locally"
6
6
  syntax "<action>"
7
7
  alias_action :"app snapshot", :root_command => true
8
8
  default_action :help
@@ -53,9 +53,9 @@ module RHC::Commands
53
53
 
54
54
  summary "Restores a previously saved snapshot."
55
55
  syntax "<application>"
56
- option ["-n", "--namespace namespace"], "Namespace of the application you are saving a snapshot", :context => :namespace_context, :required => true
57
- option ["-f", "--filepath filepath"], "Local path to save tarball (default: ./$APPNAME.tar.gz)"
58
- argument :app, "Application you are saving a snapshot (required)", ["-a", "--app app"]
56
+ option ["-n", "--namespace namespace"], "Namespace of the application you are restoring a snapshot", :context => :namespace_context, :required => true
57
+ option ["-f", "--filepath filepath"], "Local path to restore tarball"
58
+ argument :app, "Application of which you are restoring a snapshot (required)", ["-a", "--app app"]
59
59
  alias_action :"app snapshot restore", :root_command => true, :deprecated => true
60
60
  def restore(app)
61
61
 
@@ -1,10 +1,8 @@
1
- #! /usr/bin/env ruby
2
-
3
1
  require 'rhc/commands/base'
4
2
 
5
3
  module RHC::Commands
6
4
  class Sshkey < Base
7
- include RHC::SSHKeyHelpers
5
+ include RHC::SSHHelpers
8
6
 
9
7
  summary 'Manage multiple keys for the registered rhcloud user.'
10
8
  syntax '<action>'
@@ -13,14 +11,9 @@ module RHC::Commands
13
11
  summary 'Display all the SSH keys for the user account'
14
12
  syntax ''
15
13
  def list
16
- keys = rest_client.sshkeys
14
+ keys = rest_client.sshkeys.each{ |key| paragraph{ display_key(key) } }
17
15
 
18
- results do
19
- result = keys.inject('') do |r, key|
20
- r += format(key, erb)
21
- end
22
- say result
23
- end
16
+ success "You have #{keys.length} SSH keys associated with your account."
24
17
 
25
18
  0
26
19
  end
@@ -30,7 +23,7 @@ module RHC::Commands
30
23
  argument :name, 'SSH key to display', []
31
24
  def show(name)
32
25
  key = rest_client.find_key(name)
33
- say format(key, erb)
26
+ display_key(key)
34
27
 
35
28
  0
36
29
  end
@@ -71,12 +64,5 @@ module RHC::Commands
71
64
 
72
65
  0
73
66
  end
74
-
75
- private
76
- # shared ERB template for formatting SSH Key
77
- def erb
78
- return @erb if @erb # cache
79
- @erb = ::RHC::Helpers.ssh_key_display_format
80
- end
81
67
  end
82
68
  end
@@ -1,8 +1,11 @@
1
1
  require 'rhc/commands/base'
2
2
  require 'rhc/config'
3
- require 'rhc-common'
3
+ require 'rhc/ssh_helpers'
4
+
4
5
  module RHC::Commands
5
6
  class Tail < Base
7
+ include RHC::SSHHelpers
8
+
6
9
  summary "Tail the logs of an application"
7
10
  syntax "<application>"
8
11
  argument :app, "Name of application you wish to view the logs of", ["-a", "--app app"]
@@ -10,15 +13,35 @@ module RHC::Commands
10
13
  option ["-o", "--opts options"], "Options to pass to the server-side (linux based) tail command (applicable to tail command only) (-f is implicit. See the linux tail man page full list of options.) (Ex: --opts '-n 100')"
11
14
  option ["-f", "--files files"], "File glob relative to app (default <application_name>/logs/*) (optional)"
12
15
  alias_action :"app tail", :root_command => true, :deprecated => true
13
- def run(app)
14
- begin
15
- rest_domain = rest_client.find_domain(options.namespace)
16
- rest_app = rest_domain.find_application(app)
17
- rest_app.tail(options)
18
- rescue Interrupt
19
- results { say "Terminating..." }
20
- end
16
+ def run(app_name)
17
+ domain = rest_client.find_domain(options.namespace)
18
+ app = domain.find_application(app_name)
19
+ cartridges = app.cartridges
20
+
21
+ tail(cartridges.first.name, URI(app.ssh_url), options)
22
+
21
23
  0
22
24
  end
25
+
26
+ private
27
+ #Application log file tailing
28
+ def tail(cartridge_name, ssh_url, options)
29
+ debug "Tail in progress for cartridge #{cartridge_name}"
30
+
31
+ host = ssh_url.host
32
+ uuid = ssh_url.user
33
+
34
+ file_glob = options.files ? options.files : "#{cartridge_name}/logs/*"
35
+ remote_cmd = "tail#{options.opts ? ' --opts ' + Base64::encode64(options.opts).chomp : ''} #{file_glob}"
36
+ ssh_cmd = "ssh -t #{uuid}@#{host} '#{remote_cmd}'"
37
+ begin
38
+ #Use ssh -t to tail the logs
39
+ debug ssh_cmd
40
+ ssh_ruby(host, uuid, remote_cmd)
41
+ rescue
42
+ warn "You can tail this application directly with:\n#{ssh_cmd}"
43
+ raise
44
+ end
45
+ end
23
46
  end
24
47
  end
@@ -2,16 +2,90 @@ require 'rhc/vendor/parseconfig'
2
2
  require 'rhc/core_ext'
3
3
 
4
4
  module RHC
5
+
6
+ module ConfigEnv
7
+ def conf_name
8
+ 'express.conf'
9
+ end
10
+ def home_conf_dir
11
+ File.join(home_dir, '.openshift')
12
+ end
13
+ def local_config_path
14
+ File.join(home_conf_dir, conf_name)
15
+ end
16
+ def ssh_dir
17
+ File.join(home_dir, '.ssh')
18
+ end
19
+ def ssh_priv_key_file_path
20
+ File.join(ssh_dir, 'id_rsa')
21
+ end
22
+ def ssh_pub_key_file_path
23
+ File.join(ssh_dir, 'id_rsa.pub')
24
+ end
25
+ end
26
+
27
+ #
28
+ # Responsible for encapsulating the loading and retrieval of OpenShift
29
+ # configuration files and converting them to commandline option
30
+ # equivalents. It also provides the converse option - converting a set
31
+ # of commandline options back into a config file.
32
+ #
33
+ # In general, the values stored in the config should be identical (require
34
+ # little or no type conversion) to their option form. As new global
35
+ # options are added, only this class should have to change to persist that
36
+ # option.
37
+ #
38
+ # During normal use, a new Config object should load the appropriate
39
+ # settings and those settings should be converted into commandline option
40
+ # defaults.
41
+ #
42
+ # TODO: Encapsulate config writing to the home location
43
+ # TODO: Allow the config object to initialized with a path
44
+ # TODO: Remove deprecated methods, remove extra sources.
45
+ #
5
46
  class Config
47
+ include ConfigEnv
48
+
49
+ # Option name [config_key type comment_string_for_config]
50
+ # if nil, == key nil == string won't be written to file if nil
51
+ OPTIONS = {
52
+ :server => ['libra_server', nil, 'The OpenShift server to connect to'],
53
+ :rhlogin => ['default_rhlogin', nil, 'Your OpenShift login name'],
54
+ :password => nil,
55
+ :timeout => [nil, :integer, 'The default timeout for network operations'],
56
+ :insecure => [nil, :boolean, "If true, certificate errors will be ignored.\nWARNING: This may allow others to eavesdrop on your communication with OpenShift."],
57
+ :ssl_version => [nil, nil, 'The SSL protocol version to use when connecting to this server'],
58
+ :ssl_client_cert_file => [nil, :path_to_file, 'A client certificate file for use with your server'],
59
+ :ssl_ca_file => [nil, :path_to_file, 'A file containing CA one or more certificates'],
60
+ }
61
+
62
+ def self.options_to_config(options)
63
+ OPTIONS.inject([]) do |arr, (name, opts)|
64
+ opts ||= []
65
+ next arr unless opts[2]
66
+ value = options[name]
67
+ arr.concat(opts[2].each_line.to_a.map(&:strip).map{ |s| "# #{s}" })
68
+ arr << "#{value.nil? ? '#' : ''}#{opts[0] || name}=#{self.type_to_config(opts[1], value)}"
69
+ arr << ""
70
+ arr
71
+ end.join("\n")
72
+ end
73
+
74
+ def self.type_to_config(type, value)
75
+ case type
76
+ when :integer, :boolean
77
+ value.nil? ? "<#{type}>" : value
78
+ else
79
+ "\"#{value.nil? ? "<#{type || 'string'}>" : value}\""
80
+ end
81
+ end
6
82
 
83
+ # DEPRECATED - will be removed when old commands are gone
7
84
  def self.default
8
- @default ||= begin
9
- RHC::Config.new
10
- end.tap do |c|
11
- c.read_config_files
12
- end
85
+ @default ||= RHC::Config.new
13
86
  end
14
87
 
88
+ # DEPRECATED - will be removed when old commands are gone
15
89
  def self.method_missing(method, *args, &block)
16
90
  if default.respond_to?(method)
17
91
  default.send(method, *args, &block)
@@ -20,74 +94,61 @@ module RHC
20
94
  end
21
95
  end
22
96
 
97
+ # DEPRECATED - will be removed when old commands are gone
23
98
  def self.initialize
24
99
  @default = nil
25
100
  default
26
101
  end
27
102
 
103
+ # DEPRECATED - will be removed when old commands are gone
28
104
  def initialize
29
105
  set_defaults
30
-
31
- _gem_cfg = File.join(File.expand_path(File.dirname(__FILE__) + "/../../conf"), @conf_name)
32
- @global_config_path = File.exists?(@_linux_cfg) ? @_linux_cfg : _gem_cfg
33
106
  end
34
107
 
108
+ # DEPRECATED - will be removed when old commands are gone
35
109
  def read_config_files
36
- @global_config = RHC::Vendor::ParseConfig.new(@global_config_path) if File.exists?(@global_config_path)
37
- @local_config = RHC::Vendor::ParseConfig.new(File.expand_path(@local_config_path)) if File.exists?(@local_config_path)
38
- rescue Errno::EACCES => e
39
- raise Errno::EACCES.new("Could not open config file: #{e.message}")
110
+ load_config_files
40
111
  end
41
112
 
113
+ # DEPRECATED - will be removed when old commands are gone
42
114
  def set_defaults
43
115
  @defaults = RHC::Vendor::ParseConfig.new()
116
+ @opts = RHC::Vendor::ParseConfig.new() # option switches that override config file
117
+
118
+ @env_config = RHC::Vendor::ParseConfig.new()
44
119
  @global_config = nil
45
120
  @local_config = nil
46
121
  @opts_config = nil # config file passed in the options
47
- @opts = RHC::Vendor::ParseConfig.new() # option switches that override config file
122
+
48
123
  @default_proxy = nil
49
- @env_config = RHC::Vendor::ParseConfig.new()
50
124
 
51
125
  @defaults.add('libra_server', 'openshift.redhat.com')
52
126
  @env_config.add('libra_server', ENV['LIBRA_SERVER']) if ENV['LIBRA_SERVER']
53
- #
54
- # Config paths... /etc/openshift/express.conf or $GEM/conf/express.conf -> ~/.openshift/express.conf
55
- #
56
- @conf_name = 'express.conf'
57
- @home_dir = File.expand_path("~")
58
- @home_conf_path = File.join(@home_dir, '.openshift')
59
- @local_config_path = File.join(@home_conf_path, @conf_name)
60
-
61
- # config path passed in on the command line
62
- @opts_config_path = nil
63
127
 
64
- # authoritive config path
65
- # this can be @local_config_path or @opts_config_path
66
- # @opts_config_path trumps
67
- # this is used to determine where config options should be written to
68
- # when a script modifies the config such as in rhc setup
69
- @config_path = @local_config_path
70
-
71
- @ssh_priv_key_file_path = "#{@home_dir}/.ssh/id_rsa"
72
- @ssh_pub_key_file_path = "#{@home_dir}/.ssh/id_rsa.pub"
128
+ @opts_config_path = nil
129
+ end
73
130
 
74
- @_linux_cfg = '/etc/openshift/' + @conf_name
75
- @global_config_path = @_linux_cfg
131
+ def to_options
132
+ OPTIONS.inject({}) do |h, (name, opts)|
133
+ opts = Array(opts)
134
+ value = self[opts[0] || name.to_s]
135
+ if value
136
+ value = value unless value.blank?
137
+ h[name] = value unless value.nil?
138
+ end
139
+ h
140
+ end
76
141
  end
77
142
 
78
- # used for tests
79
- def home_dir=(home_dir)
80
- @home_dir=home_dir
81
- @home_conf_path = File.join(@home_dir, '.openshift')
82
- @local_config_path = File.join(@home_conf_path, @conf_name)
83
- @local_config = nil
84
- @local_config = RHC::Vendor::ParseConfig.new(File.expand_path(@local_config_path)) if File.exists?(@local_config_path)
85
- @ssh_priv_key_file_path = "#{@home_dir}/.ssh/id_rsa"
86
- @ssh_pub_key_file_path = "#{@home_dir}/.ssh/id_rsa.pub"
143
+ def save!(options)
144
+ File.open(path, 'w'){ |f| f.puts self.class.options_to_config(options) }
145
+ @opts, @opts_config, @local_config, @global_config = nil
146
+ load_config_files
147
+ self
87
148
  end
88
149
 
89
150
  def [](key)
90
- raise KeyError("Please use RHC::Config.password to access the password config") if key == "password"
151
+ lazy_init
91
152
 
92
153
  # evaluate in cascading order
93
154
  configs = [@opts, @opts_config, @env_config, @local_config, @global_config, @defaults]
@@ -100,58 +161,42 @@ module RHC
100
161
  result
101
162
  end
102
163
 
164
+ # DEPRECATED - will be removed when old commands are gone
103
165
  def get_value(key)
104
166
  self[key]
105
167
  end
106
168
 
169
+ # DEPRECATED - underlying value and command option needs to be migrated to login
107
170
  def username
108
171
  self['default_rhlogin']
109
172
  end
110
173
 
111
- # Public: configures the default user for this session
112
- def config_user(username)
113
- @defaults.add('default_rhlogin', username)
114
- end
115
-
116
- def opts_login=(username)
117
- @opts.add('default_rhlogin', username)
118
- end
119
-
120
- def opts_login
121
- @opts['default_rhlogin']
122
- end
123
-
124
- # password is not allowed in config files and can only be passed on comman line
125
- def password=(password)
126
- @opts.add('password', password)
127
- end
128
-
129
- def password
130
- @opts['password']
174
+ # DEPRECATED - will be removed when old commands are gone
175
+ def set_local_config(conf_path, must_exist=true)
176
+ conf_path = File.expand_path(conf_path)
177
+ @config_path = conf_path if @opts_config_path.nil?
178
+ @local_config = RHC::Vendor::ParseConfig.new(conf_path)
179
+ rescue Errno::EACCES => e
180
+ raise Errno::EACCES.new "Could not open config file: #{e.message}" if must_exist
131
181
  end
132
182
 
133
- def set_local_config(confpath, must_exist=true)
134
- begin
135
- @local_config_path = File.expand_path(confpath)
136
- @config_path = @local_config_path if @opts_config_path.nil?
137
- @local_config = RHC::Vendor::ParseConfig.new(@local_config_path)
138
- rescue Errno::EACCES => e
139
- if must_exist
140
- raise Errno::EACCES.new "Could not open config file: #{e.message}"
141
- end
142
- end
183
+ # DEPRECATED - needs to be renamed to something cleaner
184
+ def set_opts_config(conf_path)
185
+ @opts_config_path = File.expand_path(conf_path)
186
+ @config_path = @opts_config_path
187
+ @opts_config = RHC::Vendor::ParseConfig.new(@opts_config_path) if File.exists?(@opts_config_path)
188
+ rescue Errno::EACCES => e
189
+ raise Errno::EACCES.new "Could not open config file: #{e.message}"
143
190
  end
144
191
 
145
- def set_opts_config(confpath)
146
- begin
147
- @opts_config_path = File.expand_path(confpath)
148
- @config_path = @opts_config_path
149
- @opts_config = RHC::Vendor::ParseConfig.new(@opts_config_path) if File.exists?(@opts_config_path)
150
- rescue Errno::EACCES => e
151
- raise Errno::EACCES.new "Could not open config file: #{e.message}"
152
- end
192
+ def use_config(path)
193
+ path = File.expand_path(path)
194
+ set_opts_config(path)
195
+ rescue => e
196
+ raise ArgumentError, "Unable to read configuration file: #{e.message}", $!.backtrace
153
197
  end
154
198
 
199
+ # DEPRECATED - will be removed when old commands are gone
155
200
  def check_cpath(opts)
156
201
  unless opts["config"].nil?
157
202
  opts_config_path = File.expand_path(opts["config"])
@@ -163,24 +208,29 @@ module RHC
163
208
  end
164
209
  end
165
210
 
211
+ # DEPRECATED - may be made private
212
+ def global_config_path
213
+ linux_cfg = '/etc/openshift/' + conf_name
214
+ File.exists?(linux_cfg) ? linux_cfg : File.join(File.expand_path(File.dirname(__FILE__) + "/../../conf"), conf_name)
215
+ end
216
+
166
217
  def has_global_config?
218
+ lazy_init
167
219
  !@global_config.nil?
168
220
  end
169
221
 
170
222
  def has_local_config?
223
+ lazy_init
171
224
  !@local_config.nil?
172
225
  end
173
226
 
174
227
  def has_opts_config?
175
228
  !@opts_config.nil?
176
229
  end
177
-
178
- def has_opts?
179
- !@opts.nil?
180
- end
181
230
 
231
+ # DEPRECATED - should be moved to Helpers
182
232
  def should_run_ssh_wizard?
183
- not File.exists? @ssh_priv_key_file_path
233
+ not File.exists? ssh_priv_key_file_path
184
234
  end
185
235
 
186
236
  ##
@@ -190,29 +240,26 @@ module RHC
190
240
  # this is used to determine where config options should be written to
191
241
  # when a script modifies the config such as in rhc setup
192
242
  def config_path
193
- @config_path
243
+ @config_path ||= local_config_path
194
244
  end
195
-
196
- def local_config_path
197
- @local_config_path
198
- end
199
-
200
- def home_conf_path
201
- @home_conf_path
245
+ def path
246
+ config_path
202
247
  end
203
248
 
204
249
  def home_dir
205
- @home_dir
250
+ RHC::Config.home_dir
206
251
  end
207
252
 
208
- def ssh_pub_key_file_path
209
- @ssh_pub_key_file_path
253
+ def home_conf_path
254
+ home_conf_dir
210
255
  end
211
256
 
257
+ # DEPRECATED - will be removed when old commands are gone
212
258
  def default_rhlogin
213
259
  get_value('default_rhlogin')
214
260
  end
215
261
 
262
+ # DEPRECATED - will be removed when old commands are gone
216
263
  def default_proxy
217
264
  @default_proxy ||= (
218
265
  proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
@@ -229,14 +276,36 @@ module RHC
229
276
  )
230
277
  end
231
278
 
279
+ # DEPRECATED - will be removed when old commands are gone
232
280
  def using_proxy?
233
281
  default_proxy.instance_variable_get(:@is_proxy_class) || false
234
282
  end
235
283
 
284
+ # DEPRECATED - will be removed when old commands are gone
236
285
  def proxy_vars
237
286
  Hash[[:address,:user,:pass,:port].map do |x|
238
287
  [x,default_proxy.instance_variable_get("@proxy_#{x}")]
239
288
  end]
240
289
  end
290
+
291
+ private
292
+ # Allow mocking of the home dir
293
+ def self.home_dir
294
+ File.expand_path('~')
295
+ end
296
+
297
+ def load_config_files
298
+ @global_config = RHC::Vendor::ParseConfig.new(global_config_path) if File.exists?(global_config_path)
299
+ @local_config = RHC::Vendor::ParseConfig.new(File.expand_path(local_config_path)) if File.exists?(local_config_path)
300
+ rescue Errno::EACCES => e
301
+ raise Errno::EACCES.new("Could not open config file: #{e.message}")
302
+ end
303
+
304
+ def lazy_init
305
+ unless @loaded
306
+ load_config_files
307
+ @loaded = true
308
+ end
309
+ end
241
310
  end
242
311
  end