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.
Files changed (285) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -21
  3. data/etc/deprecations.json +10 -0
  4. data/etc/plugin_filters.json +8 -0
  5. data/lib/bundles/inspec-compliance/api.rb +1 -1
  6. data/lib/bundles/inspec-compliance/configuration.rb +1 -1
  7. data/lib/bundles/inspec-compliance/http.rb +1 -1
  8. data/lib/bundles/inspec-compliance/support.rb +1 -1
  9. data/lib/bundles/inspec-compliance/target.rb +1 -1
  10. data/lib/bundles/inspec-supermarket.rb +3 -7
  11. data/lib/bundles/inspec-supermarket/api.rb +10 -13
  12. data/lib/bundles/inspec-supermarket/cli.rb +12 -15
  13. data/lib/bundles/inspec-supermarket/target.rb +7 -11
  14. data/lib/fetchers/git.rb +14 -15
  15. data/lib/fetchers/local.rb +6 -10
  16. data/lib/fetchers/mock.rb +3 -5
  17. data/lib/fetchers/url.rb +42 -44
  18. data/lib/inspec.rb +23 -24
  19. data/lib/inspec/archive/tar.rb +2 -6
  20. data/lib/inspec/archive/zip.rb +3 -7
  21. data/lib/inspec/backend.rb +8 -9
  22. data/lib/inspec/base_cli.rb +64 -65
  23. data/lib/inspec/cached_fetcher.rb +2 -3
  24. data/lib/inspec/cli.rb +136 -97
  25. data/lib/inspec/config.rb +71 -61
  26. data/lib/inspec/control_eval_context.rb +22 -18
  27. data/lib/inspec/dependencies/cache.rb +2 -3
  28. data/lib/inspec/dependencies/dependency_set.rb +2 -3
  29. data/lib/inspec/dependencies/lockfile.rb +8 -9
  30. data/lib/inspec/dependencies/requirement.rb +7 -8
  31. data/lib/inspec/dependencies/resolver.rb +5 -7
  32. data/lib/inspec/describe.rb +2 -6
  33. data/lib/inspec/dist.rb +20 -0
  34. data/lib/inspec/dsl.rb +4 -7
  35. data/lib/inspec/dsl_shared.rb +1 -2
  36. data/lib/inspec/env_printer.rb +11 -12
  37. data/lib/inspec/errors.rb +0 -4
  38. data/lib/inspec/exceptions.rb +0 -1
  39. data/lib/inspec/expect.rb +5 -8
  40. data/lib/inspec/fetcher.rb +7 -10
  41. data/lib/inspec/file_provider.rb +24 -24
  42. data/lib/inspec/formatters.rb +3 -3
  43. data/lib/inspec/formatters/base.rb +8 -8
  44. data/lib/inspec/globals.rb +2 -2
  45. data/lib/inspec/impact.rb +5 -7
  46. data/lib/inspec/input_registry.rb +84 -33
  47. data/lib/inspec/library_eval_context.rb +3 -6
  48. data/lib/inspec/log.rb +1 -5
  49. data/lib/inspec/metadata.rb +17 -16
  50. data/lib/inspec/method_source.rb +5 -9
  51. data/lib/inspec/objects.rb +10 -12
  52. data/lib/inspec/objects/control.rb +7 -9
  53. data/lib/inspec/objects/describe.rb +9 -11
  54. data/lib/inspec/objects/each_loop.rb +1 -3
  55. data/lib/inspec/objects/input.rb +24 -26
  56. data/lib/inspec/objects/list.rb +4 -6
  57. data/lib/inspec/objects/or_test.rb +2 -4
  58. data/lib/inspec/objects/ruby_helper.rb +3 -5
  59. data/lib/inspec/objects/tag.rb +0 -2
  60. data/lib/inspec/objects/test.rb +9 -11
  61. data/lib/inspec/objects/value.rb +3 -5
  62. data/lib/inspec/plugin/v1.rb +2 -2
  63. data/lib/inspec/plugin/v1/plugin_types/cli.rb +1 -5
  64. data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +2 -5
  65. data/lib/inspec/plugin/v1/plugin_types/resource.rb +4 -6
  66. data/lib/inspec/plugin/v1/plugin_types/secret.rb +1 -5
  67. data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +1 -5
  68. data/lib/inspec/plugin/v1/plugins.rb +15 -19
  69. data/lib/inspec/plugin/v1/registry.rb +0 -4
  70. data/lib/inspec/plugin/v2.rb +8 -8
  71. data/lib/inspec/plugin/v2/activator.rb +1 -1
  72. data/lib/inspec/plugin/v2/config_file.rb +6 -6
  73. data/lib/inspec/plugin/v2/filter.rb +13 -13
  74. data/lib/inspec/plugin/v2/installer.rb +36 -24
  75. data/lib/inspec/plugin/v2/loader.rb +28 -28
  76. data/lib/inspec/plugin/v2/plugin_base.rb +15 -2
  77. data/lib/inspec/plugin/v2/plugin_types/cli.rb +5 -5
  78. data/lib/inspec/plugin/v2/plugin_types/input.rb +34 -0
  79. data/lib/inspec/plugin/v2/plugin_types/mock.rb +1 -1
  80. data/lib/inspec/plugin/v2/registry.rb +7 -7
  81. data/lib/inspec/polyfill.rb +0 -3
  82. data/lib/inspec/profile.rb +55 -63
  83. data/lib/inspec/profile_context.rb +27 -30
  84. data/lib/inspec/profile_vendor.rb +6 -9
  85. data/lib/inspec/reporters.rb +24 -24
  86. data/lib/inspec/reporters/automate.rb +17 -19
  87. data/lib/inspec/reporters/base.rb +1 -1
  88. data/lib/inspec/reporters/cli.rb +88 -91
  89. data/lib/inspec/reporters/json.rb +2 -4
  90. data/lib/inspec/reporters/json_automate.rb +1 -3
  91. data/lib/inspec/reporters/json_min.rb +1 -3
  92. data/lib/inspec/reporters/junit.rb +26 -28
  93. data/lib/inspec/reporters/yaml.rb +1 -3
  94. data/lib/inspec/require_loader.rb +0 -4
  95. data/lib/inspec/resource.rb +4 -125
  96. data/lib/inspec/resources.rb +121 -0
  97. data/lib/{resources → inspec/resources}/aide_conf.rb +24 -25
  98. data/lib/{resources → inspec/resources}/apache.rb +13 -14
  99. data/lib/{resources → inspec/resources}/apache_conf.rb +16 -17
  100. data/lib/{resources → inspec/resources}/apt.rb +17 -17
  101. data/lib/{resources → inspec/resources}/audit_policy.rb +7 -6
  102. data/lib/{resources → inspec/resources}/auditd.rb +62 -64
  103. data/lib/{resources → inspec/resources}/auditd_conf.rb +7 -8
  104. data/lib/{resources → inspec/resources}/bash.rb +6 -8
  105. data/lib/{resources → inspec/resources}/bond.rb +15 -14
  106. data/lib/{resources → inspec/resources}/bridge.rb +8 -8
  107. data/lib/{resources → inspec/resources}/chocolatey_package.rb +10 -8
  108. data/lib/{resources → inspec/resources}/command.rb +11 -10
  109. data/lib/{resources → inspec/resources}/cpan.rb +12 -12
  110. data/lib/{resources → inspec/resources}/cran.rb +9 -9
  111. data/lib/{resources → inspec/resources}/crontab.rb +47 -48
  112. data/lib/{resources → inspec/resources}/csv.rb +5 -5
  113. data/lib/{resources → inspec/resources}/dh_params.rb +5 -7
  114. data/lib/{resources → inspec/resources}/directory.rb +5 -7
  115. data/lib/{resources → inspec/resources}/docker.rb +63 -63
  116. data/lib/{resources → inspec/resources}/docker_container.rb +6 -6
  117. data/lib/{resources → inspec/resources}/docker_image.rb +9 -9
  118. data/lib/{resources → inspec/resources}/docker_object.rb +8 -13
  119. data/lib/{resources → inspec/resources}/docker_plugin.rb +6 -6
  120. data/lib/{resources → inspec/resources}/docker_service.rb +7 -7
  121. data/lib/{resources → inspec/resources}/elasticsearch.rb +40 -42
  122. data/lib/{resources → inspec/resources}/etc_fstab.rb +23 -24
  123. data/lib/{resources → inspec/resources}/etc_group.rb +26 -27
  124. data/lib/{resources → inspec/resources}/etc_hosts.rb +11 -13
  125. data/lib/{resources → inspec/resources}/etc_hosts_allow_deny.rb +25 -27
  126. data/lib/{resources → inspec/resources}/file.rb +80 -79
  127. data/lib/{resources → inspec/resources}/filesystem.rb +20 -15
  128. data/lib/{resources → inspec/resources}/firewalld.rb +26 -26
  129. data/lib/{resources → inspec/resources}/gem.rb +12 -12
  130. data/lib/{resources → inspec/resources}/groups.rb +28 -27
  131. data/lib/{resources → inspec/resources}/grub_conf.rb +46 -48
  132. data/lib/{resources → inspec/resources}/host.rb +31 -29
  133. data/lib/{resources → inspec/resources}/http.rb +24 -24
  134. data/lib/{resources → inspec/resources}/iis_app.rb +6 -7
  135. data/lib/{resources → inspec/resources}/iis_app_pool.rb +21 -19
  136. data/lib/{resources → inspec/resources}/iis_site.rb +17 -15
  137. data/lib/{resources → inspec/resources}/inetd_conf.rb +9 -10
  138. data/lib/{resources → inspec/resources}/ini.rb +7 -8
  139. data/lib/{resources → inspec/resources}/interface.rb +30 -30
  140. data/lib/{resources → inspec/resources}/iptables.rb +8 -8
  141. data/lib/{resources → inspec/resources}/json.rb +8 -10
  142. data/lib/{resources → inspec/resources}/kernel_module.rb +15 -15
  143. data/lib/{resources → inspec/resources}/kernel_parameter.rb +8 -8
  144. data/lib/{resources → inspec/resources}/key_rsa.rb +8 -10
  145. data/lib/{resources → inspec/resources}/ksh.rb +6 -8
  146. data/lib/{resources → inspec/resources}/limits_conf.rb +8 -9
  147. data/lib/{resources/login_def.rb → inspec/resources/login_defs.rb} +9 -10
  148. data/lib/{resources → inspec/resources}/mount.rb +6 -8
  149. data/lib/{resources → inspec/resources}/mssql_session.rb +16 -18
  150. data/lib/inspec/resources/mysql.rb +81 -0
  151. data/lib/{resources → inspec/resources}/mysql_conf.rb +13 -14
  152. data/lib/{resources → inspec/resources}/mysql_session.rb +16 -16
  153. data/lib/{resources → inspec/resources}/nginx.rb +16 -17
  154. data/lib/{resources → inspec/resources}/nginx_conf.rb +26 -27
  155. data/lib/{resources → inspec/resources}/npm.rb +9 -10
  156. data/lib/{resources → inspec/resources}/ntp_conf.rb +9 -10
  157. data/lib/{resources → inspec/resources}/oneget.rb +8 -8
  158. data/lib/{resources → inspec/resources}/oracledb_session.rb +33 -34
  159. data/lib/{resources → inspec/resources}/os.rb +6 -8
  160. data/lib/{resources → inspec/resources}/os_env.rb +11 -12
  161. data/lib/{resources → inspec/resources}/package.rb +66 -65
  162. data/lib/{resources → inspec/resources}/packages.rb +13 -13
  163. data/lib/{resources → inspec/resources}/parse_config.rb +8 -8
  164. data/lib/{resources → inspec/resources}/passwd.rb +18 -19
  165. data/lib/{resources → inspec/resources}/pip.rb +19 -19
  166. data/lib/{resources → inspec/resources}/platform.rb +9 -11
  167. data/lib/{resources → inspec/resources}/port.rb +134 -136
  168. data/lib/{resources → inspec/resources}/postgres.rb +40 -32
  169. data/lib/{resources → inspec/resources}/postgres_conf.rb +17 -17
  170. data/lib/{resources → inspec/resources}/postgres_hba_conf.rb +21 -23
  171. data/lib/{resources → inspec/resources}/postgres_ident_conf.rb +12 -14
  172. data/lib/{resources → inspec/resources}/postgres_session.rb +8 -9
  173. data/lib/{resources → inspec/resources}/powershell.rb +17 -13
  174. data/lib/{resources → inspec/resources}/processes.rb +29 -29
  175. data/lib/{resources/rabbitmq_conf.rb → inspec/resources/rabbitmq_config.rb} +10 -11
  176. data/lib/{resources → inspec/resources}/registry_key.rb +14 -14
  177. data/lib/inspec/resources/script.rb +1 -0
  178. data/lib/{resources → inspec/resources}/security_identifier.rb +11 -10
  179. data/lib/{resources → inspec/resources}/security_policy.rb +59 -58
  180. data/lib/{resources → inspec/resources}/service.rb +74 -75
  181. data/lib/{resources → inspec/resources}/shadow.rb +44 -45
  182. data/lib/{resources/ssh_conf.rb → inspec/resources/ssh_config.rb} +16 -17
  183. data/lib/{resources → inspec/resources}/ssl.rb +28 -29
  184. data/lib/inspec/resources/sys_info.rb +30 -0
  185. data/lib/{resources → inspec/resources}/toml.rb +5 -7
  186. data/lib/{resources → inspec/resources}/users.rb +65 -65
  187. data/lib/{resources → inspec/resources}/vbscript.rb +8 -9
  188. data/lib/{resources → inspec/resources}/virtualization.rb +60 -62
  189. data/lib/{resources → inspec/resources}/windows_feature.rb +9 -9
  190. data/lib/{resources → inspec/resources}/windows_hotfix.rb +5 -5
  191. data/lib/{resources → inspec/resources}/windows_task.rb +16 -15
  192. data/lib/{resources → inspec/resources}/wmi.rb +7 -8
  193. data/lib/{resources → inspec/resources}/x509_certificate.rb +9 -11
  194. data/lib/{resources/xinetd.rb → inspec/resources/xinetd_conf.rb} +27 -29
  195. data/lib/{resources → inspec/resources}/xml.rb +7 -7
  196. data/lib/{resources → inspec/resources}/yaml.rb +5 -6
  197. data/lib/{resources → inspec/resources}/yum.rb +10 -10
  198. data/lib/{resources → inspec/resources}/zfs_dataset.rb +6 -6
  199. data/lib/{resources → inspec/resources}/zfs_pool.rb +4 -4
  200. data/lib/inspec/rspec_extensions.rb +24 -8
  201. data/lib/inspec/rule.rb +14 -15
  202. data/lib/inspec/runner.rb +28 -28
  203. data/lib/inspec/runner_mock.rb +1 -5
  204. data/lib/inspec/runner_rspec.rb +18 -20
  205. data/lib/inspec/runtime_profile.rb +2 -5
  206. data/lib/inspec/schema.rb +142 -143
  207. data/lib/inspec/secrets.rb +3 -7
  208. data/lib/inspec/secrets/yaml.rb +3 -5
  209. data/lib/inspec/shell.rb +11 -15
  210. data/lib/inspec/shell_detector.rb +6 -7
  211. data/lib/inspec/source_reader.rb +4 -8
  212. data/lib/inspec/ui.rb +33 -39
  213. data/lib/inspec/ui_table_helper.rb +12 -0
  214. data/lib/{utils → inspec/utils}/command_wrapper.rb +4 -8
  215. data/lib/{utils → inspec/utils}/convert.rb +0 -4
  216. data/lib/{utils → inspec/utils}/database_helpers.rb +4 -8
  217. data/lib/inspec/utils/deprecation.rb +6 -0
  218. data/lib/{utils → inspec/utils}/deprecation/config_file.rb +19 -19
  219. data/lib/{utils → inspec/utils}/deprecation/deprecator.rb +12 -12
  220. data/lib/{utils → inspec/utils}/deprecation/errors.rb +1 -1
  221. data/lib/{utils → inspec/utils}/deprecation/global_method.rb +2 -2
  222. data/lib/{utils → inspec/utils}/enumerable_delegation.rb +0 -2
  223. data/lib/{utils → inspec/utils}/erlang_parser.rb +61 -65
  224. data/lib/{utils → inspec/utils}/file_reader.rb +1 -2
  225. data/lib/{utils → inspec/utils}/filter.rb +30 -33
  226. data/lib/{utils → inspec/utils}/filter_array.rb +0 -2
  227. data/lib/{utils → inspec/utils}/find_files.rb +9 -12
  228. data/lib/{utils → inspec/utils}/hash.rb +1 -5
  229. data/lib/inspec/utils/json_log.rb +15 -0
  230. data/lib/inspec/utils/latest_version.rb +13 -0
  231. data/lib/{utils → inspec/utils}/modulator.rb +0 -3
  232. data/lib/{utils → inspec/utils}/nginx_parser.rb +31 -35
  233. data/lib/{utils → inspec/utils}/object_traversal.rb +0 -3
  234. data/lib/{utils → inspec/utils}/parser.rb +45 -45
  235. data/lib/{utils → inspec/utils}/pkey_reader.rb +4 -2
  236. data/lib/{utils → inspec/utils}/simpleconfig.rb +8 -10
  237. data/lib/{utils → inspec/utils}/spdx.rb +1 -4
  238. data/lib/{utils → inspec/utils}/spdx.txt +0 -0
  239. data/lib/inspec/utils/telemetry.rb +3 -3
  240. data/lib/inspec/utils/telemetry/collector.rb +30 -9
  241. data/lib/inspec/utils/telemetry/data_series.rb +3 -1
  242. data/lib/inspec/utils/telemetry/global_methods.rb +1 -1
  243. data/lib/inspec/version.rb +1 -1
  244. data/lib/matchers/matchers.rb +22 -25
  245. data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +1 -1
  246. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +52 -45
  247. data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +18 -16
  248. data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +1 -1
  249. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +73 -73
  250. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +66 -62
  251. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +59 -57
  252. data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +11 -11
  253. data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +20 -22
  254. data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +2 -4
  255. data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +30 -27
  256. data/lib/plugins/inspec-habitat/Berksfile +2 -2
  257. data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +1 -1
  258. data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +15 -13
  259. data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +64 -63
  260. data/lib/plugins/inspec-habitat/templates/habitat/hooks/run.erb +3 -3
  261. data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +11 -11
  262. data/lib/plugins/inspec-init/lib/inspec-init.rb +1 -1
  263. data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +6 -8
  264. data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +72 -74
  265. data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +9 -11
  266. data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +4 -4
  267. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -1
  268. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec +0 -2
  269. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -2
  270. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -2
  271. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -2
  272. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -2
  273. data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +6 -7
  274. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +1 -2
  275. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +72 -70
  276. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +1 -1
  277. data/lib/plugins/shared/core_plugin_test_helper.rb +43 -38
  278. data/lib/source_readers/flat.rb +6 -10
  279. data/lib/source_readers/inspec.rb +8 -12
  280. metadata +139 -140
  281. data/lib/resources/mysql.rb +0 -82
  282. data/lib/resources/sys_info.rb +0 -28
  283. data/lib/utils/deprecation.rb +0 -6
  284. data/lib/utils/json_log.rb +0 -18
  285. 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 = 'it'
