foreman_openscap 0.7.10 → 0.7.11
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/controllers/api/v2/compliance/arf_reports_controller.rb +13 -3
- data/app/models/concerns/foreman_openscap/openscap_proxy_extensions.rb +1 -1
- data/app/models/foreman_openscap/arf_report.rb +3 -3
- data/app/views/api/v2/compliance/common/_loc.json.rabl +1 -1
- data/app/views/api/v2/compliance/common/_org.json.rabl +1 -1
- data/app/views/arf_reports/delete_multiple.html.erb +1 -1
- data/lib/foreman_openscap/version.rb +1 -1
- data/lib/tasks/foreman_openscap_tasks.rake +9 -0
- data/test/functional/api/v2/compliance/arf_reports_controller_test.rb +26 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6c747f39e8243bed36344936a0bbe366c810561
|
4
|
+
data.tar.gz: be51caca5c71a20b037e69206aa36adbc0757dc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a56f11aeb006ac17936ed6936e087df613d72d7919dbb5184ec0f49560ccb9176fd47f16da34aa88dea27fd68a0adf8ea8fdba78a80e71caeb59483cfa84a8b
|
7
|
+
data.tar.gz: 59f5429305e04a0b61b060ca9e2025249a754efbd69aa182f00079121f595bc344d3eef6bc7891fadf1b1918231dbe5fd5bec47f0c4a3e2e747da0f973172a10
|
@@ -49,9 +49,13 @@ module Api
|
|
49
49
|
|
50
50
|
def create
|
51
51
|
asset = ForemanOpenscap::Helper::get_asset(params[:cname], params[:policy_id])
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
if asset.host.openscap_proxy
|
53
|
+
arf_report = ForemanOpenscap::ArfReport.create_arf(asset, params)
|
54
|
+
asset.host.refresh_statuses
|
55
|
+
render :json => { :result => :OK, :id => arf_report.id.to_s }
|
56
|
+
else
|
57
|
+
no_proxy_for_host asset
|
58
|
+
end
|
55
59
|
end
|
56
60
|
|
57
61
|
api :GET, "/compliance/arf_reports/:id/download/", N_("Download bzipped ARF report")
|
@@ -85,6 +89,12 @@ module Api
|
|
85
89
|
render_error 'standard_error', :status => :internal_error, :locals => { :exception => error }
|
86
90
|
end
|
87
91
|
|
92
|
+
def no_proxy_for_host(asset)
|
93
|
+
msg = _('Failed to upload Arf Report, no OpenSCAP proxy set for host %s') % asset.host.name
|
94
|
+
logger.error msg
|
95
|
+
render :json => { :result => msg }, :status => :unprocessable_entity
|
96
|
+
end
|
97
|
+
|
88
98
|
def action_permission
|
89
99
|
case params[:action]
|
90
100
|
when 'download', 'download_html'
|
@@ -5,7 +5,7 @@ module ForemanOpenscap
|
|
5
5
|
def openscap_proxy_api
|
6
6
|
return @openscap_api if @openscap_api
|
7
7
|
proxy_url = openscap_proxy.url if openscap_proxy
|
8
|
-
raise ::Foreman::Exception.new(N_("No OpenSCAP proxy found for %{class} with %{id}"), { :class => self.class, :id => id }) unless proxy_url
|
8
|
+
raise ::Foreman::Exception.new(N_("No OpenSCAP proxy found for %{class} with id %{id}"), { :class => self.class, :id => id }) unless proxy_url
|
9
9
|
@openscap_api = ::ProxyAPI::Openscap.new(:url => proxy_url)
|
10
10
|
end
|
11
11
|
end
|
@@ -15,10 +15,11 @@ module ForemanOpenscap
|
|
15
15
|
has_one :policy_arf_report
|
16
16
|
has_one :policy, :through => :policy_arf_report, :dependent => :destroy
|
17
17
|
has_one :asset, :through => :host, :class_name => 'ForemanOpenscap::Asset', :as => :assetable
|
18
|
-
after_save :assign_locations_organizations
|
19
18
|
has_one :log, :foreign_key => :report_id
|
20
19
|
belongs_to :openscap_proxy, :class_name => "SmartProxy"
|
21
20
|
|
21
|
+
after_save :assign_locations_organizations
|
22
|
+
before_destroy :destroy_from_proxy
|
22
23
|
|
23
24
|
delegate :asset=, :to => :host
|
24
25
|
|
@@ -175,7 +176,7 @@ module ForemanOpenscap
|
|
175
176
|
policy.id == other.policy.id
|
176
177
|
end
|
177
178
|
|
178
|
-
def
|
179
|
+
def destroy_from_proxy
|
179
180
|
if host
|
180
181
|
begin
|
181
182
|
openscap_proxy_api.destroy_report(self, ForemanOpenscap::Helper::find_name_or_uuid_by_host(host))
|
@@ -186,7 +187,6 @@ module ForemanOpenscap
|
|
186
187
|
else
|
187
188
|
logger.error "Failed to delete report with id #{id} from proxy, no host associated with report"
|
188
189
|
end
|
189
|
-
super
|
190
190
|
end
|
191
191
|
|
192
192
|
def self.newline_to_space(string)
|
@@ -25,5 +25,5 @@
|
|
25
25
|
|
26
26
|
<%= form_tag submit_delete_multiple_arf_reports_path({:arf_report_ids => params[:arf_report_ids]}) do %>
|
27
27
|
<span class="label label-danger"><%= _('Delete') %></span>
|
28
|
-
<%= _('these
|
28
|
+
<%= _('these Compliance reports') %>
|
29
29
|
<% end %>
|
@@ -56,6 +56,15 @@ namespace :foreman_openscap do
|
|
56
56
|
ForemanOpenscap::MessageCleaner.new.clean
|
57
57
|
puts 'Done'
|
58
58
|
end
|
59
|
+
|
60
|
+
desc "Delete ArfReports without OpenSCAP proxy"
|
61
|
+
task :clean_reports_without_proxy => :environment do
|
62
|
+
User.as_anonymous_admin do
|
63
|
+
report_ids_without_proxy = ForemanOpenscap::ArfReport.unscoped.where(:openscap_proxy => nil).pluck(:id)
|
64
|
+
total = ForemanOpenscap::ArfReport.delete report_ids_without_proxy
|
65
|
+
puts "Done cleaning #{total} reports"
|
66
|
+
end
|
67
|
+
end
|
59
68
|
end
|
60
69
|
|
61
70
|
# Tests
|
@@ -6,17 +6,15 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
6
6
|
# override validation of policy (puppetclass, lookup_key overrides)
|
7
7
|
ForemanOpenscap::Policy.any_instance.stubs(:valid?).returns(true)
|
8
8
|
@host = FactoryGirl.create(:compliance_host)
|
9
|
-
@report = FactoryGirl.create(:arf_report,
|
10
|
-
:host_id => @host.id,
|
11
|
-
:openscap_proxy => FactoryGirl.create(:smart_proxy, :url => "http://smart-proxy.org:8000"))
|
12
9
|
@policy = FactoryGirl.create(:policy)
|
13
|
-
@asset =
|
10
|
+
@asset = FactoryBot.create(:asset, :assetable_id => @host.id)
|
14
11
|
|
15
12
|
@from_json = arf_from_json "#{ForemanOpenscap::Engine.root}/test/files/arf_report/arf_report.json"
|
16
13
|
@cname = '9521a5c5-8f44-495f-b087-20e86b30bf67'
|
17
14
|
end
|
18
15
|
|
19
16
|
test "should get index" do
|
17
|
+
create_arf_report
|
20
18
|
get :index, {}, set_session_user
|
21
19
|
response = ActiveSupport::JSON.decode(@response.body)
|
22
20
|
assert_not response['results'].empty?
|
@@ -24,7 +22,8 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
24
22
|
end
|
25
23
|
|
26
24
|
test "should get show" do
|
27
|
-
|
25
|
+
report = create_arf_report
|
26
|
+
get :show, { :id => report.to_param }, set_session_user
|
28
27
|
response = ActiveSupport::JSON.decode(@response.body)
|
29
28
|
refute response['passed'].blank?
|
30
29
|
refute response['failed'].blank?
|
@@ -33,9 +32,10 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
33
32
|
end
|
34
33
|
|
35
34
|
test "should download report" do
|
35
|
+
report = create_arf_report
|
36
36
|
bzipped_report = File.read "#{ForemanOpenscap::Engine.root}/test/files/arf_report/arf_report.bz2"
|
37
37
|
ForemanOpenscap::ArfReport.any_instance.stubs(:to_bzip).returns(bzipped_report)
|
38
|
-
get :download, { :id =>
|
38
|
+
get :download, { :id => report.to_param }, set_session_user
|
39
39
|
t = Tempfile.new('tmp_report')
|
40
40
|
t.write @response.body
|
41
41
|
t.close
|
@@ -60,6 +60,20 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
60
60
|
assert_equal msg_count, src_count
|
61
61
|
end
|
62
62
|
|
63
|
+
test "should not create report for host without proxy" do
|
64
|
+
asset = FactoryBot.create(:asset)
|
65
|
+
date = Time.new(1944, 6, 6)
|
66
|
+
ForemanOpenscap::Helper.stubs(:get_asset).returns(asset)
|
67
|
+
post :create,
|
68
|
+
@from_json.merge(:cname => @cname,
|
69
|
+
:policy_id => @policy.id,
|
70
|
+
:date => date.to_i),
|
71
|
+
set_session_user
|
72
|
+
assert_response :unprocessable_entity
|
73
|
+
res = JSON.parse(@response.body)
|
74
|
+
assert_equal "Failed to upload Arf Report, no OpenSCAP proxy set for host #{asset.host.name}", res["result"]
|
75
|
+
end
|
76
|
+
|
63
77
|
test "should not duplicate messages" do
|
64
78
|
dates = [Time.new(1984, 9, 15), Time.new(1932, 3, 27)]
|
65
79
|
ForemanOpenscap::Helper.stubs(:get_asset).returns(@asset)
|
@@ -145,4 +159,10 @@ class Api::V2::Compliance::ArfReportsControllerTest < ActionController::TestCase
|
|
145
159
|
file_content = File.read path
|
146
160
|
JSON.parse file_content
|
147
161
|
end
|
162
|
+
|
163
|
+
def create_arf_report
|
164
|
+
FactoryBot.create(:arf_report,
|
165
|
+
:host_id => @host.id,
|
166
|
+
:openscap_proxy => FactoryBot.create(:smart_proxy, :url => "http://smart-proxy.org:8000"))
|
167
|
+
end
|
148
168
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_openscap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- slukasik@redhat.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|