rhc 0.83.9 → 0.84.13

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ spec = Gem::Specification.new do |s|
24
24
  s.description = %q{The client tools for the OpenShift Express platform that allow for application management.}
25
25
  s.files = FileList['lib/**/*.rb', 'bin/*', 'conf/*'].to_a
26
26
  s.files += %w(LICENSE README Rakefile)
27
- s.executables = ['rhc-chk', 'rhc-create-app', 'rhc-create-domain', 'rhc-ctl-app', 'rhc-snapshot', 'rhc-user-info', 'rhc-tail-files']
27
+ s.executables = ['rhc-chk', 'rhc-create-app', 'rhc-create-domain', 'rhc-ctl-domain', 'rhc-ctl-app', 'rhc-snapshot', 'rhc-domain-info', 'rhc-user-info', 'rhc-tail-files', 'rhc-port-forward']
28
28
  begin
29
29
  # Use Ruby version to target F13, RHEL5, Windows and OSX (assume no Xcode)
30
30
  if ENV['JSON_PURE'] or (RUBY_VERSION == "1.8.6" or RUBY_PLATFORM =~ /mswin/ or RUBY_PLATFORM =~ /darwin/)
@@ -34,6 +34,9 @@ spec = Gem::Specification.new do |s|
34
34
  end
35
35
  end
36
36
  s.add_dependency('parseconfig')
37
+ if RUBY_VERSION.to_f == 1.9
38
+ s.add_dependency('test-unit')
39
+ end
37
40
  end
38
41
 
39
42
  # Define a :package task that bundles the gem
data/bin/rhc-chk CHANGED
@@ -28,9 +28,15 @@ require 'rbconfig'
28
28
  require 'yaml'
29
29
  require 'tempfile'
30
30
 
31
+ if RUBY_VERSION.to_f == 1.9
32
+ require 'rubygems'
33
+ gem 'test-unit'
34
+ end
35
+
31
36
  require 'test/unit'
32
37
  require 'test/unit/ui/console/testrunner'
33
38
 
39
+
34
40
  #
35
41
  # print help
36
42
  #
@@ -283,11 +289,18 @@ class Test3_SSH < Test::Unit::TestCase
283
289
  @@local_derived_ssh_pubkey = key_dump.to_s.strip.split(' ')[1]
284
290
 
285
291
  assert_not_nil @@local_derived_ssh_pubkey, error_for(:no_derive)
286
-
287
292
  assert_not_nil $user_info, error_for(:no_account)
288
- remote_ssh_pubkey = $user_info["user_info"]["ssh_key"]
289
293
 
290
- assert_match @@local_derived_ssh_pubkey, remote_ssh_pubkey, error_for(:no_match_pub, @libra_kfile)
294
+ $remote_ssh_pubkeys = []
295
+ additional_ssh_keys = RHC::get_ssh_keys($libra_server, $rhlogin, $password, $http)
296
+ if additional_ssh_keys && additional_ssh_keys.kind_of?(Hash)
297
+ additional_ssh_keys.each do |name, sshkey|
298
+ $remote_ssh_pubkeys.push(sshkey['key'])
299
+ end
300
+ end
301
+
302
+ $remote_ssh_pubkeys.push($user_info["user_info"]["ssh_key"])
303
+ assert $remote_ssh_pubkeys.include?(@@local_derived_ssh_pubkey), error_for(:no_match_pub, @libra_kfile)
291
304
  end
292
305
 
293
306
  def test_02_ssh_public_key
@@ -299,11 +312,8 @@ class Test3_SSH < Test::Unit::TestCase
299
312
 
300
313
  assert_not_nil @@local_ssh_pubkey, error_for(:no_pubkey, 'the remote key')
301
314
 
302
- assert_not_nil $user_info, error_for(:no_account)
303
- remote_ssh_pubkey = $user_info["user_info"]["ssh_key"]
304
-
305
315
  # Test public key and remote key
306
- assert_match @@local_ssh_pubkey, remote_ssh_pubkey, error_for(:no_match_pub,@libra_kpfile)
316
+ assert $remote_ssh_pubkeys.include?(@@local_ssh_pubkey), error_for(:no_match_pub, @libra_kfile)
307
317
  ensure
