inspec-core 4.56.58 → 5.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +24 -9
- data/etc/deprecations.json +12 -11
- data/inspec-core.gemspec +3 -5
- data/lib/inspec/base_cli.rb +14 -2
- data/lib/inspec/cli.rb +16 -7
- data/lib/inspec/dependencies/dependency_set.rb +2 -6
- data/lib/inspec/dependency_installer.rb +74 -0
- data/lib/inspec/dependency_loader.rb +97 -0
- data/lib/inspec/dsl.rb +16 -23
- data/lib/inspec/env_printer.rb +1 -1
- data/lib/inspec/errors.rb +7 -0
- data/lib/inspec/fetcher/git.rb +28 -43
- data/lib/inspec/fetcher/url.rb +1 -1
- data/lib/inspec/formatters/base.rb +22 -0
- data/lib/inspec/metadata.rb +36 -0
- data/lib/inspec/plugin/v2/plugin_types/streaming_reporter.rb +44 -1
- data/lib/inspec/profile.rb +81 -29
- data/lib/inspec/reporters/automate.rb +1 -1
- data/lib/inspec/reporters/cli.rb +1 -1
- data/lib/inspec/reporters/json.rb +31 -11
- data/lib/inspec/resource.rb +6 -0
- data/lib/inspec/resources/cassandradb_session.rb +3 -4
- data/lib/inspec/resources/cron.rb +49 -0
- data/lib/inspec/resources/file.rb +1 -1
- data/lib/inspec/resources/ibmdb2_session.rb +3 -4
- data/lib/inspec/resources/ipfilter.rb +59 -0
- data/lib/inspec/resources/ipnat.rb +58 -0
- data/lib/inspec/resources/mongodb_session.rb +1 -7
- data/lib/inspec/resources/oracledb_session.rb +7 -20
- data/lib/inspec/resources/postgres_session.rb +5 -7
- data/lib/inspec/resources/processes.rb +4 -6
- data/lib/inspec/resources/service.rb +2 -4
- data/lib/inspec/resources.rb +3 -16
- data/lib/inspec/rule.rb +1 -1
- data/lib/inspec/runner.rb +18 -1
- data/lib/inspec/runner_rspec.rb +15 -0
- data/lib/inspec/schema/exec_json.rb +59 -58
- data/lib/inspec/schema/exec_json_min.rb +16 -16
- data/lib/inspec/schema/primitives.rb +68 -51
- data/lib/inspec/schema/profile_json.rb +27 -27
- data/lib/inspec/schema.rb +1 -0
- data/lib/inspec/secrets/yaml.rb +1 -7
- data/lib/inspec/ui.rb +1 -0
- data/lib/inspec/utils/deprecated_cloud_resources_list.rb +54 -0
- data/lib/inspec/version.rb +1 -1
- data/lib/inspec.rb +3 -0
- data/lib/matchers/matchers.rb +1 -7
- data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +1 -0
- data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +9 -0
- data/lib/plugins/inspec-init/lib/inspec-init/cli_resource.rb +126 -0
- data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +9 -8
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.erb +16 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/streaming_reporter.erb +31 -0
- data/lib/plugins/inspec-init/templates/profiles/aws/inspec.yml +1 -1
- data/lib/plugins/inspec-init/templates/resources/basic/docs/resource-doc.erb +77 -0
- data/lib/plugins/inspec-init/templates/resources/basic/libraries/inspec-resource-template.erb +94 -0
- data/lib/plugins/inspec-init/templates/resources/plural/docs/resource-doc.erb +62 -0
- data/lib/plugins/inspec-init/templates/resources/plural/libraries/inspec-resource-template.erb +73 -0
- data/lib/plugins/inspec-reporter-html2/templates/body.html.erb +6 -4
- data/lib/plugins/inspec-reporter-html2/templates/control.html.erb +4 -1
- data/lib/plugins/inspec-reporter-html2/templates/profile.html.erb +2 -1
- data/lib/plugins/inspec-reporter-html2/templates/result.html.erb +1 -0
- data/lib/plugins/inspec-streaming-reporter-progress-bar/README.md +5 -0
- data/lib/plugins/inspec-streaming-reporter-progress-bar/lib/inspec-streaming-reporter-progress-bar/plugin.rb +13 -0
- data/lib/plugins/inspec-streaming-reporter-progress-bar/lib/inspec-streaming-reporter-progress-bar/streaming_reporter.rb +112 -0
- data/lib/plugins/inspec-streaming-reporter-progress-bar/lib/inspec-streaming-reporter-progress-bar/version.rb +8 -0
- data/lib/plugins/inspec-streaming-reporter-progress-bar/lib/inspec-streaming-reporter-progress-bar.rb +15 -0
- metadata +24 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c3af1b1fd71ded2286e8aa90c46c74dd20f7fb31c525e56ae03e52952c26b0f
|
4
|
+
data.tar.gz: 507db51585f790cc26af852626b3bb52f8a35f36870ee563902234f1c2664a2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00447ba26c980417a501be959fb8ca85268db4e600417c11a912181da2c75c41169d419f1177fac484a12c1c405cae3aab5912ec9cab24f9a9e4adf355d40faa
|
7
|
+
data.tar.gz: f007b4bc1998187a7313f34f8739145f5e511500e2c9ca280b7163495a6909646be25fed9b4307a27f370e5e36b94b36b558c9e8d5c67079dc6cf24fb93029ea
|
data/Gemfile
CHANGED
@@ -23,27 +23,42 @@ group :omnibus do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
group :test do
|
26
|
-
gem "chefstyle", "~> 2.
|
26
|
+
gem "chefstyle", "~> 2.0.3"
|
27
27
|
gem "concurrent-ruby", "~> 1.0"
|
28
|
-
gem "
|
28
|
+
gem "html-proofer", platforms: :ruby # do not attempt to run proofer on windows
|
29
|
+
gem "json_schemer", ">= 0.2.1", "< 0.2.19"
|
29
30
|
gem "m"
|
30
31
|
gem "minitest-sprint", "~> 1.0"
|
31
|
-
gem "minitest", "5.
|
32
|
-
gem "mocha", "~>
|
32
|
+
gem "minitest", "~> 5.5"
|
33
|
+
gem "mocha", "~> 1.1"
|
33
34
|
gem "nokogiri", "~> 1.9"
|
34
35
|
gem "pry-byebug"
|
35
36
|
gem "pry", "~> 0.10"
|
36
37
|
gem "rake", ">= 10"
|
38
|
+
gem "ruby-progressbar", "~> 1.8"
|
37
39
|
gem "simplecov", "~> 0.21"
|
38
40
|
gem "simplecov_json_formatter"
|
39
41
|
gem "webmock", "~> 3.0"
|
40
|
-
|
41
|
-
if Gem.ruby_version >= Gem::Version.new("3.0.0")
|
42
|
-
# html-proofer has a dep on io-event, which is ruby-3 only
|
43
|
-
gem "html-proofer", "~> 3.19.4", platforms: :ruby # do not attempt to run proofer on windows. Pinned to 3.19.4 as test is breaking in updated versions.
|
44
|
-
end
|
45
42
|
end
|
46
43
|
|
47
44
|
group :deploy do
|
48
45
|
gem "inquirer"
|
49
46
|
end
|
47
|
+
|
48
|
+
# Only include Test Kitchen support if we are on Ruby 2.7 or higher
|
49
|
+
# as chef-zero support requires Ruby 2.6
|
50
|
+
# See https://github.com/inspec/inspec/pull/5341
|
51
|
+
if Gem.ruby_version >= Gem::Version.new("2.7.0")
|
52
|
+
group :kitchen do
|
53
|
+
gem "berkshelf"
|
54
|
+
gem "chef", ">= 16.0" # Required to allow net-ssh > 6
|
55
|
+
gem "test-kitchen", ">= 2.8"
|
56
|
+
gem "kitchen-inspec", ">= 2.0"
|
57
|
+
gem "kitchen-dokken", ">= 2.11"
|
58
|
+
gem "git"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
if Gem.ruby_version < Gem::Version.new("2.7.0")
|
63
|
+
gem "activesupport", "6.1.4.4"
|
64
|
+
end
|
data/etc/deprecations.json
CHANGED
@@ -17,9 +17,14 @@
|
|
17
17
|
"prefix": "Inputs should be specified by using the 'inputs' key in profile metadata, not 'attributes'."
|
18
18
|
},
|
19
19
|
"aws_resources_in_resource_pack": {
|
20
|
-
"comment": "
|
21
|
-
"action": "
|
22
|
-
"prefix": "AWS resources
|
20
|
+
"comment": "Deprecated in InSpec 5",
|
21
|
+
"action": "exit",
|
22
|
+
"prefix": "AWS resources in core InSpec are deprecated and have been removed in InSpec 5. They are now part of a resource pack. Please update your profiles to depend on git@github.com:inspec/inspec-aws.git ."
|
23
|
+
},
|
24
|
+
"azure_resources_in_resource_pack": {
|
25
|
+
"comment": "Deprecated in InSpec 5",
|
26
|
+
"action": "exit",
|
27
|
+
"prefix": "Azure resources in core InSpec are deprecated and have been removed in InSpec 5. They are now part of a resource pack. Please update your profiles to depend on git@github.com:inspec/inspec-azure.git ."
|
23
28
|
},
|
24
29
|
"cli_option_json_config": {
|
25
30
|
"action": "ignore",
|
@@ -55,10 +60,6 @@
|
|
55
60
|
"action": "fail_control",
|
56
61
|
"suffix": "This property was removed in InSpec 4.0."
|
57
62
|
},
|
58
|
-
"properties_aws_iam_user": {
|
59
|
-
"action": "fail_control",
|
60
|
-
"suffix": "This property was removed in InSpec 4.0."
|
61
|
-
},
|
62
63
|
"properties_shadow": {
|
63
64
|
"action": "fail_control",
|
64
65
|
"suffix": "This property was removed in InSpec 4.0."
|
@@ -72,10 +73,6 @@
|
|
72
73
|
"action": "exit",
|
73
74
|
"suffix": "This resource was removed in InSpec 4.0."
|
74
75
|
},
|
75
|
-
"resource_azure_generic_resource": {
|
76
|
-
"action": "warn",
|
77
|
-
"prefix": "The azure_generic_resource is deprecated. Please use a specific resource. See: 'https://github.com/inspec/inspec/issues/3131'"
|
78
|
-
},
|
79
76
|
"resource_iis_website": {
|
80
77
|
"action": "exit",
|
81
78
|
"suffix": "This resource was removed in InSpec 4.0.",
|
@@ -125,6 +122,10 @@
|
|
125
122
|
"action": "warn",
|
126
123
|
"prefix": "The --hook option is being replaced by the --activator option.",
|
127
124
|
"suffix": "This options will be removed in InSpec 4.0."
|
125
|
+
},
|
126
|
+
"cli_option_target_id":{
|
127
|
+
"action": "warn",
|
128
|
+
"prefix": "The --target-id option is deprecated in InSpec 5. Its value will be ignored."
|
128
129
|
}
|
129
130
|
}
|
130
131
|
}
|
data/inspec-core.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.license = "Apache-2.0"
|
14
14
|
spec.require_paths = ["lib"]
|
15
15
|
|
16
|
-
spec.required_ruby_version = ">= 2.
|
16
|
+
spec.required_ruby_version = ">= 2.7"
|
17
17
|
|
18
18
|
# the gemfile and gemspec are necessary for appbundler so don't remove it
|
19
19
|
spec.files =
|
@@ -25,12 +25,10 @@ Gem::Specification.new do |spec|
|
|
25
25
|
# Implementation dependencies
|
26
26
|
spec.add_dependency "chef-telemetry", "~> 1.0", ">= 1.0.8" # 1.0.8+ removes the http dep
|
27
27
|
spec.add_dependency "license-acceptance", ">= 0.2.13", "< 3.0"
|
28
|
-
|
29
|
-
# recent changes made in thor library REF: https://github.com/rails/thor/releases/tag/v1.3.0 & https://github.com/rails/thor/pull/800
|
30
|
-
spec.add_dependency "thor", ">= 0.20", "< 1.3.0"
|
28
|
+
spec.add_dependency "thor", ">= 0.20", "< 2.0"
|
31
29
|
spec.add_dependency "method_source", ">= 0.8", "< 2.0"
|
32
30
|
spec.add_dependency "rubyzip", ">= 1.2.2", "< 3.0"
|
33
|
-
spec.add_dependency "rspec", ">= 3.9", "<= 3.
|
31
|
+
spec.add_dependency "rspec", ">= 3.9", "<= 3.11"
|
34
32
|
spec.add_dependency "rspec-its", "~> 1.2"
|
35
33
|
spec.add_dependency "pry", "~> 0.13"
|
36
34
|
spec.add_dependency "hashie", ">= 3.4", "< 5.0"
|
data/lib/inspec/base_cli.rb
CHANGED
@@ -99,8 +99,18 @@ module Inspec
|
|
99
99
|
desc: "Specify a particular shell to use."
|
100
100
|
option :ssl, type: :boolean,
|
101
101
|
desc: "Use SSL for transport layer encryption (WinRM)."
|
102
|
+
option :ssl_peer_fingerprint, type: :string,
|
103
|
+
desc: "Specify peer fingerprint for SSL authentication, used in lieu of certificates"
|
102
104
|
option :self_signed, type: :boolean,
|
103
105
|
desc: "Allow remote scans with self-signed certificates (WinRM)."
|
106
|
+
option :ca_trust_file, type: :string,
|
107
|
+
desc: "Specify CA trust file for SSL authentication"
|
108
|
+
option :client_cert, type: :string,
|
109
|
+
desc: "Specify client certificate for SSL authentication"
|
110
|
+
option :client_key, type: :string,
|
111
|
+
desc: "Specify client key required with client cert for SSL authentication"
|
112
|
+
option :client_key_pass, type: :string, lazy_default: -1,
|
113
|
+
desc: "Specify client cert password, if required for SSL authentication"
|
104
114
|
option :winrm_transport, type: :string, default: "negotiate",
|
105
115
|
desc: "Specify which transport to use, defaults to negotiate (WinRM)."
|
106
116
|
option :winrm_disable_sspi, type: :boolean,
|
@@ -121,7 +131,7 @@ module Inspec
|
|
121
131
|
option :insecure, type: :boolean, default: false,
|
122
132
|
desc: "Disable SSL verification on select targets"
|
123
133
|
option :target_id, type: :string,
|
124
|
-
desc: "Provide a ID which will be included on reports"
|
134
|
+
desc: "Provide a ID which will be included on reports - deprecated"
|
125
135
|
option :winrm_shell_type, type: :string, default: "powershell",
|
126
136
|
desc: "Specify a shell type for winrm (eg. 'elevated' or 'powershell')"
|
127
137
|
option :docker_url, type: :string,
|
@@ -135,6 +145,8 @@ module Inspec
|
|
135
145
|
desc: "Folder which contains referenced profiles."
|
136
146
|
option :vendor_cache, type: :string,
|
137
147
|
desc: "Use the given path for caching dependencies. (default: ~/.inspec/cache)"
|
148
|
+
option :auto_install_gems, type: :boolean, default: false,
|
149
|
+
desc: "Auto installs gem dependencies of the profile or resource pack."
|
138
150
|
end
|
139
151
|
|
140
152
|
def self.supermarket_options
|
@@ -152,7 +164,7 @@ module Inspec
|
|
152
164
|
desc: "A list of tags names that are part of controls to filter and run controls, or a list of /regexes/ to match against tags names of controls. Ignore all other tests."
|
153
165
|
option :reporter, type: :array,
|
154
166
|
banner: "one two:/output/file/path",
|
155
|
-
desc: "Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit, yaml"
|
167
|
+
desc: "Enable one or more output reporters: cli, documentation, html, progress, progress-bar, json, json-min, json-rspec, junit, yaml"
|
156
168
|
option :reporter_message_truncation, type: :string,
|
157
169
|
desc: "Number of characters to truncate failure messages and code_desc in report data to (default: no truncation)"
|
158
170
|
option :reporter_backtrace_inclusion, type: :boolean,
|
data/lib/inspec/cli.rb
CHANGED
@@ -95,8 +95,6 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
95
95
|
desc "check PATH", "verify all tests at the specified PATH"
|
96
96
|
option :format, type: :string,
|
97
97
|
desc: "The output format to use doc (default), json. If valid format is not provided then it will use the default."
|
98
|
-
option :with_cookstyle, type: :boolean,
|
99
|
-
desc: "Enable or disable cookstyle checks.", default: false
|
100
98
|
profile_options
|
101
99
|
def check(path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
102
100
|
o = config
|
@@ -189,10 +187,6 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
189
187
|
desc: "Fallback to using local archives if fetching fails."
|
190
188
|
option :ignore_errors, type: :boolean, default: false,
|
191
189
|
desc: "Ignore profile warnings."
|
192
|
-
option :check, type: :boolean, default: false,
|
193
|
-
desc: "Run profile check before archiving."
|
194
|
-
option :export, type: :boolean, default: false,
|
195
|
-
desc: "Export the profile to inspec.json and include in archive"
|
196
190
|
def archive(path)
|
197
191
|
o = config
|
198
192
|
diagnose(o)
|
@@ -207,7 +201,13 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
207
201
|
vendor_deps(path, vendor_options)
|
208
202
|
|
209
203
|
profile = Inspec::Profile.for_target(path, o)
|
210
|
-
|
204
|
+
gem_deps = profile.metadata.gem_dependencies + \
|
205
|
+
profile.locked_dependencies.list.map { |_k, v| v.profile.metadata.gem_dependencies }.flatten
|
206
|
+
unless gem_deps.empty?
|
207
|
+
o[:logger].warn "Archiving a profile that contains gem dependencies, but InSpec cannot package gems with the profile! Please archive your ~/.inspec/gems directory separately."
|
208
|
+
end
|
209
|
+
|
210
|
+
result = profile.check
|
211
211
|
|
212
212
|
if result && !o[:ignore_errors] == false
|
213
213
|
o[:logger].info "Profile check failed. Please fix the profile before generating an archive."
|
@@ -302,6 +302,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
302
302
|
def exec(*targets)
|
303
303
|
o = config
|
304
304
|
diagnose(o)
|
305
|
+
deprecate_target_id(config)
|
305
306
|
configure_logger(o)
|
306
307
|
|
307
308
|
runner = Inspec::Runner.new(o)
|
@@ -320,6 +321,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
320
321
|
option :format, type: :string
|
321
322
|
def detect
|
322
323
|
o = config
|
324
|
+
deprecate_target_id(config)
|
323
325
|
o[:command] = "platform.params"
|
324
326
|
|
325
327
|
configure_logger(o)
|
@@ -360,6 +362,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
360
362
|
desc: "Specify one or more inputs directly on the command line to the shell, as --input NAME=VALUE. Accepts single-quoted YAML and JSON structures."
|
361
363
|
def shell_func
|
362
364
|
o = config
|
365
|
+
deprecate_target_id(config)
|
363
366
|
diagnose(o)
|
364
367
|
o[:debug_shell] = true
|
365
368
|
|
@@ -447,6 +450,12 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|
447
450
|
|
448
451
|
private
|
449
452
|
|
453
|
+
def deprecate_target_id(config)
|
454
|
+
unless config[:target_id].nil?
|
455
|
+
Inspec.deprecate "cli_option_target_id"
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
450
459
|
def run_command(opts)
|
451
460
|
runner = Inspec::Runner.new(Inspec::Config.new(opts))
|
452
461
|
res = runner.eval_with_virtual_profile(opts[:command])
|
@@ -25,9 +25,7 @@ module Inspec
|
|
25
25
|
def self.from_array(dependencies, cwd, cache, backend)
|
26
26
|
dep_list = {}
|
27
27
|
dependencies.each do |d|
|
28
|
-
|
29
|
-
key_name = (d.source_version.blank? ? "#{d.name}" : "#{d.name}-#{d.source_version}") rescue "#{d.name}"
|
30
|
-
dep_list[key_name] = d
|
28
|
+
dep_list[d.name] = d
|
31
29
|
end
|
32
30
|
new(cwd, cache, dep_list, backend)
|
33
31
|
end
|
@@ -41,9 +39,7 @@ module Inspec
|
|
41
39
|
def self.flatten_dep_tree(dep_tree)
|
42
40
|
dep_list = {}
|
43
41
|
dep_tree.each do |d|
|
44
|
-
|
45
|
-
key_name = (d.source_version.blank? ? "#{d.name}" : "#{d.name}-#{d.source_version}") rescue "#{d.name}"
|
46
|
-
dep_list[key_name] = d
|
42
|
+
dep_list[d.name] = d
|
47
43
|
dep_list.merge!(flatten_dep_tree(d.dependencies))
|
48
44
|
end
|
49
45
|
dep_list
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# This class will install the gem depedencies for profiles etc.
|
2
|
+
# The basic things which is required to install dependencies is the gem path where gem needs to be installed
|
3
|
+
# and the list of gems needs to be installed.
|
4
|
+
require "rubygems/remote_fetcher"
|
5
|
+
require "forwardable" unless defined?(Forwardable)
|
6
|
+
|
7
|
+
module Inspec
|
8
|
+
class DependencyInstaller
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
attr_reader :gem_path, :requested_gems, :dependency_loader
|
12
|
+
|
13
|
+
def_delegator :dependency_loader, :inspec_gem_path
|
14
|
+
|
15
|
+
def initialize(gem_path = nil, requested_gems = [])
|
16
|
+
@dependency_loader = Inspec::DependencyLoader.new
|
17
|
+
@gem_path = gem_path || inspec_gem_path
|
18
|
+
@requested_gems = requested_gems
|
19
|
+
end
|
20
|
+
|
21
|
+
def install
|
22
|
+
requested_gems.each do |requested_gem|
|
23
|
+
version = requested_gem[:version].nil? ? "> 0" : requested_gem[:version]
|
24
|
+
install_from_remote_gems(requested_gem[:name], { version: version })
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def install_from_remote_gems(requested_gem_name, opts)
|
31
|
+
version = opts[:version].split(",")
|
32
|
+
begin
|
33
|
+
gem_dependency = Gem::Dependency.new(requested_gem_name, version || "> 0")
|
34
|
+
|
35
|
+
# BestSet is rubygems.org API + indexing, APISet is for custom sources
|
36
|
+
sources = if opts[:source]
|
37
|
+
Gem::Resolver::APISet.new(URI.join(opts[:source] + "/api/v1/dependencies"))
|
38
|
+
else
|
39
|
+
Gem::Resolver::BestSet.new
|
40
|
+
end
|
41
|
+
|
42
|
+
install_gem_to_gems_dir(gem_dependency, [sources], opts[:update_mode])
|
43
|
+
rescue Gem::RemoteFetcher::FetchError => gem_ex
|
44
|
+
ex = Inspec::GemDependencyInstallError.new(gem_ex.message)
|
45
|
+
ex.gem_name = requested_gem_name
|
46
|
+
raise ex
|
47
|
+
rescue Gem::Requirement::BadRequirementError => gem_ex
|
48
|
+
ex = Inspec::GemDependencyInstallError.new(gem_ex.message)
|
49
|
+
ex.gem_name = requested_gem_name
|
50
|
+
raise "Unparseable gem dependency '#{version}' for '#{ex.gem_name}'"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def install_gem_to_gems_dir(gem_dependency, extra_request_sets = [], update_mode = false)
|
55
|
+
# Solve the dependency (that is, find a way to install the new gem and anything it needs)
|
56
|
+
request_set = Gem::RequestSet.new(gem_dependency)
|
57
|
+
|
58
|
+
begin
|
59
|
+
solution = request_set.resolve
|
60
|
+
rescue Gem::UnsatisfiableDependencyError => gem_ex
|
61
|
+
ex = Inspec::GemDependencyInstallError.new(gem_ex.message)
|
62
|
+
ex.gem_name = gem_dependency.name
|
63
|
+
raise ex
|
64
|
+
end
|
65
|
+
|
66
|
+
# OK, perform the installation.
|
67
|
+
# Ignore deps here, because any needed deps should already be baked into gem_dependency
|
68
|
+
request_set.install_into(gem_path, true, ignore_dependencies: true, document: [])
|
69
|
+
|
70
|
+
# Locate the GemVersion for the new dependency and return it
|
71
|
+
solution.detect { |g| g.name == gem_dependency.name }.version
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# This class will load the gem depedencies for profiles etc.
|
2
|
+
# The basic things which is required to load gem dependencies is the path from which gems needs to be loaded
|
3
|
+
# and the list of gems needs to be loaded.
|
4
|
+
|
5
|
+
module Inspec
|
6
|
+
class DependencyLoader
|
7
|
+
attr_accessor :gem_path, :gem_list
|
8
|
+
|
9
|
+
# initializes the dependency_loader
|
10
|
+
def initialize(gem_path = nil, gem_list = [])
|
11
|
+
@gem_path = gem_path || inspec_gem_path
|
12
|
+
@gem_list = gem_list
|
13
|
+
end
|
14
|
+
|
15
|
+
def load
|
16
|
+
Gem.path << gem_path
|
17
|
+
Gem.refresh
|
18
|
+
|
19
|
+
gem_list.each do |gem_data|
|
20
|
+
version = gem_data[:version].nil? ? "> 0" : gem_data[:version]
|
21
|
+
activate_gem_dependency(gem_data[:name], version)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspec_gem_path
|
26
|
+
self.class.inspec_gem_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.inspec_gem_path
|
30
|
+
require "rbconfig" unless defined?(RbConfig)
|
31
|
+
ruby_abi_version = RbConfig::CONFIG["ruby_version"]
|
32
|
+
# TODO: why are we installing under the api directory for plugins?
|
33
|
+
base_dir = Inspec.config_dir
|
34
|
+
base_dir = File.realpath base_dir if File.exist? base_dir
|
35
|
+
File.join(base_dir, "gems", ruby_abi_version)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Lists all gems found in the inspec_gem_path.
|
39
|
+
# @return [Array[Gem::Specification]] Specs of all gems found.
|
40
|
+
def list_managed_gems
|
41
|
+
Dir.glob(File.join(gem_path, "specifications", "*.gemspec")).map { |p| Gem::Specification.load(p) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_installed_gems
|
45
|
+
list_managed_gems
|
46
|
+
end
|
47
|
+
|
48
|
+
def gem_installed?(name)
|
49
|
+
list_installed_gems.any? { |spec| spec.name == name }
|
50
|
+
end
|
51
|
+
|
52
|
+
def gem_version_installed?(name, version)
|
53
|
+
list_installed_gems.any? { |s| s.name == name && Gem::Requirement.new(version.split(",")) =~ s.version }
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def activate_gem_dependency(name, version_constraint = "> 0")
|
59
|
+
version_constraint = version_constraint.split(",")
|
60
|
+
gem_deps = [Gem::Dependency.new(name.to_s, version_constraint)]
|
61
|
+
managed_gem_set = Gem::Resolver::VendorSet.new
|
62
|
+
|
63
|
+
# Note: There is an issue in resolving gem dependency.
|
64
|
+
# This block resolves that issue partially.
|
65
|
+
# But this will still fail for the gems which don't have the .gemspec file.
|
66
|
+
# TODO: Find the solution to resolve gem dependencies that work for the unpackaged gems which don't have the .gemspec file.
|
67
|
+
list_managed_gems.each do |spec|
|
68
|
+
unless Dir["#{spec.gem_dir}/*.gemspec"].empty?
|
69
|
+
managed_gem_set.add_vendor_gem(spec.name, spec.gem_dir)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# TODO: Next two lines merge our managed gems with the other gems available
|
74
|
+
# in our "local universe" - which may be the system, or it could be in a Bundler microcosm,
|
75
|
+
# or rbenv, etc. Do we want to merge that, though?
|
76
|
+
distrib_gem_set = Gem::Resolver::CurrentSet.new
|
77
|
+
installed_gem_set = Gem::Resolver.compose_sets(managed_gem_set, distrib_gem_set)
|
78
|
+
|
79
|
+
# So, given what we need, and what we have available, what activations are needed?
|
80
|
+
resolver = Gem::Resolver.new(gem_deps, installed_gem_set)
|
81
|
+
|
82
|
+
begin
|
83
|
+
solution = resolver.resolve
|
84
|
+
rescue Gem::UnsatisfiableDependencyError => gem_ex
|
85
|
+
# If you broke your install, or downgraded to a plugin with a bad gemspec, you could get here.
|
86
|
+
ex = Inspec::GemDependencyLoadError.new(gem_ex.message)
|
87
|
+
raise ex
|
88
|
+
end
|
89
|
+
solution.each do |activation_request|
|
90
|
+
next if activation_request.full_spec.activated?
|
91
|
+
|
92
|
+
activation_request.full_spec.activate
|
93
|
+
# TODO: If we are under Bundler, inform it that we loaded a gem
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/inspec/dsl.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
# copyright: 2015, Dominik Richter
|
2
2
|
require "inspec/log"
|
3
3
|
require "inspec/plugin/v2"
|
4
|
+
require "inspec/utils/deprecated_cloud_resources_list"
|
4
5
|
|
5
6
|
module Inspec::DSL
|
6
7
|
attr_accessor :backend
|
7
8
|
|
8
|
-
def require_controls(id,
|
9
|
-
opts = { profile_id: id, include_all: false, backend: @backend, conf: @conf, dependencies: @dependencies
|
9
|
+
def require_controls(id, &block)
|
10
|
+
opts = { profile_id: id, include_all: false, backend: @backend, conf: @conf, dependencies: @dependencies }
|
10
11
|
::Inspec::DSL.load_spec_files_for_profile(self, opts, &block)
|
11
12
|
end
|
12
13
|
|
13
|
-
def include_controls(id,
|
14
|
-
opts = { profile_id: id, include_all: true, backend: @backend, conf: @conf, dependencies: @dependencies
|
14
|
+
def include_controls(id, &block)
|
15
|
+
opts = { profile_id: id, include_all: true, backend: @backend, conf: @conf, dependencies: @dependencies }
|
15
16
|
::Inspec::DSL.load_spec_files_for_profile(self, opts, &block)
|
16
17
|
end
|
17
18
|
|
@@ -38,8 +39,16 @@ module Inspec::DSL
|
|
38
39
|
|
39
40
|
begin
|
40
41
|
require "inspec/resources/#{id}"
|
41
|
-
rescue LoadError
|
42
|
-
|
42
|
+
rescue LoadError => e
|
43
|
+
include DeprecatedCloudResourcesList
|
44
|
+
cloud_resource = id.start_with?("aws_") ? "aws" : "azure"
|
45
|
+
|
46
|
+
# Deprecated AWS and Azure resources in InSpec 5.
|
47
|
+
if CLOUD_RESOURCES_DEPRECATED.include? id
|
48
|
+
Inspec.deprecate(:"#{cloud_resource}_resources_in_resource_pack", "Resource '#{id}'")
|
49
|
+
else
|
50
|
+
raise LoadError, "#{e.message}"
|
51
|
+
end
|
43
52
|
end
|
44
53
|
|
45
54
|
klass = Inspec::Resource.registry[id.to_s]
|
@@ -76,23 +85,7 @@ module Inspec::DSL
|
|
76
85
|
def self.load_spec_files_for_profile(bind_context, opts, &block)
|
77
86
|
dependencies = opts[:dependencies]
|
78
87
|
profile_id = opts[:profile_id]
|
79
|
-
|
80
|
-
|
81
|
-
new_profile_id = nil
|
82
|
-
if profile_version
|
83
|
-
new_profile_id = "#{profile_id}-#{profile_version}"
|
84
|
-
else
|
85
|
-
dependencies.list.each do |key, value|
|
86
|
-
# 1. Fetching VERSION from a profile dependency name which is in a format NAME-VERSION.
|
87
|
-
# 2. Matching original profile dependency name with profile name used with include or require control DSL.
|
88
|
-
source_version = value.source_version
|
89
|
-
unless source_version.blank?
|
90
|
-
profile_id_key = key.split("-#{source_version}")[0]
|
91
|
-
new_profile_id = key if profile_id_key == profile_id
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
dep_entry = new_profile_id ? dependencies.list[new_profile_id] : dependencies.list[profile_id]
|
88
|
+
dep_entry = dependencies.list[profile_id]
|
96
89
|
|
97
90
|
if dep_entry.nil?
|
98
91
|
raise <<~EOF
|
data/lib/inspec/env_printer.rb
CHANGED
@@ -35,7 +35,7 @@ module Inspec
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def print_completion_for_shell
|
38
|
-
erb = ERB.new(File.read(completion_template_path),
|
38
|
+
erb = ERB.new(File.read(completion_template_path), nil, "-")
|
39
39
|
puts erb.result(TemplateContext.new(@command_class).get_bindings)
|
40
40
|
end
|
41
41
|
|
data/lib/inspec/errors.rb
CHANGED
@@ -15,4 +15,11 @@ module Inspec
|
|
15
15
|
class ConfigError::Invalid < ConfigError; end
|
16
16
|
|
17
17
|
class UserInteractionRequired < Error; end
|
18
|
+
|
19
|
+
class GemDependencyLoadError < Error; end
|
20
|
+
|
21
|
+
class GemDependencyInstallError < Error
|
22
|
+
attr_accessor :gem_name
|
23
|
+
attr_accessor :version
|
24
|
+
end
|
18
25
|
end
|