From 7602f765546cd5d99ce8cf483cc3bedbe4fd0317 Mon Sep 17 00:00:00 2001 From: crayfishx Date: Tue, 25 Sep 2012 09:39:25 -0700 Subject: first commit --- lib/puppet/provider/gpgkey/gpgme.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/puppet/provider/gpgkey/gpgme.rb (limited to 'lib/puppet/provider/gpgkey/gpgme.rb') diff --git a/lib/puppet/provider/gpgkey/gpgme.rb b/lib/puppet/provider/gpgkey/gpgme.rb new file mode 100644 index 0000000..7a37f45 --- /dev/null +++ b/lib/puppet/provider/gpgkey/gpgme.rb @@ -0,0 +1,35 @@ +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 = "\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 += "\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 -- cgit v1.2.3