Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish as generic eyaml support for ruby #153

Open
marek-obuchowicz opened this issue Apr 15, 2015 · 2 comments
Open

Publish as generic eyaml support for ruby #153

marek-obuchowicz opened this issue Apr 15, 2015 · 2 comments

Comments

@marek-obuchowicz
Copy link

Guys,

Great piece of software. Is there any chance that you allow direct ruby calls to read+decrypt eyaml file (like YAML::load) and/or to encrypt/decript strings via function call? Would be great if we could benefit from your work not only while using hiera

@TomPoulton
Copy link
Collaborator

Hi @marek-obuchowicz, that's an interesting request. Theoretically yes that's fine, it would be good to ensure it's all modular anyway so that the encryption stuff is all isolated and the interaction with hiera is just the "presentation" layer, but we'd have to make sure all the keys and options etc are handled in a nice way for both hiera setups and direct ruby usage.

I'm working on refactoring a lot of the options handling and behind the scenes stuff so I'll bear this request in mind as I'm working on it.

@mariusor
Copy link

mariusor commented Jul 25, 2016

Until this issue can be solved in a more straight forward manner, I'm using something similar to this snippet:

I think its only benefit is not having to go through the shell, but YMMV.

require 'hiera/backend/eyaml/options'
require 'hiera/backend/eyaml/subcommands/encrypt'

def load_public_key (public_key_file)
    raise "eyaml public key file not found / readable: #{public_key_file}" unless File.readable? public_key_file

    Hiera::Backend::Eyaml::Options['pkcs7_public_key'] = public_key_file
end

def encrypt_string (input, public_key='./keys/public_key.pkcs7.pem')
    load_public_key public_key

    Hiera::Backend::Eyaml::Options[:source] = 'string'
    Hiera::Backend::Eyaml::Options[:input_data] = input
    output = Hiera::Backend::Eyaml::Subcommands::Encrypt.execute
    output.chomp
 end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants