inspec-core 4.18.39 → 4.18.51

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: 400a25b36a80a00b32bb567607830cfaa8a555661d70a2050727a8f993f9b548
4
- data.tar.gz: 84c35ae6f700290a900e96922ae7676a3f70e05b7c4d908806d284347458bf87
3
+ metadata.gz: 91c5fa977076e418e2372d7a78cbc45383cbec50ee57c7126b7625aef4a1a606
4
+ data.tar.gz: fe4ee768878acdaddf4c933ed0e41f899319fccaff69a19f942ddbbb7771b9a1
5
5
  SHA512:
6
- metadata.gz: e118d033b3ae0c6076b18ed6f13a9201517314acebb4f0607213b51832ffcdeceafc6d7cc5a7bc5aab7005093e8b41a1abc0a121e3571bf1095d579eff5b9c7a
7
- data.tar.gz: c6d77d4ab186058b6bf9175f62869d723096dc4335780c607dfaafaff5c8071ae877387ada1114966da89a9da24ab18cb372dc66ccdc5b9f97b2a953c536aac8
6
+ metadata.gz: 00c1bfcaef4c1b42f5d16d3d1eab4255a67959b9fd7e6f8c9494fdcd6a324afc20a4059c8c30521036e6a996a839eda354b84194cde32549e63301b4f4a28dfc
7
+ data.tar.gz: c40df12e404ec13c2fd1ef689e0d59e5ea6435d534763effad5372ce027fa0732e8a19f307b50761da7ecad8f6a438f7c5c4de989d024ba5d5274d7883b97355
@@ -1,6 +1,6 @@
1
1
  require "uri"
2
2
  require "inspec/fetcher"
3
- require "fetchers/url"
3
+ require "inspec/fetcher/url"
4
4
 
5
5
  # InSpec Target Helper for Supermarket
6
6
  module Supermarket
@@ -8,6 +8,8 @@ require "inspec/utils/deprecation/global_method"
8
8
  # Allow end of options during array type parsing
9
9
  # https://github.com/erikhuda/thor/issues/631
10
10
  class Thor::Arguments
11
+ alias old_parse_array parse_array
12
+
11
13
  def parse_array(_name)
12
14
  return shift if peek.is_a?(Array)
13
15
 
@@ -8,7 +8,7 @@ module Inspec
8
8
  attr_reader :cache, :target, :fetcher
9
9
  def initialize(target, cache)
10
10
  @target = target
11
- @fetcher = Inspec::Fetcher.resolve(target)
11
+ @fetcher = Inspec::Fetcher::Registry.resolve(target)
12
12
 
13
13
  if @fetcher.nil?
14
14
  raise("Could not fetch inspec profile in #{target.inspect}.")
@@ -298,7 +298,11 @@ class Inspec::InspecCLI < Inspec::BaseCLI
298
298
  def detect
299
299
  o = config
300
300
  o[:command] = "platform.params"
301
+
302
+ configure_logger(o)
303
+
301
304
  (_, res) = run_command(o)
305
+
302
306
  if o["format"] == "json"
303
307
  puts res.to_json
304
308
  else
@@ -6,7 +6,6 @@ require "stringio"
6
6
  require "forwardable"
7
7
  require "thor"
8
8
  require "base64"
9
- require "inspec/base_cli"
10
9
  require "inspec/plugin/v2/filter"
11
10
 
12
11
  module Inspec
@@ -422,6 +421,7 @@ module Inspec
422
421
 
423
422
  def finalize_set_top_level_command(options)
424
423
  options[:type] = @command_name
424
+ require "inspec/base_cli"
425
425
  Inspec::BaseCLI.inspec_cli_command = @command_name # TODO: move to a more relevant location
426
426
  end
427
427
 
@@ -26,7 +26,9 @@ module Inspec
26
26
  end
27
27
  end
28
28
 
29
- Fetcher = FetcherRegistry.new
29
+ module Fetcher
30
+ Registry = FetcherRegistry.new
31
+ end
30
32
 
31
33
  def self.fetcher(version)
32
34
  if version != 1
@@ -38,9 +40,9 @@ module Inspec
38
40
  end
39
41
 
40
42
  # TODO: remove. require up, not down.
41
- require "fetchers/local"
42
- require "fetchers/url"
43
- require "fetchers/git"
43
+ require "inspec/fetcher/local"
44
+ require "inspec/fetcher/url"
45
+ require "inspec/fetcher/git"
44
46
 
45
47
  # TODO: Remove in 4.0 when Compliance fetcher plugin is created
