Add a new namespace to configs
# File lib/rhc-common.rb, line 951 def self.add_rhlogin_config(rhlogin, uuid) f = open(File.expand_path(config_path), 'a') unless config.get_value('default_rhlogin') f.puts("# Default rhlogin to use if none is specified") f.puts("default_rhlogin=#{rhlogin}") f.puts("") end f.close end
Check / add new host to ~/.ssh/config
# File lib/rhc-common.rb, line 962 def self.add_ssh_config_host(rhc_domain, ssh_key_file_path, ssh_config, ssh_config_d) puts "Checking ~/.ssh/config" ssh_key_file_name = File.basename(ssh_key_file_path) if ssh_key_file_path =~ %r^#{ENV['HOME']}/ ssh_key_file_path = ssh_key_file_path[ENV['HOME'].length..-1] if ssh_key_file_path =~ %r^\// || ssh_key_file_path =~ %r^\\/ ssh_key_file_path = '~' + ssh_key_file_path else ssh_key_file_path = '~/' + ssh_key_file_path end end if (ssh_key_file_name != 'id_rsa') found = false begin File.open(ssh_config, "r") do |sline| while(line = sline.gets) if line.to_s.index("Host *.#{rhc_domain}") == 0 found = true break end end end rescue Errno::EACCES puts "Could not read from #{ssh_config}" puts "Reason: " + $! puts puts "Please correct this first. Then run rerun." puts exit 213 rescue Errno::ENOENT puts "Could not find #{ssh_config}. This is ok, continuing" end if found puts "Found #{rhc_domain} in ~/.ssh/config... No need to adjust" else puts " Adding #{rhc_domain} to ~/.ssh/config" begin f = File.open(ssh_config, "a") f.puts " # Added by 'rhc domain create' on #{`date`} Host *.#{rhc_domain} IdentityFile #{ssh_key_file_path} VerifyHostKeyDNS yes StrictHostKeyChecking no UserKnownHostsFile ~/.ssh/libra_known_hosts " f.close rescue Errno::EACCES puts "Could not write to #{ssh_config}" puts "Reason: " + $! puts puts "Please correct this first. Then run rerun." puts exit 214 rescue Errno::ENOENT # Make directory and config if they do not exist puts "Could not find directory: " + $! puts "creating" FileUtils.mkdir_p ssh_config_d file = File.open(ssh_config, 'w') file.close retry end end File.chmod(0700, ssh_config_d) File.chmod(0600, ssh_config) end end
Support funcs
# File lib/rhc-common.rb, line 859 def check_cpath(opts) if !opts["config"].nil? @opts_config_path = opts["config"] if !File.readable?(File.expand_path(@opts_config_path)) puts "Could not open config file: #{@opts_config_path}" exit 253 else begin @opts_config = ParseConfig.new(File.expand_path(@opts_config_path)) rescue Errno::EACCES => e puts "Could not open config file (#{@opts_config_path}): #{e.message}" exit 253 end end end end
# File lib/rhc-common.rb, line 880 def config return @opts_config ? @opts_config : @local_config end
# File lib/rhc-common.rb, line 876 def config_path return @opts_config_path ? @opts_config_path : @local_config_path end
# File lib/rhc-common.rb, line 915 def get_kfile(check_exists=true) ssh_key_file = get_var('ssh_key_file') if ssh_key_file if (File.basename(ssh_key_file) == ssh_key_file) kfile = "#{ENV['HOME']}/.ssh/#{ssh_key_file}" else kfile = File.expand_path(ssh_key_file) end else kfile = "#{ENV['HOME']}/.ssh/libra_id_rsa" end if check_exists && !File.exists?(kfile) if ssh_key_file puts "WARNING: Unable to find '#{kfile}' referenced in express.conf." kfile_not_found else kfile = "#{ENV['HOME']}/.ssh/id_rsa" if !File.exists?(kfile) puts "WARNING: Unable to find ssh key file." kfile_not_found end end end return kfile end
# File lib/rhc-common.rb, line 941 def get_kpfile(kfile, check_exists=true) kpfile = kfile + '.pub' if check_exists && !File.exists?(kpfile) puts "WARNING: Unable to find '#{kpfile}'" kfile_not_found end return kpfile end
Check for local var in
0) --config path file 1) ~/.openshift/express.conf 2) /etc/openshift/express.conf 3) $GEM/../conf/express.conf
# File lib/rhc-common.rb, line 891 def get_var(var) v = nil if !@opts_config.nil? && @opts_config.get_value(var) v = @opts_config.get_value(var) else v = @local_config.get_value(var) ? @local_config.get_value(var) : @global_config.get_value(var) end v end
# File lib/rhc-common.rb, line 901 def kfile_not_found puts "Your SSH keys are created either by running ssh-keygen (password optional) or by having the 'rhc domain create' command do it for you. If you created them on your own (or want to use an existing keypair), be sure to paste your public key into the express console at http://www.openshift.com. The client tools use the value of 'ssh_key_file' in express.conf to find your key followed by the defaults of libra_id_rsa[.pub] and then id_rsa[.pub]. " #exit 212 end