smart_proxy_openscap 0.11.0 → 0.11.1
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/lib/smart_proxy_openscap/helpers.rb +33 -0
- data/lib/smart_proxy_openscap/openscap_api.rb +32 -25
- data/lib/smart_proxy_openscap/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5b5f74d9ef8cf5528ed8352c5fcf086f066e0b4c287d7af2d793af4aa8ca8f3
|
4
|
+
data.tar.gz: 853c160e1bd5bc964cd1254462be6294c745f82903fbfe4527accc8c7b59358f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76183d6d4a6cca39f0214b9de18b642bb939ae018a4374cd642bd94751c57368a40ba8287e515bf2cf49e3700a37f4071f57b2e5132b6e5cdbbf2307ad26a6c6
|
7
|
+
data.tar.gz: c83274635c726fe521dcd43441b1abf3d87fbf6322d6fcc2c0cc07a380add1683af520edcc11ac3e254353d2bebaebcc59b8918c81fe70a4634ac8f52ba33df1
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# lib/helpers.rb
|
2
|
+
|
3
|
+
module Proxy::OpenSCAP
|
4
|
+
module Helpers
|
5
|
+
if Process.respond_to?(:fork)
|
6
|
+
def forked_response
|
7
|
+
r, w = IO.pipe
|
8
|
+
if child_id = Process.fork
|
9
|
+
w.close
|
10
|
+
data = r.read
|
11
|
+
r.close
|
12
|
+
Process.wait(child_id)
|
13
|
+
JSON.parse(data)
|
14
|
+
else
|
15
|
+
r.close
|
16
|
+
begin
|
17
|
+
body, code = yield
|
18
|
+
w.write({ code: code, body: body }.to_json)
|
19
|
+
rescue Exception => e
|
20
|
+
w.write({ code: 500, body: e.message }.to_json)
|
21
|
+
end
|
22
|
+
w.close
|
23
|
+
Process.exit!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
def forked_response
|
28
|
+
body, code = yield
|
29
|
+
{ code: code, body: body }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -8,6 +8,7 @@
|
|
8
8
|
# along with this software; if not, see http://www.gnu.org/licenses/gpl.txt
|
9
9
|
#
|
10
10
|
require 'smart_proxy_openscap/openscap_lib'
|
11
|
+
require 'smart_proxy_openscap/helpers'
|
11
12
|
|
12
13
|
module Proxy::OpenSCAP
|
13
14
|
HTTP_ERRORS = [
|
@@ -24,6 +25,7 @@ module Proxy::OpenSCAP
|
|
24
25
|
class Api < ::Sinatra::Base
|
25
26
|
include ::Proxy::Log
|
26
27
|
helpers ::Proxy::Helpers
|
28
|
+
helpers ::Proxy::OpenSCAP::Helpers
|
27
29
|
authorize_with_ssl_client
|
28
30
|
CLIENT_PATHS = Regexp.compile(%r{^(/arf/\d+|/policies/\d+/content/|/policies/\d+/tailoring/)})
|
29
31
|
|
@@ -44,32 +46,37 @@ module Proxy::OpenSCAP
|
|
44
46
|
|
45
47
|
post "/arf/:policy" do
|
46
48
|
policy = params[:policy]
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
49
|
+
response = forked_response do
|
50
|
+
begin
|
51
|
+
post_to_foreman = ForemanArfForwarder.new.post_report(@cn, policy, @reported_at, request.body.string, Proxy::OpenSCAP::Plugin.settings.timeout)
|
52
|
+
Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, @cn, post_to_foreman['id'], @reported_at).store_archive(request.body.string)
|
53
|
+
post_to_foreman.to_json
|
54
|
+
rescue Proxy::OpenSCAP::StoreReportError => e
|
55
|
+
Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, @cn, post_to_foreman['id'], @reported_at).store_failed(request.body.string)
|
56
|
+
logger.error "Failed to save Report in reports directory (#{Proxy::OpenSCAP::Plugin.settings.reportsdir}). Failed with: #{e.message}.
|
57
|
+
Saving file in #{Proxy::OpenSCAP::Plugin.settings.failed_dir}. Please copy manually to #{Proxy::OpenSCAP::Plugin.settings.reportsdir}"
|
58
|
+
{ :result => 'Storage failure on proxy, see proxy logs for details' }.to_json
|
59
|
+
rescue Nokogiri::XML::SyntaxError => e
|
60
|
+
error = "Failed to parse Arf Report, moving to #{Proxy::OpenSCAP::Plugin.settings.corrupted_dir}"
|
61
|
+
logger.error error
|
62
|
+
Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, @cn, policy, @reported_at).store_corrupted(request.body.string)
|
63
|
+
{ :result => (error << ' on proxy') }.to_json
|
64
|
+
rescue *HTTP_ERRORS => e
|
65
|
+
### If the upload to foreman fails then store it in the spooldir
|
66
|
+
msg = "Failed to upload to Foreman, saving in spool. Failed with: #{e.message}"
|
67
|
+
logger.error msg
|
68
|
+
Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.spooldir, @cn, policy, @reported_at).store_spool(request.body.string)
|
69
|
+
{ :result => msg }.to_json
|
70
|
+
rescue Proxy::OpenSCAP::StoreSpoolError => e
|
71
|
+
[e.message, 500]
|
72
|
+
rescue Proxy::OpenSCAP::ReportUploadError, Proxy::OpenSCAP::ReportDecompressError => e
|
73
|
+
{ :result => e.message }.to_json
|
74
|
+
end
|
75
|
+
end
|
76
|
+
if code = response['code']
|
77
|
+
log_halt code, response['body']
|
72
78
|
end
|
79
|
+
response['body']
|
73
80
|
end
|
74
81
|
|
75
82
|
get "/arf/:id/:cname/:date/:digest/xml" do
|
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.11.
|
4
|
+
version: 0.11.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: 2024-
|
13
|
+
date: 2024-07-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- lib/smart_proxy_openscap/fetch_scap_file.rb
|
126
126
|
- lib/smart_proxy_openscap/foreman_arf_forwarder.rb
|
127
127
|
- lib/smart_proxy_openscap/foreman_forwarder.rb
|
128
|
+
- lib/smart_proxy_openscap/helpers.rb
|
128
129
|
- lib/smart_proxy_openscap/http_config.ru
|
129
130
|
- lib/smart_proxy_openscap/openscap_api.rb
|
130
131
|
- lib/smart_proxy_openscap/openscap_exception.rb
|