inspec 2.3.28 → 3.0.0

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
  SHA256:
3
- metadata.gz: 8742ade52e04413d98857dbe243589448629c3db92d285cb943b8af4b70e6e88
4
- data.tar.gz: f04e1dac3d71463472bfbf68069838b0bbd02527412f3a184dd9f2b8d52f8975
3
+ metadata.gz: 5ca6936485ca0d43d8e2a6d4a666d00d35a0b34213395edf195e3464922ac05c
4
+ data.tar.gz: 4af42fb90e856a6fdbb03da658caf5e5a299ab490655abdee8901d292425011c
5
5
  SHA512:
6
- metadata.gz: 51d424a89a76c6cef322ff7f58747d1e7e75495bb160510436f0a02baa28f257ece67e844a4129de29cef11a2882b19248475215e9c4ac72974708728115748b
7
- data.tar.gz: 891b0c14bfc29becb71add1adc968f0d23c6e397da0cd105ed7fe8550001c10987f3b1962732b61c83b09af006a8519406285371fe207d143142e7c674dd5afa
6
+ metadata.gz: b292beb653ebc321790748a416f99a0f0b5d9c8248e34af8ed1206d1f67764f09c9336ab61c2d8bbe2d8fa134d1faf4e4363636e4388f18b4b632ba49e9b7721
7
+ data.tar.gz: 335128b72b28c6b66cf9d2d9beac4a4540a597415fe019b250597e9a6dc9db33a987c7223a5999fa243c5ef9d27d2a2c284f1d5ab5662a6742f4e1ad79a40836
data/CHANGELOG.md CHANGED
@@ -1,18 +1,19 @@
1
1
  # Change Log
2
2
  <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
3
- <!-- latest_release 2.3.28 -->
4
- ## [v2.3.28](https://github.com/inspec/inspec/tree/v2.3.28) (2019-02-08)
3
+ <!-- latest_release unreleased -->
4
+ ## Unreleased
5
5
 
