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
data/bin/rhc CHANGED
@@ -1,9 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rhc/coverage_helper'
3
3
 
4
- # Require rhc-common for wizard invocation
5
- require 'rhc-common'
6
-
7
4
  def get_args
8
5
  ARGV.shift
9
6
  args = ""
@@ -15,13 +12,16 @@ def get_args
15
12
  end
16
13
 
17
14
  begin
18
- begin
15
+ retcode = begin
19
16
  require 'rhc/cli'
20
17
  RHC::CLI.set_terminal
21
18
  RHC::CLI.start(ARGV)
22
- retcode = 0
19
+ rescue Interrupt
20
+ puts "Interrupted"
21
+ 128 + 2
23
22
  rescue SystemExit => e
24
- retcode = e.status
23
+ puts
24
+ e.status
25
25
  end
26
26
 
27
27
  if retcode == nil
@@ -32,6 +32,4 @@ begin
32
32
  end
33
33
 
34
34
  exit retcode
35
- rescue Interrupt
36
- exit 128 + 2 #INT
37
35
  end
@@ -19,6 +19,25 @@ end
19
19
  require 'test/unit'
20
20
  require 'test/unit/ui/console/testrunner'
21
21
 
22
+ class Hash
23
+ # given a potentially nested hash, overwrite the value
24
+ # if the key matches the given key
25
+ def deep_cleanse(key)
26
+ each_pair do |k,v|
27
+ case v
28
+ when Hash
29
+ v.deep_cleanse key
30
+ when Array
31
+ v.map {|e| e.deep_cleanse(key) if e.is_a? Hash}
32
+ else
33
+ if k.to_s == key
34
+ self[k] = "*" * 12
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
22
41
  #
23
42
  # print help
24
43
  #
@@ -41,6 +60,8 @@ USAGE
41
60
  exit exit_code
42
61
  end
43
62
 
63
+ warn "#{$0} has been deprecated. Please run 'rhc setup' instead."
64
+
44
65
  begin
45
66
  opts = GetoptLong.new(
46
67
  ["--debug", "-d", GetoptLong::NO_ARGUMENT],
@@ -119,14 +140,6 @@ $debuginfo = {
119
140
  }
120
141
  }
121
142
 
122
- # Don't actually log the password, but some information to help with troubleshooting
123
- if $opt['password']
124
- $debuginfo['options']['Command Line']['password'] = {
125
- "Length" => $opt['password'].length,
126
- "Starts with" => $opt['password'][0..0]
127
- }
128
- end
129
-
130
143
  #
131
144
  # Check for proxy environment
132
145
  #
@@ -167,7 +180,7 @@ module TestBase
167
180
  body = RHC::json_decode(response.body)
168
181
  body['data'] = body['data'] && body['data'] != '' ? RHC::json_decode(body['data']) : ''
169
182
  $debuginfo['fetches'] << {url.to_s => {
170
- 'body' => body,
183
+ 'body' => body.deep_cleanse('password'),
171
184
  'header' => response.instance_variable_get(:@header)
172
185
  }}
173
186
  end
@@ -518,7 +531,7 @@ class CheckRunner < Test::Unit::UI::Console::TestRunner
518
531
  if $debug
519
532
  Tempfile.open(%w(rhc-chk. .log))do |file|
520
533
  ObjectSpace.undefine_finalizer(file) # persist tempfile
521
- file.write $debuginfo.to_yaml
534
+ file.write $debuginfo.deep_cleanse('password').to_yaml
522
535
  puts
523
536
  puts "Debugging information dumped to #{file.path}"
524
537
  end
@@ -17,7 +17,7 @@ Feature: Existing Domain Operations
17
17
 
18
18
  Scenario: Domain Create Fails
19
19
  When rhc domain create is called
20
- Then the domain command should fail with an exitcode of 103
20
+ Then the domain command should fail with an exitcode of 128
21
21
 
22
22
  Scenario: Domain Delete
23
23
  When domain is deleted
@@ -8,11 +8,12 @@ module RHCHelper
8
8
  # The regex to parse the UUID output from the create app results
9
9
  UUID_OUTPUT_PATTERN = /UUID\s*(?:\:|=)\s*(.+)/i unless const_defined?(:UUID_OUTPUT_PATTERN)
10
10
  # The regex to parse the Gear Profile output from the create app results
11
- GEAR_PROFILE_OUTPUT_PATTERN = /Info.*Gear Size\s*(?:\:|=)\s*(\w+)/m unless const_defined?(:GEAR_PROFILE_OUTPUT_PATTERN)
11
+ GEAR_PROFILE_OUTPUT_PATTERN = /Gear Size\s*(?:\:|=)\s*(\w+)/m unless const_defined?(:GEAR_PROFILE_OUTPUT_PATTERN)
12
12
  # Regex to parse passwords out of logging messages
13
13
  PASSWORD_REGEX = / -p [^\s]* / unless const_defined?(:PASSWORD_REGEX)
14
14
  end
15
- \
15
+
16
+ require 'rhc_helper/api'
16
17
  require 'rhc_helper/loggable'
17
18
  require 'rhc_helper/commandify'
18
19
  require 'rhc_helper/httpify'
@@ -0,0 +1,7 @@
1
+ module RHCHelper
2
+ module API
3
+ def new_client
4
+ RHC::Rest::Client.new(:url => $end_point, :user => $username, :password => $password, :verify_mode => OpenSSL::SSL::VERIFY_NONE)
5
+ end
6
+ end
7
+ end
@@ -8,6 +8,8 @@ module RHCHelper
8
8
  class App
9
9
  extend Persistable
10
10
  extend Runnable
11
+ extend API
12
+ include API
11
13
  include Loggable
12
14
  include Commandify
13
15
  include Runnable
@@ -38,13 +40,12 @@ module RHCHelper
38
40
  # 4 - if no namespace is found, create namespace? (blank is no)
39
41
  args = [$username, $password]
40
42
  args << 'yes' unless ($keyed_users ||= []).include?($username)
41
- puts "User #{$username} has no keys" if args.length == 3
42
43
  args << '' # always skip namespace
43
44
  if $namespace
44
45
  # Namespace is already created, so don't pass anything in
45
46
  logger.info("Namespace (#{$namespace}) should be found by the wizard")
46
47
  run("rhc setup", nil, args) do |exitstatus, out, err, arg|
47
- raise "Unmatched namespace #{$namespace}" unless out.include?($namespace)
48
+ raise "Unmatched namespace #{$namespace}\n\n#{out}" unless out.include?($namespace)
48
49
  end
49
50
  else
50
51
  # Pass in a blank value for namespace to create in the next step
@@ -57,7 +58,7 @@ module RHCHelper
57
58
 
58
59
  def self.create_unique(type, scalable, gear_profile=nil, prefix="test")
59
60
  # Get a REST client to verify the application name
60
- client = RHC::Rest::Client.new($end_point, $username, $password)
61
+ client = new_client
61
62
 
62
63
  # Cleanup all test applications
63
64
  test_names = []
@@ -100,15 +101,12 @@ module RHCHelper
100
101
  persist
101
102
  end
102
103
 
104
+ # Get a REST client to verify the application is on the server
103
105
  def is_created?
104
- # Get a REST client to verify the application is on the server
105
- client = RHC::Rest::Client.new($end_point, $username, $password)
106
- begin
107
- client.domains[0].find_application(name)
108
- rescue
109
- return false
110
- end
106
+ new_client.domains[0].find_application(name)
111
107
  true
108
+ rescue RHC::ApplicationNotFoundException
109
+ false
112
110
  end
113
111
 
114
112
  def cartridge(name)
@@ -8,6 +8,7 @@ module RHCHelper
8
8
  class Domain
9
9
  extend Runnable
10
10
  extend Commandify
11
+ extend API
11
12
  include Dnsruby
12
13
 
13
14
  class << self
@@ -27,7 +28,7 @@ module RHCHelper
27
28
 
28
29
  def self.create_if_needed(prefix="test")
29
30
  unless $namespace
30
- client = RHC::Rest::Client.new($end_point, $username, $password)
31
+ client = new_client
31
32
  domain = client.domains.first
32
33
  if domain
33
34
  $namespace = domain.id
@@ -1,7 +1,5 @@
1
1
  require 'open4'
2
2
  require 'timeout'
3
- require 'iconv'
4
- require 'rubygems'
5
3
 
6
4
  module RHCHelper
7
5
  module Runnable
@@ -24,7 +22,7 @@ module RHCHelper
24
22
  end
25
23
 
26
24
  def run(cmd, arg=nil, input=[])
27
- logger.info("Running: #{cmd}")
25
+ logger.info("Running: #{cmd} #{arg}")
28
26
 
29
27
  exit_code = -1
30
28
  output = nil
@@ -39,29 +37,9 @@ module RHCHelper
39
37
  status = Open4.spawn(cmd, 'stdout' => stdout, 'stderr' => stderr, 'stdin' => stdin, 'quiet' => true)
40
38
  out, err = [stdout, stderr].map(&:string)
41
39
 
42
- #pid, stdin, stdout, stderr = Open4::popen4 cmd
43
- #input.each {|line| stdin.puts line}
44
- #stdin.close
45
-
46
- # Block until the command finishes
47
- #ignored, status = Process::waitpid2 pid
48
- #out = stdout.read.strip
49
- #err = stderr.read.strip
50
40
  stdout.close
51
41
  stderr.close
52
42
 
53
- # Force the output to ASCII-only characters or logger will barf.
54
- if (Gem::Version.new(RUBY_VERSION.dup) <=> Gem::Version.new('1.9.3')) >= 0
55
- out.encode!('UTF-8', 'UTF-8', :undef => :replace, :invalid => :replace)
56
- err.encode!('UTF-8', 'UTF-8', :undef => :replace, :invalid => :replace)
57
- else
58
- out = iconv_handler.iconv(out + ' ')[0..-2]
59
- err = iconv_handler.iconv(err + ' ')[0..-2]
60
- end
61
-
62
- logger.debug("Standard Output:\n#{out}")
63
- logger.debug("Standard Error:\n#{err}")
64
-
65
43
  # Allow a caller to pass in a block to process the output
66
44
  yield status.exitstatus, out, err, arg if block_given?
67
45
  exit_code = status.exitstatus
@@ -71,7 +49,7 @@ module RHCHelper
71
49
  logger.error("(#{$$}): Execution failed #{cmd} with exit_code: #{exit_code.to_s}")
72
50
  end
73
51
 
74
- return exit_code
52
+ exit_code
75
53
  end
76
54
  end
77
55
  end
@@ -28,7 +28,7 @@ As an OpenShift user, I want to manage SSH keys with 'rhc sshkey' commands.
28
28
  @sshkey_add
29
29
  Scenario: invalid key name is given
30
30
  When a new SSH key "key1.pub" is added as "blah\\ss"
31
- Then the command exits with status code 117
31
+ Then the command exits with status code 128
32
32
 
33
33
  @sshkey_add
34
34
  Scenario: invalid SSH key is added
@@ -43,13 +43,13 @@ As an OpenShift user, I want to manage SSH keys with 'rhc sshkey' commands.
43
43
  @sshkey_add @key1
44
44
  Scenario: SSH key with the same name already exists
45
45
  When a new SSH key "key2.pub" is added as "key1"
46
- Then the command exits with status code 120
46
+ Then the command exits with status code 128
47
47
 
48
48
  @sshkey_add
49
49
  Scenario: SSH key with the identical content already exists
50
50
  Given a new SSH key "key1.pub" is added as "key1"
51
51
  And a new SSH key "key1.pub" is added as "key2"
52
- Then the command exits with status code 121
52
+ Then the command exits with status code 128
53
53
 
54
54
  @sshkey_remove @key1
55
55
  Scenario: SSH key is deleted successfully
