Class: ForemanOpenscap::Policy
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForemanOpenscap::Policy
- Includes:
- Authorizable, Taxonomix
- Defined in:
- app/models/foreman_openscap/policy.rb
Instance Attribute Summary collapse
- #current_step ⇒ Object
-
#wizard_initiated ⇒ Object
writeonly
Sets the attribute wizard_initiated.
Class Method Summary collapse
Instance Method Summary collapse
- #current_step?(step_name) ⇒ Boolean
- #first_step? ⇒ Boolean
- #host_ids ⇒ Object
- #host_ids=(ids) ⇒ Object
- #hostgroup_ids ⇒ Object
- #hostgroup_ids=(ids) ⇒ Object
- #hostgroups ⇒ Object
- #hostgroups=(hostgroups) ⇒ Object
- #hosts ⇒ Object
- #hosts=(hosts) ⇒ Object
- #last_step? ⇒ Boolean
- #next_step ⇒ Object
- #previous_step ⇒ Object
- #rewind_step ⇒ Object
- #scan_name ⇒ Object
- #should_validate?(step_name) ⇒ Boolean
- #step_index ⇒ Object
- #step_to_i(step_name) ⇒ Object
- #steps ⇒ Object
- #to_enc ⇒ Object
- #to_enc_legacy ⇒ Object
- #to_html ⇒ Object
- #unassign_hosts(hosts) ⇒ Object
- #update_period_attrs ⇒ Object
- #used_hostgroup_ids ⇒ Object
- #used_location_ids ⇒ Object
- #used_organization_ids ⇒ Object
- #wizard_completed? ⇒ Boolean
- #wizard_initiated? ⇒ Boolean
Instance Attribute Details
#current_step ⇒ Object
106 107 108 |
# File 'app/models/foreman_openscap/policy.rb', line 106 def current_step @current_step || steps.first end |
#wizard_initiated=(value) ⇒ Object (writeonly)
Sets the attribute wizard_initiated
7 8 9 |
# File 'app/models/foreman_openscap/policy.rb', line 7 def wizard_initiated=(value) @wizard_initiated = value end |
Class Method Details
.deploy_by_variants ⇒ Object
25 26 27 |
# File 'app/models/foreman_openscap/policy.rb', line 25 def self.deploy_by_variants %w[puppet ansible manual] end |
Instance Method Details
#current_step?(step_name) ⇒ Boolean
127 128 129 |
# File 'app/models/foreman_openscap/policy.rb', line 127 def current_step?(step_name) current_step == step_name end |
#first_step? ⇒ Boolean
123 124 125 |
# File 'app/models/foreman_openscap/policy.rb', line 123 def first_step? current_step == steps.first end |
#host_ids ⇒ Object
79 80 81 |
# File 'app/models/foreman_openscap/policy.rb', line 79 def host_ids assets.where(:assetable_type => 'Host::Base').pluck(:assetable_id) end |
#host_ids=(ids) ⇒ Object
83 84 85 |
# File 'app/models/foreman_openscap/policy.rb', line 83 def host_ids=(ids) assign_ids ids, 'Host::Base' end |
#hostgroup_ids ⇒ Object
63 64 65 |
# File 'app/models/foreman_openscap/policy.rb', line 63 def hostgroup_ids assets.where(:assetable_type => 'Hostgroup').pluck(:assetable_id) end |
#hostgroup_ids=(ids) ⇒ Object
67 68 69 |
# File 'app/models/foreman_openscap/policy.rb', line 67 def hostgroup_ids=(ids) assign_ids ids, 'Hostgroup' end |
#hostgroups ⇒ Object
71 72 73 |
# File 'app/models/foreman_openscap/policy.rb', line 71 def hostgroups Hostgroup.find(hostgroup_ids) end |
#hostgroups=(hostgroups) ⇒ Object
75 76 77 |
# File 'app/models/foreman_openscap/policy.rb', line 75 def hostgroups=(hostgroups) hostgroup_ids = hostgroups.map(&:id).map(&:to_s) end |
#hosts ⇒ Object
87 88 89 |
# File 'app/models/foreman_openscap/policy.rb', line 87 def hosts Host.where(:id => host_ids) end |
#hosts=(hosts) ⇒ Object
91 92 93 |
# File 'app/models/foreman_openscap/policy.rb', line 91 def hosts=(hosts) host_ids = hosts.map(&:id).map(&:to_s) end |
#last_step? ⇒ Boolean
131 132 133 |
# File 'app/models/foreman_openscap/policy.rb', line 131 def last_step? current_step == steps.last end |
#next_step ⇒ Object
115 116 117 |
# File 'app/models/foreman_openscap/policy.rb', line 115 def next_step steps[steps.index(current_step) + 1] end |
#previous_step ⇒ Object
110 111 112 113 |
# File 'app/models/foreman_openscap/policy.rb', line 110 def previous_step return steps.last if current_step.empty? steps[steps.index(current_step) - 1] end |
#rewind_step ⇒ Object
119 120 121 |
# File 'app/models/foreman_openscap/policy.rb', line 119 def rewind_step @current_step = previous_step end |
#scan_name ⇒ Object
143 144 145 |
# File 'app/models/foreman_openscap/policy.rb', line 143 def scan_name name end |
#should_validate?(step_name) ⇒ Boolean
185 186 187 188 189 190 191 192 193 |
# File 'app/models/foreman_openscap/policy.rb', line 185 def should_validate?(step_name) if new_record? && wizard_initiated? step_index > step_to_i(step_name) elsif new_record? && !wizard_initiated? true else persisted? end end |
#step_index ⇒ Object
139 140 141 |
# File 'app/models/foreman_openscap/policy.rb', line 139 def step_index wizard_completed? ? steps.index(steps.last) : steps.index(current_step) + 1 end |
#step_to_i(step_name) ⇒ Object
95 96 97 |
# File 'app/models/foreman_openscap/policy.rb', line 95 def step_to_i(step_name) steps.index(step_name) + 1 end |
#steps ⇒ Object
99 100 101 102 103 104 |
# File 'app/models/foreman_openscap/policy.rb', line 99 def steps base_steps = [N_('Deployment Options'), N_('Policy Attributes'), N_('SCAP Content'), N_('Schedule')] base_steps << N_('Locations') if SETTINGS[:locations_enabled] base_steps << N_('Organizations') if SETTINGS[:organizations_enabled] base_steps << N_('Hostgroups') # always be last. end |
#to_enc ⇒ Object
170 171 172 173 174 175 176 177 178 179 |
# File 'app/models/foreman_openscap/policy.rb', line 170 def to_enc { 'id' => self.id, 'profile_id' => profile_for_scan, 'content_path' => "/var/lib/openscap/content/#{self.scap_content.digest}.xml", 'tailoring_path' => tailoring_file ? "/var/lib/openscap/tailoring/#{self.tailoring_file.digest}.xml" : '', 'download_path' => "/compliance/policies/#{self.id}/content/#{scap_content.digest}", 'tailoring_download_path' => tailoring_file ? "/compliance/policies/#{self.id}/tailoring/#{tailoring_file.digest}" : '' }.merge(period_enc) end |
#to_enc_legacy ⇒ Object
181 182 183 |
# File 'app/models/foreman_openscap/policy.rb', line 181 def to_enc_legacy to_enc.tap { |hash| hash['download_path'] = "/compliance/policies/#{self.id}/content" } end |
#to_html ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/foreman_openscap/policy.rb', line 49 def to_html if scap_content.nil? return (_('Cannot generate HTML guide, scap content is missing.')) end if (proxy = scap_content.proxy_url) api = ProxyAPI::Openscap.new(:url => proxy) else return (_('Cannot generate HTML guide, no valid OpenSCAP proxy server found.')) end api.policy_html_guide(scap_content.scap_file, scap_content_profile.try(:profile_id)) end |
#unassign_hosts(hosts) ⇒ Object
165 166 167 168 |
# File 'app/models/foreman_openscap/policy.rb', line 165 def unassign_hosts(hosts) host_asset_ids = ForemanOpenscap::Asset.where(:assetable_type => 'Host::Base', :assetable_id => hosts.map(&:id)).pluck(:id) self.asset_ids = self.asset_ids - host_asset_ids end |
#update_period_attrs ⇒ Object
199 200 201 202 203 204 205 206 207 208 |
# File 'app/models/foreman_openscap/policy.rb', line 199 def update_period_attrs case period when 'monthly' erase_period_attrs(%w[cron_line weekday]) when 'weekly' erase_period_attrs(%w[cron_line day_of_month]) when 'custom' erase_period_attrs(%w[weekday day_of_month]) end end |
#used_hostgroup_ids ⇒ Object
161 162 163 |
# File 'app/models/foreman_openscap/policy.rb', line 161 def used_hostgroup_ids [] end |
#used_location_ids ⇒ Object
147 148 149 150 151 152 |
# File 'app/models/foreman_openscap/policy.rb', line 147 def used_location_ids Location.joins(:taxable_taxonomies).where( 'taxable_taxonomies.taxable_type' => 'ForemanOpenscap::Policy', 'taxable_taxonomies.taxable_id' => id ).pluck("#{Location.arel_table.name}.id") end |
#used_organization_ids ⇒ Object
154 155 156 157 158 159 |
# File 'app/models/foreman_openscap/policy.rb', line 154 def used_organization_ids Organization.joins(:taxable_taxonomies).where( 'taxable_taxonomies.taxable_type' => 'ForemanOpenscap::Policy', 'taxable_taxonomies.taxable_id' => id ).pluck("#{Location.arel_table.name}.id") end |
#wizard_completed? ⇒ Boolean
135 136 137 |
# File 'app/models/foreman_openscap/policy.rb', line 135 def wizard_completed? new_record? && current_step.blank? end |
#wizard_initiated? ⇒ Boolean
195 196 197 |
# File 'app/models/foreman_openscap/policy.rb', line 195 def wizard_initiated? @wizard_initiated end |