foreman_openscap 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/mailers/foreman_openscap/policy_mailer.rb +2 -2
- data/app/models/concerns/foreman_openscap/host_extensions.rb +5 -0
- data/app/models/foreman_openscap/arf_report.rb +7 -2
- data/app/models/foreman_openscap/asset.rb +1 -1
- data/app/models/foreman_openscap/scap_content.rb +8 -3
- data/app/views/arf_reports/show_html.html.erb +1 -2
- data/app/views/foreman_openscap/policy_mailer/_hosts.erb +1 -1
- data/config/routes.rb +3 -3
- data/db/migrate/20150112152944_create_scaptimony_arf_report_raws.rb +1 -1
- data/db/migrate/20150821100137_migrate_from_scaptimony.rb +11 -1
- data/db/seeds.d/openscap_feature.rb +1 -1
- data/lib/foreman_openscap/engine.rb +3 -1
- data/lib/foreman_openscap/version.rb +1 -1
- data/test/factories/compliance_host_factory.rb +0 -1
- data/test/factories/policy_factory.rb +1 -0
- data/test/unit/arf_report_test.rb +2 -2
- data/test/unit/policy_mailer_test.rb +7 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a76b926f2bc21c2bdcd6a623b308cae1a9db5c03
|
4
|
+
data.tar.gz: e6415f8826e568b40231370f4b015a7c29b97256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f63dc300a9823d29f5c522a43ffdb4dd84cb2c9805e28233af9e000154f88ec30ca7afe86aa00bc78ce69e1030ead4fb03ccedba0bd0de843cf7aeb501d96ae
|
7
|
+
data.tar.gz: 2bb1e9497ca5c9f4501b513a9ac576d0e234a3aa176479bcd0b3d3b975fdf6b8db2dce8f78012d126913f80fc1ecff14259a71b67327b27f2f8255abff7b8d1b
|
@@ -7,8 +7,8 @@ module ForemanOpenscap
|
|
7
7
|
@time = options[:time] || 1.day.ago
|
8
8
|
|
9
9
|
@policies = ::ForemanOpenscap::Policy.all.reject { |policy| policy.assets.map(&:host).compact.empty? }
|
10
|
-
@compliant_hosts = @policies.map { |policy| Host.
|
11
|
-
@incompliant_hosts = @policies.map { |policy| Host.
|
10
|
+
@compliant_hosts = @policies.map { |policy| Host.comply_with policy }.flatten
|
11
|
+
@incompliant_hosts = @policies.map { |policy| Host.incomply_with policy }.flatten
|
12
12
|
changed_hosts_of_policies(@policies)
|
13
13
|
|
14
14
|
if user.nil? || user.mail.nil?
|
@@ -55,6 +55,11 @@ module ForemanOpenscap
|
|
55
55
|
assign_hostgroup_attributes %w(openscap_proxy_id)
|
56
56
|
end
|
57
57
|
|
58
|
+
def policies=(policies)
|
59
|
+
self.create_asset(:assetable => self) if self.asset.blank?
|
60
|
+
self.asset.policies = policies
|
61
|
+
end
|
62
|
+
|
58
63
|
def get_asset
|
59
64
|
ForemanOpenscap::Asset.where(:assetable_type => 'Host::Base', :assetable_id => id).first_or_create!
|
60
65
|
end
|
@@ -15,8 +15,13 @@ module ForemanOpenscap
|
|
15
15
|
has_one :policy, :through => :policy_arf_report
|
16
16
|
has_one :asset, :through => :host, :class_name => 'ForemanOpenscap::Asset', :as => :assetable
|
17
17
|
after_save :assign_locations_organizations
|
18
|
+
has_one :log, :foreign_key => :report_id
|
19
|
+
|
20
|
+
delegate :result, :to => :log, :allow_nil => true
|
18
21
|
validate :result, :inclusion => { :in => RESULT }
|
19
22
|
|
23
|
+
delegate :asset=, :to => :host
|
24
|
+
|
20
25
|
default_scope do
|
21
26
|
with_taxonomy_scope do
|
22
27
|
order("#{self.table_name}.created_at DESC")
|
@@ -26,12 +31,12 @@ module ForemanOpenscap
|
|
26
31
|
scope :hosts, lambda { includes(:policy) }
|
27
32
|
scope :of_policy, lambda { |policy_id| joins(:policy_arf_report).merge(PolicyArfReport.of_policy(policy_id)) }
|
28
33
|
|
29
|
-
scope :latest,
|
34
|
+
scope :latest, -> {
|
30
35
|
joins('INNER JOIN (SELECT host_id, policy_id, max(reports.id) AS id
|
31
36
|
FROM reports INNER JOIN foreman_openscap_policy_arf_reports
|
32
37
|
ON reports.id = foreman_openscap_policy_arf_reports.arf_report_id
|
33
38
|
GROUP BY host_id, policy_id) latest
|
34
|
-
ON reports.id = latest.id')
|
39
|
+
ON reports.id = latest.id') }
|
35
40
|
|
36
41
|
scope :latest_of_policy, lambda { |policy|
|
37
42
|
joins("INNER JOIN (SELECT host_id, policy_id, max(reports.id) AS id
|
@@ -4,7 +4,7 @@ module ForemanOpenscap
|
|
4
4
|
has_many :policies, :through => :asset_policies
|
5
5
|
belongs_to :assetable, :polymorphic => true
|
6
6
|
|
7
|
-
scope :hosts, where(:assetable_type => 'Host::Base')
|
7
|
+
scope :hosts, lambda { where(:assetable_type => 'Host::Base') }
|
8
8
|
|
9
9
|
def host
|
10
10
|
fetch_asset('Host::Base')
|
@@ -96,13 +96,18 @@ module ForemanOpenscap
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
def as_json(*args)
|
100
|
+
hash = super
|
101
|
+
hash["scap_file"] = scap_file.to_s.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_')
|
102
|
+
end
|
103
|
+
|
99
104
|
private
|
100
105
|
|
101
106
|
def create_profiles
|
102
107
|
profiles = fetch_profiles
|
103
|
-
profiles.each
|
104
|
-
scap_content_profiles.
|
105
|
-
|
108
|
+
profiles.each {|key, title|
|
109
|
+
scap_content_profiles.where(:profile_id => key, :title => title).first_or_create
|
110
|
+
}
|
106
111
|
end
|
107
112
|
|
108
113
|
def redigest
|
@@ -3,8 +3,7 @@
|
|
3
3
|
<div id="loading">
|
4
4
|
<div class="col-md-4"></div>
|
5
5
|
<div class="col-md-4">
|
6
|
-
<%=
|
7
|
-
<%= _('Loading...') %>
|
6
|
+
<%= spinner(_('Loading...')) %>
|
8
7
|
</div>
|
9
8
|
</div>
|
10
9
|
<iframe id="frame" style="display: none" height="100%" width="100%" frameborder="0" src="<%= parse_html_arf_report_path(@arf_report) %>"></iframe>
|
data/config/routes.rb
CHANGED
@@ -15,12 +15,12 @@ Rails.application.routes.draw do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
get 'dashboard', :to => 'compliance_dashboard#index', :as => "compliance_dashboard"
|
19
19
|
|
20
20
|
resources :policies, :only => [:index, :new, :show, :create, :edit, :update, :destroy] do
|
21
21
|
member do
|
22
|
-
|
23
|
-
|
22
|
+
get 'parse', :to => 'policies#parse'
|
23
|
+
get 'dashboard', :to => 'policy_dashboard#index', :as => 'policy_dashboard'
|
24
24
|
end
|
25
25
|
collection do
|
26
26
|
get 'auto_complete_search'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class CreateScaptimonyArfReportRaws < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :scaptimony_arf_report_raws, :id => false do |t|
|
4
|
-
t.references :arf_report, :
|
4
|
+
t.references :arf_report, :null => false
|
5
5
|
t.integer :size
|
6
6
|
t.binary :raw
|
7
7
|
end
|
@@ -1,5 +1,11 @@
|
|
1
1
|
class MigrateFromScaptimony < ActiveRecord::Migration
|
2
2
|
def up
|
3
|
+
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
|
4
|
+
# rename_tables renames the indexes, and their new names overflow, we cancel out the renaming of the indexes
|
5
|
+
alias_method :old_rename_table_indexes, :rename_table_indexes
|
6
|
+
def rename_table_indexes(a,b)
|
7
|
+
end
|
8
|
+
end
|
3
9
|
ActiveRecord::Base.connection.tables.grep(/^scaptimony/).each do |table|
|
4
10
|
rename_table table, table.sub(/^scaptimony/, "foreman_openscap")
|
5
11
|
end
|
@@ -25,7 +31,11 @@ class MigrateFromScaptimony < ActiveRecord::Migration
|
|
25
31
|
SQL
|
26
32
|
|
27
33
|
taxonomies = TaxableTaxonomy.where(:taxable_type => ["Scaptimony::ArfReport", "Scaptimony::Policy", "Scaptimony::ScapContent"])
|
28
|
-
taxonomies.each { |t| t.taxable_type = t.taxable_type.sub(/^Scaptimony/, "ForemanOpenscap")
|
34
|
+
taxonomies.each { |t| t.taxable_type = t.taxable_type.sub(/^Scaptimony/, "ForemanOpenscap")}.map(&:save!)
|
35
|
+
ensure
|
36
|
+
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
|
37
|
+
alias_method :rename_table_indexes, :old_rename_table_indexes
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
def down
|
@@ -1,2 +1,2 @@
|
|
1
|
-
f = Feature.
|
1
|
+
f = Feature.where(:name => 'Openscap').first_or_create
|
2
2
|
fail "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
|
@@ -14,7 +14,9 @@ module ForemanOpenscap
|
|
14
14
|
|
15
15
|
# Add any db migrations
|
16
16
|
initializer "foreman_openscap.load_app_instance_data" do |app|
|
17
|
-
|
17
|
+
ForemanOpenscap::Engine.paths['db/migrate'].existent.each do |path|
|
18
|
+
app.config.paths['db/migrate'] << path
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
assets_to_precompile =
|
@@ -86,8 +86,8 @@ module ForemanOpenscap
|
|
86
86
|
reports << FactoryGirl.create(:arf_report, :host_id => host.id, :status => @status)
|
87
87
|
FactoryGirl.create(:policy_arf_report, :arf_report_id => reports.last.id)
|
88
88
|
end
|
89
|
-
assert ForemanOpenscap::ArfReport.latest.include? reports[-2]
|
90
|
-
assert ForemanOpenscap::ArfReport.latest.include? reports[-1]
|
89
|
+
assert ForemanOpenscap::ArfReport.latest.to_a.include? reports[-2]
|
90
|
+
assert ForemanOpenscap::ArfReport.latest.to_a.include? reports[-1]
|
91
91
|
end
|
92
92
|
|
93
93
|
test 'should return latest report of policy for each of the hosts' do
|
@@ -11,9 +11,15 @@ class PolicyMailerTest < ActiveSupport::TestCase
|
|
11
11
|
:method => 'policy_summary',
|
12
12
|
:subscription_type => 'report',
|
13
13
|
)
|
14
|
+
#just to have some content to send
|
15
|
+
ForemanOpenscap::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
|
16
|
+
host = FactoryGirl.create(:compliance_host)
|
17
|
+
asset = FactoryGirl.create(:asset, :assetable_id => host.id)
|
18
|
+
policy = FactoryGirl.create(:policy, :assets => [asset])
|
19
|
+
arf_report = FactoryGirl.create(:arf_report, :policy => policy, :host_id => host.id)
|
20
|
+
policy_arf_report = FactoryGirl.create(:policy_arf_report, :policy_id => policy.id, :arf_report_id => arf_report.id)
|
14
21
|
|
15
22
|
@user.mail_notifications << MailNotification[:openscap_policy_summary]
|
16
|
-
|
17
23
|
ActionMailer::Base.deliveries = []
|
18
24
|
@user.user_mail_notifications.first.deliver
|
19
25
|
@email = ActionMailer::Base.deliveries.first
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_openscap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Šimon Lukašík
|
8
8
|
- Shlomi Zadok
|
9
9
|
- Marek Hulan
|
10
10
|
- Ondrej Prazak
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: deface
|