Class: ChefKeepass::User
- Inherits:
-
Object
- Object
- ChefKeepass::User
- Defined in:
- lib/chef-keepass/user.rb
Instance Attribute Summary collapse
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #decrypt_password ⇒ Object
-
#initialize(data_bag, username) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(data_bag, username) ⇒ User
Returns a new instance of User.
5 6 7 8 |
# File 'lib/chef-keepass/user.rb', line 5 def initialize(data_bag, username) @username = username @data_bag = data_bag end |
Instance Attribute Details
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/chef-keepass/user.rb', line 3 def username @username end |
Instance Method Details
#decrypt_password ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/chef-keepass/user.rb', line 10 def decrypt_password # use the private client_key file to create a decryptor private_key = open(Chef::Config[:client_key]).read private_key = OpenSSL::PKey::RSA.new(private_key) keys = Chef::DataBagItem.load(@data_bag, "#{username}_keys") unless keys[Chef::Config[:node_name]] throw "Password for #{username} is not encrypted for you! Rebuild the password data bag" end node_key = Base64.decode64(keys[Chef::Config[:node_name]]) shared_secret = private_key.private_decrypt(node_key) cred = Chef::EncryptedDataBagItem.load(@data_bag, @username, shared_secret) cred["password"] end |