Class: ChefCLI::PolicyfileServices::RmPolicy
- Inherits:
-
Object
- Object
- ChefCLI::PolicyfileServices::RmPolicy
- Defined in:
- lib/chef-cli/policyfile_services/rm_policy.rb
Instance Attribute Summary collapse
- #chef_config ⇒ Object readonly private
-
#policy_name ⇒ Object
readonly
Returns the value of attribute policy_name.
- #ui ⇒ Object readonly private
- #undo_record ⇒ Object readonly private
- #undo_stack ⇒ Object readonly private
Instance Method Summary collapse
-
#http_client ⇒ Object
private
An instance of Chef::ServerAPI configured with the user’s server URL and credentials.
-
#initialize(config: nil, ui: nil, policy_name: nil) ⇒ RmPolicy
constructor
A new instance of RmPolicy.
- #run ⇒ Object
Constructor Details
#initialize(config: nil, ui: nil, policy_name: nil) ⇒ RmPolicy
Returns a new instance of RmPolicy.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 42 def initialize(config: nil, ui: nil, policy_name: nil) @chef_config = config @ui = ui @policy_name = policy_name @policy_revision_data = nil @policy_exists = false @policy_group_data = nil @undo_record = Policyfile::UndoRecord.new @undo_stack = Policyfile::UndoStack.new end |
Instance Attribute Details
#chef_config ⇒ Object (readonly)
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.
31 32 33 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 31 def chef_config @chef_config end |
#policy_name ⇒ Object (readonly)
Returns the value of attribute policy_name.
28 29 30 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 28 def policy_name @policy_name end |
#ui ⇒ Object (readonly)
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.
34 35 36 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 34 def ui @ui end |
#undo_record ⇒ Object (readonly)
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.
37 38 39 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 37 def undo_record @undo_record end |
#undo_stack ⇒ Object (readonly)
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.
40 41 42 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 40 def undo_stack @undo_stack end |
Instance Method Details
#http_client ⇒ 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.
An instance of Chef::ServerAPI configured with the user’s server URL and credentials.
77 78 79 80 81 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 77 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 |
#run ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chef-cli/policyfile_services/rm_policy.rb', line 55 def run unless policy_exists? ui.err("Policy '#{policy_name}' does not exist on the server") return false end undo_record.description = "delete-policy #{policy_name}" unless policy_has_no_revisions? gather_policy_data_for_undo end http_client.delete("/policies/#{policy_name}") undo_stack.push(undo_record) ui.err("Removed policy '#{policy_name}'.") rescue => e raise DeletePolicyError.new("Failed to delete policy '#{policy_name}'", e) end |