Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into better_app_create_flow
Browse files Browse the repository at this point in the history
Conflicts:
	lib/rhc/wizard.rb
  • Loading branch information
smarterclayton committed Apr 15, 2013
2 parents b39461e + d7698fe commit 246de9a
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 118 deletions.
12 changes: 11 additions & 1 deletion client.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Summary: OpenShift client management tools
Name: rhc
Version: 1.7.4
Version: 1.7.5
Release: 1%{?dist}
Group: Network/Daemons
License: ASL 2.0
Expand Down Expand Up @@ -99,6 +99,16 @@ rm -rf $RPM_BUILD_ROOT
%attr(0644,-,-) /etc/bash_completion.d/rhc

%changelog
* Sat Apr 13 2013 Krishna Raman <[email protected]> 1.7.5-1
- Merge pull request #358 from
smarterclayton/bug_951352_should_retry_key_on_bad_name
([email protected])
- Bug 951352 - Retry the key name during the wizard flow ([email protected])
- Merge pull request #355 from fabianofranz/master ([email protected])
- Bug 951436 - handling Windows platform on paging ([email protected])
- Bug 951369 ([email protected])
- tito releasers update ([email protected])

* Thu Apr 11 2013 Adam Miller <[email protected]> 1.7.4-1
- Merge pull request #352 from
smarterclayton/origin_ui_13_autocomplete_and_wrapping
Expand Down
4 changes: 2 additions & 2 deletions lib/rhc/commands/alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def remove(app, app_alias)
Pass phrase for the certificate private key is required if the
provided private key is encrypted.
DESC
syntax "<application> <alias> --certificate FILE --private-key FILE [--passphrase passphrase]"
syntax "<application> <alias> --certificate FILE --private-key FILE [--passphrase PASSPHRASE]"
argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
argument :app_alias, "Custom domain name for the application (required)", []
option ["--certificate FILE"], "SSL certificate filepath (file in .crt or .pem format)", :required => true
option ["--private-key FILE"], "Private key filepath for the given SSL certificate", :required => true
option ["--passphrase passphrase"], "Private key pass phrase, required if the private key is encripted", :required => false
option ["--passphrase PASSPHRASE"], "Private key pass phrase, required if the private key is encrypted", :required => false
option ["-n", "--namespace NAME"], "Namespace of your application", :context => :namespace_context, :required => true
def update_cert(app, app_alias)
certificate_file_path = options.certificate
Expand Down
10 changes: 7 additions & 3 deletions lib/rhc/highline_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class HighLineExtension < HighLine
[:ask, :agree].each do |sym|
define_method(sym) do |*args, &block|
separate_blocks
super(*args, &block)
r = super(*args, &block)
@last_line_open = false
r
end
end

Expand All @@ -31,8 +33,10 @@ def say(msg)
if statement[-1, 1] == " " or statement[-1, 1] == "\t"
@output.print(statement)
@output.flush
true
else
@output.puts(statement)
false
end

elsif msg.respond_to? :each
Expand Down Expand Up @@ -170,7 +174,7 @@ def paragraph(&block)

def pager
#:nocov:
return if RUBY_PLATFORM =~ /win32/
return if RHC::Helpers.windows?
return unless @output.tty?

read, write = IO.pipe
Expand Down Expand Up @@ -405,4 +409,4 @@ def rows
end

$terminal = HighLineExtension.new
$terminal.indent_size = 2 if $terminal.respond_to? :indent_size
$terminal.indent_size = 2 if $terminal.respond_to? :indent_size
9 changes: 7 additions & 2 deletions lib/rhc/rest/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,21 @@ def stub_api_v12(auth=false)
def stub_user(auth=mock_user_auth)
stub_api_request(:get, 'broker/rest/user', auth).to_return(simple_user(username))
end
def stub_create_default_key
def stub_add_key(name='default')
stub_api_request(:post, 'broker/rest/user/keys', mock_user_auth).
with(:body => hash_including({:name => 'default', :type => 'ssh-rsa'})).
with(:body => hash_including({:name => name, :type => 'ssh-rsa'})).
to_return({:status => 201, :body => {}.to_json})
end
def stub_update_key(name)
stub_api_request(:put, "broker/rest/user/keys/#{name}", mock_user_auth).
with(:body => hash_including({:type => 'ssh-rsa'})).
to_return({:status => 200, :body => {}.to_json})
end
def stub_add_key_error(name, message, code=422)
stub_api_request(:post, "broker/rest/user/keys", mock_user_auth).
with(:body => hash_including({:type => 'ssh-rsa'})).
to_return({:status => code, :body => {:messages => [{:text => message, :field => 'name', :severity => 'error'}]}.to_json})
end
def stub_create_domain(name)
stub_api_request(:post, 'broker/rest/domains', mock_user_auth).
with(:body => hash_including({:id => name})).
Expand Down
4 changes: 2 additions & 2 deletions lib/rhc/ssh_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def fingerprint_for_local_key(key)
end

def fingerprint_for_default_key
fingerprint_for_local_key RHC::Config.ssh_pub_key_file_path
fingerprint_for_local_key(RHC::Config.ssh_pub_key_file_path)
end

# for an SSH public key specified by 'key', return a triple
Expand All @@ -144,7 +144,7 @@ def ssh_key_triple_for(key)
end

def ssh_key_triple_for_default_key
ssh_key_triple_for RHC::Config.ssh_pub_key_file_path
ssh_key_triple_for(RHC::Config.ssh_pub_key_file_path)
end

private
Expand Down
139 changes: 67 additions & 72 deletions lib/rhc/wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def clear_ssh_keys_cache
# return true if the account has the public key defined by
# RHC::Config::ssh_pub_key_file_path
def ssh_key_uploaded?
ssh_keys.any? { |k| k.fingerprint == fingerprint_for_default_key }
ssh_keys.present? && ssh_keys.any? { |k| k.fingerprint.present? && k.fingerprint == fingerprint_for_default_key }
end

def existing_keys_info
Expand Down Expand Up @@ -258,111 +258,106 @@ def config_ssh_key_stage
true
end

def get_preferred_key_name
key_name = 'default'
def upload_ssh_key_stage
return true if ssh_key_uploaded?

if ssh_keys.empty?
paragraph do
info "Since you do not have any keys associated with your OpenShift account, "\
"your new key will be uploaded as the 'default' key."
end
else
paragraph do
say "You can enter a name for your key, or leave it blank to use the default name. " \
"Using the same name as an existing key will overwrite the old key."
end
upload = paragraph do
agree "Your public SSH key must be uploaded to the OpenShift server to access code. Upload now? (yes|no) "
end

paragraph { existing_keys_info }
if upload
if ssh_keys.empty?
paragraph do
info "Since you do not have any keys associated with your OpenShift account, "\
"your new key will be uploaded as the 'default' key."
upload_ssh_key('default')
end
else
paragraph { existing_keys_info }

key_fingerprint = fingerprint_for_default_key
unless key_fingerprint
paragraph do
warn "Your ssh public key at #{system_path(RHC::Config.ssh_pub_key_file_path)} is invalid or unreadable. "\
"Setup can not continue until you manually remove or fix your "\
"public and private keys id_rsa keys."
end
return false
end

key_fingerprint = fingerprint_for_default_key
unless key_fingerprint
paragraph do
warn "Your ssh public key at #{system_path(RHC::Config.ssh_pub_key_file_path)} is invalid or unreadable. "\
"Setup can not continue until you manually remove or fix your "\
"public and private keys id_rsa keys."
say "You can enter a name for your key, or leave it blank to use the default name. " \
"Using the same name as an existing key will overwrite the old key."
end
return nil
ask_for_key_name
end
else
paragraph do
info "You can upload your SSH key at a later time using the 'rhc sshkey' command"
end
end

userkey = username ? username.gsub(/@.*/, '') : ''
pubkey_base_name = "#{userkey}#{hostname.gsub(/\..*\z/,'')}".gsub(/[^A-Za-z0-9]/,'').slice(0,16)
default_name = find_unique_key_name(
:keys => ssh_keys,
:base => pubkey_base_name,
:max_length => DEFAULT_MAX_LENGTH
)
true
end

paragraph do
key_name = ask("Provide a name for this key: ") do |q|
def ask_for_key_name(default_name=get_preferred_key_name)
key_name = nil
paragraph do
begin
key_name = ask "Provide a name for this key: " do |q|
q.default = default_name
q.validate = /^[0-9a-zA-Z]*$/
q.responses[:not_valid] = 'Your key name must be letters and numbers only.'
q.responses[:ask_on_error] = ''
end
end
end while !upload_ssh_key(key_name)
end
end

