rpm.rb 985 Bytes
Newer Older
Stefan Schulte's avatar
Stefan Schulte committed
1
2
3
4
5
6
Puppet::Type.type(:rpmkey).provide(:rpm) do

  commands :rpm => 'rpm'

  def self.instances
    keys = []
7
8
9
10
11
12
13
14

    begin
      rpm_query = rpm('-q','gpg-pubkey')
    rescue Puppet::ExecutionFailure
      return []
    end

    rpm_query.each_line do |line|
15
      line.chomp!
Stefan Schulte's avatar
Stefan Schulte committed
16
17
18
      if match = /^gpg-pubkey-([0-9a-f]*)-[0-9a-f]*/.match(line)
        keys << new(:name => match.captures[0].upcase, :ensure => :present)
      else
19
        warning "Unexpected rpm output #{line.inspect}. Ignoring this line."
Stefan Schulte's avatar
Stefan Schulte committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
      end
    end
    keys
  end

  def self.prefetch(resources)
    instances.each do |prov|
      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]
    rpm('--import', @resource[:source])
  end

  def exists?
    get(:ensure) != :absent
  end

  def destroy
    rpm('-e', '--allmatches', "gpg-pubkey-#{@resource[:name].downcase}")
  end

end