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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a0fee541322fe2be5e747618a102c84d5a5d7b3
4
- data.tar.gz: 90e473ab4dfa3f7d7a84f039c6607b537d8c97a2
3
+ metadata.gz: a76b926f2bc21c2bdcd6a623b308cae1a9db5c03
4
+ data.tar.gz: e6415f8826e568b40231370f4b015a7c29b97256
5
5
  SHA512:
6
- metadata.gz: f257f63e3205d94509fa5d8df3872b59dc52af37b942ebbe876178be9b8f7988d131dfa04e8526d4d5e3ceacbf06cd5f7094229fe84935baa9c8a246b7dffc56
7
- data.tar.gz: 950b2a10804f0e74ed6c8101f6f55783d647cc39ca26095d18de485e3cf66de9f51d4f72af8cdbba5054d97f63c6a483d22d6035dc180e79d636008905f50fd4
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.where(:id => policy.assets.comply_with(policy).map(&:assetable_id)) }.flatten
11
- @incompliant_hosts = @policies.map { |policy| Host.where(:id => policy.assets.incomply_with(policy).map(&:assetable_id)) }.flatten
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 do|key, title|
104
- scap_content_profiles.find_or_create_by_profile_id_and_title(key, title)
105
- end
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
- <%= image_tag('/assets/spinner.gif') %>
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>
@@ -36,7 +36,7 @@
36
36
  <%= host.scap_status_changed?(policy) ? _('Yes') : _('No') %>
37
37
  </td>
38
38
  <% else %>
39
- <td style="<%= td_style %> border-right: 0px;">
39
+ <td style="<%= td_style %>" colspan="4">
40
40
  <%= _('No ARF reports for this policy') %>
41
41
  </td>
42
42
  <% end %>
data/config/routes.rb CHANGED
@@ -15,12 +15,12 @@ Rails.application.routes.draw do
15
15
  end
16
16
  end
17
17
 
18
- match 'dashboard', :to => 'compliance_dashboard#index', :as => "compliance_dashboard"
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
- match 'parse'
23
- match 'dashboard', :to => 'policy_dashboard#index', :as => 'policy_dashboard'
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, :index => true, :null => false
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") }.map(&:save!)
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.find_or_create_by_name('Openscap')
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
- app.config.paths['db/migrate'] += ForemanOpenscap::Engine.paths['db/migrate'].existent
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 =
@@ -1,3 +1,3 @@
1
1
  module ForemanOpenscap
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -5,6 +5,5 @@ FactoryGirl.define do
5
5
  root_pass 'xybxa6JUkz63w'
6
6
  openscap_proxy FactoryGirl.build(:smart_proxy, :url => "http://test.org:8080")
7
7
  policies []
8
- asset nil
9
8
  end
10
9
  end
@@ -8,5 +8,6 @@ FactoryGirl.define do
8
8
  day_of_month '1'
9
9
  cron_line '* * * * 30'
10
10
  hosts []
11
+ assets []
11
12
  end
12
13
  end
@@ -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.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
- - "Šimon Lukašík"
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: 2015-12-09 00:00:00.000000000 Z
14
+ date: 2016-01-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: deface