class Conjur::Command::Init
Public Class Methods
configure_cert_store(certificate)
click to toggle source
# File lib/conjur/command/init.rb, line 114 def self.configure_cert_store certificate unless certificate.blank? cert_file = Tempfile.new("conjur_cert") File.write cert_file.path, certificate OpenSSL::SSL::SSLContext::DEFAULT_CERT_STORE.add_file cert_file.path end end
get_certificate(connect_hostname)
click to toggle source
# File lib/conjur/command/init.rb, line 122 def self.get_certificate connect_hostname include OpenSSL::SSL host, port = connect_hostname.split ':' port ||= 443 sock = TCPSocket.new host, port.to_i ssock = SSLSocket.new sock ssock.hostname = host ssock.connect chain = ssock.peer_cert_chain cert = chain.first fp = Digest::SHA1.digest cert.to_der # convert to hex, then split into bytes with : hexfp = (fp.unpack 'H*').first.upcase.scan(/../).join(':') ["SHA1 Fingerprint=#{hexfp}", chain.map(&:to_pem).join] rescue exit_now! "Unable to retrieve certificate from #{connect_hostname}" ensure ssock.close if ssock sock.close if sock end
write_file(filename, force) { |f| ... }
click to toggle source
# File lib/conjur/command/init.rb, line 28 def self.write_file(filename, force, &block) if File.exists?(filename) unless force force = true if highline.ask("File #{filename} exists. Overwrite (yes/no): ").strip == "yes" end exit_now! "Not overwriting #{filename}" unless force end File.open(filename, 'w') do |f| yield f end end
Private Class Methods
highline()
click to toggle source
# File lib/conjur/command/init.rb, line 148 def self.highline # isolated here so that highline is only loaded on demand require 'highline' @hl ||= HighLine.new $stdin, $stderr end