Sha256: 5a1a7b780ffdd54d67e63bb19ff6e0c2566b9d9344d90112574e73b8fdb64f27

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

# mymodule/lib/puppet/functions/gpg_encrypt.rb
Puppet::Functions.create_function(:'gpg_encrypt') do
  # Encrypts a file with GnuPG.
  # @param [String] file The file to encrypt.
  # @param [String] gpghome The path to the GnuPG home directory containing the credentials.
  # @param [String] password_file The password file to use for encryption.
  # @return [String] Returns a string of encrypted contents.
  # @example Encrypting a file.
  # gpg_encrypt('/path/to/data.txt', '/home/alice/.gnupg', '/path/to/password.txt') => 'asdnlfi378rth43rt78h4t8b3v844b'
  dispatch :gpg_encrypt do
    required_param 'String', :file
    required_param 'String', :gpghome
    required_param 'String', :password_file
    return_type 'String'
  end

  def gpg_encrypt(file, gpghome, password_file)
    begin
      require 'rapid-vaults'
    rescue LoadError
      raise 'Rapid Vaults is required to be installed on the puppet master to use this custom function!'
    end

    ENV['GNUPGHOME'] = gpghome

    RapidVaults::API.main(action: :encrypt, algorithm: :gpgme, file: file, pw: password_file)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rapid-vaults-1.1.2 lib/rapid-vaults/bindings/puppet_gpg_encrypt.rb
rapid-vaults-1.1.1 lib/rapid-vaults/integrations/puppet_gpg_encrypt.rb