6
- #### Merged Pull Requests
7
- - Remove bundler pin from 2.x series [#3795](https://github.com/inspec/inspec/pull/3795) ([clintoncwolfe](https://github.com/clintoncwolfe))
6
+ #### Enhancements
7
+ - Inspec 3.0 [#3512](https://github.com/inspec/inspec/pull/3512) ([jquick](https://github.com/jquick))
8
8
  <!-- latest_release -->
9
9
 
10
10
  <!-- release_rollup since=2.3.24 -->
11
11
  ### Changes since 2.3.24 release
12
12
 
13
+ #### Enhancements
14
+ - Inspec 3.0 [#3512](https://github.com/inspec/inspec/pull/3512) ([jquick](https://github.com/jquick)) <!-- 3.0.0 -->
15
+
13
16
  #### Merged Pull Requests
14
- - Remove bundler pin from 2.x series [#3795](https://github.com/inspec/inspec/pull/3795) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.3.28 -->
15
- - Update copyright for 2.x branch [#3794](https://github.com/inspec/inspec/pull/3794) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.3.27 -->
16
17
  - Update the text on the generic default attribute [#3508](https://github.com/inspec/inspec/pull/3508) ([jquick](https://github.com/jquick)) <!-- 2.3.26 -->
17
18
  - Change `Inspec ` to `InSpec ` where appropriate [#3494](https://github.com/inspec/inspec/pull/3494) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.3.25 -->
18
19
  <!-- release_rollup -->
data/Gemfile CHANGED
@@ -11,6 +11,7 @@ gem 'ffi', '>= 1.9.14'
11
11
  gem 'aws-sdk', '~> 2'
12
12
 
13
13
  group :test do
14
+ gem 'bundler', '~> 1.5'
14
15
  gem 'minitest', '~> 5.5'
15
16
  gem 'rake', '>= 10'
16
17
  gem 'rubocop', '= 0.49.1'
data/README.md CHANGED
@@ -439,7 +439,7 @@ Please see [TESTING_AGAINST_AZURE.md](./test/integration/aws/TESTING_AGAINST_AZU
439
439
  | **Author:** | Dominik Richter (<drichter@chef.io>) |
440
440
  | **Author:** | Christoph Hartmann (<chartmann@chef.io>) |
441
441
  | **Copyright:** | Copyright (c) 2015 Vulcano Security GmbH. |
442
- | **Copyright:** | Copyright (c) 2019 Chef Software Inc. |
442
+ | **Copyright:** | Copyright (c) 2017 Chef Software Inc. |
443
443
  | **License:** | Apache License, Version 2.0 |
444
444
 
445
445
  Licensed under the Apache License, Version 2.0 (the "License");
data/inspec.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = '>= 2.3'
28
28
 
29
- spec.add_dependency 'train', '~> 1.5', '= 1.7.1'
29
+ spec.add_dependency 'train', '~> 1.5'
30
30
  spec.add_dependency 'thor', '~> 0.20'
31
31
  spec.add_dependency 'json', '>= 1.8', '< 3.0'
32
32
  spec.add_dependency 'method_source', '~> 0.8'
@@ -82,8 +82,6 @@ module Inspec
82
82
  profile_options
83
83
  option :controls, type: :array,
84
84
  desc: 'A list of control names to run, or a list of /regexes/ to match against control names. Ignore all other tests.'
85
- option :format, type: :string,
86
- desc: '[DEPRECATED] Please use --reporter - this will be removed in InSpec 3.0'
87
85
  option :reporter, type: :array,
88
86
  banner: 'one two:/output/file/path',
89
87
  desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit, yaml'
@@ -116,23 +114,7 @@ module Inspec
116
114
  }
117
115
  end
118
116
 
119
- def self.parse_reporters(opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
120
- # merge in any legacy formats as reporter
121
- # this method will only be used for ad-hoc runners
122
- if !opts['format'].nil? && opts['reporter'].nil?
123
- warn '[DEPRECATED] The option --format is being deprecated and will be removed in inspec 3.0. Please use --reporter'
124
-
125
- # see if we are using the legacy output to write to files
126
- if opts['output']
127
- warn '[DEPRECATED] The option \'output\' is being deprecated and will be removed in inspec 3.0. Please use --reporter name:path'
128
- opts['format'] = "#{opts['format']}:#{opts['output']}"
129
- opts.delete('output')
130
- end
131
-
132
- opts['reporter'] = Array(opts['format'])
133
- opts.delete('format')
134
- end
135
-
117
+ def self.parse_reporters(opts) # rubocop:disable Metrics/AbcSize
136
118
  # default to cli report for ad-hoc runners
137
119
  opts['reporter'] = ['cli'] if opts['reporter'].nil?
138
120
 
@@ -312,10 +294,6 @@ module Inspec
312
294
  json_config = options_json
313
295
  opts.merge!(json_config)
314
296
 
315
- # remove the default reporter if we are setting a legacy format on the cli
316
- # or via json-config
317
- opts.delete('reporter') if options['format'] || json_config['format']
318
-
319
297
  # merge in any options defined via thor
320
298
  opts.merge!(options)
321
299
 
data/lib/inspec/cli.rb CHANGED
@@ -213,8 +213,6 @@ class Inspec::InspecCLI < Inspec::BaseCLI
213
213
  target_options
214
214
  option :command, aliases: :c,
215
215
  desc: 'A single command string to run instead of launching the shell'
216
- option :format, type: :string, default: nil, hide: true,
217
- desc: '[DEPRECATED] Please use --reporter - this will be removed in InSpec 3.0'
218
216
  option :reporter, type: :array,
219
217
  banner: 'one two:/output/file/path',
220
218
  desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit'
data/lib/inspec/dsl.rb CHANGED
@@ -30,8 +30,11 @@ module Inspec::DSL
30
30
  def self.load_spec_files_for_profile(bind_context, opts, &block)
31
31
  dependencies = opts[:dependencies]
32
32
  profile_id = opts[:profile_id]
33
-
34
33
  dep_entry = dependencies.list[profile_id]
34
+
35
+ # do not load any controls if the profile is not supported
36
+ return unless dep_entry.profile.supports_platform?
37
+
35
38
  if dep_entry.nil?
36
39
  raise <<~EOF
37
40
  Cannot load #{profile_id} since it is not listed as a dependency of #{bind_context.profile_name}.
@@ -69,7 +69,6 @@ module Inspec::Formatters
69
69
  name: platform(:name),
70
70
  release: platform(:release),
71
71
  target: backend_target,
72
- uuid: platform(:uuid),
73
72
  }
74
73
  end
75
74
 
@@ -159,13 +159,6 @@ module Inspec
159
159
  when Hash then [finalize_supports_elem(x, logger)]
160
160
  when Array then x.map { |e| finalize_supports_elem(e, logger) }.compact
161
161
  when nil then []
162
- else
163
- logger ||= Logger.new(nil)
164
- logger.warn(
165
- "Do not use deprecated `supports: #{x}` syntax. Instead use:\n"\
166
- "supports:\n - os-family: #{x}\n\n",
167
- )
168
- [{ :'os-family' => x }] # rubocop:disable Style/HashSyntax
169
162
  end
170
163
  end
171
164
 
@@ -159,10 +159,16 @@ module Inspec
159
159
  supports_platform? && supports_runtime?
160
160
  end
161
161
 
162
+ # We need to check if we're using a Mock'd backend for tests to function.
163
+ # @returns [TrueClass, FalseClass]
162
164
  def supports_platform?
163
165
  if @supports_platform.nil?
164
166
  @supports_platform = metadata.supports_platform?(@backend)
165
167
  end
168
+ if @backend.backend.class.to_s == 'Train::Transports::Mock::Connection'
169
+ @supports_platform = true
170
+ end
171
+
166
172
  @supports_platform
167
173
  end
168
174
 
@@ -178,7 +184,8 @@ module Inspec
178
184
  end
179
185
 
180
186
  def collect_tests(include_list = @controls)
181
- if !@tests_collected
187
+ unless @tests_collected
188
+ return unless supports_platform?
182
189
  locked_dependencies.each(&:collect_tests)
183
190
 
184
191
  tests.each do |path, content|
@@ -222,7 +229,21 @@ module Inspec
222
229
  def load_libraries
223
230
  return @runner_context if @libraries_loaded
224
231
 
225
- locked_dependencies.each do |d|
232
+ locked_dependencies.dep_list.each_with_index do |(_name, dep), i|
233
+ d = dep.profile
234
+ # this will force a dependent profile load so we are only going to add
235
+ # this metadata if the parent profile is supported.
236
+ if supports_platform? && !d.supports_platform?
237
+ # since ruby 1.9 hashes are ordered so we can just use index values here
238
+ metadata.dependencies[i][:status] = 'skipped'
239
+ msg = "Skipping profile: '#{d.name}' on unsupported platform: '#{d.backend.platform.name}/#{d.backend.platform.release}'."
240
+ metadata.dependencies[i][:skip_message] = msg
241
+ next
242
+ elsif metadata.dependencies[i]
243
+ # Currently wrapper profiles will load all dependencies, and then we
244
+ # load them again when we dive down. This needs to be re-done.
245
+ metadata.dependencies[i][:status] = 'loaded'
246
+ end
226
247
  c = d.load_libraries
227
248
  @runner_context.add_resources(c)
228
249
  end
@@ -245,7 +266,7 @@ module Inspec
245
266
  info(load_params.dup)
246
267
  end
247
268
 
248
- def info(res = params.dup) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
269
+ def info(res = params.dup) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
249
270
  # add information about the controls
250
271
  res[:controls] = res[:controls].map do |id, rule|
251
272
  next if id.to_s.empty?
@@ -284,6 +305,14 @@ module Inspec
284
305
  res[:sha256] = sha256
285
306
  res[:parent_profile] = parent_profile unless parent_profile.nil?
286
307
 
308
+ if !supports_platform?
309
+ res[:status] = 'skipped'
310
+ msg = "Skipping profile: '#{name}' on unsupported platform: '#{backend.platform.name}/#{backend.platform.release}'."
311
+ res[:skip_message] = msg
312
+ else
313
+ res[:status] = 'loaded'
314
+ end
315
+
287
316
  # convert legacy os-* supports to their platform counterpart
288
317
  if res[:supports] && !res[:supports].empty?
289
318
  res[:supports].each do |support|
@@ -335,9 +364,6 @@ module Inspec
335
364
 
336
365
  @logger.info "Checking profile in #{@target}"
337
366
  meta_path = @source_reader.target.abs_path(@source_reader.metadata.ref)
338
- if meta_path =~ /metadata\.rb$/
339
- warn.call(@target, 0, 0, nil, 'The use of `metadata.rb` is deprecated. Use `inspec.yml`.')
340
- end
341
367
 
342
368
  # verify metadata
343
369
  m_errors, m_warnings = metadata.valid
@@ -350,12 +376,6 @@ module Inspec
350
376
  # extract profile name
351
377
  result[:summary][:profile] = metadata.params[:name]
352
378
 
353
- # check if the profile is using the old test directory instead of the
354
- # new controls directory
355
- if @source_reader.tests.keys.any? { |x| x =~ %r{^test/$} }
356
- warn.call(@target, 0, 0, nil, 'Profile uses deprecated `test` directory, rename it to `controls`.')
357
- end
358
-
359
379
  count = controls_count
360
380
  result[:summary][:controls] = count
361
381
  if count == 0
@@ -542,7 +562,7 @@ module Inspec
542
562
  params[:controls] = controls = {}
543
563
  params[:groups] = groups = {}
544
564
  prefix = @source_reader.target.prefix || ''
545
- tests.each do |rule|
565
+ tests&.each do |rule|
546
566
  next if rule.nil?
547
567
  f = load_rule_filepath(prefix, rule)
548
568
  load_rule(rule, f, controls, groups)
@@ -23,7 +23,7 @@ module Inspec::Reporters
23
23
  final_report[:type] = 'inspec_report'
24
24
 
25
25
  final_report[:end_time] = Time.now.utc.strftime('%FT%TZ')
26
- final_report[:node_uuid] = @config['node_uuid'] || @run_data[:platform][:uuid]
26
+ final_report[:node_uuid] = @config['node_uuid'] || @config['target_id']
27
27
  raise Inspec::ReporterError, 'Cannot find a UUID for your node. Please specify one via json-config.' if final_report[:node_uuid].nil?
28
28
 
29
29
  final_report[:report_uuid] = @config['report_uuid'] || uuid_from_string(final_report[:end_time] + final_report[:node_uuid])
@@ -44,6 +44,11 @@ module Inspec::Reporters
44
44
 
45
45
  def render
46
46
  run_data[:profiles].each do |profile|
47
+ if profile[:status] == 'skipped'
48
+ platform = run_data[:platform]
49
+ output("Skipping profile: '#{profile[:name]}' on unsupported platform: '#{platform[:name]}/#{platform[:release]}'.")
50
+ next
51
+ end
47
52
  @control_count = 0
48
53
  output('')
49
54
  print_profile_header(profile)
@@ -112,6 +112,8 @@ module Inspec::Reporters
112
112
  depends: p[:depends],
113
113
  groups: profile_groups(p),
114
114
  controls: profile_controls(p),
115
+ status: p[:status],
116
+ skip_message: p[:skip_message],
115
117
  }
116
118
  profiles << profile.reject { |_k, v| v.nil? }
117
119
  end
data/lib/inspec/runner.rb CHANGED
@@ -80,16 +80,24 @@ module Inspec
80
80
 
81
81
  @target_profiles.each do |profile|
82
82
  @test_collector.add_profile(profile)
83
+ next unless profile.supports_platform?
84
+
83
85
  write_lockfile(profile) if @create_lockfile
84
86
  profile.locked_dependencies
85
87
  profile_context = profile.load_libraries
86
88
 
87
89
  profile_context.dependencies.list.values.each do |requirement|
90
+ unless requirement.profile.supports_platform?
91
+ Inspec::Log.warn "Skipping profile: '#{requirement.profile.name}'" \
92
+ " on unsupported platform: '#{@backend.platform.name}/#{@backend.platform.release}'."
93
+ next
94
+ end
88
95
  @test_collector.add_profile(requirement.profile)
89
96
  end
90
97
 
91
98
  @attributes = profile.runner_context.attributes if @attributes.empty?
92
- all_controls += profile.collect_tests
99
+ tests = profile.collect_tests
100
+ all_controls += tests unless tests.nil?
93
101
  end
94
102
 
95
103
  all_controls.each do |rule|
@@ -202,10 +210,6 @@ module Inspec
202
210
  "InSpec v#{Inspec::VERSION}.\n"
203
211
  end
204
212
 
205
- if !profile.supports_platform?
206
- raise "This OS/platform (#{@backend.platform.name}/#{@backend.platform.release}) is not supported by this profile."
207
- end
208
-
209
213
  true
210
214
  end
211
215
 
@@ -84,11 +84,12 @@ module Inspec
84
84
  def exit_code
85
85
  return @rspec_exit_code if @formatter.results.empty?
86
86
  stats = @formatter.results[:statistics][:controls]
87
- if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0
87
+ skipped = @formatter.results[:profiles].first[:status] == 'skipped'
88
+ if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0 && !skipped
88
89
  0
89
90
  elsif stats[:failed][:total] > 0
90
91
  @conf['distinct_exit'] ? 100 : 1
91
- elsif stats[:skipped][:total] > 0
92
+ elsif stats[:skipped][:total] > 0 || skipped
92
93
  @conf['distinct_exit'] ? 101 : 0
93
94
  else
94
95
  @rspec_exit_code
data/lib/inspec/schema.rb CHANGED
@@ -137,6 +137,8 @@ module Inspec
137
137
  'copyright_email' => { 'type' => 'string', 'optional' => true },
138
138
  'license' => { 'type' => 'string', 'optional' => true },
139
139
  'summary' => { 'type' => 'string', 'optional' => true },
140
+ 'status' => { 'type' => 'string', 'optional' => false },
141
+ 'skip_message' => { 'type' => 'string', 'optional' => true },
140
142
 
141
143
  'supports' => {
142
144
  'type' => 'array',
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '2.3.28'
7
+ VERSION = '3.0.0'
8
8
  end
@@ -26,7 +26,7 @@ module Inspec::Resources
26
26
 
27
27
  attr_reader :service, :conf_dir, :conf_path, :user
28
28
  def initialize
29
- warn '[DEPRECATED] The `apache` resource is deprecated and will be removed in InSpec 3.0.'
29
+ warn '[DEPRECATED] The `apache` resource is deprecated and will be removed in InSpec 4.0'
30
30
 
31
31
  if inspec.os.debian?
32
32
  @service = 'apache2'
@@ -56,7 +56,7 @@ module Inspec::Resources
56
56
  end
57
57
 
58
58
  def list
59
- warn '[DEPRECATION] `processes.list` is deprecated. Please use `processes.entries` instead. It will be removed in version 2.0.0.'
59
+ warn '[DEPRECATION] `processes.list` is deprecated. Please use `processes.entries` instead. It will be removed in version 4.0.'
60
60
  @list
61
61
  end
62
62
 
data/lib/resources/yum.rb CHANGED
@@ -152,29 +152,4 @@ module Inspec::Resources
152
152
  "YumRepo #{@reponame}"
153
153
  end
154
154
  end
155
-
156
- # for compatability with serverspec
157
- # this is deprecated syntax and will be removed in future versions
158
- class YumRepoLegacy < Yum
159
- name 'yumrepo'
160
-
161
- def initialize(name)
162
- super()
163
- @repository = repo(name)
164
- end
165
-
166
- def exists?
167
- deprecated
168
- @repository.exist?
169
- end
170
-
171
- def enabled?
172
- deprecated
173
- @repository.enabled?
174
- end
175
-
176
- def deprecated
177
- warn '[DEPRECATION] `yumrepo(reponame)` is deprecated. Please use `yum.repo(reponame)` instead.'
178
- end
179
- end
180
155
  end
@@ -12,14 +12,6 @@ module SourceReaders
12
12
 
13
13
  def self.resolve(target)
14
14
  return new(target, 'inspec.yml') if target.files.include?('inspec.yml')
15
- # TODO: deprecated for 1.0.0 release
16
- if target.files.include?('metadata.rb') &&
17
- (
18
- target.files.include?('controls') ||
19
- target.files.include?('test')
20
- )
21
- return new(target, 'metadata.rb')
22
- end
23
15
  nil
24
16
  end
25
17
 
@@ -68,16 +68,6 @@ module DatabaseHelper
68
68
  @results.size
69
69
  end
70
70
 
71
- def stdout
72
- warn '[DEPRECATION] The `stdout` method is deprecated. Use `row` instead.'
73
- @cmd.stdout
74
- end
75
-
76
- def stderr
77
- warn '[DEPRECATION] The `stderr` method is deprecated. Use `successful?` instead.'
78
- @cmd.stderr
79
- end
80
-
81
71
  def inspect
82
72
  to_s
83
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.28
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2018-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
- - - '='
21
- - !ruby/object:Gem::Version
22
- version: 1.7.1
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.5'
30
- - - '='
31
- - !ruby/object:Gem::Version
32
- version: 1.7.1
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: thor
35
29
  requirement: !ruby/object:Gem::Requirement