46
48
  require "plugins/inspec-compliance/lib/inspec-compliance/api"
@@ -3,7 +3,7 @@ require "fileutils"
3
3
  require "mixlib/shellout"
4
4
  require "inspec/log"
5
5
 
6
- module Fetchers
6
+ module Inspec::Fetcher
7
7
  #
8
8
  # The git fetcher uses the git binary to fetch remote git sources.
9
9
  # Git-based sources should be specified with the `git:` key in the
@@ -90,8 +90,8 @@ module Fetchers
90
90
  # vendoring to something more complex, don't bother.
91
91
  FileUtils.rmdir(destination_path) if Dir.empty?(destination_path)
92
92
 
93
- raise ArgumentError, "Cannot find relative path '#{@relative_path}' " \
94
- "within profile in git repo specified by '#{@remote_url}'"
93
+ raise Inspec::FetcherFailure, "Cannot find relative path '#{@relative_path}' " \
94
+ "within profile in git repo specified by '#{@remote_url}'"
95
95
  end
96
96
  FileUtils.cp_r("#{working_dir}/#{@relative_path}", destination_path)
97
97
  end
@@ -129,11 +129,11 @@ module Fetchers
129
129
  def resolve_ref(ref_name)
130
130
  command_string = "git ls-remote \"#{@remote_url}\" \"#{ref_name}*\""
131
131
  cmd = shellout(command_string)
132
- raise "Error running '#{command_string}': #{cmd.stderr}" unless cmd.exitstatus == 0
132
+ raise(Inspec::FetcherFailure, "Profile git dependency failed for #{@remote_url} - error running '#{command_string}': #{cmd.stderr}") unless cmd.exitstatus == 0
133
133
 
134
134
  ref = parse_ls_remote(cmd.stdout, ref_name)
135
135
  unless ref
136
- raise "Unable to resolve #{ref_name} to a specific git commit for #{@remote_url}"
136
+ raise Inspec::FetcherFailure, "Profile git dependency failed - unable to resolve #{ref_name} to a specific git commit for #{@remote_url}"
137
137
  end
138
138
 
139
139
  ref
@@ -191,7 +191,7 @@ module Fetchers
191
191
  cmd.error!
192
192
  cmd.status
193
193
  rescue Errno::ENOENT
194
- raise "To use git sources, you must have git installed."
194
+ raise Inspec::FetcherFailure, "Profile git dependency failed for #{@remote_url} - to use git sources, you must have git installed."
195
195
  end
196
196
 
197
197
  def shellout(cmd, opts = {})
@@ -1,6 +1,6 @@
1
1
  require "openssl"
2
2
 
3
- module Fetchers
3
+ module Inspec::Fetcher
4
4
  class Local < Inspec.fetcher(1)
5
5
  name "local"
6
6
  priority 0
@@ -101,7 +101,10 @@ module Fetchers
101
101
  end
102
102
 
103
103
  def perform_shasum(target)
104
- @archive_shasum ||= OpenSSL::Digest::SHA256.digest(File.read(target)).unpack("H*")[0]
104
+ return @archive_shasum if @archive_shasum
105
+ raise(Inspec::FetcherFailure, "Profile dependency local path '#{target}' does not exist") unless File.exist?(target)
106
+
107
+ @archive_shasum = OpenSSL::Digest::SHA256.digest(File.read(target)).unpack("H*")[0]
105
108
  end
106
109
 
107
110
  def resolved_source
@@ -1,6 +1,6 @@
1
1
  require "inspec/fetcher"
2
2
 
3
- module Fetchers
3
+ module Inspec::Fetcher
4
4
  class Mock < Inspec.fetcher(1)
5
5
  name "mock"
6
6
  priority 0
@@ -3,7 +3,7 @@ require "openssl"
3
3
  require "tempfile"
4
4
  require "open-uri"
5
5
 
6
- module Fetchers
6
+ module Inspec::Fetcher
7
7
  class Url < Inspec.fetcher(1)