12
+ itsy = "it"
15
13
  unless its.nil?
16
14
  if its.is_a? Array
17
- itsy = 'its(' + its.inspect + ')'
15
+ itsy = "its(" + its.inspect + ")"
18
16
  else
19
- itsy = 'its(' + its.to_s.inspect + ')'
17
+ itsy = "its(" + its.to_s.inspect + ")"
20
18
  end
21
19
  end
22
- naughty = negated ? '_not' : ''
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
- ' ' + expectation.inspect
27
+ " " + expectation.inspect
30
28
  end
31
- format('%s { should%s %s%s }', itsy, naughty, matcher, xpect)
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 = [['unknown object'.inspect]] if objarr.nil? || objarr.empty?
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] = ['entry']
13
+ t.qualifier[0] = ["entry"]
16
14
  @tests.push(t)
17
15
  t
18
16
  end
@@ -1,6 +1,4 @@
1
- # encoding:utf-8
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 Style/ClassAndModuleCamelCase
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 + '=').to_sym, prop_value)
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?('/lib/inspec/') }
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 Style/ClassAndModuleCamelCase
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::Log.warn(
93
- "Input '#{@name}' does not have a value. "\
94
- "Use --input-file to provide a value for '#{@name}' or specify a "\
95
- "value with `attribute('#{@name}', value: 'somevalue', ...)`.",
96
- ) if Inspec::BaseCLI.inspec_cli_command == :exec
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 || 'attr_' + name.downcase.strip.gsub(/\s+/, '-').gsub(/[^\w-]/, '')
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 == 'Any'
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 == 'Regexp'
374
+ if type_req == "Regexp"
377
375
  invalid_type = true if !valid_regexp?(proposed_value)
