Class: MuchSecrets::Secret
- Inherits:
-
Object
- Object
- MuchSecrets::Secret
- Defined in:
- lib/muchsecrets/secret.rb
Instance Method Summary collapse
- #encrypt_string(val) ⇒ Object
- #get_consul_secret(uri) ⇒ Object
- #get_http_secret(uri) ⇒ Object
-
#initialize(options = {}) ⇒ Secret
constructor
A new instance of Secret.
Constructor Details
#initialize(options = {}) ⇒ Secret
Returns a new instance of Secret.
6 7 8 9 10 11 |
# File 'lib/muchsecrets/secret.rb', line 6 def initialize( = {}) @private_key = [:private_key] @public_key = [:public_key] @base_url = [:base_url] || "http://consul:8500/v1/kv" @cipher = OpenSSL::Cipher.new([:cipher] || "AES-256-CFB") end |
Instance Method Details
#encrypt_string(val) ⇒ Object
23 24 25 26 |
# File 'lib/muchsecrets/secret.rb', line 23 def encrypt_string(val) cert = OpenSSL::X509::Certificate.new(File.read(@public_key)) return OpenSSL::PKCS7::encrypt([cert], val, @cipher, OpenSSL::PKCS7::BINARY) end |
#get_consul_secret(uri) ⇒ Object
18 19 20 21 |
# File 'lib/muchsecrets/secret.rb', line 18 def get_consul_secret(uri) uri = uri + '?raw' return get_http_secret(uri) end |
#get_http_secret(uri) ⇒ Object
13 14 15 16 |
# File 'lib/muchsecrets/secret.rb', line 13 def get_http_secret(uri) encrypted_secret = fetch_encrypted_http_secret(uri) return decrypt_string(encrypted_secret) end |