class ChefCLI::PolicyfileServices::RmPolicyGroup
def http_client
- Api: - private
def http_client @http_client ||= Chef::ServerAPI.new(chef_config.chef_server_url, signing_key_filename: chef_config.client_key, client_name: chef_config.node_name) end
def initialize(config: nil, ui: nil, policy_group: nil)
def initialize(config: nil, ui: nil, policy_group: nil) @chef_config = config @ui = ui @policy_group = policy_group @undo_record = Policyfile::UndoRecord.new @undo_stack = Policyfile::UndoStack.new end
def run
def run undo_record.description = "delete-policy-group #{policy_group}" policy_group_list = http_client.get("/policy_groups") unless policy_group_list.key?(policy_group) ui.err("Policy group '#{policy_group}' does not exist on the server") return false end policy_group_info = policy_group_list[policy_group] policies_in_group = policy_group_info["policies"] || [] policies_in_group.each do |name, revision_info| rev_id = revision_info["revision_id"] policy_revision_data = http_client.get("/policies/#{name}/revisions/#{rev_id}") undo_record.add_policy_revision(name, policy_group, policy_revision_data) end http_client.delete("/policy_groups/#{policy_group}") undo_record.add_policy_group(policy_group) ui.err("Removed policy group '#{policy_group}'.") undo_stack.push(undo_record) rescue => e raise DeletePolicyGroupError.new("Failed to delete policy group '#{policy_group}'", e) end