smart_proxy_openscap 0.6.2 → 0.6.3

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: 17c8ac2a2ead069f4efa7282704a31bfc92b248a
4
- data.tar.gz: bfe816a4639d132847e7ba97848aeed06829c80b
3
+ metadata.gz: 883ac2e4f642cc68a5f0745d8151df27d3abe928
4
+ data.tar.gz: edfc3d57b936f569addc9f9bf6c571164dd5d4f7
5
5
  SHA512:
6
- metadata.gz: db6215253f5ddd5f6e862b5fa01a23a06f2eaeacb16d0a82bd037b493bc5c4cdcdabd21034f425aede1013ca7189c7b98b83ef81e06c6fa5684d75402d8008e8
7
- data.tar.gz: cf76b07956f6d50a101ea9ec26432c2dd7a0206763db8732149e9d97bb97ae6114eb8b481354ecff08941e0253e90006673014913b2d9f0014cda393a27d7546
6
+ metadata.gz: a95f38139a3366889ed44c45129bcad94a1d22147926ee93e07459fb5a297ffa6727ab6676f9dfec5bc141dc423a39ad65dca4a5c8b7fcf76856dc38e788489e
7
+ data.tar.gz: 024d3d941c00fa8c965db51eaf5cd2b925512141c4e9704f8c5e9a5caa5cfbf9061a655e17e994fd00fb24be10c4c9219d7550183b5653ed4d6f20c1865729d9
@@ -3,10 +3,10 @@ module Proxy::OpenSCAP
3
3
  include ::Proxy::Log
4
4
 
5
5
  def post_arf_report(cname, policy_id, date, data)
6
+ parser = Proxy::OpenSCAP::Parse.new(data)
6
7
  begin
7
- json_data = Proxy::OpenSCAP::Parse.new(data).as_json
8
8
  foreman_api_path = upload_path(cname, policy_id, date)
9
- response = send_request(foreman_api_path, json_data)
9
+ response = send_request(foreman_api_path, parser.as_json)
10
10
  # Raise an HTTP error if the response is not 2xx (success).
11
11
  response.value
12
12
  res = JSON.parse(response.body)
@@ -18,6 +18,8 @@ module Proxy::OpenSCAP
18
18
  logger.debug response.body if response
19
19
  logger.debug e.backtrace.join("\n\t")
20
20
  raise e
21
+ ensure
22
+ parser.cleanup
21
23
  end
22
24
  res
23
25
  end
@@ -114,22 +114,28 @@ module Proxy::OpenSCAP
114
114
  end
115
115
 
116
116
  post "/scap_content/policies" do
117
+ content_parser = create_content_parser
117
118
  begin
118
- Proxy::OpenSCAP::ContentParser.new(request.body.string).extract_policies
119
+ content_parser.extract_policies
119
120
  rescue *HTTP_ERRORS => e
120
121
  log_halt 500, e.message
121
122
  rescue StandardError => e
122
123
  log_halt 500, "Error occurred: #{e.message}"
124
+ ensure
125
+ content_parser.cleanup
123
126
  end
124
127
  end
125
128
 
126
129
  post "/tailoring_file/profiles" do
130
+ content_parser = create_content_parser
127
131
  begin
128
- Proxy::OpenSCAP::ContentParser.new(request.body.string).get_profiles
132
+ content_parser.get_profiles
129
133
  rescue *HTTP_ERRORS => e
130
134
  log_halt 500, e.message
131
135
  rescue StandardError => e
132
136
  log_halt 500, "Error occurred: #{e.message}"
137
+ ensure
138
+ content_parser.cleanup
133
139
  end
134
140
  end
135
141
 
@@ -144,12 +150,15 @@ module Proxy::OpenSCAP
144
150
  end
145
151
 
146
152
  post "/scap_content/guide/:policy" do
153
+ content_parser = create_content_parser
147
154
  begin
148
- Proxy::OpenSCAP::ContentParser.new(request.body.string).guide(params[:policy])
155
+ content_parser.guide(params[:policy])
149
156
  rescue *HTTP_ERRORS => e
150
157
  log_halt 500, e.message
151
158
  rescue StandardError => e
152
159
  log_halt 500, "Error occurred: #{e.message}"
160
+ ensure
161
+ content_parser.cleanup
153
162
  end
154
163
  end
155
164
 
@@ -164,5 +173,9 @@ module Proxy::OpenSCAP
164
173
  log_halt 500, "Error occurred: #{e.message}"
165
174
  end
166
175
  end
176
+
177
+ def create_content_parser
178
+ Proxy::OpenSCAP::ContentParser.new(request.body.string)
179
+ end
167
180
  end
168
181
  end
@@ -11,6 +11,11 @@ module Proxy::OpenSCAP
11
11
  @type = type
12
12
  end
13
13
 
14
+ def cleanup
15
+ @source.destroy if @source
16
+ OpenSCAP.oscap_cleanup
17
+ end
18
+
14
19
  def allowed_types
15
20
  {
16
21
  'tailoring_file' => 'XCCDF Tailoring',
@@ -16,11 +16,21 @@ module Proxy::OpenSCAP
16
16
  size = arf_data.size
17
17
  @arf_digest = Digest::SHA256.hexdigest(arf_data)
18
18
  @arf = OpenSCAP::DS::Arf.new(:content => arf_data, :path => 'arf.xml.bz2', :length => size)
19
- @results = @arf.test_result.rr
20
- sds = @arf.report_request
21
- bench_source = sds.select_checklist!
22
- @bench = OpenSCAP::Xccdf::Benchmark.new(bench_source)
23
- @items = @bench.items
19
+ @test_result = @arf.test_result
20
+
21
+ @results = @test_result.rr
22
+ @sds = @arf.report_request
23
+ bench_source = @sds.select_checklist!
24
+ @benchmark = OpenSCAP::Xccdf::Benchmark.new(bench_source)
25
+ @items = @benchmark.items
26
+ end
27
+
28
+ def cleanup
29
+ @test_result.destroy if @test_result
30
+ @benchmark.destroy if @benchmark
31
+ @sds.destroy if @sds
32
+ @arf.destroy if @arf
33
+ OpenSCAP.oscap_cleanup
24
34
  end
25
35
 
26
36
  def as_json
@@ -10,6 +10,6 @@
10
10
 
11
11
  module Proxy
12
12
  module OpenSCAP
13
- VERSION = '0.6.2'
13
+ VERSION = '0.6.3'
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.6.2
4
+ version: 0.6.3
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: 2017-03-13 00:00:00.000000000 Z
13
+ date: 2017-03-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -157,8 +157,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.4.5
160
+ rubygems_version: 2.4.6
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: OpenSCAP plug-in for Foreman's smart-proxy.
164
164
  test_files: []
165
+ has_rdoc: