Class: Chef::Provider::ZypperRepository
- Inherits:
-
Chef::Provider
- Object
- Chef::Provider
- Chef::Provider::ZypperRepository
- Defined in:
- lib/chef/provider/zypper_repository.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider
#action, #current_resource, #logger, #new_resource, #recipe_name, #run_context
Instance Method Summary collapse
-
#cookbook_name ⇒ String
return the specified cookbook name or the cookbook containing the resource.
-
#escaped_repo_name ⇒ String
zypper repos are allowed to have spaces in the names.
-
#has_cookbook_file?(fn) ⇒ Boolean
determine if a cookbook file is available in the run.
-
#install_gpg_key(uri) ⇒ Object
install the provided gpg key.
-
#key_fingerprint(key_path) ⇒ String
extract the gpg key fingerprint from a local file.
-
#key_installed?(key_path) ⇒ boolean
is the provided key already installed.
-
#key_type(uri) ⇒ Symbol
Given the provided key URI determine what kind of chef resource we need to fetch the key.
- #load_current_resource ⇒ Object
-
#template_available?(path) ⇒ Boolean
determine if a template file is available in the current run.
Methods inherited from Chef::Provider
action, #action_nothing, #check_resource_semantics!, #cleanup_after_converge, #compile_and_converge_action, #converge_by, #converge_if_changed, #define_resource_requirements, #description, #events, include_resource_dsl?, include_resource_dsl_module, #initialize, #introduced, #node, #process_resource_requirements, provides, provides?, #requirements, #resource_collection, #resource_updated?, #run_action, #set_updated_status, supports?, use_inline_resources, #whyrun_mode?, #whyrun_supported?
Methods included from Mixin::Provides
#provided_as, #provides, #provides?
Methods included from Mixin::DescendantsTracker
#descendants, descendants, direct_descendants, #direct_descendants, find_descendants_by_name, #find_descendants_by_name, #inherited, store_inherited
Methods included from Mixin::LazyModuleInclude
#descendants, #include, #included
Methods included from Mixin::ShellOut
apply_default_env, maybe_add_timeout, #shell_out, #shell_out!
Methods included from Mixin::PowershellOut
#powershell_out, #powershell_out!
Methods included from Mixin::WindowsArchitectureHelper
#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory
Methods included from Mixin::PowershellExec
Methods included from DSL::Powershell
Methods included from DSL::RegistryHelper
#registry_data_exists?, #registry_get_subkeys, #registry_get_values, #registry_has_subkeys?, #registry_key_exists?, #registry_value_exists?
Methods included from DSL::DataQuery
#data_bag, #data_bag_item, #search, #tagged?
Methods included from EncryptedDataBagItem::CheckEncrypted
Methods included from DSL::PlatformIntrospection
#older_than_win_2012_or_8?, #platform?, #platform_family?, #value_for_platform, #value_for_platform_family
Methods included from Mixin::NotifyingBlock
#notifying_block, #subcontext_block
Methods included from DSL::DeclareResource
#build_resource, #declare_resource, #delete_resource, #delete_resource!, #edit_resource, #edit_resource!, #find_resource, #find_resource!, #resources, #with_run_context
Constructor Details
This class inherits a constructor from Chef::Provider
Instance Method Details
#cookbook_name ⇒ String
return the specified cookbook name or the cookbook containing the resource.
79 80 81 |
# File 'lib/chef/provider/zypper_repository.rb', line 79 def cookbook_name new_resource.cookbook || new_resource.cookbook_name end |
#escaped_repo_name ⇒ String
zypper repos are allowed to have spaces in the names
71 72 73 |
# File 'lib/chef/provider/zypper_repository.rb', line 71 def escaped_repo_name Shellwords.escape(new_resource.repo_name) end |
#has_cookbook_file?(fn) ⇒ Boolean
determine if a cookbook file is available in the run
95 96 97 |
# File 'lib/chef/provider/zypper_repository.rb', line 95 def has_cookbook_file?(fn) run_context.has_cookbook_file_in_cookbook?(cookbook_name, fn) end |
#install_gpg_key(uri) ⇒ Object
install the provided gpg key
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/chef/provider/zypper_repository.rb', line 144 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 |
#key_fingerprint(key_path) ⇒ String
extract the gpg key fingerprint from a local file
134 135 136 137 138 139 140 |
# File 'lib/chef/provider/zypper_repository.rb', line 134 def key_fingerprint(key_path) so = shell_out!("gpg --with-fingerprint #{key_path}") # expected output and match: http://rubular.com/r/BpfMjxySQM fingerprint = %r{pub\s*\S*/(\S*)}.match(so.stdout)[1].downcase logger.trace("GPG fingerprint of key at #{key_path} is #{fingerprint}") fingerprint end |
#key_installed?(key_path) ⇒ boolean
is the provided key already installed
122 123 124 125 126 127 128 |
# File 'lib/chef/provider/zypper_repository.rb', line 122 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 |
#key_type(uri) ⇒ Symbol
Given the provided key URI determine what kind of chef resource we need to fetch the key
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/chef/provider/zypper_repository.rb', line 106 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 |
#load_current_resource ⇒ Object
31 |
# File 'lib/chef/provider/zypper_repository.rb', line 31 def load_current_resource; end |
#template_available?(path) ⇒ Boolean
determine if a template file is available in the current run
87 88 89 |
# File 'lib/chef/provider/zypper_repository.rb', line 87 def template_available?(path) !path.nil? && run_context.has_template_in_cookbook?(cookbook_name, path) end |