378
- elsif type_req == 'Numeric'
376
+ elsif type_req == "Numeric"
379
377
  invalid_type = true if !valid_numeric?(proposed_value)
380
- elsif type_req == 'Boolean'
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
- 'Num' => 'Numeric',
402
- 'Regex' => 'Regexp',
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)
@@ -1,14 +1,12 @@
1
- # encoding:utf-8
2
-
3
1
  module Inspec
4
2
  class List < Value
5
3
  def map
6
- raise 'Inspec::List.map needs to be called with a block' unless block_given?
4
+ raise "Inspec::List.map needs to be called with a block" unless block_given?
7
5
  t = List.new
8
- t.qualifier = [['x']]
6
+ t.qualifier = [["x"]]
9
7
  yield(t)
10
- return if t.qualifier == [['x']]
11
- @qualifier.push(['map', "{ |x| #{t.to_ruby} }"])
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 { |test|
21
+ all_tests = @tests.map do |test|
24
22
  test.negate!
25
23
  test
26
- }.map(&:to_ruby).join("\n")
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] == 'map' && q.length == 2
9
- q[0] + ' ' + q[1]
6
+ elsif q[0] == "map" && q.length == 2
7
+ q[0] + " " + q[1]
10
8
  else
11
- q[0] + '(' + q[1..-1].map(&:inspect).join(', ') + ')'
9
+ q[0] + "(" + q[1..-1].map(&:inspect).join(", ") + ")"
12
10
  end
