Commit 349e516e authored by Stefan Schulte's avatar Stefan Schulte
Browse files

maint: Adapt code to follow latest styleguide

Update our puppet type in order to follow the latest styleguide and make
rubocop happy
parent cccbf90e
Puppet::Type.type(:rpmkey).provide(:rpm) do Puppet::Type.type(:rpmkey).provide(:rpm) do
commands rpm: 'rpm'
commands :rpm => 'rpm'
def self.instances def self.instances
keys = [] keys = []
begin begin
rpm_query = rpm('-q','gpg-pubkey') rpm_query = rpm('-q', 'gpg-pubkey')
rescue Puppet::ExecutionFailure rescue Puppet::ExecutionFailure
return [] return []
end end
rpm_query.each_line do |line| rpm_query.each_line do |line|
line.chomp! line.chomp!
if match = /^gpg-pubkey-([0-9a-f]*)-[0-9a-f]*/.match(line) if (match = %r{^gpg-pubkey-([0-9a-f]*)-[0-9a-f]*}.match(line))
keys << new(:name => match.captures[0].upcase, :ensure => :present) keys << new(name: match.captures[0].upcase, ensure: :present)
else else
warning "Unexpected rpm output #{line.inspect}. Ignoring this line." warning "Unexpected rpm output #{line.inspect}. Ignoring this line."
end end
...@@ -24,14 +23,14 @@ Puppet::Type.type(:rpmkey).provide(:rpm) do ...@@ -24,14 +23,14 @@ Puppet::Type.type(:rpmkey).provide(:rpm) do
def self.prefetch(resources) def self.prefetch(resources)
instances.each do |prov| instances.each do |prov|
if resource = resources[prov.name] if (resource = resources[prov.name])
resource.provider = prov resource.provider = prov
end end
end end
end end
def create def create
raise Puppet::Error, "Cannot add key without a source" unless @resource[:source] raise Puppet::Error, 'Cannot add key without a source' unless @resource[:source]
rpm('--import', @resource[:source]) rpm('--import', @resource[:source])
end end
...@@ -42,5 +41,4 @@ Puppet::Type.type(:rpmkey).provide(:rpm) do ...@@ -42,5 +41,4 @@ Puppet::Type.type(:rpmkey).provide(:rpm) do
def destroy def destroy
rpm('-e', '--allmatches', "gpg-pubkey-#{@resource[:name].downcase}") rpm('-e', '--allmatches', "gpg-pubkey-#{@resource[:name].downcase}")
end end
end end
Puppet::Type.newtype(:rpmkey) do Puppet::Type.newtype(:rpmkey) do
@doc = "Define public GPG keys that should be part of the rpm @doc = "Define public GPG keys that should be part of the rpm
keyring." keyring."
newparam(:name) do newparam(:name) do
desc "The name of the key. This is the keyID (in hex) in desc 'The name of the key. This is the keyID (in hex) in
uppercase." uppercase.'
isnamevar isnamevar
validate do |value| validate do |value|
raise Puppet::Error, "Name must not be empty" if value.empty? raise Puppet::Error, 'Name must not be empty' if value.empty?
unless value =~ /^[0-9A-F]*$/ unless value.match? %r{^[0-9A-F]*$}
raise Puppet::Error, "Invalid key #{value}. The key has be a valid keyID (in hex) in uppercase." raise Puppet::Error, "Invalid key #{value}. The key has be a valid keyID (in hex) in uppercase."
end end
end end
...@@ -20,11 +19,10 @@ Puppet::Type.newtype(:rpmkey) do ...@@ -20,11 +19,10 @@ Puppet::Type.newtype(:rpmkey) do
ensurable ensurable
newparam(:source) do newparam(:source) do
desc "The source of the public key if the key is not already imported." desc 'The source of the public key if the key is not already imported.'
end end
autorequire(:file) do autorequire(:file) do
self[:source] if self[:source] =~ /^\// self[:source] if %r{^\/}.match?(self[:source])
end end
end end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment