inspec-core 3.9.0 → 3.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6060db98285f1a0cdb5d521ad533a502a0481c57ad613baf2c0469d520966f23
4
- data.tar.gz: 0ccdf80c41296d07328c5fd7bb172e75aca2e9c40acbef9813d7aa442be95c89
3
+ metadata.gz: 96ff01311bc29d2878ccaa989af9b586229a74cf6c4e22a5d15cccec333ab8b9
4
+ data.tar.gz: 727e2df3d8d54bbf57fa4cd91b6dbb2a2d45b8124ee2fa6aaff2e8e29ad8c5fe
5
5
  SHA512:
6
- metadata.gz: 5199f204d872c74e1091021828b28f210ba2eb81d164af3365edcddb9ffe6bdb45b261fddb3109c27bd77ac5345cf009145e7c0606754a27530c594e2e511d63
7
- data.tar.gz: e2c1e9ac924684a2dfb26665a88ee31fc66c6813c7aeb04bf6e312875c5efd69aea924da4e1bf43b27483adaaa1516c35711d8b69aa12c40b0853ac70c234e9a
6
+ metadata.gz: 158b57f8f27e24c0a4c3dd9f6f0db7701ed1deac01872d6832332bfc523eea695f8af4654bbabdc6e1fdf649eff3ea007f37417d3e5dda92bf097fb5d1fe0438
7
+ data.tar.gz: 994876c13c21a6a2230c945e2668515b75d5ac30202de624da721cb929e10fdcd96fb159a935e9119f0b92ed92ff75a8cf480a7937e5b159cc1dadd021eea719
@@ -20,6 +20,7 @@ require 'inspec/input_registry'
20
20
  require 'inspec/rspec_extensions'
21
21
  require 'inspec/globals'
22
22
  require 'inspec/impact'
23
+ require 'inspec/utils/telemetry'
23
24
 
24
25
  require 'inspec/plugin/v2'
25
26
  require 'inspec/plugin/v1'
@@ -107,8 +107,10 @@ module Inspec
107
107
  option :reporter, type: :array,
108
108
  banner: 'one two:/output/file/path',
109
109
  desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit, yaml'
110
- option :attrs, type: :array,
110
+ option :input_file, type: :array,
111
111
  desc: 'Load one or more input files, a YAML file with values for the profile to use'
112
+ option :attrs, type: :array,
113
+ desc: 'Legacy name for --input-file - deprecated.'
112
114
  option :create_lockfile, type: :boolean,
113
115
  desc: 'Write out a lockfile based on this execution (unless one already exists)'
114
116
  option :backend_cache, type: :boolean,
@@ -23,8 +23,8 @@ module Inspec
23
23
 
24
24
  # output warn message if we are in a exec call
25
25
  Inspec::Log.warn(
26
- "Attribute '#{@name}' does not have a value. "\
27
- "Use --attrs to provide a value for '#{@name}' or specify a "\
26
+ "Input '#{@name}' does not have a value. "\
27
+ "Use --input-file to provide a value for '#{@name}' or specify a "\
28
28
  "value with `attribute('#{@name}', value: 'somevalue', ...)`.",
29
29
  ) if Inspec::BaseCLI.inspec_cli_command == :exec
30
30
  end
@@ -151,10 +151,14 @@ module Inspec
151
151
 
152
152
  # determine all inputs before the execution, fetch data from secrets backend
153
153
  def load_inputs(options)
154
- # TODO: - rename :attributes and :attrs - these are both user-visible
154
+ # TODO: - rename :attributes - it is user-visible
155
155
  options[:attributes] ||= {}
156
156
 
157
- secrets_targets = options[:attrs]
157
+ if options.key?(:attrs)
158
+ Inspec.deprecate(:rename_attributes_to_inputs, 'Use --input-file on the command line instead of --attrs.')
159
+ options[:input_file] = options.delete(:attrs)
160
+ end
161
+ secrets_targets = options[:input_file]
158
162
  return options[:attributes] if secrets_targets.nil?
159
163
 
160
164
  secrets_targets.each do |target|
@@ -0,0 +1,3 @@
1
+ require 'inspec/utils/telemetry/collector'
2
+ require 'inspec/utils/telemetry/data_series'
3
+ require 'inspec/utils/telemetry/global_methods'
@@ -0,0 +1,60 @@
1
+ require 'inspec/utils/telemetry/data_series'
2
+ require 'singleton'
3
+
4
+ module Inspec::Telemetry
5
+ # A Singleton collection of data series objects.
6
+ class Collector
7
+ include Singleton
8
+
9
+ def initialize
10
+ @data_series = []
11
+ @enabled = true
12
+ end
13
+
14
+ # Add a data series to the collection.
15
+ # @return [True]
16
+ def add_data_series(data_series)
17
+ @data_series << data_series
18
+ end
19
+
20
+ # Is the Telemetry system enabled or disabled?
21
+ # Always true until we add configuration parsing.
22
+ # @return [True, False]
23
+ def telemetry_enabled?
24
+ @enabled
25
+ end
26
+
27
+ # A way to disable the telemetry system.
28
+ # @return [True]
29
+ def disable_telemetry
30
+ @enabled = false
31
+ end
32
+
33
+ # The entire data series collection.
34
+ # @return [Array]
35
+ def list_data_series
36
+ @data_series
37
+ end
38
+
39
+ # Finds the data series object with the specified name and returns it.
40
+ # If it does not exist then creates a new data series with that name
41
+ # and returns it.
42
+ # @return [Inspec::Telemetry::DataSeries]
43
+ def find_or_create_data_series(name)
44
+ ds = @data_series.select { |data_series| data_series.name.eql?(name) }
45
+ if ds.empty?
46
+ new_data_series = Inspec::Telemetry::DataSeries.new(name)
47
+ @data_series << new_data_series
48
+ new_data_series
49
+ else
50
+ ds.first
51
+ end
52
+ end
53
+
54
+ # Blanks the contents of the data series collection.
55
+ # @return [True]
56
+ def reset
57
+ @data_series = []
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,42 @@
1
+ require 'json'
2
+
3
+ # A minimal Dataseries Object
4
+ # Stores the name of the data series and an array of data.
5
+ # Stored data should be a object that supports #to_s
6
+ module Inspec::Telemetry
7
+ class DataSeries
8
+ def initialize(name)
9
+ @name = name
10
+ @enabled = true
11
+ @data ||= []
12
+ end
13
+
14
+ attr_reader :data, :name
15
+
16
+ # This needs to also be set by configuration.
17
+ def enabled?
18
+ @enabled
19
+ end
20
+
21
+ def disable
22
+ @enabled = false
23
+ end
24
+
25
+ def <<(appending_data)
26
+ data << appending_data
27
+ end
28
+
29
+ alias push <<
30
+
31
+ def to_h
32
+ {
33
+ name: @name,
34
+ data: @data,
35
+ }
36
+ end
37
+
38
+ def to_json
39
+ to_h.to_json
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require 'inspec/utils/telemetry'
2
+
3
+ module Inspec
4
+ # A Global method to add a data series object to the Telemetry Collection.
5
+ # `data_series_name`s are unique, so `:dependency_group` will always return
6
+ # the same object.
7
+ # `data_point` is optional, you may also supply a block with several data points.
8
+ # All data points should allow #to_s
9
+ def self.record_telemetry_data(data_series_name, data_point = nil)
10
+ coll = Inspec::Telemetry::Collector.instance
11
+ return unless coll.telemetry_enabled?
12
+ ds = coll.find_or_create_data_series(data_series_name)
13
+ return unless ds.enabled?
14
+
15
+ if block_given?
16
+ ds << yield
17
+ else
18
+ ds << data_point
19
+ end
20
+ end
21
+ end
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '3.9.0'
7
+ VERSION = '3.9.3'
8
8
  end
@@ -41,6 +41,7 @@ module Inspec::Resources
41
41
  @user = opts.fetch(:user, nil)
42
42
  @path = opts.fetch(:path, nil)
43
43
  raise Inspec::Exceptions::ResourceFailed, 'A user or path must be supplied.' if @user.nil? && @path.nil?
44
+ raise Inspec::Exceptions::ResourceFailed, 'Either user or path must be supplied, not both!' if !@user.nil? && !@path.nil?
44
45
  else
45
46
  @user = opts
46
47
  @path = nil
@@ -49,7 +50,12 @@ module Inspec::Resources
49
50
  end
50
51
 
51
52
  def read_crontab
52
- ct = is_system_crontab? ? inspec.file(@path).content : inspec.command(crontab_cmd).stdout
53
+ if is_system_crontab?
54
+ raise Inspec::Exceptions::ResourceFailed, "Supplied crontab path '#{@path}' must exist!" if !inspec.file(@path).exist?
55
+ ct = inspec.file(@path).content
56
+ else
57
+ ct = inspec.command(crontab_cmd).stdout
58
+ end
53
59
  ct.lines.map { |l| parse_crontab_line(l) }.compact
54
60
  end
55
61
 
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: 3.9.0
4
+ version: 3.9.3
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-04-01 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train-core
@@ -468,6 +468,10 @@ files:
468
468
  - lib/inspec/shell_detector.rb
469
469
  - lib/inspec/source_reader.rb
470
470
  - lib/inspec/ui.rb
471
+ - lib/inspec/utils/telemetry.rb
472
+ - lib/inspec/utils/telemetry/collector.rb
473
+ - lib/inspec/utils/telemetry/data_series.rb
474
+ - lib/inspec/utils/telemetry/global_methods.rb
471
475
  - lib/inspec/version.rb
472
476
  - lib/matchers/matchers.rb
473
477
  - lib/plugins/README.md