inspec 1.51.0 → 1.51.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -15
- data/README.md +1 -1
- data/docs/glossary.md +99 -0
- data/docs/resources/aide_conf.md.erb +16 -9
- data/docs/resources/apache.md.erb +66 -0
- data/docs/resources/apache_conf.md.erb +11 -5
- data/docs/resources/apt.md.erb +1 -1
- data/docs/resources/audit_policy.md.erb +1 -1
- data/docs/resources/auditd_conf.md.erb +12 -9
- data/docs/resources/bash.md.erb +24 -12
- data/docs/resources/bond.md.erb +26 -24
- data/docs/resources/bridge.md.erb +18 -11
- data/docs/resources/bsd_service.md.erb +11 -2
- data/docs/resources/command.md.erb +30 -29
- data/docs/resources/cpan.md.erb +33 -17
- data/docs/resources/cran.md.erb +26 -17
- data/docs/resources/crontab.md.erb +18 -1
- data/docs/resources/csv.md.erb +13 -7
- data/docs/resources/{dh_params.md → dh_params.md.erb} +30 -6
- data/docs/resources/directory.md.erb +9 -4
- data/docs/resources/docker.md.erb +1 -1
- data/docs/resources/docker_container.md.erb +32 -26
- data/docs/resources/docker_image.md.erb +29 -26
- data/docs/resources/docker_service.md.erb +37 -31
- data/docs/resources/elasticsearch.md.erb +18 -32
- data/docs/resources/etc_fstab.md.erb +19 -15
- data/docs/resources/etc_group.md.erb +13 -39
- data/docs/resources/etc_hosts.md.erb +12 -5
- data/docs/resources/etc_hosts_allow.md.erb +9 -4
- data/docs/resources/etc_hosts_deny.md.erb +12 -7
- data/docs/resources/file.md.erb +139 -134
- data/docs/resources/filesystem.md.erb +5 -4
- data/docs/resources/firewalld.md.erb +1 -1
- data/docs/resources/gem.md.erb +2 -2
- data/docs/resources/group.md.erb +1 -1
- data/docs/resources/host.md.erb +1 -1
- data/docs/resources/iis_app.md.erb +1 -1
- data/docs/resources/iis_site.md.erb +1 -1
- data/docs/resources/interface.md.erb +1 -1
- data/docs/resources/iptables.md.erb +1 -1
- data/docs/resources/json.md.erb +1 -1
- data/docs/resources/kernel_module.md.erb +1 -1
- data/docs/resources/kernel_parameter.md.erb +1 -1
- data/docs/resources/launchd_service.md.erb +1 -1
- data/docs/resources/limits_conf.md.erb +1 -1
- data/docs/resources/login_def.md.erb +1 -1
- data/docs/resources/mount.md.erb +1 -1
- data/docs/resources/mysql_conf.md.erb +1 -1
- data/docs/resources/nginx_conf.md.erb +1 -1
- data/docs/resources/npm.md.erb +1 -1
- data/docs/resources/oneget.md.erb +1 -1
- data/docs/resources/os.md.erb +1 -1
- data/docs/resources/os_env.md.erb +2 -2
- data/docs/resources/package.md.erb +1 -1
- data/docs/resources/packages.md.erb +66 -0
- data/docs/resources/parse_config.md.erb +1 -1
- data/docs/resources/parse_config_file.md.erb +1 -1
- data/docs/resources/passwd.md.erb +1 -1
- data/docs/resources/pip.md.erb +1 -1
- data/docs/resources/port.md.erb +1 -1
- data/docs/resources/postgres_conf.md.erb +1 -1
- data/docs/resources/postgres_session.md.erb +1 -1
- data/docs/resources/powershell.md.erb +2 -2
- data/docs/resources/processes.md.erb +1 -1
- data/docs/resources/registry_key.md.erb +1 -1
- data/docs/resources/runit_service.md.erb +1 -1
- data/docs/resources/security_policy.md.erb +1 -1
- data/docs/resources/service.md.erb +1 -1
- data/docs/resources/shadow.md.erb +1 -1
- data/docs/resources/ssh_config.md.erb +1 -1
- data/docs/resources/sshd_config.md.erb +1 -1
- data/docs/resources/ssl.md.erb +1 -1
- data/docs/resources/sys_info.md.erb +1 -1
- data/docs/resources/systemd_service.md.erb +1 -1
- data/docs/resources/sysv_service.md.erb +1 -1
- data/docs/resources/upstart_service.md.erb +1 -1
- data/docs/resources/user.md.erb +1 -1
- data/docs/resources/users.md.erb +1 -1
- data/docs/resources/windows_feature.md.erb +1 -1
- data/docs/resources/windows_hotfix.md.erb +1 -1
- data/docs/resources/xinetd_conf.md.erb +1 -1
- data/docs/resources/xml.md.erb +1 -1
- data/docs/resources/yaml.md.erb +1 -1
- data/docs/resources/yum.md.erb +1 -1
- data/lib/inspec.rb +2 -1
- data/lib/inspec/base_cli.rb +98 -18
- data/lib/inspec/cli.rb +33 -21
- data/lib/inspec/formatters.rb +3 -0
- data/lib/inspec/formatters/base.rb +208 -0
- data/lib/inspec/formatters/json_rspec.rb +20 -0
- data/lib/inspec/formatters/show_progress.rb +12 -0
- data/lib/inspec/objects.rb +1 -0
- data/lib/inspec/objects/describe.rb +92 -0
- data/lib/inspec/reporters.rb +33 -0
- data/lib/inspec/reporters/base.rb +23 -0
- data/lib/inspec/reporters/cli.rb +395 -0
- data/lib/inspec/reporters/json.rb +132 -0
- data/lib/inspec/reporters/json_min.rb +44 -0
- data/lib/inspec/reporters/junit.rb +77 -0
- data/lib/inspec/runner.rb +14 -1
- data/lib/inspec/runner_rspec.rb +34 -14
- data/lib/inspec/schema.rb +1 -0
- data/lib/inspec/shell.rb +0 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/apache.rb +20 -0
- data/lib/resources/apache_conf.rb +33 -8
- data/lib/resources/audit_policy.rb +1 -1
- data/lib/resources/packages.rb +4 -3
- metadata +17 -4
- data/lib/inspec/rspec_json_formatter.rb +0 -940
@@ -99,7 +99,7 @@ This is also possible with `systemd_service`, `runit_service`, `sysv_service`, `
|
|
99
99
|
|
100
100
|
## Matchers
|
101
101
|
|
102
|
-
|
102
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
103
103
|
|
104
104
|
### be_enabled
|
105
105
|
|
@@ -78,7 +78,7 @@ The following examples show how to use this InSpec audit resource.
|
|
78
78
|
|
79
79
|
## Matchers
|
80
80
|
|
81
|
-
|
81
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
82
82
|
|
83
83
|
### count
|
84
84
|
|
@@ -66,7 +66,7 @@ The following examples show how to use this InSpec audit resource.
|
|
66
66
|
|
67
67
|
## Matchers
|
68
68
|
|
69
|
-
|
69
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
70
70
|
|
71
71
|
### name
|
72
72
|
|
@@ -69,7 +69,7 @@ The following examples show how to use this InSpec audit resource.
|
|
69
69
|
|
70
70
|
## Matchers
|
71
71
|
|
72
|
-
|
72
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
73
73
|
|
74
74
|
### name
|
75
75
|
|
data/docs/resources/ssl.md.erb
CHANGED
@@ -85,7 +85,7 @@ Or execute the profile directly via URL:
|
|
85
85
|
|
86
86
|
## Matchers
|
87
87
|
|
88
|
-
|
88
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
89
89
|
|
90
90
|
### be_enabled
|
91
91
|
|
@@ -32,7 +32,7 @@ The following examples show how to use this InSpec audit resource.
|
|
32
32
|
|
33
33
|
## Matchers
|
34
34
|
|
35
|
-
|
35
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
36
36
|
|
37
37
|
### hostname
|
38
38
|
|
@@ -35,7 +35,7 @@ The path to the service manager's control may be specified for situations where
|
|
35
35
|
|
36
36
|
## Matchers
|
37
37
|
|
38
|
-
|
38
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
39
39
|
|
40
40
|
### be_enabled
|
41
41
|
|
@@ -35,7 +35,7 @@ The path to the service manager's control may be specified for situations where
|
|
35
35
|
|
36
36
|
## Matchers
|
37
37
|
|
38
|
-
|
38
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
39
39
|
|
40
40
|
### be_enabled
|
41
41
|
|
@@ -35,7 +35,7 @@ The path to the service manager's control may be specified for situations where
|
|
35
35
|
|
36
36
|
## Matchers
|
37
37
|
|
38
|
-
|
38
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
39
39
|
|
40
40
|
### be_enabled
|
41
41
|
|
data/docs/resources/user.md.erb
CHANGED
@@ -64,7 +64,7 @@ The `nginx` user is typically `www-data`, but on CentOS it's `nginx`. The follow
|
|
64
64
|
|
65
65
|
## Matchers
|
66
66
|
|
67
|
-
|
67
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
68
68
|
|
69
69
|
### exist
|
70
70
|
|
data/docs/resources/users.md.erb
CHANGED
@@ -51,7 +51,7 @@ The following examples show how to use this InSpec audit resource.
|
|
51
51
|
|
52
52
|
## Matchers
|
53
53
|
|
54
|
-
|
54
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
55
55
|
|
56
56
|
### exist
|
57
57
|
|
@@ -37,7 +37,7 @@ The following examples show how to use this InSpec audit resource.
|
|
37
37
|
|
38
38
|
## Matchers
|
39
39
|
|
40
|
-
|
40
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
41
41
|
|
42
42
|
### be_installed
|
43
43
|
|
@@ -43,7 +43,7 @@ The following examples show how to use this InSpec audit resource.
|
|
43
43
|
|
44
44
|
## Matchers
|
45
45
|
|
46
|
-
|
46
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
47
47
|
|
48
48
|
### be_installed
|
49
49
|
|
@@ -90,7 +90,7 @@ All three settings can be tested in the same block as well:
|
|
90
90
|
|
91
91
|
## Matchers
|
92
92
|
|
93
|
-
|
93
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
94
94
|
|
95
95
|
### be_enabed
|
96
96
|
|
data/docs/resources/xml.md.erb
CHANGED
@@ -75,7 +75,7 @@ The following examples show how to use this InSpec audit resource.
|
|
75
75
|
|
76
76
|
## Matchers
|
77
77
|
|
78
|
-
|
78
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
79
79
|
|
80
80
|
### name
|
81
81
|
|
data/docs/resources/yaml.md.erb
CHANGED
@@ -59,7 +59,7 @@ The following examples show how to use this InSpec audit resource.
|
|
59
59
|
|
60
60
|
## Matchers
|
61
61
|
|
62
|
-
|
62
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
63
63
|
|
64
64
|
### name
|
65
65
|
|
data/docs/resources/yum.md.erb
CHANGED
@@ -60,7 +60,7 @@ The following examples show how to use this InSpec audit resource.
|
|
60
60
|
|
61
61
|
## Matchers
|
62
62
|
|
63
|
-
|
63
|
+
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
64
64
|
|
65
65
|
### be_enabled
|
66
66
|
|
data/lib/inspec.rb
CHANGED
@@ -9,11 +9,12 @@ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
9
9
|
require 'inspec/version'
|
10
10
|
require 'inspec/exceptions'
|
11
11
|
require 'inspec/profile'
|
12
|
-
require 'inspec/rspec_json_formatter'
|
13
12
|
require 'inspec/rule'
|
14
13
|
require 'matchers/matchers'
|
15
14
|
require 'inspec/runner'
|
16
15
|
require 'inspec/shell'
|
16
|
+
require 'inspec/formatters'
|
17
|
+
require 'inspec/reporters'
|
17
18
|
|
18
19
|
# all utils that may be required by plugins
|
19
20
|
require 'inspec/base_cli'
|
data/lib/inspec/base_cli.rb
CHANGED
@@ -58,7 +58,10 @@ module Inspec
|
|
58
58
|
option :controls, type: :array,
|
59
59
|
desc: 'A list of controls to run. Ignore all other tests.'
|
60
60
|
option :format, type: :string,
|
61
|
-
desc: '
|
61
|
+
desc: '[DEPRECATED] Please use --reporter - this will be removed in InSpec 3.0'
|
62
|
+
option :reporter, type: :array,
|
63
|
+
banner: 'one two:/output/file/path',
|
64
|
+
desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit'
|
62
65
|
option :color, type: :boolean,
|
63
66
|
desc: 'Use colors in output.'
|
64
67
|
option :attrs, type: :array,
|
@@ -71,36 +74,105 @@ module Inspec
|
|
71
74
|
desc: 'Write out a lockfile based on this execution (unless one already exists)'
|
72
75
|
option :backend_cache, type: :boolean,
|
73
76
|
desc: 'Allow caching for backend command output.'
|
77
|
+
option :show_progress, type: :boolean,
|
78
|
+
desc: 'Show progress while executing tests.'
|
74
79
|
end
|
75
80
|
|
76
81
|
def self.default_options
|
77
82
|
{
|
78
83
|
exec: {
|
84
|
+
'reporter' => ['cli'],
|
85
|
+
'show_progress' => false,
|
79
86
|
'color' => true,
|
80
87
|
'create_lockfile' => true,
|
81
88
|
'backend_cache' => false,
|
82
89
|
},
|
90
|
+
shell: {
|
91
|
+
'reporter' => ['cli'],
|
92
|
+
},
|
83
93
|
}
|
84
94
|
end
|
85
95
|
|
86
|
-
|
96
|
+
def self.parse_reporters(opts)
|
97
|
+
# merge in any legacy formats as reporter
|
98
|
+
# this method will only be used for ad-hoc runners
|
99
|
+
if !opts['format'].nil? && opts['reporter'].nil?
|
100
|
+
warn '[DEPRECATED] The option --format is being is being deprecated and will be removed in inspec 3.0. Please use --reporter'
|
101
|
+
opts['reporter'] = Array(opts['format'])
|
102
|
+
opts.delete('format')
|
103
|
+
end
|
87
104
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
105
|
+
# parse out cli to proper report format
|
106
|
+
if opts['reporter'].is_a?(Array)
|
107
|
+
reports = {}
|
108
|
+
opts['reporter'].each do |report|
|
109
|
+
reporter_name, target = report.split(':')
|
110
|
+
if target.nil? || target.strip == '-'
|
111
|
+
reports[reporter_name] = { 'stdout' => true }
|
112
|
+
else
|
113
|
+
reports[reporter_name] = {
|
114
|
+
'file' => target,
|
115
|
+
'stdout' => false,
|
116
|
+
}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
opts['reporter'] = reports
|
120
|
+
end
|
94
121
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
122
|
+
# add in stdout if not specified
|
123
|
+
if opts['reporter'].is_a?(Hash)
|
124
|
+
opts['reporter'].each do |reporter_name, config|
|
125
|
+
opts['reporter'][reporter_name] = {} if config.nil?
|
126
|
+
opts['reporter'][reporter_name]['stdout'] = true if opts['reporter'][reporter_name].empty?
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
validate_reporters(opts['reporter'])
|
131
|
+
opts
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.validate_reporters(reporters)
|
135
|
+
return if reporters.nil?
|
136
|
+
|
137
|
+
valid_types = [
|
138
|
+
'json',
|
139
|
+
'json-min',
|
140
|
+
'json-rspec',
|
141
|
+
'cli',
|
142
|
+
'junit',
|
143
|
+
'html',
|
144
|
+
'documentation',
|
145
|
+
'progress',
|
146
|
+
]
|
147
|
+
|
148
|
+
reporters.each do |k, _v|
|
149
|
+
raise NotImplementedError, "'#{k}' is not a valid reporter type." unless valid_types.include?(k)
|
150
|
+
end
|
151
|
+
|
152
|
+
# check to make sure we are only reporting one type to stdout
|
153
|
+
stdout = 0
|
154
|
+
reporters.each_value do |v|
|
155
|
+
stdout += 1 if v['stdout'] == true
|
156
|
+
end
|
157
|
+
|
158
|
+
raise ArgumentError, 'The option --reporter can only have a single report outputting to stdout.' if stdout > 1
|
101
159
|
end
|
102
160
|
|
103
|
-
|
161
|
+
private
|
162
|
+
|
163
|
+
def suppress_log_output?(opts)
|
164
|
+
return false if opts['reporter'].nil?
|
165
|
+
match = %w{json json-min json-rspec junit html} & opts['reporter'].keys
|
166
|
+
unless match.empty?
|
167
|
+
match.each do |m|
|
168
|
+
# check to see if we are outputting to stdout
|
169
|
+
return true if opts['reporter'][m]['stdout'] == true
|
170
|
+
end
|
171
|
+
end
|
172
|
+
false
|
173
|
+
end
|
174
|
+
|
175
|
+
def diagnose(opts)
|
104
176
|
return unless opts['diagnose']
|
105
177
|
puts "InSpec version: #{Inspec::VERSION}"
|
106
178
|
puts "Train version: #{Train::VERSION}"
|
@@ -132,15 +204,23 @@ module Inspec
|
|
132
204
|
|
133
205
|
def merged_opts(type = nil)
|
134
206
|
opts = {}
|
207
|
+
opts[:type] = type unless type.nil?
|
135
208
|
|
136
209
|
# start with default options if we have any
|
137
|
-
opts = BaseCLI.default_options[type] unless type.nil?
|
210
|
+
opts = BaseCLI.default_options[type] unless type.nil? || BaseCLI.default_options[type].nil?
|
138
211
|
|
139
212
|
# merge in any options from json-config
|
140
213
|
opts.merge!(options_json)
|
141
214
|
|
215
|
+
# remove the default reporter if we are setting a legacy format on the cli
|
216
|
+
opts.delete('reporter') if options['format']
|
217
|
+
|
142
218
|
# merge in any options defined via thor
|
143
219
|
opts.merge!(options)
|
220
|
+
|
221
|
+
# parse reporter options
|
222
|
+
opts = BaseCLI.parse_reporters(opts) if %i(exec shell).include?(type)
|
223
|
+
|
144
224
|
Thor::CoreExt::HashWithIndifferentAccess.new(opts)
|
145
225
|
end
|
146
226
|
|
@@ -210,7 +290,7 @@ module Inspec
|
|
210
290
|
#
|
211
291
|
loc = if o.log_location
|
212
292
|
o.log_location
|
213
|
-
elsif
|
293
|
+
elsif suppress_log_output?(o)
|
214
294
|
STDERR
|
215
295
|
else
|
216
296
|
STDOUT
|
@@ -221,7 +301,7 @@ module Inspec
|
|
221
301
|
|
222
302
|
o[:logger] = Logger.new(STDOUT)
|
223
303
|
# output json if we have activated the json formatter
|
224
|
-
if
|
304
|
+
if o['log-format'] == 'json'
|
225
305
|
o[:logger].formatter = Logger::JSONFormatter.new
|
226
306
|
end
|
227
307
|
o[:logger].level = get_log_level(o.log_level)
|
data/lib/inspec/cli.rb
CHANGED
@@ -32,16 +32,22 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
32
32
|
desc: 'A list of controls to include. Ignore all other tests.'
|
33
33
|
profile_options
|
34
34
|
def json(target)
|
35
|
-
diagnose
|
36
35
|
o = opts.dup
|
36
|
+
diagnose(o)
|
37
37
|
o[:ignore_supports] = true
|
38
38
|
o[:backend] = Inspec::Backend.create(target: 'mock://')
|
39
39
|
o[:check_mode] = true
|
40
40
|
|
41
41
|
profile = Inspec::Profile.for_target(target, o)
|
42
|
+
info = profile.info
|
43
|
+
# add in inspec version
|
44
|
+
info[:generator] = {
|
45
|
+
name: 'inspec',
|
46
|
+
version: Inspec::VERSION,
|
47
|
+
}
|
42
48
|
dst = o[:output].to_s
|
43
49
|
if dst.empty?
|
44
|
-
puts JSON.dump(
|
50
|
+
puts JSON.dump(info)
|
45
51
|
else
|
46
52
|
if File.exist? dst
|
47
53
|
puts "----> updating #{dst}"
|
@@ -49,7 +55,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
49
55
|
puts "----> creating #{dst}"
|
50
56
|
end
|
51
57
|
fdst = File.expand_path(dst)
|
52
|
-
File.write(fdst, JSON.dump(
|
58
|
+
File.write(fdst, JSON.dump(info))
|
53
59
|
end
|
54
60
|
rescue StandardError => e
|
55
61
|
pretty_handle_exception(e)
|
@@ -59,8 +65,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
59
65
|
option :format, type: :string
|
60
66
|
profile_options
|
61
67
|
def check(path) # rubocop:disable Metrics/AbcSize
|
62
|
-
diagnose
|
63
68
|
o = opts.dup
|
69
|
+
diagnose(o)
|
64
70
|
o[:ignore_supports] = true # we check for integrity only
|
65
71
|
o[:backend] = Inspec::Backend.create(target: 'mock://')
|
66
72
|
o[:check_mode] = true
|
@@ -69,7 +75,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
69
75
|
profile = Inspec::Profile.for_target(path, o)
|
70
76
|
result = profile.check
|
71
77
|
|
72
|
-
if
|
78
|
+
if o['format'] == 'json'
|
73
79
|
puts JSON.generate(result)
|
74
80
|
else
|
75
81
|
%w{location profile controls timestamp valid}.each do |item|
|
@@ -128,9 +134,9 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
128
134
|
option :ignore_errors, type: :boolean, default: false,
|
129
135
|
desc: 'Ignore profile warnings.'
|
130
136
|
def archive(path)
|
131
|
-
diagnose
|
132
|
-
|
133
137
|
o = opts.dup
|
138
|
+
diagnose(o)
|
139
|
+
|
134
140
|
o[:logger] = Logger.new(STDOUT)
|
135
141
|
o[:logger].level = get_log_level(o.log_level)
|
136
142
|
o[:backend] = Inspec::Backend.create(target: 'mock://')
|
@@ -138,13 +144,13 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
138
144
|
profile = Inspec::Profile.for_target(path, o)
|
139
145
|
result = profile.check
|
140
146
|
|
141
|
-
if result && !
|
147
|
+
if result && !o[:ignore_errors] == false
|
142
148
|
o[:logger].info 'Profile check failed. Please fix the profile before generating an archive.'
|
143
149
|
return exit 1
|
144
150
|
end
|
145
151
|
|
146
152
|
# generate archive
|
147
|
-
exit 1 unless profile.archive(
|
153
|
+
exit 1 unless profile.archive(o)
|
148
154
|
rescue StandardError => e
|
149
155
|
pretty_handle_exception(e)
|
150
156
|
end
|
@@ -152,19 +158,23 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
152
158
|
desc 'exec PATHS', 'run all test files at the specified PATH.'
|
153
159
|
exec_options
|
154
160
|
def exec(*targets)
|
155
|
-
diagnose
|
156
161
|
o = opts(:exec).dup
|
162
|
+
diagnose(o)
|
157
163
|
configure_logger(o)
|
158
164
|
|
159
|
-
# check for deprecated --cache
|
160
165
|
# TODO: REMOVE for inspec 2.0
|
161
166
|
if o.key?('cache')
|
162
167
|
o[:vendor_cache] = o[:cache]
|
163
168
|
o[:logger].warn '[DEPRECATED] The use of `--cache` is being deprecated in InSpec 2.0. Please use `--vendor-cache` instead.'
|
164
169
|
end
|
165
170
|
|
166
|
-
|
167
|
-
|
171
|
+
runner = Inspec::Runner.new(o)
|
172
|
+
targets.each { |target| runner.add_target(target) }
|
173
|
+
|
174
|
+
exit runner.run
|
175
|
+
rescue ArgumentError, RuntimeError, Train::UserError => e
|
176
|
+
$stderr.puts e.message
|
177
|
+
exit 1
|
168
178
|
rescue StandardError => e
|
169
179
|
pretty_handle_exception(e)
|
170
180
|
end
|
@@ -173,10 +183,10 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
173
183
|
target_options
|
174
184
|
option :format, type: :string
|
175
185
|
def detect
|
176
|
-
o = opts.dup
|
186
|
+
o = opts(:detect).dup
|
177
187
|
o[:command] = 'os.params'
|
178
188
|
(_, res) = run_command(o)
|
179
|
-
if
|
189
|
+
if o['format'] == 'json'
|
180
190
|
puts res.to_json
|
181
191
|
else
|
182
192
|
headline('Operating System Details')
|
@@ -194,16 +204,18 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
194
204
|
option :command, aliases: :c,
|
195
205
|
desc: 'A single command string to run instead of launching the shell'
|
196
206
|
option :format, type: :string, default: nil, hide: true,
|
197
|
-
desc: '
|
207
|
+
desc: '[DEPRECATED] Please use --reporter - this will be removed in InSpec 3.0'
|
208
|
+
option :reporter, type: :array,
|
209
|
+
banner: 'one two:/output/file/path',
|
210
|
+
desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit'
|
198
211
|
option :depends, type: :array, default: [],
|
199
212
|
desc: 'A space-delimited list of local folders containing profiles whose libraries and resources will be loaded into the new shell'
|
200
213
|
def shell_func
|
201
|
-
|
202
|
-
o
|
214
|
+
o = opts(:shell).dup
|
215
|
+
diagnose(o)
|
203
216
|
o[:debug_shell] = true
|
204
217
|
|
205
|
-
|
206
|
-
log_device = json_output ? nil : STDOUT
|
218
|
+
log_device = suppress_log_output?(o) ? nil : STDOUT
|
207
219
|
o[:logger] = Logger.new(log_device)
|
208
220
|
o[:logger].level = get_log_level(o.log_level)
|
209
221
|
|
@@ -216,7 +228,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
216
228
|
exit res unless run_type == :ruby_eval
|
217
229
|
|
218
230
|
# No InSpec tests - just print evaluation output.
|
219
|
-
res = (res.respond_to?(:to_json) ? res.to_json : JSON.dump(res)) if
|
231
|
+
res = (res.respond_to?(:to_json) ? res.to_json : JSON.dump(res)) if o['reporter']&.keys&.include?('json')
|
220
232
|
puts res
|
221
233
|
exit 0
|
222
234
|
rescue RuntimeError, Train::UserError => e
|