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 +4 -4
- data/lib/foreman_scap_client/client.rb +31 -13
- data/lib/foreman_scap_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f5a6bc1a8e9ab962c33f4902ff845e6b7bcacf3
|
4
|
+
data.tar.gz: c692d959c101d2d18f63ea6c399a98dc8f99df7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
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
|
129
|
-
return if File.exist?(config[
|
130
|
-
puts "File #{config[
|
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[
|
133
|
-
uri = URI.parse(download_uri(config[
|
134
|
-
puts "Download
|
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
|
-
|
138
|
-
open(config[
|
139
|
-
file <<
|
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 "
|
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
|
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.
|
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:
|
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.
|
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
|