Class: Chef::EncryptedAttribute::RemoteNode
- Inherits:
-
Object
- Object
- Chef::EncryptedAttribute::RemoteNode
- Includes:
- SearchHelper, Mixin::ParamsValidate
- Defined in:
- lib/chef/encrypted_attribute/remote_node.rb
Overview
Remote Node object to read and save node attributes remotely.
Class Method Summary collapse
-
.cache ⇒ CacheLru
Remote node attribute values cache.
Instance Method Summary collapse
-
#delete_attribute(attr_ary) ⇒ Boolean
Deletes a remote node attribute.
-
#initialize(name) ⇒ RemoteNode
constructor
Remote Node object constructor.
-
#load_attribute(attr_ary, rows = 1000, partial_search = true) ⇒ Mixed
Loads a remote node attribute.
-
#name(arg = nil) ⇒ String
Read or set node name.
-
#save_attribute(attr_ary, value) ⇒ Mixed
Saves a remote node attribute.
Methods included from SearchHelper
#assert_normal_search_response, #assert_partial_search_response, #assert_search_keys, #catch_search_exceptions, #empty_search?, #escape, #escape_query, #filter_normal_search_response, #filter_partial_search_response, #generate_partial_search_keys, #normal_search, #parse_normal_search_response, #parse_normal_search_row_attribute, #parse_partial_search_response, #partial_search, #query, #search, #search_by_name, #valid_search_keys?, #valid_search_keys_key?, #valid_search_keys_value?
Constructor Details
#initialize(name) ⇒ RemoteNode
Remote Node object constructor.
34 35 36 |
# File 'lib/chef/encrypted_attribute/remote_node.rb', line 34 def initialize(name) name(name) end |
Class Method Details
.cache ⇒ CacheLru
Remote node attribute values cache.
It is disabled by default. You can enable it changing it's size:
Chef::EncryptedAttribute::RemoteNode.cache.max_size(1024)
47 48 49 50 |
# File 'lib/chef/encrypted_attribute/remote_node.rb', line 47 def self.cache # disabled by default @@cache ||= Chef::EncryptedAttribute::CacheLru.new(0) end |
Instance Method Details
#delete_attribute(attr_ary) ⇒ Boolean
Deletes a remote node attribute.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/chef/encrypted_attribute/remote_node.rb', line 112 def delete_attribute(attr_ary) assert_attribute_array(attr_ary) cache_key = cache_key(name, attr_ary) node = Chef::Node.load(name) last = attr_ary.pop node_attr = attr_ary.reduce(node.normal) do |a, k| a.respond_to?(:key?) && a.key?(k) ? a[k] : nil end if node_attr.respond_to?(:key?) && node_attr.key?(last) node_attr.delete(last) node.save self.class.cache.delete(cache_key) true else false end end |
#load_attribute(attr_ary, rows = 1000, partial_search = true) ⇒ Mixed
Loads a remote node attribute.
75 76 77 78 79 80 81 82 |
# File 'lib/chef/encrypted_attribute/remote_node.rb', line 75 def load_attribute(attr_ary, rows = 1000, partial_search = true) assert_attribute_array(attr_ary) cache_key = cache_key(name, attr_ary) return self.class.cache[cache_key] if self.class.cache.key?(cache_key) keys = { 'value' => attr_ary } res = search_by_name(:node, @name, keys, rows, partial_search) self.class.cache[cache_key] = parse_search_result(res) end |
#name(arg = nil) ⇒ String
Read or set node name.
56 57 58 59 60 61 62 63 |
# File 'lib/chef/encrypted_attribute/remote_node.rb', line 56 def name(arg = nil) # TODO: clean the cache when changed? set_or_return( :name, arg, kind_of: String ) end |
#save_attribute(attr_ary, value) ⇒ Mixed
Saves a remote node attribute.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/chef/encrypted_attribute/remote_node.rb', line 90 def save_attribute(attr_ary, value) assert_attribute_array(attr_ary) cache_key = cache_key(name, attr_ary) node = Chef::Node.load(name) last = attr_ary.pop node_attr = attr_ary.reduce(node.normal) do |a, k| a[k] = Mash.new unless a.key?(k) a[k] end node_attr[last] = value node.save self.class.cache[cache_key] = value end |