class Chef::Knife::WindowsCertInstall
Public Instance Methods
get_cert_passphrase()
click to toggle source
# File lib/chef/knife/windows_cert_install.rb, line 32 def get_cert_passphrase print "Enter given certificate's passphrase (empty for no passphrase):" passphrase = STDIN.gets passphrase.strip end
run()
click to toggle source
# File lib/chef/knife/windows_cert_install.rb, line 38 def run STDOUT.sync = STDERR.sync = true if Chef::Platform.windows? if @name_args.empty? ui.error "Please specify the certificate path. e.g- 'knife windows cert install <path>" exit 1 end file_path = @name_args.first config[:cert_passphrase] = get_cert_passphrase unless config[:cert_passphrase] begin ui.info "Adding certificate to the Windows Certificate Store..." result = `powershell.exe -Command " '#{config[:cert_passphrase]}' | certutil -importPFX '#{file_path}' AT_KEYEXCHANGE"` if $?.exitstatus == 0 ui.info "Certificate added to Certificate Store" else ui.info "Error adding the certificate. Use -VV option for details" end Chef::Log.debug "#{result}" rescue => e puts "ERROR: + #{e}" end else ui.error "Certificate can be installed on Windows system only" exit 1 end end