smart_proxy_openscap 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/smart-proxy-openscap-send +15 -0
- data/lib/smart_proxy_openscap/fetch_file.rb +2 -0
- data/lib/smart_proxy_openscap/foreman_forwarder.rb +11 -9
- data/lib/smart_proxy_openscap/openscap_api.rb +3 -1
- data/lib/smart_proxy_openscap/openscap_exception.rb +1 -0
- data/lib/smart_proxy_openscap/openscap_import_api.rb +1 -1
- data/lib/smart_proxy_openscap/spool_forwarder.rb +4 -2
- data/lib/smart_proxy_openscap/version.rb +1 -1
- data/settings.d/openscap.yml.example +5 -0
- 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: 614be4ed227de0a533a7a469807851eb26149a3c
|
4
|
+
data.tar.gz: b3a2db8cb3a01adf4b9385da6ae0bf1576bc244a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eca67114def703b9797e1a4749593690a476b643fa65eba24a7814f2e2d4352e22406f91c9b75eb668329e6b0559cdd3a9be1906b2347ff85eedb82210bc7dda
|
7
|
+
data.tar.gz: 9883048c8cbc9a7c36ac749ca7c24e5e07930863878f200072238cf1eab644069a8e66e6c3ae79a73e5061e1b4f9b00e23507f0d8dbad3772a4c5a8835872797
|
@@ -37,10 +37,25 @@ if !Proxy::SETTINGS.foreman_url
|
|
37
37
|
exit 437
|
38
38
|
end
|
39
39
|
|
40
|
+
lockfile = File.join(loaded_settings.spooldir, "spool.lock")
|
41
|
+
|
42
|
+
Signal.trap("TERM") {
|
43
|
+
FileUtils.rm(lockfile) if File.exist?(lockfile)
|
44
|
+
exit
|
45
|
+
}
|
46
|
+
|
47
|
+
if File.exist? lockfile
|
48
|
+
logger.debug "Lock file #{lockfile} for openscap spool exists, not sending spool to server"
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
40
52
|
begin
|
53
|
+
FileUtils.touch lockfile
|
41
54
|
Proxy::OpenSCAP::send_spool_to_foreman(loaded_settings)
|
42
55
|
rescue StandardError => e
|
43
56
|
logger.error e
|
44
57
|
puts "#{e} See #{Proxy::OpenSCAP.fullpath(loaded_settings.openscap_send_log_file)}"
|
45
58
|
exit 438
|
59
|
+
ensure
|
60
|
+
FileUtils.rm lockfile
|
46
61
|
end
|
@@ -46,6 +46,8 @@ module Proxy::OpenSCAP
|
|
46
46
|
def fetch_scap_content_xml(file_download_path)
|
47
47
|
foreman_request = Proxy::HttpRequest::ForemanRequest.new
|
48
48
|
req = foreman_request.request_factory.create_get(file_download_path)
|
49
|
+
timeout = Proxy::OpenSCAP::Plugin.settings.timeout
|
50
|
+
foreman_request.http.read_timeout = timeout if timeout
|
49
51
|
response = foreman_request.send_request(req)
|
50
52
|
response.value
|
51
53
|
response.body
|
@@ -1,22 +1,23 @@
|
|
1
|
+
require 'smart_proxy_openscap/openscap_exception'
|
2
|
+
|
1
3
|
module Proxy::OpenSCAP
|
2
4
|
class ForemanForwarder < Proxy::HttpRequest::ForemanRequest
|
3
5
|
include ::Proxy::Log
|
4
6
|
|
5
|
-
def post_arf_report(cname, policy_id, date, data)
|
7
|
+
def post_arf_report(cname, policy_id, date, data, timeout)
|
6
8
|
begin
|
7
9
|
foreman_api_path = upload_path(cname, policy_id, date)
|
8
10
|
json = Proxy::OpenSCAP::ArfParser.new(cname, policy_id, date).as_json(data)
|
9
|
-
response = send_request(foreman_api_path, json)
|
11
|
+
response = send_request(foreman_api_path, json, timeout)
|
10
12
|
# Raise an HTTP error if the response is not 2xx (success).
|
11
13
|
response.value
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
logger.debug response.body
|
16
|
-
|
14
|
+
JSON.parse(response.body)
|
15
|
+
rescue Net::HTTPServerException => e
|
16
|
+
logger.debug "Received response: #{response.code} #{response.msg}"
|
17
|
+
logger.debug response.body
|
18
|
+
raise ReportUploadError, e.message if response.code.to_i == 422
|
17
19
|
raise e
|
18
20
|
end
|
19
|
-
res
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
@@ -25,13 +26,14 @@ module Proxy::OpenSCAP
|
|
25
26
|
"/api/v2/compliance/arf_reports/#{cname}/#{policy_id}/#{date}"
|
26
27
|
end
|
27
28
|
|
28
|
-
def send_request(path, body)
|
29
|
+
def send_request(path, body, timeout)
|
29
30
|
# Override the parent method to set the right headers
|
30
31
|
path = [uri.path, path].join('/') unless uri.path.empty?
|
31
32
|
req = Net::HTTP::Post.new(URI.join(uri.to_s, path).path)
|
32
33
|
req.add_field('Accept', 'application/json,version=2')
|
33
34
|
req.content_type = 'application/json'
|
34
35
|
req.body = body
|
36
|
+
http.read_timeout = timeout if timeout
|
35
37
|
http.request(req)
|
36
38
|
end
|
37
39
|
end
|
@@ -37,7 +37,7 @@ module Proxy::OpenSCAP
|
|
37
37
|
policy = params[:policy]
|
38
38
|
|
39
39
|
begin
|
40
|
-
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string)
|
40
|
+
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string, Proxy::OpenSCAP::Plugin.settings.timeout)
|
41
41
|
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date).store_archive(request.body.string)
|
42
42
|
post_to_foreman.to_json
|
43
43
|
rescue Proxy::OpenSCAP::StoreReportError => e
|
@@ -58,6 +58,8 @@ module Proxy::OpenSCAP
|
|
58
58
|
{ :result => msg }.to_json
|
59
59
|
rescue Proxy::OpenSCAP::StoreSpoolError => e
|
60
60
|
log_halt 500, e.message
|
61
|
+
rescue Proxy::OpenSCAP::ReportUploadError => e
|
62
|
+
{ :result => e.message }.to_json
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
@@ -12,7 +12,7 @@ module Proxy::OpenSCAP
|
|
12
12
|
policy = params[:policy_id]
|
13
13
|
log_halt(500, "Insufficient data") if (cn.nil? || date.nil?)
|
14
14
|
|
15
|
-
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string)
|
15
|
+
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string, Proxy::OpenSCAP::Plugin.settings.timeout)
|
16
16
|
begin
|
17
17
|
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date).store_archive(request.body.string)
|
18
18
|
rescue Proxy::OpenSCAP::StoreReportError => e
|
@@ -52,7 +52,7 @@ module Proxy::OpenSCAP
|
|
52
52
|
|
53
53
|
def forward_arf_file(cname, policy_id, date, arf_file_path)
|
54
54
|
data = File.open(arf_file_path, 'rb') { |io| io.read }
|
55
|
-
post_to_foreman = ForemanForwarder.new.post_arf_report(cname, policy_id, date, data)
|
55
|
+
post_to_foreman = ForemanForwarder.new.post_arf_report(cname, policy_id, date, data, @loaded_settings.timeout)
|
56
56
|
Proxy::OpenSCAP::StorageFS.new(@loaded_settings.reportsdir, cname, post_to_foreman['id'], date).store_archive(data)
|
57
57
|
File.delete arf_file_path
|
58
58
|
rescue Proxy::OpenSCAP::OpenSCAPException => e
|
@@ -60,7 +60,9 @@ module Proxy::OpenSCAP
|
|
60
60
|
|
61
61
|
Proxy::OpenSCAP::StorageFS.new(@loaded_settings.corrupted_dir, cname, policy_id, date).
|
62
62
|
move_corrupted(arf_file_path.split('/').last, @loaded_settings.spooldir)
|
63
|
-
|
63
|
+
rescue Proxy::OpenSCAP::ReportUploadError => e
|
64
|
+
logger.error "Failed to upload Arf Report at #{arf_file_path}, cause: #{e.message}, the report will be deleted."
|
65
|
+
File.delete arf_file_path
|
64
66
|
rescue StandardError => e
|
65
67
|
logger.error "smart-proxy-openscap-send failed to upload Compliance report for #{cname}, generated on #{Time.at date.to_i}. Cause: #{e}"
|
66
68
|
end
|
@@ -26,3 +26,8 @@
|
|
26
26
|
# Directory where corrupted OpenSCAP report XML are stored
|
27
27
|
# When proxy cannot parse the report sent by client
|
28
28
|
#:corrupted_dir: /var/lib/foreman-proxy/openscap/corrupted
|
29
|
+
|
30
|
+
# The time we wait for response after the upload request connection was established, in seconds.
|
31
|
+
# Affects sending reports to Foreman (directly and from spool) and fetching scap content or tailoring file
|
32
|
+
# for distribution to clients
|
33
|
+
#:timeout: 60
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_openscap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Šimon Lukašík
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|