Permalink
Browse files

Merge remote-tracking branch 'origin/master' into avoid_creating_conf…

…_file_during_spec_tests

Conflicts:
	spec/rhc/common_spec.rb
  • Loading branch information...
2 parents c3bc992 + 600e73a commit a630b1a8bcd0f46d38f86304f0720060118fa53a @smarterclayton smarterclayton committed Oct 19, 2012
View
@@ -3,3 +3,4 @@ pkg/
Gemfile.lock
coverage
*~
+.rvmrc
View
@@ -5,6 +5,7 @@ require 'rhc/coverage_helper'
require 'rhc-common'
require 'net/http'
require 'net/https'
+require 'net/ssh'
require 'rbconfig'
require 'yaml'
require 'tempfile'
@@ -357,18 +358,26 @@ class Test3_SSH < Test::Unit::TestCase
end
def agent_key_fingerprints
- @@agent_keys.nil? ? nil : @@agent_keys.map{|x| x.to_s.split("\n")[1..-2].join('') }
+ @@agent_keys.nil? ? nil : @@agent_keys.map{|x| x.fingerprint }
end
def libra_public_key
- @@local_ssh_pubkey ||= (
- fp = File.open(@libra_kpfile)
- fp.gets.split(' ')[1]
+ @@local_ssh_pubkey ||= libra_public_key_content.split(' ')[1]
+ end
+
+ def libra_public_key_content
+ @@local_ssh_pubkey_content ||= (
+ fp = File.open(@libra_kpfile)
+ fp.gets
)
ensure
fp.close if fp
end
+ def libra_public_key_fingerprint
+ Net::SSH::KeyFactory.load_data_public_key(libra_public_key_content).fingerprint
+ end
+
def test_01_local_files
[
[@libra_kfile, /[4-7]00/], # Needs to at least be readable by user and nobody else
@@ -381,7 +390,7 @@ class Test3_SSH < Test::Unit::TestCase
def test_02_ssh_agent
require_agent_keys
- assert agent_key_names.include?(File.expand_path(@libra_kfile)) ,error_for(:pubkey_not_loaded, ": #{@libra_kpfile}")
+ assert agent_key_fingerprints.include?(libra_public_key_fingerprint) ,error_for(:pubkey_not_loaded, ": #{@libra_kpfile}")
end
def test_03_remote_ssh_keys
View
@@ -3,7 +3,7 @@
Summary: OpenShift client management tools
Name: rhc
-Version: 0.99.7
+Version: 0.99.9
Release: 1%{?dist}
Group: Network/Daemons
License: ASL 2.0
@@ -115,6 +115,21 @@ rm -rf $RPM_BUILD_ROOT
%attr(0644,-,-) /etc/bash_completion.d/rhc
%changelog
+* Thu Oct 18 2012 Adam Miller <admiller@redhat.com> 0.99.9-1
+- Merge pull request #186 from
+ smarterclayton/bug_821107_allow_unknown_ssh_keys_to_be_uploaded
+ (openshift+bot@redhat.com)
+- Bug 821107 - Allow an unrecognizable SSH key to be uploaded
+ (ccoleman@redhat.com)
+
+* Thu Oct 18 2012 Adam Miller <admiller@redhat.com> 0.99.8-1
+- These superfluous 'Accept' headers were throwing off specs on Linux.
+ (asari.ruby@gmail.com)
+- Tweak debug messages based on feedback. (asari.ruby@gmail.com)
+- Addresses US2853. Allows REST Client to negotiate with OpenShift server which
+ API version to use in order to communicate. (asari.ruby@gmail.com)
+- Looks like #179 needs specs to cover the added lines. (asari.ruby@gmail.com)
+
* Tue Oct 16 2012 Adam Miller <admiller@redhat.com> 0.99.7-1
- Merge pull request #179 from J5/bugfix (openshift+bot@redhat.com)
- Merge pull request #180 from J5/bugfix2 (dmcphers@redhat.com)
View
@@ -63,6 +63,12 @@ def set_endpoint
raise "Username not found in environment (RHC_USERNAME)" unless $username
raise "Password not found in environment (RHC_PASSWORD)" unless $password
+$user_register_script_format = "/usr/bin/ss-register-user -l admin -p admin --username %s --userpass %s"
+if ENV['REGISTER_USER']
+ command = $user_register_script_format % [$username,$password]
+ %x[#{command}]
+end
+
def _log(msg)
puts msg unless ENV['QUIET']
end
View
@@ -53,8 +53,8 @@ def self.deprecated?
command_name = Commander::Runner.instance.command_name_from_args
command = Commander::Runner.instance.active_command
- new_cmd = deprecated[command_name]
- if deprecated[command_name]
+ new_cmd = deprecated[command_name.to_sym]
+ if new_cmd
new_cmd = "rhc #{command.name}" if new_cmd == true
RHC::Helpers.deprecated_command new_cmd
end
@@ -88,7 +88,7 @@ def self.to_commander(instance=Commander::Runner.instance)
o[:arg] = Commander::Runner.switch_to_sym(o[:switches].last)
end
- deprecated[name] = opts[:deprecated] unless opts[:deprecated].nil?
+ deprecated[name.to_sym] = opts[:deprecated] unless opts[:deprecated].nil?
args_metadata = opts[:args] || []
args_metadata.each do |arg_meta|
@@ -107,7 +107,7 @@ def self.to_commander(instance=Commander::Runner.instance)
# prepend the current resource
alias_components = name.split(" ")
alias_components[-1] = a[:action]
- alias_cmd = alias_components.join(' ')
+ alias_cmd = alias_components.join(' ').to_sym
end
deprecated[alias_cmd] = true if a[:deprecated]
@@ -103,7 +103,7 @@ def restore(app)
end
rescue Timeout::Error, Errno::EADDRNOTAVAIL, Errno::EADDRINUSE, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Net::SSH::AuthenticationFailed => e
debug e.backtrace
- raise RHC::SnapshotRestoreException.new "Error in trying to restore snapshot. You can try to save manually by running:\n#{ssh_cmd}"
+ raise RHC::SnapshotRestoreException.new "Error in trying to restore snapshot. You can try to restore manually by running:\n#{ssh_cmd}"
end
else
View
@@ -35,17 +35,23 @@ def show(name)
end
summary 'Add SSH key to the user account'
- syntax '<name> <SSH Key file>'
+ syntax '<name> <path to SSH key file>'
argument :name, 'Name for this key', []
argument :key, 'SSH public key filepath', []
+ option ['--confirm'], 'Bypass key validation'
def add(name, key)
type, content, comment = ssh_key_triple_for(key)
# validate the user input before sending it to the server
begin
Net::SSH::KeyFactory.load_data_public_key "#{type} #{content}"
rescue NotImplementedError, OpenSSL::PKey::PKeyError, Net::SSH::Exception => e
- raise ::RHC::KeyDataInvalidException.new("File '#{key}' contains invalid data")
+ debug e.inspect
+ if options.confirm
+ warn 'The key you are uploading is not recognized. You may not be able to authenticate to your application through Git or SSH.'
+ else
+ raise ::RHC::KeyDataInvalidException.new("File '#{key}' does not appear to be a recognizable key file (#{e}). You may specify the '--confirm' flag to add the key anyway.")
+ end
end
rest_client.add_key(name, content, type)
View
@@ -1,6 +1,7 @@
# From Rails core_ext/object.rb
require 'rhc/json'
require 'open-uri'
+require 'highline'
class Object
def present?
@@ -24,6 +25,15 @@ def chunk(chunk_size=1024)
end
end
+class String
+ # Wrap string by the given length, and join it with the given character.
+ # The method doesn't distinguish between words, it will only work based on
+ # the length.
+ def wrap(wrap_length=80, char="\n")
+ scan(/.{#{wrap_length}}|.+/).join(char)
+ end
+end
+
#
# Allow http => https redirection, see
# http://bugs.ruby-lang.org/issues/859 to 1.8.7 for rough
@@ -38,3 +48,55 @@ def self.redirectable?(uri1, uri2) # :nodoc:
(/\A(?:http|ftp)\z/i =~ uri1.scheme && /\A(?:https?|ftp)\z/i =~ uri2.scheme)
end
end
+
+# Some versions of highline get in an infinite loop when trying to wrap.
+# Fixes BZ 866530.
+class HighLine
+ def wrap(text)
+ wrapped_text = []
+ text.each_line do |line|
+ word = []
+ i = chars_in_line = 0
+ chars = line.split(//)
+ while i < chars.length do
+ c = chars[i]
+ color_code = nil
+ # escape character probably means color code, let's check
+ if c == "\e"
+ color_code = line[i..i+6].match(/\e\[\d{1,2}m/)
+ # it's a color code
+ if color_code
+ i += color_code[0].length
+ # first the existing word buffer then the color code
+ wrapped_text << word.join.wrap(@wrap_at) << color_code[0]
+ word.clear
+ end
+ end
+ # not a color code sequence
+ if !color_code
+ chars_in_line += 1
+ # time to wrap the line?
+ if chars_in_line == @wrap_at
+ wrapped_text.pop if wrapped_text.last =~ / /
+ wrapped_text << "\n"
+ chars_in_line = 0
+ end
+ # space, so move the word to wrapped buffer and start a new word
+ if c =~ / /
+ wrapped_text << word.join.wrap(@wrap_at) << ' '
+ word.clear
+ chars_in_line += 1
+ # any other character
+ else
+ word << c
+ end
+ i += 1
+ end
+ end
+ # moves the rest of the word buffer
+ wrapped_text << word.join.wrap(@wrap_at)
+ end
+ return wrapped_text.join
+ end
+
+end
View
@@ -1,12 +1,22 @@
require 'base64'
require 'rhc/json'
require 'rhc/rest/base'
+require 'uri'
module RHC
module Rest
class Client < Base
- def initialize(end_point, username, password, use_debug=false)
+ attr_reader :server_api_versions, :client_api_versions
+ # Keep the list of supported API versions here
+ # The list may not necessarily be sorted; we will select the last
+ # matching one supported by the server.
+ # See #api_version_negotiated
+ CLIENT_API_VERSIONS = [1.0, 1.1, 1.2]
+
+ def initialize(end_point, username, password, use_debug=false, preferred_api_versions = CLIENT_API_VERSIONS)
@debug = use_debug
+ @end_point = end_point
+ @server_api_versions = []
debug "Connecting to #{end_point}"
credentials = nil
@@ -20,11 +30,37 @@ def initialize(end_point, username, password, use_debug=false)
# :nocov:
@@headers["Authorization"] = "Basic #{credentials}"
@@headers["User-Agent"] = RHC::Helpers.user_agent rescue nil
- #first get the API
RestClient.proxy = ENV['http_proxy']
- request = new_request(:url => end_point, :method => :get, :headers => @@headers)
-
- super({:links => request(request)}, use_debug)
+
+ # if API version negotiation is unsuccessful, execute this
+ default_request = new_request(:url => @end_point, :method => :get, :headers => @@headers)
+
+ # we'll be popping from preferred_api_versions in the while loop below
+ # so we need to dup the versions we prefer
+ @client_api_versions = preferred_api_versions.dup
+
+ begin
+ while !api_version_negotiated && !preferred_api_versions.empty?
+ api_version = preferred_api_versions.pop
+ debug "Checking API version #{api_version}"
+
+ @@headers["Accept"] = "application/json; version=#{api_version}"
+ request = new_request(:url => @end_point, :method => :get, :headers => @@headers)
+ begin
+ json_response = ::RHC::Json.decode(request.execute)
+ @server_api_versions = json_response['supported_api_versions']
+ links = json_response['data']
+ rescue RestClient::NotAcceptable
+ # try the next version
+ debug "Server does not support API version #{api_version}"
+ end
+ end
+ debug "Using API version #{api_version_negotiated}" if api_version_negotiated
+ warn_about_api_versions
+ rescue Exception => e
+ raise ResourceAccessException.new("Failed to access resource: #{e.message}")
+ end
+ super({:links => links || request(default_request)}, use_debug)
end
def add_domain(id)
@@ -118,6 +154,35 @@ def logout
debug "Logout/Close client"
end
alias :close :logout
+
+
+ ### API version related methods
+ def api_version_match?
+ ! api_version_negotiated.nil?
+ end
+
+ # return the API version that the server and this client agreed on
+ def api_version_negotiated
+ return nil unless @server_api_versions
+ client_api_versions.reverse. # choose the last API version listed
+ detect { |v| @server_api_versions.include? v }
+ end
+
+ def api_version_current?
+ current_client_api_version == api_version_negotiated
+ end
+
+ def current_client_api_version
+ client_api_versions.last
+ end
+
+ def warn_about_api_versions
+ if !api_version_match?
+ # API versions did not match
+ warn "WARNING: API version mismatch. This client supports #{client_api_versions.join(', ')}
+but server at #{URI.parse(@end_point).host} supports #{@server_api_versions.join(', ')}."
+ end
+ end
end
end
end
View
@@ -2,7 +2,7 @@ module RHC
module VERSION #:nocov:
MAJOR = 0
MINOR = 99
- MICRO = 7
+ MICRO = 9
#PRE = ''
STRING = [MAJOR,MINOR,MICRO].compact.join('.')
end
View
@@ -34,6 +34,7 @@ def initialize(config, opts=nil)
@libra_server = @libra_server ? @libra_server : "openshift.redhat.com"
end
@config.config_user opts.rhlogin if opts && opts.rhlogin
+ @debug = config['debug']
end
# Public: Runs the setup wizard to make sure ~/.openshift and ~/.ssh are correct
@@ -47,6 +48,7 @@ def initialize(config, opts=nil)
def run
stages.each do |stage|
# FIXME: cleanup if we fail
+ debug "Running #{stage}"
if (self.send stage).nil?
return nil
end
@@ -94,7 +96,7 @@ def login_stage
# instantiate a REST client that stages can use
end_point = "https://#{@libra_server}/broker/rest/api"
- @rest_client = RHC::Rest::Client.new(end_point, @username, @password)
+ @rest_client = RHC::Rest::Client.new(end_point, @username, @password, @debug)
# confirm that the REST client can connect
return false unless @rest_client.user
@@ -430,6 +432,10 @@ def has_git?
rescue
false
end
+
+ def debug?
+ @debug
+ end
end
class RerunWizard < Wizard
View
@@ -1 +1 @@
-0.99.7-1 /
+0.99.9-1 /
Oops, something went wrong.

0 comments on commit a630b1a

Please sign in to comment.