inspec-core 4.3.2 → 4.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -21
- data/etc/deprecations.json +10 -0
- data/etc/plugin_filters.json +8 -0
- data/lib/bundles/inspec-compliance/api.rb +1 -1
- data/lib/bundles/inspec-compliance/configuration.rb +1 -1
- data/lib/bundles/inspec-compliance/http.rb +1 -1
- data/lib/bundles/inspec-compliance/support.rb +1 -1
- data/lib/bundles/inspec-compliance/target.rb +1 -1
- data/lib/bundles/inspec-supermarket.rb +3 -7
- data/lib/bundles/inspec-supermarket/api.rb +10 -13
- data/lib/bundles/inspec-supermarket/cli.rb +12 -15
- data/lib/bundles/inspec-supermarket/target.rb +7 -11
- data/lib/fetchers/git.rb +14 -15
- data/lib/fetchers/local.rb +6 -10
- data/lib/fetchers/mock.rb +3 -5
- data/lib/fetchers/url.rb +42 -44
- data/lib/inspec.rb +23 -24
- data/lib/inspec/archive/tar.rb +2 -6
- data/lib/inspec/archive/zip.rb +3 -7
- data/lib/inspec/backend.rb +8 -9
- data/lib/inspec/base_cli.rb +64 -65
- data/lib/inspec/cached_fetcher.rb +2 -3
- data/lib/inspec/cli.rb +136 -97
- data/lib/inspec/config.rb +71 -61
- data/lib/inspec/control_eval_context.rb +22 -18
- data/lib/inspec/dependencies/cache.rb +2 -3
- data/lib/inspec/dependencies/dependency_set.rb +2 -3
- data/lib/inspec/dependencies/lockfile.rb +8 -9
- data/lib/inspec/dependencies/requirement.rb +7 -8
- data/lib/inspec/dependencies/resolver.rb +5 -7
- data/lib/inspec/describe.rb +2 -6
- data/lib/inspec/dist.rb +20 -0
- data/lib/inspec/dsl.rb +4 -7
- data/lib/inspec/dsl_shared.rb +1 -2
- data/lib/inspec/env_printer.rb +11 -12
- data/lib/inspec/errors.rb +0 -4
- data/lib/inspec/exceptions.rb +0 -1
- data/lib/inspec/expect.rb +5 -8
- data/lib/inspec/fetcher.rb +7 -10
- data/lib/inspec/file_provider.rb +24 -24
- data/lib/inspec/formatters.rb +3 -3
- data/lib/inspec/formatters/base.rb +8 -8
- data/lib/inspec/globals.rb +2 -2
- data/lib/inspec/impact.rb +5 -7
- data/lib/inspec/input_registry.rb +84 -33
- data/lib/inspec/library_eval_context.rb +3 -6
- data/lib/inspec/log.rb +1 -5
- data/lib/inspec/metadata.rb +17 -16
- data/lib/inspec/method_source.rb +5 -9
- data/lib/inspec/objects.rb +10 -12
- data/lib/inspec/objects/control.rb +7 -9
- data/lib/inspec/objects/describe.rb +9 -11
- data/lib/inspec/objects/each_loop.rb +1 -3
- data/lib/inspec/objects/input.rb +24 -26
- data/lib/inspec/objects/list.rb +4 -6
- data/lib/inspec/objects/or_test.rb +2 -4
- data/lib/inspec/objects/ruby_helper.rb +3 -5
- data/lib/inspec/objects/tag.rb +0 -2
- data/lib/inspec/objects/test.rb +9 -11
- data/lib/inspec/objects/value.rb +3 -5
- data/lib/inspec/plugin/v1.rb +2 -2
- data/lib/inspec/plugin/v1/plugin_types/cli.rb +1 -5
- data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +2 -5
- data/lib/inspec/plugin/v1/plugin_types/resource.rb +4 -6
- data/lib/inspec/plugin/v1/plugin_types/secret.rb +1 -5
- data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +1 -5
- data/lib/inspec/plugin/v1/plugins.rb +15 -19
- data/lib/inspec/plugin/v1/registry.rb +0 -4
- data/lib/inspec/plugin/v2.rb +8 -8
- data/lib/inspec/plugin/v2/activator.rb +1 -1
- data/lib/inspec/plugin/v2/config_file.rb +6 -6
- data/lib/inspec/plugin/v2/filter.rb +13 -13
- data/lib/inspec/plugin/v2/installer.rb +36 -24
- data/lib/inspec/plugin/v2/loader.rb +28 -28
- data/lib/inspec/plugin/v2/plugin_base.rb +15 -2
- data/lib/inspec/plugin/v2/plugin_types/cli.rb +5 -5
- data/lib/inspec/plugin/v2/plugin_types/input.rb +34 -0
- data/lib/inspec/plugin/v2/plugin_types/mock.rb +1 -1
- data/lib/inspec/plugin/v2/registry.rb +7 -7
- data/lib/inspec/polyfill.rb +0 -3
- data/lib/inspec/profile.rb +55 -63
- data/lib/inspec/profile_context.rb +27 -30
- data/lib/inspec/profile_vendor.rb +6 -9
- data/lib/inspec/reporters.rb +24 -24
- data/lib/inspec/reporters/automate.rb +17 -19
- data/lib/inspec/reporters/base.rb +1 -1
- data/lib/inspec/reporters/cli.rb +88 -91
- data/lib/inspec/reporters/json.rb +2 -4
- data/lib/inspec/reporters/json_automate.rb +1 -3
- data/lib/inspec/reporters/json_min.rb +1 -3
- data/lib/inspec/reporters/junit.rb +26 -28
- data/lib/inspec/reporters/yaml.rb +1 -3
- data/lib/inspec/require_loader.rb +0 -4
- data/lib/inspec/resource.rb +4 -125
- data/lib/inspec/resources.rb +121 -0
- data/lib/{resources → inspec/resources}/aide_conf.rb +24 -25
- data/lib/{resources → inspec/resources}/apache.rb +13 -14
- data/lib/{resources → inspec/resources}/apache_conf.rb +16 -17
- data/lib/{resources → inspec/resources}/apt.rb +17 -17
- data/lib/{resources → inspec/resources}/audit_policy.rb +7 -6
- data/lib/{resources → inspec/resources}/auditd.rb +62 -64
- data/lib/{resources → inspec/resources}/auditd_conf.rb +7 -8
- data/lib/{resources → inspec/resources}/bash.rb +6 -8
- data/lib/{resources → inspec/resources}/bond.rb +15 -14
- data/lib/{resources → inspec/resources}/bridge.rb +8 -8
- data/lib/{resources → inspec/resources}/chocolatey_package.rb +10 -8
- data/lib/{resources → inspec/resources}/command.rb +11 -10
- data/lib/{resources → inspec/resources}/cpan.rb +12 -12
- data/lib/{resources → inspec/resources}/cran.rb +9 -9
- data/lib/{resources → inspec/resources}/crontab.rb +47 -48
- data/lib/{resources → inspec/resources}/csv.rb +5 -5
- data/lib/{resources → inspec/resources}/dh_params.rb +5 -7
- data/lib/{resources → inspec/resources}/directory.rb +5 -7
- data/lib/{resources → inspec/resources}/docker.rb +63 -63
- data/lib/{resources → inspec/resources}/docker_container.rb +6 -6
- data/lib/{resources → inspec/resources}/docker_image.rb +9 -9
- data/lib/{resources → inspec/resources}/docker_object.rb +8 -13
- data/lib/{resources → inspec/resources}/docker_plugin.rb +6 -6
- data/lib/{resources → inspec/resources}/docker_service.rb +7 -7
- data/lib/{resources → inspec/resources}/elasticsearch.rb +40 -42
- data/lib/{resources → inspec/resources}/etc_fstab.rb +23 -24
- data/lib/{resources → inspec/resources}/etc_group.rb +26 -27
- data/lib/{resources → inspec/resources}/etc_hosts.rb +11 -13
- data/lib/{resources → inspec/resources}/etc_hosts_allow_deny.rb +25 -27
- data/lib/{resources → inspec/resources}/file.rb +80 -79
- data/lib/{resources → inspec/resources}/filesystem.rb +20 -15
- data/lib/{resources → inspec/resources}/firewalld.rb +26 -26
- data/lib/{resources → inspec/resources}/gem.rb +12 -12
- data/lib/{resources → inspec/resources}/groups.rb +28 -27
- data/lib/{resources → inspec/resources}/grub_conf.rb +46 -48
- data/lib/{resources → inspec/resources}/host.rb +31 -29
- data/lib/{resources → inspec/resources}/http.rb +24 -24
- data/lib/{resources → inspec/resources}/iis_app.rb +6 -7
- data/lib/{resources → inspec/resources}/iis_app_pool.rb +21 -19
- data/lib/{resources → inspec/resources}/iis_site.rb +17 -15
- data/lib/{resources → inspec/resources}/inetd_conf.rb +9 -10
- data/lib/{resources → inspec/resources}/ini.rb +7 -8
- data/lib/{resources → inspec/resources}/interface.rb +30 -30
- data/lib/{resources → inspec/resources}/iptables.rb +8 -8
- data/lib/{resources → inspec/resources}/json.rb +8 -10
- data/lib/{resources → inspec/resources}/kernel_module.rb +15 -15
- data/lib/{resources → inspec/resources}/kernel_parameter.rb +8 -8
- data/lib/{resources → inspec/resources}/key_rsa.rb +8 -10
- data/lib/{resources → inspec/resources}/ksh.rb +6 -8
- data/lib/{resources → inspec/resources}/limits_conf.rb +8 -9
- data/lib/{resources/login_def.rb → inspec/resources/login_defs.rb} +9 -10
- data/lib/{resources → inspec/resources}/mount.rb +6 -8
- data/lib/{resources → inspec/resources}/mssql_session.rb +16 -18
- data/lib/inspec/resources/mysql.rb +81 -0
- data/lib/{resources → inspec/resources}/mysql_conf.rb +13 -14
- data/lib/{resources → inspec/resources}/mysql_session.rb +16 -16
- data/lib/{resources → inspec/resources}/nginx.rb +16 -17
- data/lib/{resources → inspec/resources}/nginx_conf.rb +26 -27
- data/lib/{resources → inspec/resources}/npm.rb +9 -10
- data/lib/{resources → inspec/resources}/ntp_conf.rb +9 -10
- data/lib/{resources → inspec/resources}/oneget.rb +8 -8
- data/lib/{resources → inspec/resources}/oracledb_session.rb +33 -34
- data/lib/{resources → inspec/resources}/os.rb +6 -8
- data/lib/{resources → inspec/resources}/os_env.rb +11 -12
- data/lib/{resources → inspec/resources}/package.rb +66 -65
- data/lib/{resources → inspec/resources}/packages.rb +13 -13
- data/lib/{resources → inspec/resources}/parse_config.rb +8 -8
- data/lib/{resources → inspec/resources}/passwd.rb +18 -19
- data/lib/{resources → inspec/resources}/pip.rb +19 -19
- data/lib/{resources → inspec/resources}/platform.rb +9 -11
- data/lib/{resources → inspec/resources}/port.rb +134 -136
- data/lib/{resources → inspec/resources}/postgres.rb +40 -32
- data/lib/{resources → inspec/resources}/postgres_conf.rb +17 -17
- data/lib/{resources → inspec/resources}/postgres_hba_conf.rb +21 -23
- data/lib/{resources → inspec/resources}/postgres_ident_conf.rb +12 -14
- data/lib/{resources → inspec/resources}/postgres_session.rb +8 -9
- data/lib/{resources → inspec/resources}/powershell.rb +17 -13
- data/lib/{resources → inspec/resources}/processes.rb +29 -29
- data/lib/{resources/rabbitmq_conf.rb → inspec/resources/rabbitmq_config.rb} +10 -11
- data/lib/{resources → inspec/resources}/registry_key.rb +14 -14
- data/lib/inspec/resources/script.rb +1 -0
- data/lib/{resources → inspec/resources}/security_identifier.rb +11 -10
- data/lib/{resources → inspec/resources}/security_policy.rb +59 -58
- data/lib/{resources → inspec/resources}/service.rb +74 -75
- data/lib/{resources → inspec/resources}/shadow.rb +44 -45
- data/lib/{resources/ssh_conf.rb → inspec/resources/ssh_config.rb} +16 -17
- data/lib/{resources → inspec/resources}/ssl.rb +28 -29
- data/lib/inspec/resources/sys_info.rb +30 -0
- data/lib/{resources → inspec/resources}/toml.rb +5 -7
- data/lib/{resources → inspec/resources}/users.rb +65 -65
- data/lib/{resources → inspec/resources}/vbscript.rb +8 -9
- data/lib/{resources → inspec/resources}/virtualization.rb +60 -62
- data/lib/{resources → inspec/resources}/windows_feature.rb +9 -9
- data/lib/{resources → inspec/resources}/windows_hotfix.rb +5 -5
- data/lib/{resources → inspec/resources}/windows_task.rb +16 -15
- data/lib/{resources → inspec/resources}/wmi.rb +7 -8
- data/lib/{resources → inspec/resources}/x509_certificate.rb +9 -11
- data/lib/{resources/xinetd.rb → inspec/resources/xinetd_conf.rb} +27 -29
- data/lib/{resources → inspec/resources}/xml.rb +7 -7
- data/lib/{resources → inspec/resources}/yaml.rb +5 -6
- data/lib/{resources → inspec/resources}/yum.rb +10 -10
- data/lib/{resources → inspec/resources}/zfs_dataset.rb +6 -6
- data/lib/{resources → inspec/resources}/zfs_pool.rb +4 -4
- data/lib/inspec/rspec_extensions.rb +24 -8
- data/lib/inspec/rule.rb +14 -15
- data/lib/inspec/runner.rb +28 -28
- data/lib/inspec/runner_mock.rb +1 -5
- data/lib/inspec/runner_rspec.rb +18 -20
- data/lib/inspec/runtime_profile.rb +2 -5
- data/lib/inspec/schema.rb +142 -143
- data/lib/inspec/secrets.rb +3 -7
- data/lib/inspec/secrets/yaml.rb +3 -5
- data/lib/inspec/shell.rb +11 -15
- data/lib/inspec/shell_detector.rb +6 -7
- data/lib/inspec/source_reader.rb +4 -8
- data/lib/inspec/ui.rb +33 -39
- data/lib/inspec/ui_table_helper.rb +12 -0
- data/lib/{utils → inspec/utils}/command_wrapper.rb +4 -8
- data/lib/{utils → inspec/utils}/convert.rb +0 -4
- data/lib/{utils → inspec/utils}/database_helpers.rb +4 -8
- data/lib/inspec/utils/deprecation.rb +6 -0
- data/lib/{utils → inspec/utils}/deprecation/config_file.rb +19 -19
- data/lib/{utils → inspec/utils}/deprecation/deprecator.rb +12 -12
- data/lib/{utils → inspec/utils}/deprecation/errors.rb +1 -1
- data/lib/{utils → inspec/utils}/deprecation/global_method.rb +2 -2
- data/lib/{utils → inspec/utils}/enumerable_delegation.rb +0 -2
- data/lib/{utils → inspec/utils}/erlang_parser.rb +61 -65
- data/lib/{utils → inspec/utils}/file_reader.rb +1 -2
- data/lib/{utils → inspec/utils}/filter.rb +30 -33
- data/lib/{utils → inspec/utils}/filter_array.rb +0 -2
- data/lib/{utils → inspec/utils}/find_files.rb +9 -12
- data/lib/{utils → inspec/utils}/hash.rb +1 -5
- data/lib/inspec/utils/json_log.rb +15 -0
- data/lib/inspec/utils/latest_version.rb +13 -0
- data/lib/{utils → inspec/utils}/modulator.rb +0 -3
- data/lib/{utils → inspec/utils}/nginx_parser.rb +31 -35
- data/lib/{utils → inspec/utils}/object_traversal.rb +0 -3
- data/lib/{utils → inspec/utils}/parser.rb +45 -45
- data/lib/{utils → inspec/utils}/pkey_reader.rb +4 -2
- data/lib/{utils → inspec/utils}/simpleconfig.rb +8 -10
- data/lib/{utils → inspec/utils}/spdx.rb +1 -4
- data/lib/{utils → inspec/utils}/spdx.txt +0 -0
- data/lib/inspec/utils/telemetry.rb +3 -3
- data/lib/inspec/utils/telemetry/collector.rb +30 -9
- data/lib/inspec/utils/telemetry/data_series.rb +3 -1
- data/lib/inspec/utils/telemetry/global_methods.rb +1 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/matchers/matchers.rb +22 -25
- data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +1 -1
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +52 -45
- data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +18 -16
- data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +1 -1
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +73 -73
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +66 -62
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +59 -57
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +11 -11
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +20 -22
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +2 -4
- data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +30 -27
- data/lib/plugins/inspec-habitat/Berksfile +2 -2
- data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +1 -1
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +15 -13
- data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +64 -63
- data/lib/plugins/inspec-habitat/templates/habitat/hooks/run.erb +3 -3
- data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +11 -11
- data/lib/plugins/inspec-init/lib/inspec-init.rb +1 -1
- data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +6 -8
- data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +72 -74
- data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +9 -11
- data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +4 -4
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -1
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -2
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -2
- data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +6 -7
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +1 -2
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +72 -70
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +1 -1
- data/lib/plugins/shared/core_plugin_test_helper.rb +43 -38
- data/lib/source_readers/flat.rb +6 -10
- data/lib/source_readers/inspec.rb +8 -12
- metadata +139 -140
- data/lib/resources/mysql.rb +0 -82
- data/lib/resources/sys_info.rb +0 -28
- data/lib/utils/deprecation.rb +0 -6
- data/lib/utils/json_log.rb +0 -18
- data/lib/utils/latest_version.rb +0 -22
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding:utf-8
|
2
|
-
|
3
1
|
module Inspec
|
4
2
|
class Describe
|
5
3
|
# Internal helper to structure test objects.
|
@@ -11,24 +9,24 @@ module Inspec
|
|
11
9
|
end
|
12
10
|
|
13
11
|
def to_ruby
|
14
|
-
itsy =
|
12
|
+
itsy = "it"
|
15
13
|
unless its.nil?
|
16
14
|
if its.is_a? Array
|
17
|
-
itsy =
|
15
|
+
itsy = "its(" + its.inspect + ")"
|
18
16
|
else
|
19
|
-
itsy =
|
17
|
+
itsy = "its(" + its.to_s.inspect + ")"
|
20
18
|
end
|
21
19
|
end
|
22
|
-
naughty = negated ?
|
20
|
+
naughty = negated ? "_not" : ""
|
23
21
|
xpect = if expectation.nil?
|
24
|
-
|
22
|
+
""
|
25
23
|
elsif expectation.class == Regexp
|
26
24
|
# without this, xpect values like / \/zones\// will not be parsed properly
|
27
25
|
"(#{expectation.inspect})"
|
28
26
|
else
|
29
|
-
|
27
|
+
" " + expectation.inspect
|
30
28
|
end
|
31
|
-
format(
|
29
|
+
format("%s { should%s %s%s }", itsy, naughty, matcher, xpect)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -84,8 +82,8 @@ module Inspec
|
|
84
82
|
vars += "\n" unless vars.empty?
|
85
83
|
|
86
84
|
objarr = @qualifier
|
87
|
-
objarr = [[
|
88
|
-
obj = objarr.map { |q| ruby_qualifier(q) }.join(
|
85
|
+
objarr = [["unknown object".inspect]] if objarr.nil? || objarr.empty?
|
86
|
+
obj = objarr.map { |q| ruby_qualifier(q) }.join(".")
|
89
87
|
|
90
88
|
rbtests = tests.map(&:to_ruby).join("\n ")
|
91
89
|
format("%sdescribe %s do\n %s\nend", vars, obj, rbtests)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding:utf-8
|
2
|
-
|
3
1
|
module Inspec
|
4
2
|
class EachLoop < List
|
5
3
|
attr_reader :variables
|
@@ -12,7 +10,7 @@ module Inspec
|
|
12
10
|
|
13
11
|
def add_test(t = nil)
|
14
12
|
t ||= Test.new
|
15
|
-
t.qualifier[0] = [
|
13
|
+
t.qualifier[0] = ["entry"]
|
16
14
|
@tests.push(t)
|
17
15
|
t
|
18
16
|
end
|
data/lib/inspec/objects/input.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'utils/deprecation'
|
1
|
+
require "inspec/utils/deprecation"
|
4
2
|
|
5
3
|
# For backwards compatibility during the rename (see #3802),
|
6
4
|
# maintain the Inspec::Attribute namespace for people checking for
|
@@ -8,7 +6,7 @@ require 'utils/deprecation'
|
|
8
6
|
module Inspec
|
9
7
|
class Attribute
|
10
8
|
# This only exists to create the Inspec::Attribute::DEFAULT_ATTRIBUTE symbol with a class
|
11
|
-
class DEFAULT_ATTRIBUTE; end # rubocop: disable
|
9
|
+
class DEFAULT_ATTRIBUTE; end # rubocop: disable Naming/ClassAndModuleCamelCase
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
@@ -44,7 +42,7 @@ module Inspec
|
|
44
42
|
properties.each do |prop_name, prop_value|
|
45
43
|
if EVENT_PROPERTIES.include? prop_name
|
46
44
|
# OK, save the property
|
47
|
-
send((prop_name.to_s +
|
45
|
+
send((prop_name.to_s + "=").to_sym, prop_value)
|
48
46
|
else
|
49
47
|
raise "Unrecognized property to Input::Event: #{prop_name}"
|
50
48
|
end
|
@@ -62,7 +60,7 @@ module Inspec
|
|
62
60
|
end
|
63
61
|
|
64
62
|
def diagnostic_string
|
65
|
-
to_h.reject { |_, val| val.nil? }.to_a.map { |pair| "#{pair[0]}: '#{pair[1]}'" }.join(
|
63
|
+
to_h.reject { |_, val| val.nil? }.to_a.map { |pair| "#{pair[0]}: '#{pair[1]}'" }.join(", ")
|
66
64
|
end
|
67
65
|
|
68
66
|
def to_h
|
@@ -73,7 +71,7 @@ module Inspec
|
|
73
71
|
|
74
72
|
def self.probe_stack
|
75
73
|
frames = caller_locations(2, 40)
|
76
|
-
frames.reject! { |f| f.path && f.path.include?(
|
74
|
+
frames.reject! { |f| f.path && f.path.include?("/lib/inspec/") }
|
77
75
|
frames.first
|
78
76
|
end
|
79
77
|
end
|
@@ -84,16 +82,18 @@ module Inspec
|
|
84
82
|
# This special class is used to represent the value when an input has
|
85
83
|
# not been assigned a value. This allows a user to explicitly assign nil
|
86
84
|
# to an input.
|
87
|
-
class NO_VALUE_SET # rubocop: disable
|
85
|
+
class NO_VALUE_SET # rubocop: disable Naming/ClassAndModuleCamelCase
|
88
86
|
def initialize(name)
|
89
87
|
@name = name
|
90
88
|
|
91
89
|
# output warn message if we are in a exec call
|
92
|
-
Inspec::
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
90
|
+
if Inspec::BaseCLI.inspec_cli_command == :exec
|
91
|
+
Inspec::Log.warn(
|
92
|
+
"Input '#{@name}' does not have a value. "\
|
93
|
+
"Use --input-file to provide a value for '#{@name}' or specify a "\
|
94
|
+
"value with `attribute('#{@name}', value: 'somevalue', ...)`."
|
95
|
+
)
|
96
|
+
end
|
97
97
|
end
|
98
98
|
|
99
99
|
def method_missing(*_)
|
@@ -224,7 +224,7 @@ module Inspec
|
|
224
224
|
provider: options[:provider] || :unknown,
|
225
225
|
priority: options[:priority] || Inspec::Input::DEFAULT_PRIORITY_FOR_UNKNOWN_CALLER,
|
226
226
|
file: location.path,
|
227
|
-
line: location.lineno
|
227
|
+
line: location.lineno
|
228
228
|
)
|
229
229
|
|
230
230
|
if options.key?(:default)
|
@@ -257,7 +257,7 @@ module Inspec
|
|
257
257
|
action: :create,
|
258
258
|
provider: options[:provider],
|
259
259
|
file: loc.path,
|
260
|
-
line: loc.lineno
|
260
|
+
line: loc.lineno
|
261
261
|
)
|
262
262
|
end
|
263
263
|
|
@@ -289,11 +289,9 @@ module Inspec
|
|
289
289
|
priority: priority,
|
290
290
|
value: new_value,
|
291
291
|
file: location.path,
|
292
|
-
line: location.lineno
|
292
|
+
line: location.lineno
|
293
293
|
)
|
294
294
|
enforce_type_restriction!
|
295
|
-
|
296
|
-
new_value
|
297
295
|
end
|
298
296
|
|
299
297
|
def value
|
@@ -320,7 +318,7 @@ module Inspec
|
|
320
318
|
end
|
321
319
|
|
322
320
|
def ruby_var_identifier
|
323
|
-
identifier ||
|
321
|
+
identifier || "attr_" + name.downcase.strip.gsub(/\s+/, "-").gsub(/[^\w-]/, "")
|
324
322
|
end
|
325
323
|
|
326
324
|
def to_ruby
|
@@ -332,7 +330,7 @@ module Inspec
|
|
332
330
|
# send the default: option as well. See #3759
|
333
331
|
res.push " default: #{value.inspect}," unless value.to_s.empty?
|
334
332
|
res.push " description: '#{description}'," unless description.to_s.empty?
|
335
|
-
res.push
|
333
|
+
res.push "})"
|
336
334
|
res.join("\n")
|
337
335
|
end
|
338
336
|
|
@@ -368,16 +366,16 @@ module Inspec
|
|
368
366
|
return unless has_value?
|
369
367
|
|
370
368
|
type_req = type
|
371
|
-
return if type_req ==
|
369
|
+
return if type_req == "Any"
|
372
370
|
|
373
371
|
proposed_value = current_value
|
374
372
|
|
375
373
|
invalid_type = false
|
376
|
-
if type_req ==
|
374
|
+
if type_req == "Regexp"
|
377
375
|
invalid_type = true if !valid_regexp?(proposed_value)
|
378
|
-
elsif type_req ==
|
376
|
+
elsif type_req == "Numeric"
|
379
377
|
invalid_type = true if !valid_numeric?(proposed_value)
|
380
|
-
elsif type_req ==
|
378
|
+
elsif type_req == "Boolean"
|
381
379
|
invalid_type = true if ![true, false].include?(proposed_value)
|
382
380
|
elsif proposed_value.is_a?(Module.const_get(type_req)) == false
|
383
381
|
# TODO: why is this case here?
|
@@ -398,8 +396,8 @@ module Inspec
|
|
398
396
|
|
399
397
|
type_req = type.capitalize
|
400
398
|
abbreviations = {
|
401
|
-
|
402
|
-
|
399
|
+
"Num" => "Numeric",
|
400
|
+
"Regex" => "Regexp",
|
403
401
|
}
|
404
402
|
type_req = abbreviations[type_req] if abbreviations.key?(type_req)
|
405
403
|
if !VALID_TYPES.include?(type_req)
|
data/lib/inspec/objects/list.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
# encoding:utf-8
|
2
|
-
|
3
1
|
module Inspec
|
4
2
|
class List < Value
|
5
3
|
def map
|
6
|
-
raise
|
4
|
+
raise "Inspec::List.map needs to be called with a block" unless block_given?
|
7
5
|
t = List.new
|
8
|
-
t.qualifier = [[
|
6
|
+
t.qualifier = [["x"]]
|
9
7
|
yield(t)
|
10
|
-
return if t.qualifier == [[
|
11
|
-
@qualifier.push([
|
8
|
+
return if t.qualifier == [["x"]]
|
9
|
+
@qualifier.push(["map", "{ |x| #{t.to_ruby} }"])
|
12
10
|
self
|
13
11
|
end
|
14
12
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding:utf-8
|
2
|
-
|
3
1
|
module Inspec
|
4
2
|
class OrTest
|
5
3
|
attr_reader :tests
|
@@ -20,10 +18,10 @@ module Inspec
|
|
20
18
|
if @negated
|
21
19
|
# We don't use the describe.one wrapper when negated because:
|
22
20
|
# !(test1 || test2) same as (!test1 && !test2) where && is implicit in inspec
|
23
|
-
all_tests = @tests.map
|
21
|
+
all_tests = @tests.map do |test|
|
24
22
|
test.negate!
|
25
23
|
test
|
26
|
-
|
24
|
+
end.map(&:to_ruby).join("\n")
|
27
25
|
|
28
26
|
all_tests
|
29
27
|
else
|
@@ -1,14 +1,12 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module Inspec
|
4
2
|
module RubyHelper
|
5
3
|
def ruby_qualifier(q)
|
6
4
|
if q.length <= 1
|
7
5
|
q[0]
|
8
|
-
elsif q[0] ==
|
9
|
-
q[0] +
|
6
|
+
elsif q[0] == "map" && q.length == 2
|
7
|
+
q[0] + " " + q[1]
|
10
8
|
else
|
11
|
-
q[0] +
|
9
|
+
q[0] + "(" + q[1..-1].map(&:inspect).join(", ") + ")"
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
data/lib/inspec/objects/tag.rb
CHANGED
data/lib/inspec/objects/test.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding:utf-8
|
2
|
-
|
3
1
|
module Inspec
|
4
2
|
class Test
|
5
3
|
attr_accessor :qualifier, :matcher, :expectation, :skip, :negated, :variables, :only_if
|
@@ -43,17 +41,17 @@ module Inspec
|
|
43
41
|
return nil if @qualifier.empty?
|
44
42
|
|
45
43
|
resource = @qualifier.length > 1 ? @qualifier[0..-2] : [@qualifier[0]]
|
46
|
-
res = resource.map { |q| ruby_qualifier(q) }.join(
|
44
|
+
res = resource.map { |q| ruby_qualifier(q) }.join(".")
|
47
45
|
xres = nil
|
48
46
|
|
49
47
|
if @qualifier.length > 1
|
50
48
|
last = @qualifier[-1]
|
51
|
-
last_call = last.is_a?(Array) ? last[0].to_s :
|
52
|
-
if last.length == 1 && last_call !~ /^to_.$/ && !last_call.include?(
|
49
|
+
last_call = last.is_a?(Array) ? last[0].to_s : ""
|
50
|
+
if last.length == 1 && last_call !~ /^to_.$/ && !last_call.include?("[") && !last_call.empty?
|
53
51
|
# this will go in its()
|
54
52
|
xres = last_call
|
55
53
|
else
|
56
|
-
res +=
|
54
|
+
res += "." + ruby_qualifier(last) unless last_call.empty?
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
@@ -65,15 +63,15 @@ module Inspec
|
|
65
63
|
vars = variables.map(&:to_ruby).join("\n")
|
66
64
|
vars += "\n" unless vars.empty?
|
67
65
|
res, xtra = describe_chain
|
68
|
-
itsy = xtra.nil? ?
|
69
|
-
naughty = @negated ?
|
66
|
+
itsy = xtra.nil? ? "it" : "its(" + xtra.to_s.inspect + ")"
|
67
|
+
naughty = @negated ? "_not" : ""
|
70
68
|
xpect = if !defined?(@expectation)
|
71
|
-
|
69
|
+
""
|
72
70
|
elsif @expectation.class == Regexp
|
73
71
|
# without this, xpect values like / \/zones\// will not be parsed properly
|
74
72
|
"(#{@expectation.inspect})"
|
75
|
-
elsif xpect !=
|
76
|
-
|
73
|
+
elsif xpect != ""
|
74
|
+
" " + expectation.inspect
|
77
75
|
end
|
78
76
|
format("%s%sdescribe %s do\n %s { should%s %s%s }\nend",
|
79
77
|
only_if_clause, vars, res, itsy, naughty, matcher, xpect)
|
data/lib/inspec/objects/value.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding:utf-8
|
2
|
-
|
3
1
|
module Inspec
|
4
2
|
class Value
|
5
3
|
include ::Inspec::RubyHelper
|
@@ -14,12 +12,12 @@ module Inspec
|
|
14
12
|
end
|
15
13
|
|
16
14
|
def to_ruby
|
17
|
-
res = @variable.nil? ?
|
18
|
-
res + @qualifier.map { |x| ruby_qualifier(x) }.join(
|
15
|
+
res = @variable.nil? ? "" : "#{@variable} = "
|
16
|
+
res + @qualifier.map { |x| ruby_qualifier(x) }.join(".")
|
19
17
|
end
|
20
18
|
|
21
19
|
def name_variable(cache = [])
|
22
|
-
@variable = Array(
|
20
|
+
@variable = Array("a".."z").find { |x| !cache.include?(x) }
|
23
21
|
cache.push(@variable)
|
24
22
|
@variable
|
25
23
|
end
|
data/lib/inspec/plugin/v1.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "inspec/plugin/v1/plugins"
|
2
|
+
require "inspec/plugin/v1/registry"
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
# author: Dominik Richter
|
3
|
-
# author: Christoph Hartmann
|
1
|
+
require "inspec/exceptions"
|
4
2
|
|
5
3
|
module Inspec
|
6
4
|
module ResourceBehaviors
|
@@ -45,7 +43,7 @@ module Inspec
|
|
45
43
|
# Even tho this is defined as an instance method, it gets added to
|
46
44
|
# Inspec::Plugins::Resource via `extend`, so this is actually a class defintion.
|
47
45
|
def method_missing(method_name, *arguments, &block)
|
48
|
-
require
|
46
|
+
require "inspec/plugin/v2"
|
49
47
|
# Check to see if there is a resource_dsl plugin activator hook with the method name
|
50
48
|
registry = Inspec::Plugin::V2::Registry.instance
|
51
49
|
hook = registry.find_activators(plugin_type: :resource_dsl, activator_name: method_name).first
|
@@ -118,7 +116,7 @@ module Inspec
|
|
118
116
|
|
119
117
|
def check_supports
|
120
118
|
status = inspec.platform.supported?(@supports)
|
121
|
-
fail_msg = "Resource
|
119
|
+
fail_msg = "Resource `#{@__resource_name__}` is not supported on platform #{inspec.platform.name}/#{inspec.platform.release}."
|
122
120
|
fail_resource(fail_msg) unless status
|
123
121
|
status
|
124
122
|
end
|
@@ -150,7 +148,7 @@ module Inspec
|
|
150
148
|
|
151
149
|
# Warn if a resource pack is overwriting a core resource.
|
152
150
|
# Suppress warning if the resource is an AWS resource, see #3822
|
153
|
-
if __resource_registry.key?(name) && !name.start_with?(
|
151
|
+
if __resource_registry.key?(name) && !name.start_with?("aws_")
|
154
152
|
Inspec::Log.warn("Overwriting resource #{name}. To reference a specific version of #{name} use the resource() method")
|
155
153
|
end
|
156
154
|
__resource_registry[name] = cl
|
@@ -1,19 +1,15 @@
|
|
1
|
-
|
2
|
-
# author: Dominik Richter
|
3
|
-
# author: Christoph Hartmann
|
4
|
-
|
5
|
-
require 'forwardable'
|
1
|
+
require "forwardable"
|
6
2
|
|
7
3
|
module Inspec
|
8
4
|
# Resource Plugins
|
9
5
|
# NOTE: the autoloading here is rendered moot by the fact that
|
10
6
|
# all core plugins are `require`'d by the base inspec.rb
|
11
7
|
module Plugins
|
12
|
-
autoload :Resource,
|
13
|
-
autoload :CLI,
|
14
|
-
autoload :Fetcher,
|
15
|
-
autoload :SourceReader,
|
16
|
-
autoload :Secret,
|
8
|
+
autoload :Resource, "inspec/plugin/v1/plugin_types/resource"
|
9
|
+
autoload :CLI, "inspec/plugin/v1/plugin_types/cli"
|
10
|
+
autoload :Fetcher, "inspec/plugin/v1/plugin_types/fetcher"
|
11
|
+
autoload :SourceReader, "inspec/plugin/v1/plugin_types/source_reader"
|
12
|
+
autoload :Secret, "inspec/plugin/v1/plugin_types/secret"
|
17
13
|
end
|
18
14
|
|
19
15
|
# PLEASE NOTE: The Plugin system is an internal mechanism for connecting
|
@@ -30,24 +26,24 @@ module Inspec
|
|
30
26
|
@paths = []
|
31
27
|
|
32
28
|
# load plugins in the same gem installation
|
33
|
-
lib_home = File.expand_path(File.join(__FILE__,
|
34
|
-
@paths += Dir[lib_home+
|
29
|
+
lib_home = File.expand_path(File.join(__FILE__, "..", "..", "..", ".."))
|
30
|
+
@paths += Dir[lib_home + "/inspec-*-*/lib/inspec-*rb"]
|
35
31
|
|
36
32
|
# traverse out of inspec-vX.Y.Z/lib/inspec/plugins.rb
|
37
|
-
@home = home || File.join(Inspec.config_dir,
|
38
|
-
@paths += Dir[File.join(@home,
|
33
|
+
@home = home || File.join(Inspec.config_dir, "plugins")
|
34
|
+
@paths += Dir[File.join(@home, "**{,/*/**}", "*.gemspec")]
|
39
35
|
.map { |x| File.dirname(x) }
|
40
|
-
.map { |x| Dir[File.join(x,
|
36
|
+
.map { |x| Dir[File.join(x, "lib", "inspec-*.rb")] }
|
41
37
|
.flatten
|
42
38
|
|
43
39
|
# load bundled plugins
|
44
40
|
bundled_dir = File.expand_path(File.dirname(__FILE__))
|
45
|
-
@paths += Dir[File.join(bundled_dir,
|
41
|
+
@paths += Dir[File.join(bundled_dir, "..", "bundles", "inspec-*.rb")].flatten
|
46
42
|
|
47
43
|
# map paths to names
|
48
|
-
@registry = Hash[@paths.map
|
49
|
-
[File.basename(x,
|
50
|
-
|
44
|
+
@registry = Hash[@paths.map do |x|
|
45
|
+
[File.basename(x, ".rb"), x]
|
46
|
+
end]
|
51
47
|
end
|
52
48
|
|
53
49
|
def load(name)
|