Class: ChefDK::Policyfile::Lister
- Inherits:
-
Object
- Object
- ChefDK::Policyfile::Lister
- Defined in:
- lib/chef-dk/policyfile/lister.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#policy_lock_content ⇒ Object
Returns the value of attribute policy_lock_content.
Instance Method Summary collapse
- #active_revisions ⇒ Object
- #empty? ⇒ Boolean
- #http_client ⇒ Object
-
#initialize(config: nil) ⇒ Lister
constructor
A new instance of Lister.
- #orphaned_revisions(policy_name) ⇒ Object
-
#policies_by_group ⇒ Object
A Hash with the following format: “dev” => { “appserver” => “1111111111111111111111111111111111111111111111111111111111111111”, “load-balancer” => “5555555555555555555555555555555555555555555555555555555555555555”, “db” => “9999999999999999999999999999999999999999999999999999999999999999” }.
-
#policies_by_name ⇒ Object
A Hash with the following format { “appserver” => { “1111111111111111111111111111111111111111111111111111111111111111” => {}, “2222222222222222222222222222222222222222222222222222222222222222” => {} },.
- #revision_ids_by_group_for(policy_name) ⇒ Object
- #revision_ids_by_group_for_each_policy ⇒ Object
- #revision_info_for(policy_name, _revision_id_list) ⇒ Object
-
#set!(policies_by_name, policies_by_group) ⇒ Object
private
Sets internal copy of policyfile data to policies_by_name and policies_by_group.
Constructor Details
#initialize(config: nil) ⇒ Lister
Returns a new instance of Lister.
116 117 118 119 120 121 122 |
# File 'lib/chef-dk/policyfile/lister.rb', line 116 def initialize(config: nil) @config = config @policies_by_name = nil @policies_by_group = nil @policy_lock_content = {} @active_revisions = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
114 115 116 |
# File 'lib/chef-dk/policyfile/lister.rb', line 114 def config @config end |
#policy_lock_content ⇒ Object
Returns the value of attribute policy_lock_content.
112 113 114 |
# File 'lib/chef-dk/policyfile/lister.rb', line 112 def policy_lock_content @policy_lock_content end |
Instance Method Details
#active_revisions ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/chef-dk/policyfile/lister.rb', line 173 def active_revisions @active_revisions ||= policies_by_group.inject(Set.new) do |set, (_group, policy_name_rev_id_map)| policy_name_rev_id_map.each do |policy_name, rev_id| set << rev_id end set end end |
#empty? ⇒ Boolean
182 183 184 |
# File 'lib/chef-dk/policyfile/lister.rb', line 182 def empty? policies_by_name.empty? && policies_by_group.empty? end |
#http_client ⇒ Object
186 187 188 189 190 |
# File 'lib/chef-dk/policyfile/lister.rb', line 186 def http_client @http_client ||= ChefDK::AuthenticatedHTTP.new(config.chef_server_url, signing_key_filename: config.client_key, client_name: config.node_name) end |
#orphaned_revisions(policy_name) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/chef-dk/policyfile/lister.rb', line 165 def orphaned_revisions(policy_name) orphans = [] policies_by_name[policy_name].each do |rev_id, _data| orphans << rev_id unless active_revisions.include?(rev_id) end orphans end |
#policies_by_group ⇒ Object
A Hash with the following format:
"dev" => {
"appserver" => "1111111111111111111111111111111111111111111111111111111111111111",
"load-balancer" => "5555555555555555555555555555555555555555555555555555555555555555",
"db" => "9999999999999999999999999999999999999999999999999999999999999999"
}
141 142 143 144 |
# File 'lib/chef-dk/policyfile/lister.rb', line 141 def policies_by_group @policies_by_group || fetch_policy_lists @policies_by_group end |
#policies_by_name ⇒ Object
A Hash with the following format
{
"appserver" => {
"1111111111111111111111111111111111111111111111111111111111111111" => {},
"2222222222222222222222222222222222222222222222222222222222222222" => {}
},
130 131 132 133 |
# File 'lib/chef-dk/policyfile/lister.rb', line 130 def policies_by_name @policies_by_name || fetch_policy_lists @policies_by_name end |
#revision_ids_by_group_for(policy_name) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/chef-dk/policyfile/lister.rb', line 157 def revision_ids_by_group_for(policy_name) map = policies_by_group.inject({}) do |rev_id_map, (group_name, rev_id_map_for_group)| rev_id_map[group_name] = rev_id_map_for_group[policy_name] rev_id_map end PolicyGroupRevIDMap.new(policy_name, map) end |
#revision_ids_by_group_for_each_policy ⇒ Object
150 151 152 153 154 155 |
# File 'lib/chef-dk/policyfile/lister.rb', line 150 def revision_ids_by_group_for_each_policy policies_by_name.each do |policy_name, _policies| rev_id_by_group = revision_ids_by_group_for(policy_name) yield policy_name, rev_id_by_group end end |
#revision_info_for(policy_name, _revision_id_list) ⇒ Object
146 147 148 |
# File 'lib/chef-dk/policyfile/lister.rb', line 146 def revision_info_for(policy_name, _revision_id_list) RevIDLockDataMap.new(policy_name, policy_lock_content[policy_name]) end |
#set!(policies_by_name, policies_by_group) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets internal copy of policyfile data to policies_by_name and policies_by_group. Used for internal testing.
195 196 197 198 199 |
# File 'lib/chef-dk/policyfile/lister.rb', line 195 def set!(policies_by_name, policies_by_group) @policies_by_name = policies_by_name @policies_by_group = policies_by_group @active_revisions = nil end |