summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-09-28 17:06:28 -0700
committerTim Smith <tsmith@chef.io>2018-02-26 12:22:02 -0800
commit423e66625eb9bd744a5db979b326f6d2afb3d1e1 (patch)
tree3512de4308ee3452d6def82c42d599d1ad2dd06b
parentdbfd95f42a382b276a70011d28960159e3cc8f65 (diff)
downloadchef-423e66625eb9bd744a5db979b326f6d2afb3d1e1.tar.gz
Break key type detection into its own method
A) Method was getting big B) We can test this now Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/apt_repository.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb
index 814ccea5de..831afad083 100644
--- a/lib/chef/provider/apt_repository.rb
+++ b/lib/chef/provider/apt_repository.rb
@@ -147,18 +147,28 @@ class Chef
(installed_keys & proposed_keys).sort == proposed_keys.sort
end
+ # Given the provided key URI determine what kind of chef resource we need
+ # to fetch the key
+ # @param [String] uri the uri of the gpg key (local path or http URL)
+ #
+ # @raise [Chef::Exceptions::FileNotFound] Key isn't remote or found in the current run
+ #
+ # @return [Symbol] :remote_file or :cookbook_file
+ def key_type(uri)
+ if uri.start_with?("http")
+ :remote_file
+ elsif has_cookbook_file?(uri)
+ :cookbook_file
+ else
+ raise Chef::Exceptions::FileNotFound, "Cannot locate key file: #{uri}"
+ end
+ end
+
def install_key_from_uri(key)
key_name = key.gsub(/[^0-9A-Za-z\-]/, "_")
cached_keyfile = ::File.join(Chef::Config[:file_cache_path], key_name)
- type = if key.start_with?("http")
- :remote_file
- elsif has_cookbook_file?(key)
- :cookbook_file
- else
- raise Chef::Exceptions::FileNotFound, "Cannot locate key file"
- end
- declare_resource(type, cached_keyfile) do
+ declare_resource(key_type(key), cached_keyfile) do
source key
mode "0644"
sensitive new_resource.sensitive