13
11
  end
14
12
  end
@@ -1,5 +1,3 @@
1
- # encoding:utf-8
2
-
3
1
  module Inspec
4
2
  class Tag
5
3
  attr_accessor :key, :value
@@ -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?('[') && !last_call.empty?
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 += '.' + ruby_qualifier(last) unless last_call.empty?
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? ? 'it' : 'its(' + xtra.to_s.inspect + ')'
69
- naughty = @negated ? '_not' : ''
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
- ' ' + expectation.inspect
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)
@@ -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? ? '' : "#{@variable} = "
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('a'..'z').find { |x| !cache.include?(x) }
20
+ @variable = Array("a".."z").find { |x| !cache.include?(x) }
23
21
  cache.push(@variable)
24
22
  @variable
25
23
  end
@@ -1,2 +1,2 @@
1
- require 'inspec/plugin/v1/plugins'
2
- require 'inspec/plugin/v1/registry'
1
+ require "inspec/plugin/v1/plugins"
2
+ require "inspec/plugin/v1/registry"
@@ -1,8 +1,4 @@
1
- # encoding: utf-8
2
- # author: Christoph Hartmann
3
- # author: Dominik Richter
4
-
5
- require 'inspec/plugin/v1/registry'
1
+ require "inspec/plugin/v1/registry"
6
2
 
