foreman_scap_client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28238d64ee3a46f8c5a26d708296465a01f36e4
4
- data.tar.gz: 55b7c4e5c6f3e409b29e86eb1dfb09ead09a7341
3
+ metadata.gz: 8f5a6bc1a8e9ab962c33f4902ff845e6b7bcacf3
4
+ data.tar.gz: c692d959c101d2d18f63ea6c399a98dc8f99df7a
5
5
  SHA512:
6
- metadata.gz: 50008f95f40178fb2840eaf529f882bbbee3bfe35850fbe364b9b17a73dfc34566d5b97aca5c176c4895420a826f74afc8742024f89115d63077d8621d15e219
7
- data.tar.gz: aa2121ee4ae12f90d8d6c3305a53719caf1a40d478b628e2cd0fbd86f82e6077f3f411c2c12b90d0b2736495691f39e5c994be2136f7e9e6160f14618a3f2647
6
+ metadata.gz: ce8cef68f46660c12b1e1fc1895681713fc06387eccb06a7ec03dad8bf7049952a24b8d9066255fcdee4f7d0bd202989d8199912492cc393ab5ab42e796e72aa
7
+ data.tar.gz: 8145d9d2dfd42bffe66d4daf7120410bfad5796f77a7ca857fc25851ff083bea67b88bc82083060bfa7c212f19d07bafdeab973340f156fc72ad60cf04adc9ab
@@ -9,10 +9,13 @@ module ForemanScapClient
9
9
  CONFIG_FILE = '/etc/foreman_scap_client/config.yaml'
10
10
 
11
11
  class Client
12
+ attr_reader :config, :policy_id, :tailored
13
+
12
14
  def run(policy_id)
13
15
  @policy_id = policy_id
14
- ensure_policy_exist
16
+ load_config
15
17
  ensure_scan_file
18
+ ensure_tailoring_file
16
19
  Dir.mktmpdir do |dir|
17
20
  @tmp_dir = dir
18
21
  scan
@@ -23,8 +26,10 @@ module ForemanScapClient
23
26
 
24
27
  private
25
28
 
26
- def config
29
+ def load_config
27
30
  @config ||= YAML.load_file(CONFIG_FILE)
31
+ ensure_policy_exist
32
+ @tailored = @config[policy_id][:tailoring_path] && !@config[policy_id][:tailoring_path].empty?
28
33
  rescue => e
29
34
  puts 'Config file could not be loaded'
30
35
  puts e.message
@@ -57,7 +62,11 @@ module ForemanScapClient
57
62
  else
58
63
  profile = ''
59
64
  end
60
- "oscap xccdf eval #{profile} --results-arf #{results_path} #{config[@policy_id][:content_path]}"
65
+ "oscap xccdf eval #{profile} #{tailoring_subcommand} --results-arf #{results_path} #{config[@policy_id][:content_path]}"
66
+ end
67
+
68
+ def tailoring_subcommand
69
+ tailored ? "--tailoring-file #{config[policy_id][:tailoring_path]}" : ""
61
70
  end
62
71
 
63
72
  def bzip_command
@@ -125,25 +134,34 @@ module ForemanScapClient
125
134
  end
126
135
  end
127
136
 
128
- def ensure_scan_file
129
- return if File.exist?(config[@policy_id][:content_path])
130
- puts "File #{config[@policy_id][:content_path]} is missing. Downloading it from proxy"
137
+ def ensure_file(dir, download_path, type_humanized)
138
+ return if File.exist?(config[policy_id][dir])
139
+ puts "File #{config[policy_id][dir]} is missing. Downloading it from proxy."
131
140
  begin
132
- FileUtils.mkdir_p(File.dirname(config[@policy_id][:content_path]))
133
- uri = URI.parse(download_uri(config[@policy_id][:download_path]))
134
- puts "Download scap content xml from: #{uri}"
141
+ FileUtils.mkdir_p(File.dirname(config[policy_id][dir]))
142
+ uri = URI.parse(download_uri(config[policy_id][download_path]))
143
+ puts "Download #{type_humanized} xml from: #{uri}"
135
144
  request = generate_https_object(uri).get(uri.path)
136
145
  request.value
137
- scap_content_xml = request.body
138
- open(config[@policy_id][:content_path], 'wb') do |file|
139
- file << scap_content_xml
146
+ ds_content_xml = request.body
147
+ open(config[policy_id][dir], 'wb') do |file|
148
+ file << ds_content_xml
140
149
  end
141
150
  rescue StandardError => e
142
- puts "SCAP file is missing and download failed with error: #{e.message}"
151
+ puts "#{type_humanized} is missing and download failed with error: #{e.message}"
143
152
  exit(5)
144
153
  end
145
154
  end
146
155
 
156
+ def ensure_scan_file
157
+ ensure_file :content_path, :download_path, "SCAP content"
158
+ end
159
+
160
+ def ensure_tailoring_file
161
+ return unless tailored
162
+ ensure_file :tailoring_path, :tailoring_download_path, "Tailoring file"
163
+ end
164
+
147
165
  def download_uri(download_path)
148
166
  foreman_proxy_uri + "#{download_path}"
149
167
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanScapClient
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_scap_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-01 00:00:00.000000000 Z
13
+ date: 2017-02-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - "/usr/bin/bzip2"
81
81
  rubyforge_project:
82
- rubygems_version: 2.4.6
82
+ rubygems_version: 2.4.5
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Client script that runs openscap scan and uploads the result to foreman proxy