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
commands :rpm => 'rpm'
commands rpm: 'rpm'
def self.instances
keys = []
begin
rpm_query = rpm('-q','gpg-pubkey')
rpm_query = rpm('-q', 'gpg-pubkey')
rescue Puppet::ExecutionFailure
return []
end
rpm_query.each_line do |line|
line.chomp!
if match = /^gpg-pubkey-([0-9a-f]*)-[0-9a-f]*/.match(line)
keys << new(:name => match.captures[0].upcase, :ensure => :present)
if (match = %r{^gpg-pubkey-([0-9a-f]*)-[0-9a-f]*}.match(line))
keys << new(name: match.captures[0].upcase, ensure: :present)
else
warning "Unexpected rpm output #{line.inspect}. Ignoring this line."
end
......@@ -24,14 +23,14 @@ Puppet::Type.type(:rpmkey).provide(:rpm) do
def self.prefetch(resources)
instances.each do |prov|
if resource = resources[prov.name]
if (resource = resources[prov.name])
resource.provider = prov
end
end
end
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])
end
......@@ -42,5 +41,4 @@ Puppet::Type.type(:rpmkey).provide(:rpm) do
def destroy
rpm('-e', '--allmatches', "gpg-pubkey-#{@resource[:name].downcase}")
end
end
Puppet::Type.newtype(:rpmkey) do
@doc = "Define public GPG keys that should be part of the rpm
keyring."
newparam(:name) do
desc "The name of the key. This is the keyID (in hex) in
uppercase."
desc 'The name of the key. This is the keyID (in hex) in
uppercase.'
isnamevar
validate do |value|
raise Puppet::Error, "Name must not be empty" if value.empty?
unless value =~ /^[0-9A-F]*$/
raise Puppet::Error, 'Name must not be empty' if value.empty?
unless value.match? %r{^[0-9A-F]*$}
raise Puppet::Error, "Invalid key #{value}. The key has be a valid keyID (in hex) in uppercase."
end
end
......@@ -20,11 +19,10 @@ Puppet::Type.newtype(:rpmkey) do
ensurable
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
autorequire(:file) do
self[:source] if self[:source] =~ /^\//
self[:source] if %r{^\/}.match?(self[:source])
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