Class: Conjur::Command::Init
Class Method Summary
collapse
acting_as_option, api, command, command_impl_for_list, command_options_for_list, display, display_members, hide_docs, method_missing, prompt_for_password, require_arg, retire_resource, retire_role
#conjur_account, #full_resource_id, #get_kind_and_id_from_args
Class Method Details
.get_certificate(connect_hostname) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/conjur/command/init.rb', line 124
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
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
|
.highline ⇒ Object
148
149
150
151
152
|
# File 'lib/conjur/command/init.rb', line 148
def self.highline
require 'highline'
@hl ||= HighLine.new $stdin, $stderr
end
|
.write_file(filename, force, &block) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# 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
|