7
3
  module Inspec
8
4
  module Plugins
@@ -1,8 +1,5 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
- require 'inspec/file_provider'
5
- require 'inspec/plugin/v1/registry'
1
+ require "inspec/file_provider"
2
+ require "inspec/plugin/v1/registry"
6
3
 
7
4
  module Inspec
8
5
  module Plugins
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
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 'inspec/plugin/v2'
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 #{@__resource_name__.capitalize} is not supported on platform #{inspec.platform.name}/#{inspec.platform.release}."
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?('aws_')
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,8 +1,4 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'inspec/plugin/v1/registry'
1
+ require "inspec/plugin/v1/registry"
6
2
 
7
3
  module Inspec
8
4
  module Plugins
@@ -1,8 +1,4 @@
1
- # encoding: utf-8
2
- # author: Dominik Richter
3
- # author: Christoph Hartmann
4
-
5
- require 'inspec/plugin/v1/registry'
1
+ require "inspec/plugin/v1/registry"
6
2
 
7
3
  module Inspec
8
4
  module Plugins
@@ -1,19 +1,15 @@
1
- # encoding: utf-8
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, 'inspec/plugin/v1/plugin_types/resource'
13
- autoload :CLI, 'inspec/plugin/v1/plugin_types/cli'
14
- autoload :Fetcher, 'inspec/plugin/v1/plugin_types/fetcher'
15
- autoload :SourceReader, 'inspec/plugin/v1/plugin_types/source_reader'
16
- autoload :Secret, 'inspec/plugin/v1/plugin_types/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+'/inspec-*-*/lib/inspec-*rb']
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, 'plugins')
38
- @paths += Dir[File.join(@home, '**{,/*/**}', '*.gemspec')]
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, 'lib', 'inspec-*.rb')] }
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, '..', 'bundles', 'inspec-*.rb')].flatten
41
+ @paths += Dir[File.join(bundled_dir, "..", "bundles", "inspec-*.rb")].flatten
46
42
 
47
43
  # map paths to names
48
- @registry = Hash[@paths.map { |x|
49
- [File.basename(x, '.rb'), 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)