Class: Ridley::DataBagItemObject
- Inherits:
-
ChefObject
- Object
- ChefObject
- Ridley::DataBagItemObject
- Defined in:
- lib/ridley/chef_objects/data_bag_item_obect.rb
Instance Attribute Summary collapse
- #data_bag ⇒ Ridley::DataBagObject readonly
Instance Method Summary collapse
-
#decrypt ⇒ Hash
Decrypts this data bag item.
-
#decrypt_value(value) ⇒ Hash
Decrypts an individual value stored inside the data bag item.
- #from_hash(hash) ⇒ Object
-
#initialize(resource, data_bag, new_attrs = {}) ⇒ DataBagItemObject
constructor
A new instance of DataBagItemObject.
-
#reload ⇒ Object
Reload the attributes of the instantiated resource.
-
#save ⇒ Boolean
Creates a resource on the target remote or updates one if the resource already exists.
-
#update ⇒ Boolean
Updates the instantiated resource on the target remote with any changes made to self.
Methods inherited from ChefObject
#<=>, #==, chef_id, #chef_id, chef_json_class, chef_type, #eql?, #hash, #inspect, set_chef_id, set_chef_json_class, set_chef_type
Constructor Details
#initialize(resource, data_bag, new_attrs = {}) ⇒ DataBagItemObject
Returns a new instance of DataBagItemObject.
19 20 21 22 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 19 def initialize(resource, data_bag, new_attrs = {}) super(resource, new_attrs) @data_bag = data_bag end |
Instance Attribute Details
#data_bag ⇒ Ridley::DataBagObject (readonly)
7 8 9 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 7 def data_bag @data_bag end |
Instance Method Details
#decrypt ⇒ Hash
Decrypts this data bag item.
45 46 47 48 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 45 def decrypt decrypted_hash = Hash[_attributes_.map { |key, value| [key, key == "id" ? value : decrypt_value(value)] }] mass_assign(decrypted_hash) end |
#decrypt_value(value) ⇒ Hash
Decrypts an individual value stored inside the data bag item.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 59 def decrypt_value(value) if encrypted_data_bag_secret.nil? raise Errors::EncryptedDataBagSecretNotSet end decoded_value = Base64.decode64(value) cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc') cipher.decrypt cipher.pkcs5_keyivgen(encrypted_data_bag_secret) decrypted_value = cipher.update(decoded_value) + cipher.final YAML.load(decrypted_value) end |
#from_hash(hash) ⇒ Object
99 100 101 102 103 104 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 99 def from_hash(hash) hash = Hashie::Mash.new(hash.to_hash) mass_assign(hash.has_key?(:raw_data) ? hash[:raw_data] : hash) self end |
#reload ⇒ Object
Reload the attributes of the instantiated resource
77 78 79 80 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 77 def reload mass_assign(resource.find(data_bag, self)._attributes_) self end |
#save ⇒ Boolean
Creates a resource on the target remote or updates one if the resource already exists.
32 33 34 35 36 37 38 39 40 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 32 def save raise Errors::InvalidResource.new(self.errors) unless valid? mass_assign(resource.create(data_bag, self)._attributes_) true rescue Errors::HTTPConflict self.update true end |
#update ⇒ Boolean
Updates the instantiated resource on the target remote with any changes made to self
89 90 91 92 93 94 |
# File 'lib/ridley/chef_objects/data_bag_item_obect.rb', line 89 def update raise Errors::InvalidResource.new(self.errors) unless valid? mass_assign(resource.update(data_bag, self)._attributes_) true end |