key_name
def get_preferred_key_name
userkey = username ? username.gsub(/@.*/, '') : ''
pubkey_base_name = "#{userkey}#{hostname.gsub(/\..*\z/,'')}".gsub(/[^A-Za-z0-9]/,'').slice(0,16)
find_unique_key_name(pubkey_base_name)
end

# given the base name and the maximum length,
# find a name that does not clash with what is in opts[:keys]
def find_unique_key_name(opts)
keys = opts[:keys] || ssh_keys
base = opts[:base] || 'default'
max = opts[:max_length] || DEFAULT_MAX_LENGTH
def find_unique_key_name(base='default')
max = DEFAULT_MAX_LENGTH
key_name_suffix = 1
candidate = base
while ssh_keys.detect { |k| k.name == candidate }
candidate = base.slice(0, max - key_name_suffix.to_s.length) +
key_name_suffix.to_s
candidate = base.slice(0, max - key_name_suffix.to_s.length) + key_name_suffix.to_s
key_name_suffix += 1
end
candidate
end

def upload_ssh_key
key_name = get_preferred_key_name
return false unless key_name
def upload_ssh_key(key_name)
return false unless key_name.present?

type, content, comment = ssh_key_triple_for_default_key
indent do
say table([['Type:', type], ['Fingerprint:', fingerprint_for_default_key]])
end

paragraph do
if !ssh_keys.empty? && ssh_keys.any? { |k| k.name == key_name }
clear_ssh_keys_cache
say "Key with the name #{key_name} already exists. Updating ... "
if !ssh_keys.empty? && ssh_keys.any? { |k| k.name == key_name }
clear_ssh_keys_cache
paragraph do
say "Key with the name '#{key_name}' already exists. Updating ... "
key = rest_client.find_key(key_name)
key.update(type, content)
else
clear_ssh_keys_cache
say "Uploading key '#{key_name}' from #{system_path(RHC::Config::ssh_pub_key_file_path)} ... "
rest_client.add_key key_name, content, type
success "done"
end
success "done"
end

true
end

def upload_ssh_key_stage
return true if ssh_key_uploaded?

upload = paragraph do
agree "Your public SSH key must be uploaded to the OpenShift server to access code. Upload now? (yes|no) "
end

if upload
upload_ssh_key
else
paragraph do
info "You can upload your SSH key at a later time using the 'rhc sshkey' command"
clear_ssh_keys_cache
begin
rest_client.add_key(key_name, content, type)
paragraph{ say "Uploading key '#{key_name}' ... #{color('done', :green)}" }
rescue RHC::Rest::ValidationException => e
error e.message || "Unknown error during key upload."
return false
end
end

true
end
end


##
# Alert the user that they should manually install tools if they are not
Expand Down
2 changes: 1 addition & 1 deletion rel-eng/packages/rhc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.4-1 /
1.7.5-1 /
2 changes: 1 addition & 1 deletion rel-eng/releasers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
releaser = tito.release.DistGitReleaser
branches = libra-rhel-6

[onprem]
[ose-1.2]
releaser = tito.release.DistGitReleaser
branches = devops-1-rhel-6
2 changes: 1 addition & 1 deletion spec/rhc/commands/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
before{ rest_client.domains.clear }
let(:arguments) { ['app', 'create', 'app1', 'mock_standalone_cart-1'] }
# skips login stage and insecure check because of mock rest client, doesn't check keys
it { run_output(['mydomain', 'y', 'mykey']).should match(/This wizard.*Checking your namespace.*Your domain name 'mydomain' has been successfully created.*Creating application.*Your public SSH key.*Uploading key 'mykey' from.*Downloading the application.*Success/m) }
it { run_output(['mydomain', 'y', 'mykey']).should match(/This wizard.*Checking your namespace.*Your domain name 'mydomain' has been successfully created.*Creating application.*Your public SSH key.*Uploading key 'mykey' .*Downloading the application.*Success/m) }
end

context 'when run without a cart' do
Expand Down
Loading

0 comments on commit 246de9a

Please sign in to comment.