Browse Source

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

master
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 @@
Puppet::Type.type(:gpgkey).provide(:gpgme) do
require 'gpgme'
def exists?
! GPGME::Key.find(:secret, keyname()).empty?
end

def create
ctx = GPGME::Ctx.new
keydata = "<GnupgKeyParms format=\"internal\">\n"
keydata += "Key-Type: " +@resource.value(:keytype)+"\n"
keydata += "Key-Length: " +@resource.value(:keylength)+"\n"
keydata += "Subkey-Type: " +@resource.value(:subkeytype)+"\n"
keydata += "Subkey-Length: " +@resource.value(:subkeylength)+"\n"
keydata += "Name-Real: " +@resource.value(:name)+"\n"
keydata += "Name-Comment: " +keyname()+"\n"
keydata += "Name-Email: " +@resource.value(:email)+"\n"
keydata += "Expire-Date: " +@resource.value(:expire)+"\n"
keydata += "Passphrase: " +@resource.value(:password)+"\n"
keydata += "</GnupgKeyParms>\n"

ctx.genkey(keydata, nil, nil)
end

def destroy
GPGME::Key.find(:secret, keyname()).each do |key|
key.delete!(true)
end
end

private
def keyname
keyname = 'puppet#' + @resource.value(:name) + '#'
return keyname
end

end

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

@@ -0,0 +1,45 @@
Puppet::Type.newtype(:gpgkey) do
ensurable
@doc = "Creates and managed GPG keys through GPGME"

newparam(:name, :namevar => true) do
desc 'The name of the GPG key, this will use the Real Name attribute of the key'
end

newparam(:keytype) do
defaultto 'RSA'
desc 'GPG Key Type'
end

newparam(:keylength) do
defaultto '4096'
desc 'Key Length (default 4096)'
end

newparam(:subkeytype) do
defaultto 'RSA'
desc 'GPG Sub Key Type'
end

newparam(:subkeylength) do
defaultto '4096'
desc 'Sub Key Length (default 4096)'
end

newparam(:email) do
defaultto 'puppet@localhost'
end

newparam(:expire) do
defaultto '0'
end

newparam(:password) do
defaultto ''
end

newparam(:armour) do
defaultto true
end

end

Loading…
Cancel
Save