308
318
  fp.close if fp
309
319
  end
@@ -313,11 +323,11 @@ class Test3_SSH < Test::Unit::TestCase
313
323
  end
314
324
 
315
325
  def test_06_ssh_agent
316
- loaded_keys = `ssh-add -L`.to_a
326
+ loaded_keys = `ssh-add -L`.lines.to_a
317
327
  # Make sure we can load keys from ssh-agent
318
328
  assert !loaded_keys.empty?, error_for(:no_keys_loaded)
319
329
  loaded_keys.map!{|key| key.split(' ')[1]}
320
-
330
+
321
331
  assert_not_nil @@local_ssh_pubkey, error_for(:no_pubkey, 'the keys in ssh-agent')
322
332
  assert loaded_keys.include?(@@local_ssh_pubkey),error_for(:pubkey_not_loaded)
323
333
  end
@@ -455,4 +465,4 @@ $messages = YAML.load <<-EOF
455
465
  :no_keys_loaded: Either ssh-agent is not running or you do not have any keys loaded
456
466
  :pubkey_not_loaded: Your public key is not loaded into a running ssh-agent
457
467
  :cant_ssh: "Cannot SSH into your app: %s"
458
- EOF
468
+ EOF
@@ -216,11 +216,15 @@ else
216
216
  system("ssh-keygen -t rsa -f '#{ssh_key_file_path}'")
217
217
  end
218
218
 
219
- ssh_key = File.open(ssh_pub_key_file_path).gets.chomp.split(' ')[1]
219
+ ssh_keyfile_contents = File.open(ssh_pub_key_file_path).gets.chomp.split(' ')
220
+ ssh_key = ssh_keyfile_contents[1]
221
+ ssh_key_type = ssh_keyfile_contents[0]
220
222
 
221
223
  data = {'namespace' => opt['namespace'],
222
224
  'rhlogin' => opt['rhlogin'],
223
- 'ssh' => ssh_key}
225
+ 'ssh' => ssh_key,
226
+ 'key_type' => ssh_key_type}
227
+
224
228
  if (opt['alter'])
225
229
  data[:alter] = true
226
230
  not_found_message = "A user with rhlogin '#{opt['rhlogin']}' does not have a registered domain. Be sure to run rhc-create-domain without -a|--alter first."
@@ -295,4 +299,4 @@ EOF
295
299
  else
296
300
  RHC::print_response_err(response)
297
301
  end
298
- exit 1
302
+ exit 1
data/bin/rhc-ctl-app CHANGED
@@ -144,10 +144,6 @@ if opt['command'] and (opt['alias'] and !(opt['command'] =~ /-alias$/)) || ((opt
144
144
  p_usage
145
145
  end
146
146
 
147
- if opt["command"] == "threaddump"
148
- print "NOTE: The threaddump command is only applicable to applications of type jbossas-7.0. The thread dump file will be available via 'rhc-tail-files -f app-name/jbossas-7.0/stdout.log'"
149
- end
150
-
151
147
  password = opt['password']
152
148
  if !password
153
149
  password = RHC::get_password
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'rhc-common'
25
+
26
+ #
27
+ # print help
28
+ #
29
+ def p_usage
30
+
31
+ puts <<USAGE
32
+
33
+ Usage: #{$0}
34
+ Manage multiple keys for the registered rhcloud user.
35
+
36
+ rhc-ctl-domain -l <rhlogin> [-p <passwd>] (-a <key-name> [-k <ssh-pubkey>] | -r <key-name> | -u <key-name> [-k <ssh-pubkey>])
37
+
38
+ -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (required)
39
+ -p|--password password RHLogin password (optional, will prompt)
40
+ -n|--namespace namespace Namespace for your application(s) (alphanumeric - max #{RHC::DEFAULT_MAX_LENGTH} chars) (required for destroying domain)
41
+ -a|--add-ssh-key key-name Add SSH key to the user account (key-name is the user-specified identifier for the key)
42
+ -r|--remove-ssh-key key-name Remove SSH key from the user account
43
+ -u|--update-ssh-key key-name Update SSH key for the user account
44
+ --destroy Destroys the domain and any added ssh keys
45
+ -k|--ssh key-filepath SSH public key filepath
46
+ --config path Path of alternate config file
47
+ -d|--debug Print Debug info
48
+ -h|--help Show Usage info
49
+
50
+ USAGE
51
+ exit 255
52
+ end
53
+
54
+ begin
55
+ opts = GetoptLong.new(
56
+ ["--debug", "-d", GetoptLong::NO_ARGUMENT],
57
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
58
+ ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
59
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
60
+ ["--namespace", "-n", GetoptLong::REQUIRED_ARGUMENT],
61
+ ["--add-ssh-key", "-a", GetoptLong::REQUIRED_ARGUMENT],
62
+ ["--remove-ssh-key", "-r", GetoptLong::REQUIRED_ARGUMENT],
63
+ ["--update-ssh-key", "-u", GetoptLong::REQUIRED_ARGUMENT],
64
+ ["--destroy", GetoptLong::NO_ARGUMENT],
65
+ ["--ssh", "-k", GetoptLong::REQUIRED_ARGUMENT],
66
+ ["--config", GetoptLong::REQUIRED_ARGUMENT]
67
+ )
68
+
69
+ command_list = ['add-ssh-key', 'remove-ssh-key', 'update-ssh-key', 'destroy']
70
+ command_count = 0
71
+ opt = {}
72
+ opts.each do |o, a|
73
+ opt[o[2..-1]] = a.to_s
74
+
75
+ # check to see if there are multiple commands
76
+ if command_list.include?(o[2..-1])
77
+ command_count += 1
78
+ end
79
+ end
80
+ rescue Exception => e
81
+ #puts e.message
82
+ p_usage
83
+ end
84
+
85
+ # If provided a config path, check it
86
+ check_cpath(opt)
87
+
88
+ # Pull in configs from files
89
+ libra_server = get_var('libra_server')
90
+ debug = get_var('debug') == 'false' ? nil : get_var('debug')
91
+ opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
92
+
93
+ if opt['help']
94
+ p_usage
95
+ end
96
+
97
+ if opt['debug']
98
+ debug = true
99
+ end
100
+ RHC::debug(debug)
101
+
102
+ # Validate for no command or multiple commands being specified
103
+ if command_count == 0
104
+ puts "Missing command! You must specify the operation to perform."
105
+ p_usage
106
+ elsif command_count > 1
107
+ puts "Multiple commands specified! You can only perform one operation at a time."
108
+ p_usage
109
+ end
110
+
111
+ if opt['destroy'] && !RHC::check_namespace(opt['namespace'])
112
+ puts "Missing or invalid namespace! You must specify the namespace in order to destroy it."
113
+ p_usage
114
+ end
115
+
116
+
117
+ # This is taken care of by the command_count validation performed earlier
118
+ #if !opt['rhlogin'] || !(opt['add-key'] || opt['remove-key'] || opt['update-key'] || opt['list-keys']) || \
119
+ # (opt['add-key'] && (opt['remove-key'] || opt['update-key'] || opt['list-keys'])) || \
120
+ # (opt['remove-key'] && (opt['add-key'] || opt['update-key'] || opt['list-keys'])) || \
121
+ # (opt['update-key'] && (opt['add-key'] || opt['remove-key'] || opt['list-keys'])) || \
122
+ # (opt['list-keys'] && (opt['add-key'] || opt['remove-key'] || opt['update-key']))
123
+ # p_usage
124
+ #end
125
+
126
+ if !RHC::check_rhlogin(opt['rhlogin']) || \
127
+ (opt['add-ssh-key'] && !RHC::check_key(opt['add-ssh-key'])) || \
128
+ (opt['remove-ssh-key'] && !RHC::check_key(opt['remove-ssh-key'])) || \
129
+ (opt['update-ssh-key'] && !RHC::check_key(opt['update-ssh-key']))
130
+ p_usage
131
+ end
132
+
133
+ password = opt['password']
134
+ if !password
135
+ password = RHC::get_password
136
+ end
137
+
138
+ #
139
+ # Read user public ssh key
140
+ if opt['add-ssh-key'] || opt['update-ssh-key']
141
+ if opt['ssh']
142
+ if File.readable?(opt['ssh'])
143
+ begin
144
+ ssh_keyfile_contents = File.open(opt['ssh']).gets.chomp.split(' ')
145
+ ssh_key = ssh_keyfile_contents[1]
146
+ ssh_key_type = ssh_keyfile_contents[0]
147
+ rescue Exception => e
148
+ puts "Invalid public keyfile format! Please specify a valid user public keyfile."
149
+ exit 1
150
+ end
151
+ else
152
+ puts "Unable to read user public keyfile #{opt['ssh']}"
153
+ exit 1
154
+ end
155
+ else # create key
156
+ key_name = opt['add-ssh-key'] ? opt['add-ssh-key'] : opt['update-ssh-key']
157
+ puts "Generating ssh key pair for user '#{key_name}' in the dir '#{Dir.pwd}/'"
158
+ # Use system for interaction
159
+ system("ssh-keygen -t rsa -f '#{key_name}'")
160
+ ssh_pub_key_file = Dir.pwd + '/' + key_name + '.pub'
161
+ ssh_keyfile_contents = File.open(ssh_pub_key_file).gets.chomp.split(' ')
162
+ ssh_key = ssh_keyfile_contents[1]
163
+ ssh_key_type = ssh_keyfile_contents[0]
164
+ end
165
+ end
166
+
167
+ data = {}
168
+ data[:rhlogin] = opt['rhlogin']
169
+ if opt['add-ssh-key']
170
+ url = URI.parse("https://#{libra_server}/broker/ssh_keys")
171
+ data[:key_name] = opt['add-ssh-key']
172
+ data[:ssh] = ssh_key
173
+ data[:action] = 'add-key'
174
+ data[:key_type] = ssh_key_type
175
+ elsif opt['remove-ssh-key']
176
+ url = URI.parse("https://#{libra_server}/broker/ssh_keys")
177
+ data[:key_name] = opt['remove-ssh-key']
178
+ data[:action] = 'remove-key'
179
+ elsif opt['update-ssh-key']
180
+ url = URI.parse("https://#{libra_server}/broker/ssh_keys")
181
+ data[:key_name] = opt['update-ssh-key']
182
+ data[:ssh] = ssh_key
183
+ data[:action] = 'update-key'
184
+ data[:key_type] = ssh_key_type
185
+ elsif opt['destroy']
186
+ url = URI.parse("https://#{libra_server}/broker/domain")
187
+ data[:delete] = true
188
+ data[:namespace] = opt['namespace']
189
+ end
190
+
191
+ RHC::print_post_data(data)
192
+ json_data = RHC::generate_json(data)
193
+
194
+ response = RHC::http_post(@http, url, json_data, password)
195
+
196
+ if response.code == '200'
197
+ begin
198
+ json_resp = JSON.parse(response.body)
199
+ RHC::update_server_api_v(json_resp)
200
+ RHC::print_response_success(json_resp)
201
+ puts "Success"
202
+ exit 0
203
+ rescue JSON::ParserError
204
+ RHC::print_response_err(response)
205
+ end
206
+ else
207
+ RHC::print_response_err(response)
208
+ end
209
+ puts "Failure"
210
+ exit 1
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'rhc-common'
25
+
26
+ #
27
+ # print help
28
+ #
29
+ def p_usage
30
+ rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
31
+ puts <<USAGE
32
+
33
+ Usage: #{$0}
34
+ Display information about a user
35
+
36
+ -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (#{rhlogin})
37
+ -p|--password password RHLogin password (optional, will prompt)
38
+ -a|--apps List applications for rhlogin
39
+ -i|--info Show user info
40
+ -d|--debug Print Debug info
41
+ -h|--help Show Usage info
42
+ --config path Path of alternate config file
43
+ --timeout # Timeout, in seconds, for connection
44
+
45
+ USAGE
46
+ exit 255
47
+ end
48
+
49
+ begin
50
+ opts = GetoptLong.new(
51
+ ["--debug", "-d", GetoptLong::NO_ARGUMENT],
52
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
53
+ ["--apps", "-a", GetoptLong::NO_ARGUMENT],
54
+ ["--info", "-i", GetoptLong::NO_ARGUMENT],
55
+ ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
56
+ ["--config", GetoptLong::REQUIRED_ARGUMENT],
57
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
58
+ ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
59
+ )
60
+ opt = {}
61
+ opts.each do |o, a|
62
+ opt[o[2..-1]] = a.to_s
63
+ end
64
+ rescue Exception => e
65
+ #puts e.message
66
+ p_usage
67
+ end
68
+
69
+ # If provided a config path, check it
70
+ check_cpath(opt)
71
+
72
+ # Pull in configs from files
73
+ libra_server = get_var('libra_server')
74
+ debug = get_var('debug') == 'false' ? nil : get_var('debug')
75
+
76
+ if opt["help"]
77
+ p_usage
78
+ end
79
+
80
+ if opt["debug"]
81
+ debug = true
82
+ end
83
+ RHC::debug(debug)
84
+
85
+ RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
86
+
87
+ opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
88
+
89
+ if !RHC::check_rhlogin(opt['rhlogin'])
90
+ p_usage
91
+ end
92
+
93
+ password = opt['password']
94
+ if !password
95
+ password = RHC::get_password
96
+ end
97
+
98
+ opt['apps'] = true if not opt['info'] and not opt['apps']
99
+ user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, true)
100
+
101
+ if opt['info']
102
+ ssh_keys = RHC::get_ssh_keys(libra_server, opt['rhlogin'], password, @http)
103
+
104
+ puts "User Info"
105
+ puts "========="
106
+ puts "Namespace: #{user_info['user_info']['namespace']}"
107
+ #puts " UUID: #{user_info['user_info']['uuid']}"
108
+ puts " RHLogin: #{user_info['user_info']['rhlogin']}"
109
+ puts "Primary SSH key: #{user_info['user_info']['ssh_key']}"
110
+ puts "Primary SSH key type: #{user_info['user_info']['ssh_type']}" unless user_info['user_info']['ssh_type'].to_s.strip.length == 0
111
+
112
+ if ssh_keys && ssh_keys.kind_of?(Hash)
113
+ puts ""
114
+ puts "Additional SSH keys"
115
+ puts "==================="
116
+ ssh_keys.each do |name, keyval|
117
+ puts "Name: #{name}"
118
+ puts " Key: #{keyval['key']}"
119
+ puts "Type: #{keyval['type']}"
120
+ puts ""
121
+ end
122
+ puts "Use rhc-ctl-domain for managing additional ssh keys"
123
+ end
124
+
125
+ end
126
+
127
+ if opt['apps']
128
+ puts "\n\n" if opt['info']
129
+
130
+ puts "Application Info"
131
+ puts "================"
132
+ unless user_info['app_info'].empty?
133
+ user_info['app_info'].each do |key, val|
134
+ puts key
135
+ puts " Framework: #{val['framework']}"
136
+ puts " Creation: #{val['creation_time']}"
137
+ puts " UUID: #{val['uuid']}"
138
+ puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
139
+ puts " Public URL: http://#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/"
140
+ if val['aliases'] && !val['aliases'].empty?
141
+ puts " Aliases: #{val['aliases'].join(', ')}"
142
+ end
143
+ puts ""
144
+ puts " Embedded: "
145
+ if val['embedded'] && !val['embedded'].empty?
146
+ val['embedded'].each do |embed_key, embed_val|
147
+ if embed_val.has_key?('info') && !embed_val['info'].empty?
148
+ puts " #{embed_key} - #{embed_val['info']}"
149
+ else
150
+ puts " #{embed_key}"
151
+ end
152
+ end
153
+ else
154
+ puts " None"
155
+ end
156
+ puts ""
157
+ end
158
+ else
159
+ puts "No applications found. You can use rhc-create-app to create new applications."
160
+ end
161
+
162
+ end
163
+
164
+ exit 0
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2011 Red Hat, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation files
6
+ # (the "Software"), to deal in the Software without restriction,
7
+ # including without limitation the rights to use, copy, modify, merge,
8
+ # publish, distribute, sublicense, and/or sell copies of the Software,
9
+ # and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'rhc-common'
25
+
26
+ #
27
+ # print help
28
+ #
29
+ def p_usage
30
+ rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
31
+ puts <<USAGE
32
+
33
+ Usage: #{$0}
34
+ Forward remote ports to the workstation
35
+
36
+ -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (#{rhlogin})
37
+ -a|--app Target application (required)
38
+ -p|--password password RHLogin password (optional, will prompt)
39
+ -d|--debug Print Debug info
40
+ -h|--help Show Usage info
41
+ --config path Path of alternate config file
42
+ --timeout # Timeout, in seconds, for connection
43
+
44
+ USAGE
45
+ exit 255
46
+ end
47
+
48
+ begin
49
+ opts = GetoptLong.new(
50
+ ["--debug", "-d", GetoptLong::NO_ARGUMENT],
51
+ ["--help", "-h", GetoptLong::NO_ARGUMENT],
52
+ ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
53
+ ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
54
+ ["--config", GetoptLong::REQUIRED_ARGUMENT],
55
+ ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
56
+ ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
57
+ )
58
+ opt = {}
59
+ opts.each do |o, a|
60
+ opt[o[2..-1]] = a.to_s
61
+ end
62
+ rescue Exception => e
63
+ #puts e.message
64
+ p_usage
65
+ end
66
+
67
+ # If provided a config path, check it
68
+ check_cpath(opt)
69
+
70
+ # Pull in configs from files
71
+ libra_server = get_var('libra_server')
72
+ debug = get_var('debug') == 'false' ? nil : get_var('debug')
73
+
74
+ if opt['help'] || !opt['app']
75
+ p_usage
76
+ end
77
+
78
+ if opt['debug']
79
+ debug = true
80
+ end
81
+ RHC::debug(debug)
82
+
83
+ RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
84
+
85
+ opt['rhlogin'] = get_var('default_rhlogin') unless opt['rhlogin']
86
+
87
+ if !RHC::check_rhlogin(opt['rhlogin'])
88
+ p_usage
89
+ end
90
+
91
+ password = opt['password']
92
+ if !password
93
+ password = RHC::get_password
94
+ end
95
+
96
+ user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, false)
97
+
98
+ app_name = opt['app']
99
+
100
+ unless user_info['app_info'][app_name]
101
+ puts
102
+ puts "Could not find app '#{app_name}'. Please run rhc-user-info to get a list"
103
+ puts "of your current running applications"
104
+ puts
105
+ exit 101
106
+ end
107
+
108
+ app_uuid = user_info['app_info'][app_name]['uuid']
109
+ namespace = user_info['user_info']['namespace']
110
+ rhc_domain = user_info['user_info']['rhc_domain']
111
+
112
+ puts "Checking available ports..."
113
+
114
+ hosts_and_ports, hosts_and_ports_descriptions = RHC::list_ports(rhc_domain, namespace, app_name, app_uuid, debug)
115
+
116
+ if hosts_and_ports.length == 0
117
+ puts
118
+ puts "No available ports to forward"
119
+ exit 102
120
+ end
121
+
122
+ puts
123
+
124
+ hosts_and_ports_descriptions.each { |description| puts "Binding #{description}..." }
125
+
126
+ ssh_cmd = "ssh -N "
127
+ hosts_and_ports.each { |port| ssh_cmd << "-L #{port}:#{port} " }
128
+ ssh_cmd << "#{app_uuid}@#{app_name}-#{namespace}.#{rhc_domain}"
129
+
130
+ puts ssh_cmd if debug
131
+ puts
132
+ puts "Use ctl + c to stop"
133
+
134
+ begin
135
+ exec ssh_cmd
136
+ rescue SystemCallError
137
+ puts
138
+ puts "Error trying to forward ports. You can try to forward manually by running:"
139
+ puts
140
+ puts ssh_cmd
141
+ puts
142
+ exit 1
143
+ end
144
+
145
+ # never
146
+ exit 1
data/bin/rhc-user-info CHANGED
@@ -21,127 +21,17 @@
21
21
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  # SOFTWARE.
23
23
 
24
- require 'rhc-common'
25
24
 
26
- #
27
- # print help
28
- #
29
- def p_usage
30
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
31
- puts <<USAGE
32
-
33
- Usage: #{$0}
34
- Display information about a user
35
-
36
- -l|--rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift Express access) (#{rhlogin})
37
- -p|--password password RHLogin password (optional, will prompt)
38
- -a|--apps List applications for rhlogin
39
- -i|--info Show user info
40
- -d|--debug Print Debug info
41
- -h|--help Show Usage info
42
- --config path Path of alternate config file
43
- --timeout # Timeout, in seconds, for connection
44
-
45
- USAGE
46
- exit 255
47
- end
48
25
 
49
- begin
50
- opts = GetoptLong.new(
51
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
52
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
53
- ["--apps", "-a", GetoptLong::NO_ARGUMENT],
54
- ["--info", "-i", GetoptLong::NO_ARGUMENT],
55
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
56
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
57
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
58
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
59
- )
60
- opt = {}
61
- opts.each do |o, a|
62
- opt[o[2..-1]] = a.to_s
63
- end
64
- rescue Exception => e
65
- #puts e.message
66
- p_usage
67
- end
68
-
69
- # If provided a config path, check it
70
- check_cpath(opt)
71
-
72
- # Pull in configs from files
73
- libra_server = get_var('libra_server')
74
- debug = get_var('debug') == 'false' ? nil : get_var('debug')
26
+ # print deprecation warning
27
+ puts "Warning: This command is deprecated. Please use rhc-domain-info instead."
28
+ puts""
75
29
 
76
- if opt["help"]
77
- p_usage
30
+ args = ""
31
+ ARGV.each do|a|
32
+ args += " #{a}"
78
33
  end
79
34
 
80
- if opt["debug"]
81
- debug = true
82
- end
83
- RHC::debug(debug)
84
-
85
- RHC::timeout(opt["timeout"] ? opt["timeout"] : get_var('timeout'))
86
-
87
- opt["rhlogin"] = get_var('default_rhlogin') unless opt["rhlogin"]
88
-
89
- if !RHC::check_rhlogin(opt['rhlogin'])
90
- p_usage
91
- end
92
-
93
- password = opt['password']
94
- if !password
95
- password = RHC::get_password
96
- end
97
-
98
- opt['apps'] = true if not opt['info'] and not opt['apps']
99
- user_info = RHC::get_user_info(libra_server, opt['rhlogin'], password, @http, true)
100
-
101
- if opt['info']
102
- puts "User Info"
103
- puts "========="
104
- puts "Namespace: #{user_info['user_info']['namespace']}"
105
- #puts " UUID: #{user_info['user_info']['uuid']}"
106
- puts " RHLogin: #{user_info['user_info']['rhlogin']}"
107
- puts " ssh_key: #{user_info['user_info']['ssh_key']}"
108
- end
109
-
110
- if opt['apps']
111
- puts "\n\n" if opt['info']
112
-
113
- puts "Application Info"
114
- puts "================"
115
- unless user_info['app_info'].empty?
116
- user_info['app_info'].each do |key, val|
117
- puts key
118
- puts " Framework: #{val['framework']}"
119
- puts " Creation: #{val['creation_time']}"
120
- puts " UUID: #{val['uuid']}"
121
- puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
122
- puts " Public URL: http://#{key}-#{user_info['user_info']['namespace']}.#{user_info['user_info']['rhc_domain']}/"
123
- if val['aliases'] && !val['aliases'].empty?
124
- puts " Aliases: #{val['aliases'].join(', ')}"
125
- end
126
- puts ""
127
- puts " Embedded: "
128
- if val['embedded'] && !val['embedded'].empty?
129
- val['embedded'].each do |embed_key, embed_val|
130
- if embed_val.has_key?('info') && !embed_val['info'].empty?
131
- puts " #{embed_key} - #{embed_val['info']}"
132
- else
133
- puts " #{embed_key}"
134
- end
135
- end
136
- else
137
- puts " None"
138
- end
139
- puts ""
140
- end
141
- else
142
- puts "No applications found. You can use rhc-create-app to create new applications."
143
- end
144
-
145
- end
35
+ system("rhc-domain-info #{args} 2>&1")
146
36
 
147
- exit 0
37
+ exit 0
data/lib/rhc-common.rb CHANGED
@@ -39,7 +39,7 @@ module RHC
39
39
  APP_NAME_MAX_LENGTH = 32
40
40
  MAX_RETRIES = 7
41
41
  DEFAULT_DELAY = 2
42
- API = "1.1.1"
42
+ API = "1.1.2"
43
43
  PATTERN_VERSION=/\A\d+\.\d+\.\d+\z/
44
44
  @mytimeout = 10
45
45
  @mydebug = false
@@ -165,6 +165,10 @@ module RHC
165
165
  check_field(namespace, 'namespace', DEFAULT_MAX_LENGTH)
166
166
  end
167
167
 
168
+ def self.check_key(keyname)
169
+ check_field(keyname, 'keyname', DEFAULT_MAX_LENGTH)
170
+ end
171
+
168
172
  def self.check_field(field, type, max=0)
169
173
  if field
170
174
  if field =~ /[^0-9a-zA-Z]/
@@ -243,6 +247,40 @@ module RHC
243
247
  user_info
244
248
  end
245
249
 
250
+ def self.get_ssh_keys(libra_server, rhlogin, password, net_http)
251
+ data = {'rhlogin' => rhlogin, 'action' => 'list-keys'}
252
+ if @mydebug
253
+ data[:debug] = true
254
+ end
255
+ print_post_data(data)
256
+ json_data = generate_json(data)
257
+
258
+ url = URI.parse("https://#{libra_server}/broker/ssh_keys")
259
+ response = http_post(net_http, url, json_data, password)
260
+
261
+ unless response.code == '200'
262
+ if response.code == '401'
263
+ puts "Invalid user credentials"
264
+ exit 97
265
+ else
266
+ print_response_err(response)
267
+ end
268
+ exit 1
269
+ end
270
+ begin
271
+ json_resp = JSON.parse(response.body)
272
+ rescue JSON::ParserError
273
+ exit 1
274
+ end
275
+ update_server_api_v(json_resp)
276
+ begin
277
+ ssh_keys = (JSON.parse(json_resp['data'].to_s))['keys']
278
+ rescue JSON::ParserError
279
+ exit 1
280
+ end
281
+ ssh_keys
282
+ end
283
+
246
284
  def self.get_password
247
285
  password = nil
248
286
  begin
@@ -851,4 +889,4 @@ def get_kpfile(kfile, check_exists=true)
851
889
  kfile_not_found
852
890
  end
853
891
  return kpfile
854
- end
892
+ end
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: 321
4
+ hash: 341
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 83
9
- - 9
10
- version: 0.83.9
8
+ - 84
9
+ - 13
10
+ version: 0.84.13
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: 2011-12-19 00:00:00 Z
18
+ date: 2012-01-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json_pure
@@ -51,10 +51,13 @@ executables:
51
51
  - rhc-chk
52
52
  - rhc-create-app
53
53
  - rhc-create-domain
54
+ - rhc-ctl-domain
54
55
  - rhc-ctl-app
55
56
  - rhc-snapshot
57
+ - rhc-domain-info
56
58
  - rhc-user-info
57
59
  - rhc-tail-files
60
+ - rhc-port-forward
58
61
  extensions: []
59
62
 
60
63
  extra_rdoc_files: []
@@ -62,12 +65,15 @@ extra_rdoc_files: []
62
65
  files:
63
66
  - lib/rhc-common.rb
64
67
  - bin/rhc-ctl-app
65
- - bin/rhc-tail-files
66
- - bin/rhc-user-info
67
- - bin/rhc-snapshot
68
- - bin/rhc-chk
69
68
  - bin/rhc-create-app
69
+ - bin/rhc-chk
70
70
  - bin/rhc-create-domain
71
+ - bin/rhc-domain-info
72
+ - bin/rhc-user-info
73
+ - bin/rhc-port-forward
74
+ - bin/rhc-snapshot
75
+ - bin/rhc-tail-files
76
+ - bin/rhc-ctl-domain
71
77
  - conf/express.conf
72
78
  - LICENSE
73
79
  - README