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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d72c5e418a9d30974b6154fbbdaf68e0c1cf88852626683021100310920e109a
4
- data.tar.gz: d306fa47b4a2120c87d0ac8e7a4a0967cf9e77d8b689e83a2c4ccf655f227533
3
+ metadata.gz: d5b5f74d9ef8cf5528ed8352c5fcf086f066e0b4c287d7af2d793af4aa8ca8f3
4
+ data.tar.gz: 853c160e1bd5bc964cd1254462be6294c745f82903fbfe4527accc8c7b59358f
5
5
  SHA512:
6
- metadata.gz: 9cba3aded1feccdd109d77c43579fc997388759ef00746da23e2c4005368655c7a04b4e971d7047cc67cca131b3dbf2ab07e789c3750c17d28fe5f7c26566ff0
7
- data.tar.gz: 565420ad4a7368b91207eaa727c4243bb3abc09b92d806d8c98fd77f32b7346d216cd244afe14db8262b2b69e7f79b62bba9755abfe6197eb4ace92b41d67adc
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
- begin
49
- post_to_foreman = ForemanArfForwarder.new.post_report(@cn, policy, @reported_at, request.body.string, Proxy::OpenSCAP::Plugin.settings.timeout)
50
- Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, @cn, post_to_foreman['id'], @reported_at).store_archive(request.body.string)
51
- post_to_foreman.to_json
52
- rescue Proxy::OpenSCAP::StoreReportError => e
53
- Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, @cn, post_to_foreman['id'], @reported_at).store_failed(request.body.string)
54
- logger.error "Failed to save Report in reports directory (#{Proxy::OpenSCAP::Plugin.settings.reportsdir}). Failed with: #{e.message}.
55
- Saving file in #{Proxy::OpenSCAP::Plugin.settings.failed_dir}. Please copy manually to #{Proxy::OpenSCAP::Plugin.settings.reportsdir}"
56
- { :result => 'Storage failure on proxy, see proxy logs for details' }.to_json
57
- rescue Nokogiri::XML::SyntaxError => e
58
- error = "Failed to parse Arf Report, moving to #{Proxy::OpenSCAP::Plugin.settings.corrupted_dir}"
59
- logger.error error
60
- Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.corrupted_dir, @cn, policy, @reported_at).store_corrupted(request.body.string)
61
- { :result => (error << ' on proxy') }.to_json
62
- rescue *HTTP_ERRORS => e
63
- ### If the upload to foreman fails then store it in the spooldir
64
- msg = "Failed to upload to Foreman, saving in spool. Failed with: #{e.message}"
65
- logger.error msg
66
- Proxy::OpenSCAP::StorageFs.new(Proxy::OpenSCAP::Plugin.settings.spooldir, @cn, policy, @reported_at).store_spool(request.body.string)
67
- { :result => msg }.to_json
68
- rescue Proxy::OpenSCAP::StoreSpoolError => e
69
- log_halt 500, e.message
70
- rescue Proxy::OpenSCAP::ReportUploadError, Proxy::OpenSCAP::ReportDecompressError => e
71
- { :result => e.message }.to_json
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
@@ -10,6 +10,6 @@
10
10
 
11
11
  module Proxy
12
12
  module OpenSCAP
13
- VERSION = '0.11.0'
13
+ VERSION = '0.11.1'
14
14
  end
15
15
  end
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.0
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-05-30 00:00:00.000000000 Z
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