diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-07-24 10:33:49 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-09-25 18:35:33 -0700 |
commit | f41f6264d6eeb21333891d121d241a3eb4b8c8f2 (patch) | |
tree | 7cadab771a903da4a302fb46e52552abf1741e3a | |
parent | 3aec7f28c2311126e96131298d2af777056d7d20 (diff) | |
download | chef-f41f6264d6eeb21333891d121d241a3eb4b8c8f2.tar.gz |
Improve how we prompt for passwords and don't mutate config
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/knife/windows_cert_install.rb | 8 | ||||
-rw-r--r-- | lib/chef/knife/windows_listener_create.rb | 10 |
2 files changed, 7 insertions, 11 deletions
diff --git a/lib/chef/knife/windows_cert_install.rb b/lib/chef/knife/windows_cert_install.rb index e8d72315e3..3023dd8166 100644 --- a/lib/chef/knife/windows_cert_install.rb +++ b/lib/chef/knife/windows_cert_install.rb @@ -30,9 +30,7 @@ class Chef description: "Passphrase for certificate." def get_cert_passphrase - print "Enter given certificate's passphrase (empty for no passphrase):" - passphrase = STDIN.gets - passphrase.strip + config[:cert_passphrase] || ui.ask("Enter given certificate's passphrase (empty for no passphrase): ", echo: false) end def run @@ -48,11 +46,11 @@ class Chef exit 1 end file_path = @name_args.first - config[:cert_passphrase] = get_cert_passphrase unless config[:cert_passphrase] + cert_passphrase = get_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"` + result = `powershell.exe -Command " '#{cert_passphrase}' | certutil -importPFX '#{file_path}' AT_KEYEXCHANGE"` if $?.exitstatus == 0 ui.info "Certificate added to Certificate Store" else diff --git a/lib/chef/knife/windows_listener_create.rb b/lib/chef/knife/windows_listener_create.rb index d2a9c3f2b4..6828da8be6 100644 --- a/lib/chef/knife/windows_listener_create.rb +++ b/lib/chef/knife/windows_listener_create.rb @@ -16,12 +16,12 @@ # require_relative "../knife" -require "chef-utils" unless defined?(ChefUtils::CANARY) class Chef class Knife class WindowsListenerCreate < Knife deps do + require "chef-utils" unless defined?(ChefUtils::CANARY) require "openssl" end @@ -55,9 +55,7 @@ class Chef description: "Passphrase for certificate." def get_cert_passphrase - print "Enter given certificate's passphrase (empty for no passphrase):" - passphrase = STDIN.gets - passphrase.strip + config[:cert_passphrase] || ui.ask("Enter given certificate's passphrase (empty for no passphrase): ", echo: false) end def run @@ -70,8 +68,8 @@ class Chef begin if config[:cert_install] - config[:cert_passphrase] = get_cert_passphrase unless config[:cert_passphrase] - result = `powershell.exe -Command " '#{config[:cert_passphrase]}' | certutil -importPFX '#{config[:cert_install]}' AT_KEYEXCHANGE"` + cert_passphrase = get_cert_passphrase + result = `powershell.exe -Command " '#{cert_passphrase}' | certutil -importPFX '#{config[:cert_install]}' AT_KEYEXCHANGE"` if $?.exitstatus ui.info "Certificate installed to Certificate Store" result = `powershell.exe -Command " echo (Get-PfxCertificate #{config[:cert_install]}).thumbprint "` |