diff options
author | John McCrae <john.mccrae@progress.com> | 2021-04-14 13:07:10 -0700 |
---|---|---|
committer | John McCrae <john.mccrae@progress.com> | 2021-04-14 13:07:10 -0700 |
commit | 6ff58f825eb978d2b0adf726e5d69c79659b7469 (patch) | |
tree | df12ccacffe730ae105666af2a4d409136d6abf9 | |
parent | b7c27cd1b1803bdcf65d1c8fc835fc6b916792dd (diff) | |
download | chef-6ff58f825eb978d2b0adf726e5d69c79659b7469.tar.gz |
correcting style errors
Signed-off-by: John McCrae <john.mccrae@progress.com>
-rw-r--r-- | lib/chef/resource/windows_certificate.rb | 23 | ||||
-rw-r--r-- | spec/functional/resource/windows_certificate_spec.rb | 4 |
2 files changed, 13 insertions, 14 deletions
diff --git a/lib/chef/resource/windows_certificate.rb b/lib/chef/resource/windows_certificate.rb index e253c39fdf..151284e325 100644 --- a/lib/chef/resource/windows_certificate.rb +++ b/lib/chef/resource/windows_certificate.rb @@ -80,7 +80,7 @@ class Chef description: "Use the `CurrentUser` store instead of the default `LocalMachine` store. Note: Prior to #{ChefUtils::Dist::Infra::CLIENT}. 16.10 this property was ignored.", default: false - deprecated_property_alias :cert_path, :output_path, 'The cert_path property was renamed output_path in the 17.0 release of this cookbook. Please update your cookbooks to use the new property name.' + deprecated_property_alias :cert_path, :output_path, "The cert_path property was renamed output_path in the 17.0 release of this cookbook. Please update your cookbooks to use the new property name." # lazy used to set default value of sensitive to true if password is set property :sensitive, [TrueClass, FalseClass], @@ -140,7 +140,7 @@ class Chef end action :fetch, description: "Fetches a certificate." do - if !new_resource.output_path + unless new_resource.output_path raise Chef::Exceptions::ResourceNotFound, "You must include an output_path parameter when calling the fetch action" end @@ -178,7 +178,7 @@ class Chef store.add(cert_obj) end - def add_pfx_cert(path) #expecting a path object here. + def add_pfx_cert(path) exportable = new_resource.exportable ? 1 : 0 store = ::Win32::Certstore.open(new_resource.store_name, store_location: native_cert_location) store.add_pfx(path, new_resource.pfx_password, exportable) @@ -200,11 +200,11 @@ class Chef end def fetch_key - require "openssl" + require "openssl" unless defined?(OpenSSL) file_name = ::File.basename(new_resource.output_path, ::File.extname(new_resource.output_path)) directory = ::File.dirname(new_resource.output_path) pfx_file = file_name + ".pfx" - new_pfx_output_path = ::File.join(Chef::FileCache.create_cache_path('pfx_files'), pfx_file) + new_pfx_output_path = ::File.join(Chef::FileCache.create_cache_path("pfx_files"), pfx_file) powershell_exec(pfx_ps_cmd(resolve_thumbprint(new_resource.source), store_location: ps_cert_location, store_name: new_resource.store_name, output_path: new_pfx_output_path, password: new_resource.pfx_password )) pkcs12 = OpenSSL::PKCS12.new(::File.binread(new_pfx_output_path), new_resource.pfx_password) f = ::File.open(new_resource.output_path, "w") @@ -219,12 +219,11 @@ class Chef if type == "file" ::File.extname(file_name) elsif type == "url" - require 'open-uri' + require "open-uri" unless defined?(OpenURI) uri = URI.parse(file_name) output_file = ::File.basename(uri.path) ::File.extname(output_file) end - end def get_file_name(path_name) @@ -233,20 +232,19 @@ class Chef if type == "file" ::File.extname(path_name) elsif type == "url" - require 'open-uri' + require "open-uri" unless defined?(OpenURI) uri = URI.parse(path_name) ::File.basename(uri.path) end - end # did I get passed a file, a url, or a mistake? def url_or_file?(source) - require 'uri' + require "uri" unless defined?(URI) uri = URI.parse(source) - if source == uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS) + if source == uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) "url" elsif ::File.file?(source) "file" @@ -269,6 +267,7 @@ class Chef def resolve_thumbprint(thumbprint) return thumbprint if valid_thumbprint?(thumbprint) + powershell_exec!(get_thumbprint(new_resource.store_name, ps_cert_location, new_resource.source)).result end @@ -394,7 +393,7 @@ class Chef raise Chef::Exceptions::FileNotFound, message end elsif type == "url" - require 'uri' + require "uri" unless defined?(URI) uri = URI(new_resource.source) state = uri.is_a?(URI::HTTP) && !uri.host.nil? ? true : false if state diff --git a/spec/functional/resource/windows_certificate_spec.rb b/spec/functional/resource/windows_certificate_spec.rb index c504beb66c..5c336d216a 100644 --- a/spec/functional/resource/windows_certificate_spec.rb +++ b/spec/functional/resource/windows_certificate_spec.rb @@ -234,7 +234,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do resource.run_action(:create) end - it "succeeds with the main certificate's thumbprint", :focus do + it "succeeds with the main certificate's thumbprint" do expect(Chef::Log).to receive(:info).with("Certificate is valid") resource.source = p7b_thumbprint @@ -310,7 +310,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only do resource.run_action(:create) end - it "exports a PFX file with a valid thumbprint", :focus do + it "exports a PFX file with a valid thumbprint" do resource.source = tests_thumbprint resource.pfx_password = password resource.output_path = pfx_output_path |