Class: ForemanOpenscap::Policy
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ForemanOpenscap::Policy
show all
- Includes:
- Authorizable, PolicyCommon, Taxonomix
- Defined in:
- app/models/foreman_openscap/policy.rb
Constant Summary
collapse
- STEPS_LIST =
[N_('Deployment Options'), N_('Policy Attributes'), N_('SCAP Content'), N_('Schedule'), N_('Locations'), N_('Organizations'), N_('Hostgroups')]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#cron_line_split, #update_period_attrs, #valid_cron_line, #valid_day_of_month, #valid_weekday
Instance Attribute Details
#current_step ⇒ Object
118
119
120
|
# File 'app/models/foreman_openscap/policy.rb', line 118
def current_step
@current_step || steps.first
end
|
#wizard_initiated=(value) ⇒ Object
Sets the attribute wizard_initiated
9
10
11
|
# File 'app/models/foreman_openscap/policy.rb', line 9
def wizard_initiated=(value)
@wizard_initiated = value
end
|
Class Method Details
.deploy_by_variants ⇒ Object
28
29
30
|
# File 'app/models/foreman_openscap/policy.rb', line 28
def self.deploy_by_variants
%w[puppet ansible manual]
end
|
Instance Method Details
#change_deploy_type(params) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'app/models/foreman_openscap/policy.rb', line 67
def change_deploy_type(params)
self.class.transaction do
if params[:deploy_by] && deploy_by != params[:deploy_by]
assign_attributes params
ForemanOpenscap::LookupKeyOverrider.new(self).override
end
errors.none? && update(params)
end
end
|
#current_step?(step_name) ⇒ Boolean
139
140
141
|
# File 'app/models/foreman_openscap/policy.rb', line 139
def current_step?(step_name)
current_step == step_name
end
|
#first_step? ⇒ Boolean
135
136
137
|
# File 'app/models/foreman_openscap/policy.rb', line 135
def first_step?
current_step == steps.first
end
|
#host_ids ⇒ Object
94
95
96
|
# File 'app/models/foreman_openscap/policy.rb', line 94
def host_ids
assets.where(:assetable_type => 'Host::Base').pluck(:assetable_id)
end
|
#host_ids=(ids) ⇒ Object
98
99
100
|
# File 'app/models/foreman_openscap/policy.rb', line 98
def host_ids=(ids)
assign_ids ids, 'Host::Base'
end
|
#hostgroup_ids ⇒ Object
78
79
80
|
# File 'app/models/foreman_openscap/policy.rb', line 78
def hostgroup_ids
assets.where(:assetable_type => 'Hostgroup').pluck(:assetable_id)
end
|
#hostgroup_ids=(ids) ⇒ Object
82
83
84
|
# File 'app/models/foreman_openscap/policy.rb', line 82
def hostgroup_ids=(ids)
assign_ids ids, 'Hostgroup'
end
|
#hostgroups ⇒ Object
86
87
88
|
# File 'app/models/foreman_openscap/policy.rb', line 86
def hostgroups
::Hostgroup.find(hostgroup_ids)
end
|
#hostgroups=(hostgroups) ⇒ Object
90
91
92
|
# File 'app/models/foreman_openscap/policy.rb', line 90
def hostgroups=(hostgroups)
hostgroup_ids = hostgroups.map(&:id).map(&:to_s)
end
|
#hosts ⇒ Object
102
103
104
|
# File 'app/models/foreman_openscap/policy.rb', line 102
def hosts
::Host.where(:id => host_ids)
end
|
#hosts=(hosts) ⇒ Object
106
107
108
|
# File 'app/models/foreman_openscap/policy.rb', line 106
def hosts=(hosts)
host_ids = hosts.map(&:id).map(&:to_s)
end
|
#last_step? ⇒ Boolean
143
144
145
|
# File 'app/models/foreman_openscap/policy.rb', line 143
def last_step?
current_step == steps.last
end
|
#next_step ⇒ Object
127
128
129
|
# File 'app/models/foreman_openscap/policy.rb', line 127
def next_step
steps[steps.index(current_step) + 1]
end
|
#previous_step ⇒ Object
122
123
124
125
|
# File 'app/models/foreman_openscap/policy.rb', line 122
def previous_step
return steps.last if current_step.empty?
steps[steps.index(current_step) - 1]
end
|
#rewind_step ⇒ Object
131
132
133
|
# File 'app/models/foreman_openscap/policy.rb', line 131
def rewind_step
@current_step = previous_step
end
|
#scan_name ⇒ Object
155
156
157
|
# File 'app/models/foreman_openscap/policy.rb', line 155
def scan_name
name
end
|
#should_validate?(step_name) ⇒ Boolean
199
200
201
202
203
204
205
206
207
|
# File 'app/models/foreman_openscap/policy.rb', line 199
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
151
152
153
|
# File 'app/models/foreman_openscap/policy.rb', line 151
def step_index
wizard_completed? ? steps.index(steps.last) : steps.index(current_step) + 1
end
|
#step_to_i(step_name) ⇒ Object
110
111
112
|
# File 'app/models/foreman_openscap/policy.rb', line 110
def step_to_i(step_name)
steps.index(step_name) + 1
end
|
#steps ⇒ Object
114
115
116
|
# File 'app/models/foreman_openscap/policy.rb', line 114
def steps
STEPS_LIST
end
|
#to_enc ⇒ Object
188
189
190
191
192
193
194
195
196
197
|
# File 'app/models/foreman_openscap/policy.rb', line 188
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_html ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/models/foreman_openscap/policy.rb', line 53
def to_html
if scap_content.nil?
return html_error_message(_('Cannot generate HTML guide, scap content is missing.'))
end
if (proxy = scap_content.proxy_url)
api = ProxyAPI::Openscap.new(:url => proxy)
else
return html_error_message(_('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
177
178
179
180
181
182
183
184
185
186
|
# File 'app/models/foreman_openscap/policy.rb', line 177
def unassign_hosts(hosts)
policy_host_assets = ForemanOpenscap::Asset.joins(:asset_policies).where(
:assetable_type => 'Host::Base',
:assetable_id => hosts.map(&:id),
:foreman_openscap_asset_policies => { :policy_id => id }
).pluck(:id)
self.asset_ids = self.asset_ids - policy_host_assets
ForemanOpenscap::Asset.where(:id => policy_host_assets).destroy_all
end
|
#used_hostgroup_ids ⇒ Object
173
174
175
|
# File 'app/models/foreman_openscap/policy.rb', line 173
def used_hostgroup_ids
[]
end
|
#used_location_ids ⇒ Object
159
160
161
162
163
164
|
# File 'app/models/foreman_openscap/policy.rb', line 159
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
166
167
168
169
170
171
|
# File 'app/models/foreman_openscap/policy.rb', line 166
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
147
148
149
|
# File 'app/models/foreman_openscap/policy.rb', line 147
def wizard_completed?
new_record? && current_step.blank?
end
|
#wizard_initiated? ⇒ Boolean
209
210
211
|
# File 'app/models/foreman_openscap/policy.rb', line 209
def wizard_initiated?
@wizard_initiated
end
|