class ChefCLI::Policyfile::Lister
def active_revisions
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
def empty?
def empty? policies_by_name.empty? && policies_by_group.empty? end
def fetch_policy_lists
def fetch_policy_lists policy_list_data = http_client.get("policies") set_policies_by_name_from_api(policy_list_data) policy_group_data = http_client.get("policy_groups") set_policies_by_group_from_api(policy_group_data) end
def http_client
def http_client @http_client ||= Chef::ServerAPI.new(config.chef_server_url, signing_key_filename: config.client_key, client_name: config.node_name) end
def initialize(config: nil)
def initialize(config: nil) @config = config @policies_by_name = nil @policies_by_group = nil @policy_lock_content = {} @active_revisions = nil end
def orphaned_revisions(policy_name)
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
def policies_by_group
"db" => "9999999999999999999999999999999999999999999999999999999999999999"
"load-balancer" => "5555555555555555555555555555555555555555555555555555555555555555",
"appserver" => "1111111111111111111111111111111111111111111111111111111111111111",
"dev" => {
A Hash with the following format:
def policies_by_group @policies_by_group || fetch_policy_lists @policies_by_group end
def policies_by_name
"2222222222222222222222222222222222222222222222222222222222222222" => {}
"1111111111111111111111111111111111111111111111111111111111111111" => {},
"appserver" => {
{
A Hash with the following format
def policies_by_name @policies_by_name || fetch_policy_lists @policies_by_name end
def revision_ids_by_group_for(policy_name)
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
def revision_ids_by_group_for_each_policy
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
def revision_info_for(policy_name, _revision_id_list)
def revision_info_for(policy_name, _revision_id_list) RevIDLockDataMap.new(policy_name, policy_lock_content[policy_name]) end
def set!(policies_by_name, policies_by_group)
- Api: - private
def set!(policies_by_name, policies_by_group) @policies_by_name = policies_by_name @policies_by_group = policies_by_group @active_revisions = nil end
def set_policies_by_group_from_api(policy_group_data)
def set_policies_by_group_from_api(policy_group_data) @policies_by_group = policy_group_data.inject({}) do |map, (policy_group, policy_info)| map[policy_group] = (policy_info["policies"] || []).inject({}) do |rev_map, (policy_name, rev_info)| rev_map[policy_name] = rev_info["revision_id"]; rev_map end map end end
def set_policies_by_name_from_api(policy_list_data)
def set_policies_by_name_from_api(policy_list_data) @policies_by_name = policy_list_data.inject({}) do |map, (policy_name, policy_info)| map[policy_name] = policy_info["revisions"] map end end