Browse Source

Add a GPG key type and provider from https://github.com/crayfishx/puppet-gpg

Aaron Hicks 6 years ago
parent
commit
d9596c67e6
2 changed files with 81 additions and 0 deletions
  1. 36
    0
      lib/puppet/provider/gpgkey/gpgme.rb
  2. 45
    0
      lib/puppet/type/gpgkey.rb

+ 36
- 0
lib/puppet/provider/gpgkey/gpgme.rb View File

@@ -0,0 +1,36 @@
1
+Puppet::Type.type(:gpgkey).provide(:gpgme) do
2
+  require 'gpgme'
3
+  def exists?
4
+    ! GPGME::Key.find(:secret, keyname()).empty?
5
+  end
6
+
7
+  def create
8
+    ctx = GPGME::Ctx.new
9
+    keydata = "<GnupgKeyParms format=\"internal\">\n"
10
+    keydata += "Key-Type: "       +@resource.value(:keytype)+"\n"
11
+    keydata += "Key-Length: "     +@resource.value(:keylength)+"\n"
12
+    keydata += "Subkey-Type: "    +@resource.value(:subkeytype)+"\n"
13
+    keydata += "Subkey-Length: "  +@resource.value(:subkeylength)+"\n"
14
+    keydata += "Name-Real: "      +@resource.value(:name)+"\n"
15
+    keydata += "Name-Comment: "   +keyname()+"\n"
16
+    keydata += "Name-Email: "     +@resource.value(:email)+"\n"
17
+    keydata += "Expire-Date: "    +@resource.value(:expire)+"\n"
18
+    keydata += "Passphrase: "     +@resource.value(:password)+"\n"
19
+    keydata += "</GnupgKeyParms>\n"
20
+
21
+    ctx.genkey(keydata, nil, nil)
22
+  end
23
+
24
+  def destroy
25
+    GPGME::Key.find(:secret, keyname()).each do |key|
26
+      key.delete!(true)
27
+    end
28
+  end
29
+
30
+  private
31
+  def keyname
32
+    keyname = 'puppet#' + @resource.value(:name) + '#'
33
+    return keyname
34
+  end
35
+
36
+end

+ 45
- 0
lib/puppet/type/gpgkey.rb View File

@@ -0,0 +1,45 @@
1
+Puppet::Type.newtype(:gpgkey) do
2
+    ensurable
3
+    @doc = "Creates and managed GPG keys through GPGME"
4
+
5
+    newparam(:name, :namevar => true) do
6
+      desc 'The name of the GPG key, this will use the Real Name attribute of the key'
7
+    end
8
+
9
+    newparam(:keytype) do
10
+      defaultto 'RSA'
11
+      desc 'GPG Key Type'
12
+    end
13
+
14
+    newparam(:keylength) do
15
+      defaultto '4096'
16
+      desc 'Key Length (default 4096)'
17
+    end
18
+
19
+    newparam(:subkeytype) do
20
+      defaultto 'RSA'
21
+      desc 'GPG Sub Key Type'
22
+    end
23
+
24
+    newparam(:subkeylength) do
25
+      defaultto '4096'
26
+      desc 'Sub Key Length (default 4096)'
27
+    end
28
+
29
+    newparam(:email) do
30
+      defaultto 'puppet@localhost'
31
+    end
32
+
33
+    newparam(:expire) do
34
+      defaultto '0'
35
+    end
36
+
37
+    newparam(:password) do
38
+      defaultto ''
39
+    end
40
+
41
+    newparam(:armour) do
42
+      defaultto true
43
+    end
44
+
45
+end

Loading…
Cancel
Save