smart_proxy_openscap 0.7.0 → 0.7.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
  SHA1:
3
- metadata.gz: f62ed4762438b0c37885cb031bdec5257e72721c
4
- data.tar.gz: f4060366424d6b06adb28c21732286c984a70fc7
3
+ metadata.gz: 614be4ed227de0a533a7a469807851eb26149a3c
4
+ data.tar.gz: b3a2db8cb3a01adf4b9385da6ae0bf1576bc244a
5
5
  SHA512:
6
- metadata.gz: d1b8e805310270da3fe76bea4771d29c150a2a6ed7d5fbaa62d156c0edcd59aba152f5e36cd4cc47de36396fb3b2806a0d21cb1c9a996a3b89bd8497767b41f3
7
- data.tar.gz: ff8b396f02fea2f3244bde0988a5ef6a39d643b5f38917199221968d88a85e18714d4b39f0ee2432ef9f654fbb01260dbefe796737704ffaadb451689e9a66e9
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
- res = JSON.parse(response.body)
13
- raise StandardError, "Received response: #{response.code} #{response.msg}" unless res['result'] == 'OK'
14
- rescue StandardError => e
15
- logger.debug response.body if response
16
- logger.debug e.backtrace.join("\n\t")
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
 
@@ -5,4 +5,5 @@ module Proxy::OpenSCAP
5
5
  class StoreFailedError < StandardError; end
6
6
  class FileNotFound < StandardError; end
7
7
  class StoreCorruptedError < StandardError; end
8
+ class ReportUploadError < StandardError; end
8
9
  end
@@ -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
@@ -10,6 +10,6 @@
10
10
 
11
11
  module Proxy
12
12
  module OpenSCAP
13
- VERSION = '0.7.0'
13
+ VERSION = '0.7.1'
14
14
  end
15
15
  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.0
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-10-12 00:00:00.000000000 Z
13
+ date: 2018-11-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake