class Chef::Provider::ZypperRepository
Public Instance Methods
return the specified cookbook name or the cookbook containing the resource.
@return [String] name of the cookbook
# File lib/chef/provider/zypper_repository.rb, line 80 def cookbook_name new_resource.cookbook || new_resource.cookbook_name end
zypper repos are allowed to have spaces in the names @return [String] escaped repo string
# File lib/chef/provider/zypper_repository.rb, line 72 def escaped_repo_name Shellwords.escape(new_resource.repo_name) end
determine if a cookbook file is available in the run @param [String] fn the path to the template file
@return [Boolean] cookbook file exists or doesn't
# File lib/chef/provider/zypper_repository.rb, line 96 def has_cookbook_file?(fn) run_context.has_cookbook_file_in_cookbook?(cookbook_name, fn) end
install the provided gpg key @param [String] uri the uri of the local or remote gpg key
# File lib/chef/provider/zypper_repository.rb, line 145 def install_gpg_key(uri) unless uri logger.trace("'gpgkey' property not provided or set to nil. Skipping key import.") return end cached_keyfile = ::File.join(Chef::Config[:file_cache_path], uri.split("/")[-1]) declare_resource(key_type(new_resource.gpgkey), cached_keyfile) do source uri mode "0644" sensitive new_resource.sensitive action :create end declare_resource(:execute, "import gpg key from #{new_resource.gpgkey}") do command "/bin/rpm --import #{cached_keyfile}" not_if { key_installed?(cached_keyfile) } action :run end end
extract the gpg key fingerprint from a local file @param [String] key_path the path to the key on the local filesystem
@return [String] the fingerprint of the key
# File lib/chef/provider/zypper_repository.rb, line 135 def key_fingerprint(key_path) so = shell_out!("gpg --with-fingerprint #{key_path}") # expected output and match: http://rubular.com/r/BpfMjxySQM fingerprint = /pub\s*\S*\/(\S*)/.match(so.stdout)[1].downcase logger.trace("GPG fingerprint of key at #{key_path} is #{fingerprint}") fingerprint end
is the provided key already installed @param [String] key_path the path to the key on the local filesystem
@return [boolean] is the key already known by rpm
# File lib/chef/provider/zypper_repository.rb, line 123 def key_installed?(key_path) so = shell_out("rpm -qa gpg-pubkey*") # expected output & match: http://rubular.com/r/RdF7EcXEtb status = /gpg-pubkey-#{key_fingerprint(key_path)}/.match(so.stdout) logger.trace("GPG key at #{key_path} is known by rpm? #{status ? "true" : "false"}") status 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
# File lib/chef/provider/zypper_repository.rb, line 107 def key_type(uri) if uri.start_with?("http") logger.trace("Will use :remote_file resource to cache the gpg key locally") :remote_file elsif has_cookbook_file?(uri) logger.trace("Will use :cookbook_file resource to cache the gpg key locally") :cookbook_file else raise Chef::Exceptions::FileNotFound, "Cannot determine location of gpgkey. Must start with 'http' or be a file managed by #{Chef::Dist::PRODUCT}." end end
# File lib/chef/provider/zypper_repository.rb, line 31 def load_current_resource end
determine if a template file is available in the current run @param [String] path the path to the template file
@return [Boolean] template file exists or doesn't
# File lib/chef/provider/zypper_repository.rb, line 88 def template_available?(path) !path.nil? && run_context.has_template_in_cookbook?(cookbook_name, path) end