Class: RuboCop::Cop::Chef::ChefDeprecations::DeprecatedYumRepositoryProperties

Inherits:
RuboCop::Cop
  • Object
show all
Includes:
RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb

Overview

With the release of Chef Infra Client 12.14 and the yum cookbook 3.0 several properties in the yum_repository resource were renamed. url -> baseurl, keyurl -> gpgkey, and mirrorexpire -> mirror_expire.

Examples:


# bad
yum_repository 'OurCo' do
  description 'OurCo yum repository'
  url 'http://artifacts.ourco.org/foo/bar'
  keyurl 'http://artifacts.ourco.org/pub/yum/RPM-GPG-KEY-OURCO-6'
  mirrorexpire 1440
  action :create
end

# good
yum_repository 'OurCo' do
  description 'OurCo yum repository'
  baseurl 'http://artifacts.ourco.org/foo/bar'
  gpgkey 'http://artifacts.ourco.org/pub/yum/RPM-GPG-KEY-OURCO-6'
  mirror_expire 1440
  action :create
end

Constant Summary collapse

MSG =
'With the release of Chef Infra Client 12.14 and the yum cookbook 3.0 several properties in the yum_repository resource were renamed. url -> baseurl, keyurl -> gpgkey, and mirrorexpire -> mirror_expire.'.freeze

Instance Method Summary collapse

Methods included from RuboCop::Chef::CookbookHelpers

#match_property_in_resource?, #match_resource_type?, #method_arg_ast_to_string, #resource_block_name_if_string

Instance Method Details

#autocorrect(node) ⇒ Object



56
57
58
59
60
# File 'lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb', line 56

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(node.loc.expression, node.loc.expression.source.gsub(/^url/, 'baseurl').gsub(/^keyurl/, 'gpgkey').gsub(/^mirrorexpire/, 'mirror_expire'))
  end
end

#on_block(node) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb', line 48

def on_block(node)
  %w(url keyurl mirrorexpire).each do |prop|
    match_property_in_resource?(:yum_repository, prop, node) do |prop_node|
      add_offense(prop_node, location: :expression, message: MSG, severity: :refactor)
    end
  end
end