@@ -32,7 +32,7 @@ Then /^the (.+) cartridge should be (.*)$/ do |name,status|
32
32
  when :stopped
33
33
  "(.+) stopped"
34
34
  when :removed
35
- "Invalid cartridge specified: '#{name}'"
35
+ "Cartridge '#{name}' cannot be found in application"
36
36
  else
37
37
  raise "Unrecognized status type #{status}"
38
38
  end
@@ -61,14 +61,14 @@ end
61
61
 
62
62
  Then /^the (\w+) scaling value should be (.*)$/ do |minmax,value|
63
63
  expected = {
64
- :min => "Minimum",
65
- :max => "Maximum"
64
+ :min => "minimum",
65
+ :max => "maximum"
66
66
  }[minmax.to_sym]
67
67
 
68
- value = (value == "-1" ? "available gears" : value)
68
+ value = (value == "-1" ? "available" : value)
69
69
 
70
- match_string = [expected,value].join(" = ")
71
- regex = Regexp.new(/\s+#{match_string}/)
70
+ match_string = [expected,value].join(": ")
71
+ regex = Regexp.new(/\b#{match_string}/)
72
72
 
73
73
  @app.cartridge(@cartridge_name).send(:show).should match(regex)
74
74
  end
@@ -22,7 +22,6 @@ Given /^the libra client tools$/ do
22
22
  end
23
23
 
24
24
  When /^the setup wizard is run$/ do
25
- puts "Running setup"
26
25
  RHCHelper::App.rhc_setup
27
26
 
28
27
  # Force a refresh of the loaded RHC state
@@ -35,11 +35,11 @@ end
35
35
  Then /^the output (does not include|includes) (.*)$/ do |includes,str|
36
36
  regex = case str
37
37
  when /^the key information for "(.*?)"$/
38
- /Name: #{$1}/
38
+ /#{$1} \(type\: /
39
39
  when "deprecation warning"
40
40
  /deprecated/
41
41
  when "the key information"
42
- /Name:.*Type:.*Fingerprint:/m
42
+ /type: .*?\n\s*-+\n\s*Fingerprint: /m
43
43
  end
44
44
  includes = case includes
45
45
  when "does not"
@@ -1,5 +1,4 @@
1
1
  Before('@clean') do
2
- puts "Cleaning applications and keys now"
3
2
  clean_applications(true)
4
3
  end
5
4
 
@@ -4,10 +4,12 @@ require 'rhc/coverage_helper'
4
4
  SimpleCov.at_exit{ SimpleCov.result.format! } if defined? SimpleCov
5
5
 
6
6
  require 'rhc_helper'
7
- require 'rhc/rest'
7
+ require 'rhc'
8
8
  require 'rhc/config'
9
+ require 'rhc/commands'
9
10
  require 'rhc/helpers'
10
11
  require 'rhc/commands'
12
+ require 'pry' if ENV['PRY']
11
13
 
12
14
  def set_path
13
15
  ENV["PATH"] = "#{ENV['RHC_LOCAL_PATH']}:#{ENV['PATH']}" if ENV['RHC_LOCAL_PATH']
@@ -97,7 +99,7 @@ def clean_applications(leave_domain = false)
97
99
 
98
100
  users.each do |user|
99
101
  _log "\tUser: #{user}"
100
- client = RHC::Rest::Client.new($end_point, user, $password)
102
+ client = RHC::Rest::Client.new(:url => $end_point, :user => user, :password => $password, :verify_mode => OpenSSL::SSL::VERIFY_NONE)
101
103
  client.domains.each do |domain|
102
104
  _log "\t\tDomain: #{domain.id}"
103
105
  domain.applications.each do |app|
@@ -125,7 +127,7 @@ unless ENV['NO_CLEAN']
125
127
 
126
128
  # Start with a clean config
127
129
  _log " Replacing express.conf with the specified libra_server"
128
- File.open(RHC::Config::local_config_path, 'w') {|f| f.write("libra_server=#{URI.parse($end_point).host}") }
130
+ File.open(RHC::Config::local_config_path, 'w') {|f| f.write("libra_server=#{URI.parse($end_point).host}\ninsecure=true") }
129
131
  RHC::Config.initialize
130
132
 
131
133
  # Clean up temp dir
@@ -13,7 +13,7 @@ require 'rhc/rest'
13
13
  require 'rhc/helpers'
14
14
  require 'rhc/config'
15
15
  require 'rhc/wizard'
16
- require 'rhc/targz'
16
+ require 'rhc/tar_gz'
17
17
  require 'rhc/json'
18
18
 
19
19
  module RHC
data/lib/rhc.rb CHANGED
@@ -2,24 +2,25 @@
2
2
  # FIXME Remove rubygems from requirements, ensure library is correct
3
3
 
4
4
  # Only require external gem dependencies here
5
- require 'rest_client'
6
5
  require 'logger'
6
+ require 'pp'
7
+
8
+ require 'pry' if ENV['PRY']
7
9
 
8
10
  # Extend core methods
9
11
  require 'rhc/core_ext'
10
12
 
11
13
  module RHC
12
- autoload :Helpers, 'rhc/helpers'
13
- autoload :Rest, 'rhc/rest'
14
- autoload :HelpFormatter, 'rhc/help_formatter'
14
+ autoload :Auth, 'rhc/auth'
15
15
  autoload :CommandRunner, 'rhc/command_runner'
16
- autoload :VERSION, 'rhc/version'
17
16
  autoload :Commands, 'rhc/commands'
18
17
  autoload :Config, 'rhc/config'
18
+ autoload :Helpers, 'rhc/helpers'
19
+ autoload :HelpFormatter, 'rhc/help_formatter'
20
+ autoload :Rest, 'rhc/rest'
21
+ autoload :TarGz, 'rhc/tar_gz'
22
+ autoload :VERSION, 'rhc/version'
19
23
  end
20
24
 
21
25
  require 'rhc/exceptions'
22
26
 
23
- # Replace me with proper autoloads on the module RHC
24
- require 'rhc-common'
25
-
@@ -0,0 +1,3 @@
1
+ module RHC::Auth
2
+ autoload :Basic, 'rhc/auth/basic'
3
+ end
@@ -0,0 +1,54 @@
1
+ module RHC::Auth
2
+ class Basic
3
+ attr_reader :cookie
4
+
5
+ def initialize(*args)
6
+ if args[0].is_a?(String) or args.length > 1
7
+ @username, @password = args
8
+ else
9
+ @options = args[0] || Commander::Command::Options.new
10
+ @username = options[:rhlogin]
11
+ @password = options[:password]
12
+ @no_interactive = options[:noprompt]
13
+ end
14
+ @skip_interactive = !@password.nil?
15
+ end
16
+
17
+ def to_request(request)
18
+ (request[:cookies] ||= {})[:rh_sso] = cookie if cookie
19
+ request[:user] ||= username || (request[:lazy_auth] != true && ask_username) || nil
20
+ request[:password] ||= password || (username? && request[:lazy_auth] != true && ask_password) || nil
21
+ request
22
+ end
23
+
24
+ def retry_auth?(response)
25
+ if response.status == 401
26
+ @cookie = nil
27
+ error "Username or password is not correct" if username? && password
28
+ unless @skip_interactive or @no_interactive
29
+ ask_username unless username?
30
+ ask_password
31
+ true
32
+ end
33
+ else
34
+ @cookie ||= Array(response.cookies).inject(nil){ |v, c| c.name == 'rh_sso' ? c.value : v }
35
+ false
36
+ end
37
+ end
38
+
39
+ protected
40
+ include RHC::Helpers
41
+ attr_reader :options, :username, :password
42
+
43
+ def ask_username
44
+ @username = ask("Login to #{openshift_server}: ") unless @no_interactive
45
+ end
46
+ def ask_password
47
+ @password = ask("Password: ") { |q| q.echo = '*' } unless @no_interactive
48
+ end
49
+
50
+ def username?
51
+ username.present?
52
+ end
53
+ end
54
+ end