smart_proxy_openscap 0.5.3 → 0.5.4
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 +7 -7
- data/Gemfile +4 -0
- data/README.md +1 -1
- data/lib/smart_proxy_openscap/http_config.ru +5 -0
- data/lib/smart_proxy_openscap/openscap_api.rb +7 -13
- data/lib/smart_proxy_openscap/openscap_import_api.rb +32 -0
- data/lib/smart_proxy_openscap/openscap_plugin.rb +5 -5
- data/lib/smart_proxy_openscap/openscap_report_parser.rb +8 -0
- data/lib/smart_proxy_openscap/storage_fs.rb +1 -1
- data/lib/smart_proxy_openscap/{openscap_version.rb → version.rb} +1 -1
- data/smart_proxy_openscap.gemspec +1 -1
- data/test/test_helper.rb +1 -0
- metadata +64 -83
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
---
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
---
|
|
2
|
+
SHA512:
|
|
3
|
+
data.tar.gz: 1e3762a0add8f215482859c23933ef292a73c2512d18100d06ae47a452c4607a7ae65787a9c7adec74ceee8bf432461190eca7e23e61f8e8023939491285ab62
|
|
4
|
+
metadata.gz: 6833ac54593b8ce05f55570e9aba27df9c42041721dd5e8e84ceb70ee0331cb643b092297e76f8ce515f3ba87c05acf521e76617ae2133c46da6c411e11c1739
|
|
5
|
+
SHA1:
|
|
6
|
+
data.tar.gz: 451634ad2aaf6c9b1f7cf19c3a99a18dea15d097
|
|
7
|
+
metadata.gz: 50bd53594454c8b43afd26904e978a01a8a8004c
|
data/Gemfile
CHANGED
|
@@ -6,3 +6,7 @@ group :development do
|
|
|
6
6
|
gem 'rubocop'
|
|
7
7
|
gem 'smart_proxy', :github => "theforeman/smart-proxy", :branch => 'develop'
|
|
8
8
|
end
|
|
9
|
+
|
|
10
|
+
# load local gemfile
|
|
11
|
+
local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local.rb')
|
|
12
|
+
self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
|
data/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Learn more about [Foreman-OpenSCAP](https://github.com/theforeman/foreman_opensc
|
|
|
26
26
|
- Add smart_proxy_openscap to your smart proxy `bundler.d/openscap.rb` gemfile:
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
~$ gem 'smart_proxy_openscap', :git => https://github.com/theforeman/smart_proxy_openscap.git
|
|
29
|
+
~$ gem 'smart_proxy_openscap', :git => 'https://github.com/theforeman/smart_proxy_openscap.git'
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
If you don't install through RPM and you are using bundler, you may need to create
|
|
@@ -37,18 +37,15 @@ module Proxy::OpenSCAP
|
|
|
37
37
|
|
|
38
38
|
begin
|
|
39
39
|
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string)
|
|
40
|
-
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date)
|
|
41
|
-
.store_archive(request.body.string)
|
|
40
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date).store_archive(request.body.string)
|
|
42
41
|
rescue Proxy::OpenSCAP::StoreReportError => e
|
|
43
|
-
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, cn, post_to_foreman['id'], date)
|
|
44
|
-
.store_failed(request.body.string)
|
|
42
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, cn, post_to_foreman['id'], date).store_failed(request.body.string)
|
|
45
43
|
logger.error "Failed to save Report in reports directory (#{Proxy::OpenSCAP::Plugin.settings.reportsdir}). Failed with: #{e.message}.
|
|
46
44
|
Saving file in #{Proxy::OpenSCAP::Plugin.settings.failed_dir}. Please copy manually to #{Proxy::OpenSCAP::Plugin.settings.reportsdir}"
|
|
47
45
|
rescue *HTTP_ERRORS => e
|
|
48
46
|
### If the upload to foreman fails then store it in the spooldir
|
|
49
47
|
logger.error "Failed to upload to Foreman, saving in spool. Failed with: #{e.message}"
|
|
50
|
-
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.spooldir, cn, policy, date)
|
|
51
|
-
.store_spool(request.body.string)
|
|
48
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.spooldir, cn, policy, date).store_spool(request.body.string)
|
|
52
49
|
rescue Proxy::OpenSCAP::StoreSpoolError => e
|
|
53
50
|
log_halt 500, e.message
|
|
54
51
|
end
|
|
@@ -57,8 +54,7 @@ module Proxy::OpenSCAP
|
|
|
57
54
|
get "/arf/:id/:cname/:date/:digest/xml" do
|
|
58
55
|
content_type 'application/x-bzip2'
|
|
59
56
|
begin
|
|
60
|
-
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date])
|
|
61
|
-
.get_arf_xml(params[:digest])
|
|
57
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).get_arf_xml(params[:digest])
|
|
62
58
|
rescue FileNotFound => e
|
|
63
59
|
log_halt 500, "Could not find requested file, #{e.message}"
|
|
64
60
|
end
|
|
@@ -66,17 +62,15 @@ module Proxy::OpenSCAP
|
|
|
66
62
|
|
|
67
63
|
delete "/arf/:id/:cname/:date/:digest" do
|
|
68
64
|
begin
|
|
69
|
-
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date])
|
|
70
|
-
.delete_arf_file
|
|
65
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).delete_arf_file
|
|
71
66
|
rescue FileNotFound => e
|
|
72
|
-
|
|
67
|
+
logger.debug "Could not find requested file, #{e.message} - Assuming deleted"
|
|
73
68
|
end
|
|
74
69
|
end
|
|
75
70
|
|
|
76
71
|
get "/arf/:id/:cname/:date/:digest/html" do
|
|
77
72
|
begin
|
|
78
|
-
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date])
|
|
79
|
-
.get_arf_html(params[:digest])
|
|
73
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, params[:cname], params[:id], params[:date]).get_arf_html(params[:digest])
|
|
80
74
|
rescue FileNotFound => e
|
|
81
75
|
log_halt 500, "Could not find requested file, #{e.message}"
|
|
82
76
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Proxy::OpenSCAP
|
|
2
|
+
class ImportApi < ::Sinatra::Base
|
|
3
|
+
include ::Proxy::Log
|
|
4
|
+
helpers ::Proxy::Helpers
|
|
5
|
+
authorize_with_trusted_hosts
|
|
6
|
+
|
|
7
|
+
require 'smart_proxy_openscap/openscap_lib'
|
|
8
|
+
|
|
9
|
+
post "/arf/:cname/:policy_id/:date" do
|
|
10
|
+
cn = params[:cname]
|
|
11
|
+
date = params[:date]
|
|
12
|
+
policy = params[:policy_id]
|
|
13
|
+
log_halt(500, "Insufficient data") if (cn.nil? || date.nil?)
|
|
14
|
+
|
|
15
|
+
post_to_foreman = ForemanForwarder.new.post_arf_report(cn, policy, date, request.body.string)
|
|
16
|
+
begin
|
|
17
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.reportsdir, cn, post_to_foreman['id'], date).store_archive(request.body.string)
|
|
18
|
+
rescue Proxy::OpenSCAP::StoreReportError => e
|
|
19
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.failed_dir, cn, post_to_foreman['id'], date).store_failed(request.body.string)
|
|
20
|
+
logger.error "Failed to save Report in reports directory (#{Proxy::OpenSCAP::Plugin.settings.reportsdir}). Failed with: #{e.message}.
|
|
21
|
+
Saving file in #{Proxy::OpenSCAP::Plugin.settings.failed_dir}. Please copy manually to #{Proxy::OpenSCAP::Plugin.settings.reportsdir}"
|
|
22
|
+
rescue *HTTP_ERRORS => e
|
|
23
|
+
### If the upload to foreman fails then store it in the spooldir
|
|
24
|
+
logger.error "Failed to upload to Foreman, saving in spool. Failed with: #{e.message}"
|
|
25
|
+
Proxy::OpenSCAP::StorageFS.new(Proxy::OpenSCAP::Plugin.settings.spooldir, cn, policy, date).store_spool(request.body.string)
|
|
26
|
+
rescue Proxy::OpenSCAP::StoreSpoolError => e
|
|
27
|
+
log_halt 500, e.message
|
|
28
|
+
end
|
|
29
|
+
{:success => true, :arf_id => post_to_foreman['id']}.to_json
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
# along with this software; if not, see http://www.gnu.org/licenses/gpl.txt
|
|
9
9
|
#
|
|
10
10
|
|
|
11
|
-
require 'smart_proxy_openscap/
|
|
11
|
+
require 'smart_proxy_openscap/version'
|
|
12
12
|
|
|
13
13
|
module Proxy::OpenSCAP
|
|
14
14
|
class Plugin < ::Proxy::Plugin
|
|
@@ -18,9 +18,9 @@ module Proxy::OpenSCAP
|
|
|
18
18
|
https_rackup_path File.expand_path("http_config.ru", File.expand_path("../", __FILE__))
|
|
19
19
|
|
|
20
20
|
default_settings :spooldir => '/var/spool/foreman-proxy/openscap',
|
|
21
|
-
:openscap_send_log_file => 'logs/openscap-send.log',
|
|
22
|
-
:contentdir => 'openscap/content',
|
|
23
|
-
:reportsdir => 'openscap/reports',
|
|
24
|
-
:failed_dir => 'openscap/failed'
|
|
21
|
+
:openscap_send_log_file => File.join(APP_ROOT, 'logs/openscap-send.log'),
|
|
22
|
+
:contentdir => File.join(APP_ROOT, 'openscap/content'),
|
|
23
|
+
:reportsdir => File.join(APP_ROOT, 'openscap/reports'),
|
|
24
|
+
:failed_dir => File.join(APP_ROOT, 'openscap/failed')
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -7,6 +7,8 @@ require 'openscap/xccdf/rule'
|
|
|
7
7
|
require 'openscap/xccdf/fix'
|
|
8
8
|
require 'openscap/xccdf/benchmark'
|
|
9
9
|
require 'json'
|
|
10
|
+
require 'iconv' if RUBY_VERSION.start_with? '1.8'
|
|
11
|
+
|
|
10
12
|
module Proxy::OpenSCAP
|
|
11
13
|
class Parse
|
|
12
14
|
def initialize(arf_data)
|
|
@@ -81,9 +83,15 @@ module Proxy::OpenSCAP
|
|
|
81
83
|
# Sets the replacement string to the given value. The default replacement
|
|
82
84
|
# string is "\uFFFD" for Unicode encoding forms, and "?" otherwise.
|
|
83
85
|
def ascii8bit_to_utf8(string)
|
|
86
|
+
return ascii8bit_to_utf8_legacy(string) if RUBY_VERSION.start_with? '1.8'
|
|
84
87
|
string.to_s.encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_')
|
|
85
88
|
end
|
|
86
89
|
|
|
90
|
+
# String#encode appeared first in 1.9, so we need a workaround for 1.8
|
|
91
|
+
def ascii8bit_to_utf8_legacy(string)
|
|
92
|
+
Iconv.conv('UTF-8//IGNORE', 'UTF-8', string.to_s)
|
|
93
|
+
end
|
|
94
|
+
|
|
87
95
|
def hash_a8b(ary)
|
|
88
96
|
ary.map do |hash|
|
|
89
97
|
Hash[hash.map { |key, value| [ascii8bit_to_utf8(key), ascii8bit_to_utf8(value)] }]
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,98 +1,78 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smart_proxy_openscap
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.4
|
|
5
5
|
platform: ruby
|
|
6
|
-
authors:
|
|
7
|
-
-
|
|
6
|
+
authors:
|
|
7
|
+
- !binary |
|
|
8
|
+
xaBpbW9uIEx1a2HFocOtaw==
|
|
9
|
+
|
|
8
10
|
- Shlomi Zadok
|
|
9
11
|
- Marek Hulan
|
|
10
12
|
autorequire:
|
|
11
13
|
bindir: bin
|
|
12
14
|
cert_chain: []
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
|
|
16
|
+
date: 2016-06-02 00:00:00 Z
|
|
17
|
+
dependencies:
|
|
18
|
+
- !ruby/object:Gem::Dependency
|
|
16
19
|
name: rake
|
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
|
18
|
-
requirements:
|
|
19
|
-
- - ">="
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: '0'
|
|
22
|
-
type: :development
|
|
23
20
|
prerelease: false
|
|
24
|
-
|
|
25
|
-
requirements:
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
name: rack-test
|
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
|
32
|
-
requirements:
|
|
33
|
-
- - ">="
|
|
34
|
-
- !ruby/object:Gem::Version
|
|
35
|
-
version: '0'
|
|
21
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- &id002
|
|
24
|
+
- ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: "0"
|
|
36
27
|
type: :development
|
|
28
|
+
version_requirements: *id001
|
|
29
|
+
- !ruby/object:Gem::Dependency
|
|
30
|
+
name: rack-test
|
|
37
31
|
prerelease: false
|
|
38
|
-
|
|
39
|
-
requirements:
|
|
40
|
-
-
|
|
41
|
-
- !ruby/object:Gem::Version
|
|
42
|
-
version: '0'
|
|
43
|
-
- !ruby/object:Gem::Dependency
|
|
44
|
-
name: mocha
|
|
45
|
-
requirement: !ruby/object:Gem::Requirement
|
|
46
|
-
requirements:
|
|
47
|
-
- - ">="
|
|
48
|
-
- !ruby/object:Gem::Version
|
|
49
|
-
version: '0'
|
|
32
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- *id002
|
|
50
35
|
type: :development
|
|
36
|
+
version_requirements: *id003
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
name: mocha
|
|
51
39
|
prerelease: false
|
|
52
|
-
|
|
53
|
-
requirements:
|
|
54
|
-
-
|
|
55
|
-
- !ruby/object:Gem::Version
|
|
56
|
-
version: '0'
|
|
57
|
-
- !ruby/object:Gem::Dependency
|
|
58
|
-
name: webmock
|
|
59
|
-
requirement: !ruby/object:Gem::Requirement
|
|
60
|
-
requirements:
|
|
61
|
-
- - ">="
|
|
62
|
-
- !ruby/object:Gem::Version
|
|
63
|
-
version: '0'
|
|
40
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- *id002
|
|
64
43
|
type: :development
|
|
44
|
+
version_requirements: *id004
|
|
45
|
+
- !ruby/object:Gem::Dependency
|
|
46
|
+
name: webmock
|
|
65
47
|
prerelease: false
|
|
66
|
-
|
|
67
|
-
requirements:
|
|
68
|
-
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
- !ruby/object:Gem::Dependency
|
|
48
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- *id002
|
|
51
|
+
type: :development
|
|
52
|
+
version_requirements: *id005
|
|
53
|
+
- !ruby/object:Gem::Dependency
|
|
72
54
|
name: openscap
|
|
73
|
-
requirement: !ruby/object:Gem::Requirement
|
|
74
|
-
requirements:
|
|
75
|
-
- - ">="
|
|
76
|
-
- !ruby/object:Gem::Version
|
|
77
|
-
version: 0.4.3
|
|
78
|
-
type: :runtime
|
|
79
55
|
prerelease: false
|
|
80
|
-
|
|
81
|
-
requirements:
|
|
56
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
82
58
|
- - ">="
|
|
83
|
-
- !ruby/object:Gem::Version
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
84
60
|
version: 0.4.3
|
|
61
|
+
type: :runtime
|
|
62
|
+
version_requirements: *id006
|
|
85
63
|
description: |-
|
|
86
64
|
A plug-in to the Foreman's smart-proxy which receives
|
|
87
65
|
bzip2ed ARF files and forwards them to the Foreman.
|
|
88
66
|
email: slukasik@redhat.com
|
|
89
|
-
executables:
|
|
67
|
+
executables:
|
|
90
68
|
- smart-proxy-openscap-send
|
|
91
69
|
extensions: []
|
|
70
|
+
|
|
92
71
|
extra_rdoc_files: []
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
-
|
|
72
|
+
|
|
73
|
+
files:
|
|
74
|
+
- .rubocop.yml
|
|
75
|
+
- .rubocop_todo.yml
|
|
96
76
|
- COPYING
|
|
97
77
|
- Gemfile
|
|
98
78
|
- README.md
|
|
@@ -108,13 +88,14 @@ files:
|
|
|
108
88
|
- lib/smart_proxy_openscap/openscap_api.rb
|
|
109
89
|
- lib/smart_proxy_openscap/openscap_content_parser.rb
|
|
110
90
|
- lib/smart_proxy_openscap/openscap_exception.rb
|
|
91
|
+
- lib/smart_proxy_openscap/openscap_import_api.rb
|
|
111
92
|
- lib/smart_proxy_openscap/openscap_lib.rb
|
|
112
93
|
- lib/smart_proxy_openscap/openscap_plugin.rb
|
|
113
94
|
- lib/smart_proxy_openscap/openscap_report_parser.rb
|
|
114
|
-
- lib/smart_proxy_openscap/openscap_version.rb
|
|
115
95
|
- lib/smart_proxy_openscap/spool_forwarder.rb
|
|
116
96
|
- lib/smart_proxy_openscap/storage.rb
|
|
117
97
|
- lib/smart_proxy_openscap/storage_fs.rb
|
|
98
|
+
- lib/smart_proxy_openscap/version.rb
|
|
118
99
|
- settings.d/openscap.yml.example
|
|
119
100
|
- smart_proxy_openscap.gemspec
|
|
120
101
|
- test/data/arf_report
|
|
@@ -125,27 +106,27 @@ files:
|
|
|
125
106
|
- test/scap_content_parser_api_test.rb
|
|
126
107
|
- test/test_helper.rb
|
|
127
108
|
homepage: http://github.com/OpenSCAP/smart_proxy_openscap
|
|
128
|
-
licenses:
|
|
109
|
+
licenses:
|
|
129
110
|
- GPL-3
|
|
130
111
|
metadata: {}
|
|
112
|
+
|
|
131
113
|
post_install_message:
|
|
132
114
|
rdoc_options: []
|
|
133
|
-
|
|
115
|
+
|
|
116
|
+
require_paths:
|
|
134
117
|
- lib
|
|
135
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
|
-
requirements:
|
|
137
|
-
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
requirements:
|
|
142
|
-
- - ">="
|
|
143
|
-
- !ruby/object:Gem::Version
|
|
144
|
-
version: '0'
|
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- *id002
|
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- *id002
|
|
145
124
|
requirements: []
|
|
125
|
+
|
|
146
126
|
rubyforge_project:
|
|
147
|
-
rubygems_version: 2.
|
|
127
|
+
rubygems_version: 2.0.17
|
|
148
128
|
signing_key:
|
|
149
129
|
specification_version: 4
|
|
150
130
|
summary: OpenSCAP plug-in for Foreman's smart-proxy.
|
|
151
131
|
test_files: []
|
|
132
|
+
|