8
8
  MIME_TYPES = {
9
9
  "application/x-zip-compressed" => ".zip",
@@ -205,15 +205,24 @@ module Fetchers
205
205
  @temp_archive_path = archive.path
206
206
  end
207
207
 
208
+ def open(target, opts) # overridden so we can control who we're talking to
209
+ URI.open(target, opts)
210
+ rescue NoMethodError # TODO: remove when we drop ruby 2.4
211
+ super(target, opts) # Kernel#open
212
+ end
213
+
208
214
  def open_via_uri(target)
209
215
  opts = http_opts
210
216
 
211
- if opts[:http_basic_authentication]
212
- # OpenURI does not support userinfo so we need to remove it
213
- open(target.sub("#{@target_uri.userinfo}@", ""), opts)
214
- else
215
- open(target, opts)
216
- end
217
+ # OpenURI does not support userinfo so we need to remove it
218
+ # https://ruby-doc.org/stdlib-2.5.0/libdoc/open-uri/rdoc/OpenURI/OpenRead.html#method-i-open
219
+ target = target.sub("#{@target_uri.userinfo}@", "") if
220
+ opts[:http_basic_authentication]
221
+
222
+ open(target, opts)
223
+
224
+ rescue SocketError, Errno::ECONNREFUSED, OpenURI::HTTPError => e
225
+ raise Inspec::FetcherFailure, "Profile URL dependency #{target} could not be fetched: #{e.message}"
217
226
  end
218
227
 
219
228
  def download_archive(path)
@@ -264,7 +273,7 @@ module Fetchers
264
273
  end
265
274
  end
266
275
  unless keys_missing_values.empty?
267
- raise "Unable to fetch profile - the following HTTP headers have no value: " \
276
+ raise Inspec::FetcherFailure, "Unable to fetch profile - the following HTTP headers have no value: " \
268
277
  "#{keys_missing_values.join(", ")}"
269
278
  end
270
279
  end
@@ -17,7 +17,7 @@ module Inspec
17
17
  #
18
18
  class Fetcher < PluginRegistry::Plugin
19
19
  def self.plugin_registry
20
- Inspec::Fetcher
20
+ Inspec::Fetcher::Registry
21
21
  end
22
22
 
23
23
  attr_accessor :target
@@ -431,7 +431,13 @@ module Inspec::Plugin::V2
431
431
  end
432
432
 
433
433
  # find all gem specification directories
434
- directories = [Gem::Specification.default_specifications_dir]
434
+
435
+ spec_dir = if Gem.respond_to? :default_specifications_dir
436
+ Gem.default_specifications_dir
437
+ else
438
+ Gem::Specification.default_specifications_dir
439
+ end
440
+ directories = [spec_dir]
435
441
  unless defined?(::Bundler)
436
442
  # add in any others that do not start with the user directory
437
443
  directories += Gem::Specification.dirs.find_all do |path|
@@ -1,4 +1,5 @@
1
- require "inspec/resources/command"
1
+ # circular: require "inspec/resource"
2
+ # but... already being included by inspec/resource.rb
2
3
 
3
4
  module Inspec::Resources
4
5
  class GemPackage < Inspec.resource(1)
@@ -38,6 +39,8 @@ module Inspec::Resources
38
39
  def info
39
40
  return @info if defined?(@info)
40
41
 
42
+ require "inspec/resources/command"
43
+
41
44
  cmd = inspec.command("#{@gem_binary} list --local -a -q \^#{@package_name}\$")
42
45
  return {} unless cmd.exit_status == 0
43
46
 
@@ -96,7 +96,7 @@ module Inspec::Resources
96
96
 
97
97
  def parse_csv_result(cmd)
98
98
  require "csv"
99
- table = CSV.parse(cmd.stdout, { headers: true })
99
+ table = CSV.parse(cmd.stdout, headers: true)
100
100
 
101
101
  # remove first row, since it will be a seperator line
102
102
  table.delete(0)
@@ -52,12 +52,6 @@ module Inspec::Resources
52
52
  .register_column(:inactive_days, field: "inactive_days")
53
53
  .register_column(:expiry_dates, field: "expiry_date")
54
54
  .register_column(:reserved, field: "reserved")
55
- # These are deprecated, but we need to "alias" them
56
- filtertable
57
- .register_custom_property(:user) { |table, value| table.resource.user(value) }
58
- .register_custom_property(:password) { |table, value| table.resource.password(value) }
59
- .register_custom_property(:last_change) { |table, value| table.resource.last_change(value) }
60
- .register_custom_property(:expiry_date) { |table, value| table.resource.expiry_date(value) }
61
55
 
62
56
  filtertable.register_custom_property(:content) do |t, _|
63
57
  t.entries.map do |e|
@@ -223,6 +223,10 @@ module Inspec::Resources
223
223
  meta_info[:userflags] unless meta_info.nil?
224
224
  end
225
225
 
226
+ def lastlogin
227
+ meta_info[:lastlogin] unless meta_info.nil?
228
+ end
229
+
226
230
  # returns the minimum days between password changes
227
231
  def mindays
228
232
  credentials[:mindays] unless credentials.nil?
@@ -632,6 +636,7 @@ module Inspec::Resources
632
636
  shell: res[:shell],
633
637
  domain: res[:domain],
634
638
  userflags: res[:userflags],
639
+ lastlogin: res[:lastlogin],
635
640
  }
636
641
  end
637
642
 
@@ -715,6 +720,7 @@ module Inspec::Resources
715
720
  home = $_.HomeDirectory[0]
716
721
  shell = $null
717
722
  domain = $Computername
723
+ lastlogin = if($_.lastlogin.getType().Tostring() -eq "System.Management.Automation.PSMethod" ){ $null }else{[String]$_.lastlogin}
718
724
  }
719
725
  } | ConvertTo-Json
720
726
  EOH
@@ -11,14 +11,13 @@ module Inspec
11
11
  module DescribeDslLazyLoader
12
12
  # Support for Describe DSL plugins
13
13
  def method_missing(method_name, *arguments, &block)
14
- # TODO: need a backend available at the describe level... class method somewhere?
15
- # # see if it is a resource first
16
- # begin
17
- # resource = Inspec::DSL.method_missing_resource(:where_is_backend?, method_name, *arguments)
18
- # return resource if resource
19
- # rescue LoadError
20
- # # pass through
21
- # end
14
+ begin
15
+ backend = metadata[:backend] # populated via Inspec::Runner#add_resource
16
+ resource = Inspec::DSL.method_missing_resource(backend, method_name, *arguments)
17
+ return resource if resource
18
+ rescue LoadError
19
+ # pass through
20
+ end
22
21
 
23
22
  # Check to see if there is a describe_dsl plugin activator hook with the method name
24
23
  registry = Inspec::Plugin::V2::Registry.instance
@@ -228,7 +228,7 @@ module Inspec
228
228
  end
229
229
 
230
230
  def eval_with_virtual_profile(command)
231
- require "fetchers/mock"
231
+ require "inspec/fetcher/mock"
232
232
  add_target({ "inspec.yml" => "name: inspec-shell" })
233
233
  our_profile = @target_profiles.first
234
234
  ctx = our_profile.runner_context
@@ -307,6 +307,8 @@ module Inspec
307
307
  def add_resource(method_name, arg, opts, block)
308
308
  case method_name
309
309
  when "describe"
310
+ opts = { backend: @test_collector.backend }.merge opts
311
+
310
312
  @test_collector.example_group(*arg, opts, &block)
311
313
  when "expect"
312
314
  block.example_group
@@ -10,6 +10,8 @@ require "inspec/rspec_extensions"
10
10
 
11
11
  module Inspec
12
12
  class RunnerRspec
13
+ attr_accessor :formatter
14
+
13
15
  def initialize(conf)
14
16
  @conf = conf
15
17
  @formatter = nil
@@ -22,19 +24,26 @@ module Inspec
22
24
  # @param [Type] &block the block associated with this example group
23
25
  # @return [RSpecExampleGroup]
24
26
  def example_group(*args, &block)
27
+ # NOTE: this RUNS immediately
25
28
  RSpec::Core::ExampleGroup.describe(*args, &block)
26
29
  end
27
30
 
31
+ def formatters
32
+ RSpec.configuration.formatters.grep(Inspec::Formatters::Base)
33
+ end
34
+
28
35
  # Add a full profile to the runner. Only pulls in metadata
29
36
  #
30
37
  # @param [Inspec::Profile] profile
31
38
  # @return [nil]
32
39
  def add_profile(profile)
33
- RSpec.configuration.formatters
34
- .find_all { |c| c.is_a?(Inspec::Formatters::Base) }
35
- .each do |fmt|
36
- fmt.add_profile(profile)
37
- end
40
+ formatters.each do |fmt|
41
+ fmt.add_profile(profile)
42
+ end
43
+ end
44
+
45
+ def backend
46
+ formatters.first.backend
38
47
  end
39
48
 
40
49
  # Configure the backend of the runner.
@@ -42,11 +51,9 @@ module Inspec
42
51
  # @param [Inspec::Backend] backend
43
52
  # @return [nil]
44
53
  def backend=(backend)
45
- RSpec.configuration.formatters
46
- .find_all { |c| c.is_a?(Inspec::Formatters::Base) }
47
- .each do |fmt|
48
- fmt.backend = backend
49
- end
54
+ formatters.each do |fmt|
55
+ fmt.backend = backend
56
+ end
50
57
  end
