Class: Conjur::Command::Init
- Inherits:
-
Conjur::Command
- Object
- Conjur::Command
- Conjur::Command::Init
- Defined in:
- lib/conjur/command/init.rb
Class Method Summary collapse
Methods inherited from Conjur::Command
acting_as_option, api, command, command_impl_for_list, command_options_for_list, display, display_members, hide_docs, method_missing, require_arg, retire_resource, retire_role
Methods included from IdentifierManipulation
#conjur_account, #full_resource_id, #get_kind_and_id_from_args
Class Method Details
.get_certificate(connect_hostname) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/conjur/command/init.rb', line 128 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.connect cert = ssock.peer_cert 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}", cert.to_pem] rescue exit_now! "Unable to retrieve certificate from #{connect_hostname}" ensure ssock.close if ssock sock.close if sock end |
.write_file(filename, force, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/conjur/command/init.rb', line 29 def self.write_file(filename, force, &block) if File.exists?(filename) unless force hl = HighLine.new $stdin, $stderr force = true if hl.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 |