51
58
 
52
59
  # Add an example group to the list of registered tests.
@@ -227,6 +227,8 @@ module XinetdParser
227
227
  def parse_xinetd(raw) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
228
228
  return {} if raw.nil?
229
229
 
230
+ require "inspec/utils/simpleconfig"
231
+
230
232
  res = {}
231
233
  cur_group = nil
232
234
  simple_conf = []
@@ -273,5 +275,3 @@ module XinetdParser
273
275
  res
274
276
  end
275
277
  end
276
-
277
- require "inspec/utils/simpleconfig"
@@ -1,3 +1,3 @@
1
1
  module Inspec
2
- VERSION = "4.18.39".freeze
2
+ VERSION = "4.18.51".freeze
3
3
  end
@@ -254,7 +254,7 @@ RSpec::Matchers.define :cmp do |first_expected| # rubocop:disable Metrics/BlockL
254
254
  return actual.send(op, expected.to_i)
255
255
  elsif expected.is_a?(String) && boolean?(expected) && [true, false].include?(actual)
256
256
  return actual.send(op, to_boolean(expected))
257
- elsif expected.is_a?(Integer) && integer?(actual)
257
+ elsif expected.is_a?(Integer) && actual.is_a?(String) && integer?(actual)
258
258
  return actual.to_i.send(op, expected)
259
259
  elsif expected.is_a?(Float) && float?(actual)
260
260
  return actual.to_f.send(op, expected)
@@ -8,7 +8,7 @@ require "inspec/dist"
8
8
  # similar to `inspec exec http://localhost:2134/owners/%base%/compliance/%ssh%/tar --user %token%`
9
9
  module InspecPlugins
10
10
  module Compliance
11
- class Fetcher < Fetchers::Url
11
+ class Fetcher < Inspec::Fetcher::Url
12
12
  include Inspec::Dist
13
13
 
14
14
  name "compliance"
@@ -1,8 +1,6 @@
1
1
  pkg_name=<%= "inspec-profile-#{profile.name}" %>
2
2
  pkg_version=<%= profile.version %>
3
3
  pkg_origin=<%= habitat_origin %>
4
- pkg_deps=(chef/inspec)
5
- pkg_build_deps=(chef/inspec core/jq-static)
6
4
  pkg_svc_user=root
7
5
  <%= "pkg_license='#{profile.metadata.params[:license]}'" if profile.metadata.params[:license]%>
8
6
  pkg_scaffolding="chef/scaffolding-chef-inspec"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.18.39
4
+ version: 4.18.51
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-11-14 00:00:00.000000000 Z
11
+ date: 2019-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train-core
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef-telemetry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: license-acceptance
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -105,9 +119,6 @@ dependencies:
105
119
  requirement: !ruby/object:Gem::Requirement
106
120
  requirements:
107
121
  - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '3.0'
110
- - - "<"
111
122
  - !ruby/object:Gem::Version
112
123
  version: '3.9'
113
124
  type: :runtime
@@ -115,9 +126,6 @@ dependencies:
115
126
  version_requirements: !ruby/object:Gem::Requirement
116
127
  requirements:
117
128
  - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '3.0'
120
- - - "<"
121
129
  - !ruby/object:Gem::Version
122
130
  version: '3.9'
123
131
  - !ruby/object:Gem::Dependency
@@ -380,10 +388,6 @@ files:
380
388
  - lib/bundles/inspec-supermarket/api.rb
381
389
  - lib/bundles/inspec-supermarket/cli.rb
382
390
  - lib/bundles/inspec-supermarket/target.rb
383
- - lib/fetchers/git.rb
384
- - lib/fetchers/local.rb
385
- - lib/fetchers/mock.rb
386
- - lib/fetchers/url.rb
387
391
  - lib/inspec.rb
388
392
  - lib/inspec/archive/tar.rb
389
393
  - lib/inspec/archive/zip.rb
@@ -410,6 +414,10 @@ files:
410
414
  - lib/inspec/exceptions.rb
411
415
  - lib/inspec/expect.rb
412
416
  - lib/inspec/fetcher.rb
417
+ - lib/inspec/fetcher/git.rb
418
+ - lib/inspec/fetcher/local.rb
419
+ - lib/inspec/fetcher/mock.rb
420
+ - lib/inspec/fetcher/url.rb
413
421
  - lib/inspec/file_provider.rb
414
422
  - lib/inspec/formatters.rb
415
423
  - lib/inspec/formatters/base.rb