inspec 4.3.2 → 4.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +36 -38
  3. data/README.md +37 -21
  4. data/etc/deprecations.json +10 -0
  5. data/etc/plugin_filters.json +8 -0
  6. data/inspec.gemspec +38 -39
  7. data/lib/bundles/inspec-compliance/api.rb +1 -1
  8. data/lib/bundles/inspec-compliance/configuration.rb +1 -1
  9. data/lib/bundles/inspec-compliance/http.rb +1 -1
  10. data/lib/bundles/inspec-compliance/support.rb +1 -1
  11. data/lib/bundles/inspec-compliance/target.rb +1 -1
  12. data/lib/bundles/inspec-supermarket.rb +3 -7
  13. data/lib/bundles/inspec-supermarket/api.rb +10 -13
  14. data/lib/bundles/inspec-supermarket/cli.rb +12 -15
  15. data/lib/bundles/inspec-supermarket/target.rb +7 -11
  16. data/lib/fetchers/git.rb +14 -15
  17. data/lib/fetchers/local.rb +6 -10
  18. data/lib/fetchers/mock.rb +3 -5
  19. data/lib/fetchers/url.rb +42 -44
  20. data/lib/inspec.rb +23 -24
  21. data/lib/inspec/archive/tar.rb +2 -6
  22. data/lib/inspec/archive/zip.rb +3 -7
  23. data/lib/inspec/backend.rb +8 -9
  24. data/lib/inspec/base_cli.rb +64 -65
  25. data/lib/inspec/cached_fetcher.rb +2 -3
  26. data/lib/inspec/cli.rb +136 -97
  27. data/lib/inspec/config.rb +71 -61
  28. data/lib/inspec/control_eval_context.rb +22 -18
  29. data/lib/inspec/dependencies/cache.rb +2 -3
  30. data/lib/inspec/dependencies/dependency_set.rb +2 -3
  31. data/lib/inspec/dependencies/lockfile.rb +8 -9
  32. data/lib/inspec/dependencies/requirement.rb +7 -8
  33. data/lib/inspec/dependencies/resolver.rb +5 -7
  34. data/lib/inspec/describe.rb +2 -6
  35. data/lib/inspec/dist.rb +20 -0
  36. data/lib/inspec/dsl.rb +4 -7
  37. data/lib/inspec/dsl_shared.rb +1 -2
  38. data/lib/inspec/env_printer.rb +11 -12
  39. data/lib/inspec/errors.rb +0 -4
  40. data/lib/inspec/exceptions.rb +0 -1
  41. data/lib/inspec/expect.rb +5 -8
  42. data/lib/inspec/fetcher.rb +7 -10
  43. data/lib/inspec/file_provider.rb +24 -24
  44. data/lib/inspec/formatters.rb +3 -3
  45. data/lib/inspec/formatters/base.rb +8 -8
  46. data/lib/inspec/globals.rb +2 -2
  47. data/lib/inspec/impact.rb +5 -7
  48. data/lib/inspec/input_registry.rb +84 -33
  49. data/lib/inspec/library_eval_context.rb +3 -6
  50. data/lib/inspec/log.rb +1 -5
  51. data/lib/inspec/metadata.rb +17 -16
  52. data/lib/inspec/method_source.rb +5 -9
  53. data/lib/inspec/objects.rb +10 -12
  54. data/lib/inspec/objects/control.rb +7 -9
  55. data/lib/inspec/objects/describe.rb +9 -11
  56. data/lib/inspec/objects/each_loop.rb +1 -3
  57. data/lib/inspec/objects/input.rb +24 -26
  58. data/lib/inspec/objects/list.rb +4 -6
  59. data/lib/inspec/objects/or_test.rb +2 -4
  60. data/lib/inspec/objects/ruby_helper.rb +3 -5
  61. data/lib/inspec/objects/tag.rb +0 -2
  62. data/lib/inspec/objects/test.rb +9 -11
  63. data/lib/inspec/objects/value.rb +3 -5
  64. data/lib/inspec/plugin/v1.rb +2 -2
  65. data/lib/inspec/plugin/v1/plugin_types/cli.rb +1 -5
  66. data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +2 -5
  67. data/lib/inspec/plugin/v1/plugin_types/resource.rb +4 -6
  68. data/lib/inspec/plugin/v1/plugin_types/secret.rb +1 -5
  69. data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +1 -5
  70. data/lib/inspec/plugin/v1/plugins.rb +15 -19
  71. data/lib/inspec/plugin/v1/registry.rb +0 -4
  72. data/lib/inspec/plugin/v2.rb +8 -8
  73. data/lib/inspec/plugin/v2/activator.rb +1 -1
  74. data/lib/inspec/plugin/v2/config_file.rb +6 -6
  75. data/lib/inspec/plugin/v2/filter.rb +13 -13
  76. data/lib/inspec/plugin/v2/installer.rb +36 -24
  77. data/lib/inspec/plugin/v2/loader.rb +28 -28
  78. data/lib/inspec/plugin/v2/plugin_base.rb +15 -2
  79. data/lib/inspec/plugin/v2/plugin_types/cli.rb +5 -5
  80. data/lib/inspec/plugin/v2/plugin_types/input.rb +34 -0
  81. data/lib/inspec/plugin/v2/plugin_types/mock.rb +1 -1
  82. data/lib/inspec/plugin/v2/registry.rb +7 -7
  83. data/lib/inspec/polyfill.rb +0 -3
  84. data/lib/inspec/profile.rb +55 -63
  85. data/lib/inspec/profile_context.rb +27 -30
  86. data/lib/inspec/profile_vendor.rb +6 -9
  87. data/lib/inspec/reporters.rb +24 -24
  88. data/lib/inspec/reporters/automate.rb +17 -19
  89. data/lib/inspec/reporters/base.rb +1 -1
  90. data/lib/inspec/reporters/cli.rb +88 -91
  91. data/lib/inspec/reporters/json.rb +2 -4
  92. data/lib/inspec/reporters/json_automate.rb +1 -3
  93. data/lib/inspec/reporters/json_min.rb +1 -3
  94. data/lib/inspec/reporters/junit.rb +26 -28
  95. data/lib/inspec/reporters/yaml.rb +1 -3
  96. data/lib/inspec/require_loader.rb +0 -4
  97. data/lib/inspec/resource.rb +4 -125
  98. data/lib/inspec/resources.rb +121 -0
  99. data/lib/{resources → inspec/resources}/aide_conf.rb +24 -25
  100. data/lib/{resources → inspec/resources}/apache.rb +13 -14
  101. data/lib/{resources → inspec/resources}/apache_conf.rb +16 -17
  102. data/lib/{resources → inspec/resources}/apt.rb +17 -17
  103. data/lib/{resources → inspec/resources}/audit_policy.rb +7 -6
  104. data/lib/{resources → inspec/resources}/auditd.rb +62 -64
  105. data/lib/{resources → inspec/resources}/auditd_conf.rb +7 -8
  106. data/lib/{resources → inspec/resources}/bash.rb +6 -8
  107. data/lib/{resources → inspec/resources}/bond.rb +15 -14
  108. data/lib/{resources → inspec/resources}/bridge.rb +8 -8
  109. data/lib/{resources → inspec/resources}/chocolatey_package.rb +10 -8
  110. data/lib/{resources → inspec/resources}/command.rb +11 -10
  111. data/lib/{resources → inspec/resources}/cpan.rb +12 -12
  112. data/lib/{resources → inspec/resources}/cran.rb +9 -9
  113. data/lib/{resources → inspec/resources}/crontab.rb +47 -48
  114. data/lib/{resources → inspec/resources}/csv.rb +5 -5
  115. data/lib/{resources → inspec/resources}/dh_params.rb +5 -7
  116. data/lib/{resources → inspec/resources}/directory.rb +5 -7
  117. data/lib/{resources → inspec/resources}/docker.rb +63 -63
  118. data/lib/{resources → inspec/resources}/docker_container.rb +6 -6
  119. data/lib/{resources → inspec/resources}/docker_image.rb +9 -9
  120. data/lib/{resources → inspec/resources}/docker_object.rb +8 -13
  121. data/lib/{resources → inspec/resources}/docker_plugin.rb +6 -6
  122. data/lib/{resources → inspec/resources}/docker_service.rb +7 -7
  123. data/lib/{resources → inspec/resources}/elasticsearch.rb +40 -42
  124. data/lib/{resources → inspec/resources}/etc_fstab.rb +23 -24
  125. data/lib/{resources → inspec/resources}/etc_group.rb +26 -27
  126. data/lib/{resources → inspec/resources}/etc_hosts.rb +11 -13
  127. data/lib/{resources → inspec/resources}/etc_hosts_allow_deny.rb +25 -27
  128. data/lib/{resources → inspec/resources}/file.rb +80 -79
  129. data/lib/{resources → inspec/resources}/filesystem.rb +20 -15
  130. data/lib/{resources → inspec/resources}/firewalld.rb +26 -26
  131. data/lib/{resources → inspec/resources}/gem.rb +12 -12
  132. data/lib/{resources → inspec/resources}/groups.rb +28 -27
  133. data/lib/{resources → inspec/resources}/grub_conf.rb +46 -48
  134. data/lib/{resources → inspec/resources}/host.rb +31 -29
  135. data/lib/{resources → inspec/resources}/http.rb +24 -24
  136. data/lib/{resources → inspec/resources}/iis_app.rb +6 -7
  137. data/lib/{resources → inspec/resources}/iis_app_pool.rb +21 -19
  138. data/lib/{resources → inspec/resources}/iis_site.rb +17 -15
  139. data/lib/{resources → inspec/resources}/inetd_conf.rb +9 -10
  140. data/lib/{resources → inspec/resources}/ini.rb +7 -8
  141. data/lib/{resources → inspec/resources}/interface.rb +30 -30
  142. data/lib/{resources → inspec/resources}/iptables.rb +8 -8
  143. data/lib/{resources → inspec/resources}/json.rb +8 -10
  144. data/lib/{resources → inspec/resources}/kernel_module.rb +15 -15
  145. data/lib/{resources → inspec/resources}/kernel_parameter.rb +8 -8
  146. data/lib/{resources → inspec/resources}/key_rsa.rb +8 -10
  147. data/lib/{resources → inspec/resources}/ksh.rb +6 -8
  148. data/lib/{resources → inspec/resources}/limits_conf.rb +8 -9
  149. data/lib/{resources/login_def.rb → inspec/resources/login_defs.rb} +9 -10
  150. data/lib/{resources → inspec/resources}/mount.rb +6 -8
  151. data/lib/{resources → inspec/resources}/mssql_session.rb +16 -18
  152. data/lib/inspec/resources/mysql.rb +81 -0
  153. data/lib/{resources → inspec/resources}/mysql_conf.rb +13 -14
  154. data/lib/{resources → inspec/resources}/mysql_session.rb +16 -16
  155. data/lib/{resources → inspec/resources}/nginx.rb +16 -17
  156. data/lib/{resources → inspec/resources}/nginx_conf.rb +26 -27
  157. data/lib/{resources → inspec/resources}/npm.rb +9 -10
  158. data/lib/{resources → inspec/resources}/ntp_conf.rb +9 -10
  159. data/lib/{resources → inspec/resources}/oneget.rb +8 -8
  160. data/lib/{resources → inspec/resources}/oracledb_session.rb +33 -34
  161. data/lib/{resources → inspec/resources}/os.rb +6 -8
  162. data/lib/{resources → inspec/resources}/os_env.rb +11 -12
  163. data/lib/{resources → inspec/resources}/package.rb +66 -65
  164. data/lib/{resources → inspec/resources}/packages.rb +13 -13
  165. data/lib/{resources → inspec/resources}/parse_config.rb +8 -8
  166. data/lib/{resources → inspec/resources}/passwd.rb +18 -19
  167. data/lib/{resources → inspec/resources}/pip.rb +19 -19
  168. data/lib/{resources → inspec/resources}/platform.rb +9 -11
  169. data/lib/{resources → inspec/resources}/port.rb +134 -136
  170. data/lib/{resources → inspec/resources}/postgres.rb +40 -32
  171. data/lib/{resources → inspec/resources}/postgres_conf.rb +17 -17
  172. data/lib/{resources → inspec/resources}/postgres_hba_conf.rb +21 -23
  173. data/lib/{resources → inspec/resources}/postgres_ident_conf.rb +12 -14
  174. data/lib/{resources → inspec/resources}/postgres_session.rb +8 -9
  175. data/lib/{resources → inspec/resources}/powershell.rb +17 -13
  176. data/lib/{resources → inspec/resources}/processes.rb +29 -29
  177. data/lib/{resources/rabbitmq_conf.rb → inspec/resources/rabbitmq_config.rb} +10 -11
  178. data/lib/{resources → inspec/resources}/registry_key.rb +14 -14
  179. data/lib/inspec/resources/script.rb +1 -0
  180. data/lib/{resources → inspec/resources}/security_identifier.rb +11 -10
  181. data/lib/{resources → inspec/resources}/security_policy.rb +59 -58
  182. data/lib/{resources → inspec/resources}/service.rb +74 -75
  183. data/lib/{resources → inspec/resources}/shadow.rb +44 -45
  184. data/lib/{resources/ssh_conf.rb → inspec/resources/ssh_config.rb} +16 -17
  185. data/lib/{resources → inspec/resources}/ssl.rb +28 -29
  186. data/lib/inspec/resources/sys_info.rb +30 -0
  187. data/lib/{resources → inspec/resources}/toml.rb +5 -7
  188. data/lib/{resources → inspec/resources}/users.rb +65 -65
  189. data/lib/{resources → inspec/resources}/vbscript.rb +8 -9
  190. data/lib/{resources → inspec/resources}/virtualization.rb +60 -62
  191. data/lib/{resources → inspec/resources}/windows_feature.rb +9 -9
  192. data/lib/{resources → inspec/resources}/windows_hotfix.rb +5 -5
  193. data/lib/{resources → inspec/resources}/windows_task.rb +16 -15
  194. data/lib/{resources → inspec/resources}/wmi.rb +7 -8
  195. data/lib/{resources → inspec/resources}/x509_certificate.rb +9 -11
  196. data/lib/{resources/xinetd.rb → inspec/resources/xinetd_conf.rb} +27 -29
  197. data/lib/{resources → inspec/resources}/xml.rb +7 -7
  198. data/lib/{resources → inspec/resources}/yaml.rb +5 -6
  199. data/lib/{resources → inspec/resources}/yum.rb +10 -10
  200. data/lib/{resources → inspec/resources}/zfs_dataset.rb +6 -6
  201. data/lib/{resources → inspec/resources}/zfs_pool.rb +4 -4
  202. data/lib/inspec/rspec_extensions.rb +24 -8
  203. data/lib/inspec/rule.rb +14 -15
  204. data/lib/inspec/runner.rb +28 -28
  205. data/lib/inspec/runner_mock.rb +1 -5
  206. data/lib/inspec/runner_rspec.rb +18 -20
  207. data/lib/inspec/runtime_profile.rb +2 -5
  208. data/lib/inspec/schema.rb +142 -143
  209. data/lib/inspec/secrets.rb +3 -7
  210. data/lib/inspec/secrets/yaml.rb +3 -5
  211. data/lib/inspec/shell.rb +11 -15
  212. data/lib/inspec/shell_detector.rb +6 -7
  213. data/lib/inspec/source_reader.rb +4 -8
  214. data/lib/inspec/ui.rb +33 -39
  215. data/lib/inspec/ui_table_helper.rb +12 -0
  216. data/lib/{utils → inspec/utils}/command_wrapper.rb +4 -8
  217. data/lib/{utils → inspec/utils}/convert.rb +0 -4
  218. data/lib/{utils → inspec/utils}/database_helpers.rb +4 -8
  219. data/lib/inspec/utils/deprecation.rb +6 -0
  220. data/lib/{utils → inspec/utils}/deprecation/config_file.rb +19 -19
  221. data/lib/{utils → inspec/utils}/deprecation/deprecator.rb +12 -12
  222. data/lib/{utils → inspec/utils}/deprecation/errors.rb +1 -1
  223. data/lib/{utils → inspec/utils}/deprecation/global_method.rb +2 -2
  224. data/lib/{utils → inspec/utils}/enumerable_delegation.rb +0 -2
  225. data/lib/{utils → inspec/utils}/erlang_parser.rb +61 -65
  226. data/lib/{utils → inspec/utils}/file_reader.rb +1 -2
  227. data/lib/{utils → inspec/utils}/filter.rb +30 -33
  228. data/lib/{utils → inspec/utils}/filter_array.rb +0 -2
  229. data/lib/{utils → inspec/utils}/find_files.rb +9 -12
  230. data/lib/{utils → inspec/utils}/hash.rb +1 -5
  231. data/lib/inspec/utils/json_log.rb +15 -0
  232. data/lib/inspec/utils/latest_version.rb +13 -0
  233. data/lib/{utils → inspec/utils}/modulator.rb +0 -3
  234. data/lib/{utils → inspec/utils}/nginx_parser.rb +31 -35
  235. data/lib/{utils → inspec/utils}/object_traversal.rb +0 -3
  236. data/lib/{utils → inspec/utils}/parser.rb +45 -45
  237. data/lib/{utils → inspec/utils}/pkey_reader.rb +4 -2
  238. data/lib/{utils → inspec/utils}/simpleconfig.rb +8 -10
  239. data/lib/{utils → inspec/utils}/spdx.rb +1 -4
  240. data/lib/{utils → inspec/utils}/spdx.txt +0 -0
  241. data/lib/inspec/utils/telemetry.rb +3 -3
  242. data/lib/inspec/utils/telemetry/collector.rb +30 -9
  243. data/lib/inspec/utils/telemetry/data_series.rb +3 -1
  244. data/lib/inspec/utils/telemetry/global_methods.rb +1 -1
  245. data/lib/inspec/version.rb +1 -1
  246. data/lib/matchers/matchers.rb +22 -25
  247. data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +1 -1
  248. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +52 -45
  249. data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +18 -16
  250. data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +12 -11
  251. data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +1 -1
  252. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +73 -73
  253. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +66 -62
  254. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +59 -57
  255. data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +11 -11
  256. data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +20 -22
  257. data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +2 -4
  258. data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +30 -27
  259. data/lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb +12 -14
  260. data/lib/plugins/inspec-compliance/test/integration/default/cli.rb +39 -41
  261. data/lib/plugins/inspec-compliance/test/unit/api/login_test.rb +64 -64
  262. data/lib/plugins/inspec-compliance/test/unit/api_test.rb +157 -156
  263. data/lib/plugins/inspec-compliance/test/unit/target_test.rb +85 -85
  264. data/lib/plugins/inspec-habitat/Berksfile +2 -2
  265. data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +1 -1
  266. data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +15 -13
  267. data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +64 -63
  268. data/lib/plugins/inspec-habitat/templates/habitat/hooks/run.erb +3 -3
  269. data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +11 -11
  270. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile +1 -1
  271. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb +8 -8
  272. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb +17 -17
  273. data/lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb +9 -8
  274. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb +14 -14
  275. data/lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb +4 -4
  276. data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +42 -41
  277. data/lib/plugins/inspec-init/lib/inspec-init.rb +1 -1
  278. data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +6 -8
  279. data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +72 -74
  280. data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +9 -11
  281. data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +4 -4
  282. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -1
  283. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec +0 -2
  284. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -2
  285. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -2
  286. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -2
  287. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -2
  288. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +5 -5
  289. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +1 -3
  290. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +2 -2
  291. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +2 -2
  292. data/lib/plugins/inspec-init/templates/profiles/aws/controls/example.rb +10 -11
  293. data/lib/plugins/inspec-init/templates/profiles/azure/controls/example.rb +4 -5
  294. data/lib/plugins/inspec-init/templates/profiles/gcp/controls/example.rb +10 -11
  295. data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +6 -7
  296. data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +51 -50
  297. data/lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb +35 -33
  298. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +1 -2
  299. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +72 -70
  300. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +1 -1
  301. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +1 -1
  302. data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +281 -271
  303. data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +41 -41
  304. data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +25 -6
  305. data/lib/plugins/shared/core_plugin_test_helper.rb +43 -38
  306. data/lib/resource_support/aws.rb +67 -67
  307. data/lib/resource_support/aws/aws_plural_resource_mixin.rb +4 -1
  308. data/lib/resource_support/aws/aws_resource_mixin.rb +4 -3
  309. data/lib/resource_support/aws/aws_singular_resource_mixin.rb +4 -1
  310. data/lib/resources/aws/aws_billing_report.rb +15 -8
  311. data/lib/resources/aws/aws_billing_reports.rb +10 -7
  312. data/lib/resources/aws/aws_cloudtrail_trail.rb +9 -5
  313. data/lib/resources/aws/aws_cloudtrail_trails.rb +9 -5
  314. data/lib/resources/aws/aws_cloudwatch_alarm.rb +9 -5
  315. data/lib/resources/aws/aws_cloudwatch_log_metric_filter.rb +12 -8
  316. data/lib/resources/aws/aws_config_delivery_channel.rb +13 -9
  317. data/lib/resources/aws/aws_config_recorder.rb +10 -6
  318. data/lib/resources/aws/aws_ebs_volume.rb +12 -8
  319. data/lib/resources/aws/aws_ebs_volumes.rb +9 -5
  320. data/lib/resources/aws/aws_ec2_instance.rb +14 -11
  321. data/lib/resources/aws/aws_ec2_instances.rb +9 -5
  322. data/lib/resources/aws/aws_ecs_cluster.rb +11 -7
  323. data/lib/resources/aws/aws_eks_cluster.rb +13 -9
  324. data/lib/resources/aws/aws_elb.rb +9 -5
  325. data/lib/resources/aws/aws_elbs.rb +9 -5
  326. data/lib/resources/aws/aws_flow_log.rb +17 -13
  327. data/lib/resources/aws/aws_iam_access_key.rb +15 -11
  328. data/lib/resources/aws/aws_iam_access_keys.rb +19 -15
  329. data/lib/resources/aws/aws_iam_group.rb +9 -5
  330. data/lib/resources/aws/aws_iam_groups.rb +9 -5
  331. data/lib/resources/aws/aws_iam_password_policy.rb +13 -10
  332. data/lib/resources/aws/aws_iam_policies.rb +9 -5
  333. data/lib/resources/aws/aws_iam_policy.rb +16 -12
  334. data/lib/resources/aws/aws_iam_role.rb +9 -5
  335. data/lib/resources/aws/aws_iam_root_user.rb +12 -8
  336. data/lib/resources/aws/aws_iam_user.rb +12 -12
  337. data/lib/resources/aws/aws_iam_users.rb +10 -10
  338. data/lib/resources/aws/aws_kms_key.rb +12 -8
  339. data/lib/resources/aws/aws_kms_keys.rb +9 -5
  340. data/lib/resources/aws/aws_rds_instance.rb +11 -8
  341. data/lib/resources/aws/aws_route_table.rb +11 -7
  342. data/lib/resources/aws/aws_route_tables.rb +10 -6
  343. data/lib/resources/aws/aws_s3_bucket.rb +14 -11
  344. data/lib/resources/aws/aws_s3_bucket_object.rb +12 -9
  345. data/lib/resources/aws/aws_s3_buckets.rb +9 -7
  346. data/lib/resources/aws/aws_security_group.rb +16 -12
  347. data/lib/resources/aws/aws_security_groups.rb +12 -8
  348. data/lib/resources/aws/aws_sns_subscription.rb +15 -11
  349. data/lib/resources/aws/aws_sns_topic.rb +10 -6
  350. data/lib/resources/aws/aws_sns_topics.rb +9 -5
  351. data/lib/resources/aws/aws_sqs_queue.rb +18 -14
  352. data/lib/resources/aws/aws_subnet.rb +11 -7
  353. data/lib/resources/aws/aws_subnets.rb +9 -5
  354. data/lib/resources/aws/aws_vpc.rb +10 -6
  355. data/lib/resources/aws/aws_vpcs.rb +9 -5
  356. data/lib/resources/azure/azure_backend.rb +20 -18
  357. data/lib/resources/azure/azure_generic_resource.rb +13 -15
  358. data/lib/resources/azure/azure_resource_group.rb +17 -19
  359. data/lib/resources/azure/azure_virtual_machine.rb +6 -8
  360. data/lib/resources/azure/azure_virtual_machine_data_disk.rb +6 -8
  361. data/lib/source_readers/flat.rb +6 -10
  362. data/lib/source_readers/inspec.rb +8 -12
  363. metadata +141 -142
  364. data/lib/resources/mysql.rb +0 -82
  365. data/lib/resources/sys_info.rb +0 -28
  366. data/lib/utils/deprecation.rb +0 -6
  367. data/lib/utils/json_log.rb +0 -18
  368. data/lib/utils/latest_version.rb +0 -22
@@ -1,32 +1,31 @@
1
- # encoding: utf-8
2
1
  # copyright: 2015, Dominik Richter
3
- # author: Dominik Richter
4
- # author: Christoph Hartmann
5
2
 
6
3
  libdir = File.dirname(__FILE__)
7
4
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
8
5
 
9
- require 'inspec/version'
10
- require 'inspec/exceptions'
11
- require 'utils/deprecation'
12
- require 'inspec/profile'
13
- require 'inspec/rule'
14
- require 'matchers/matchers'
15
- require 'inspec/runner'
16
- require 'inspec/shell'
17
- require 'inspec/formatters'
18
- require 'inspec/reporters'
19
- require 'inspec/input_registry'
20
- require 'inspec/rspec_extensions'
21
- require 'inspec/globals'
22
- require 'inspec/impact'
23
- require 'inspec/utils/telemetry'
6
+ require "inspec/version"
7
+ require "inspec/exceptions"
8
+ require "inspec/utils/deprecation"
9
+ require "inspec/profile"
10
+ require "inspec/rule"
11
+ require "matchers/matchers"
12
+ require "inspec/runner"
13
+ require "inspec/shell"
14
+ require "inspec/formatters"
15
+ require "inspec/reporters"
16
+ require "inspec/input_registry"
17
+ require "inspec/rspec_extensions"
18
+ require "inspec/globals"
19
+ require "inspec/impact"
20
+ require "inspec/utils/telemetry"
21
+ require "inspec/utils/telemetry/global_methods"
24
22
 
25
- require 'inspec/plugin/v2'
26
- require 'inspec/plugin/v1'
23
+ require "inspec/plugin/v2"
24
+ require "inspec/plugin/v1"
27
25
 
28
26
  # all utils that may be required by legacy plugins
29
- require 'inspec/base_cli'
30
- require 'inspec/fetcher'
31
- require 'inspec/source_reader'
32
- require 'inspec/resource'
27
+ require "inspec/base_cli"
28
+ require "inspec/fetcher"
29
+ require "inspec/source_reader"
30
+ require "inspec/resource"
31
+ require "inspec/resources"
@@ -1,13 +1,9 @@
1
- # encoding: utf-8
2
- # author: Christoph Hartmann
3
- # author: Dominik Richter
4
-
5
- require 'rubygems/package'
1
+ require "rubygems/package"
6
2
 
7
3
  module Inspec::Archive
8
4
  class TarArchiveGenerator
9
5
  def archive(base_dir, files, archive)
10
- File.open(archive, 'wb') do |file|
6
+ File.open(archive, "wb") do |file|
11
7
  Zlib::GzipWriter.wrap(file) do |gz|
12
8
  Gem::Package::TarWriter.new(gz) do |tar|
13
9
  files.each do |input_filename|
@@ -1,10 +1,6 @@
1
- # encoding: utf-8
2
- # author: Christoph Hartmann
3
- # author: Dominik Richter
4
-
5
- require 'rubygems'
6
- require 'zip'
7
- require 'pathname'
1
+ require "rubygems"
2
+ require "zip"
3
+ require "pathname"
8
4
 
9
5
  module Inspec::Archive
10
6
  class ZipArchiveGenerator
@@ -1,10 +1,9 @@
1
- # encoding: utf-8
2
1
  # copyright: 2015, Dominik Richter
3
- # author: Dominik Richter
4
- # author: Christoph Hartmann
5
2
 
6
- require 'train'
7
- require 'inspec/config'
3
+ require "train"
4
+ require "inspec/config"
5
+ require "inspec/version"
6
+ require "inspec/resource"
8
7
 
9
8
  module Inspec
10
9
  module Backend
@@ -28,7 +27,7 @@ module Inspec
28
27
 
29
28
  # Ruby internal for printing a nice name for this class
30
29
  def to_s
31
- 'Inspec::Backend::Class'
30
+ "Inspec::Backend::Class"
32
31
  end
33
32
 
34
33
  # Ruby internal for pretty-printing a summary for this class
@@ -57,15 +56,15 @@ module Inspec
57
56
  # Set caching settings. We always want to enable caching for
58
57
  # the Mock transport for testing.
59
58
  if config[:backend_cache] || config[:backend] == :mock
60
- Inspec::Log.debug 'Option backend_cache is enabled'
59
+ Inspec::Log.debug "Option backend_cache is enabled"
61
60
  connection.enable_cache(:file)
62
61
  connection.enable_cache(:command)
63
62
  elsif config[:debug_shell]
64
- Inspec::Log.debug 'Option backend_cache is disabled'
63
+ Inspec::Log.debug "Option backend_cache is disabled"
65
64
  connection.disable_cache(:file)
66
65
  connection.disable_cache(:command)
67
66
  else
68
- Inspec::Log.debug 'Option backend_cache is disabled'
67
+ Inspec::Log.debug "Option backend_cache is disabled"
69
68
  connection.disable_cache(:file)
70
69
  connection.disable_cache(:command)
71
70
  end
@@ -1,11 +1,8 @@
1
- # encoding: utf-8
2
- # author: Christoph Hartmann
3
- # author: Dominik Richter
4
-
5
- require 'thor'
6
- require 'inspec/log'
7
- require 'inspec/profile_vendor'
8
- require 'inspec/ui'
1
+ require "thor"
2
+ require "inspec/log"
3
+ require "inspec/ui"
4
+ require "inspec/config"
5
+ require "inspec/utils/deprecation/global_method"
9
6
 
10
7
  # Allow end of options during array type parsing
11
8
  # https://github.com/erikhuda/thor/issues/631
@@ -34,107 +31,107 @@ module Inspec
34
31
 
35
32
  def self.target_options # rubocop:disable MethodLength
36
33
  option :target, aliases: :t, type: :string,
37
- desc: 'Simple targeting option using URIs, e.g. ssh://user:pass@host:port'
34
+ desc: "Simple targeting option using URIs, e.g. ssh://user:pass@host:port"
38
35
  option :backend, aliases: :b, type: :string,
39
- desc: 'Choose a backend: local, ssh, winrm, docker.'
36
+ desc: "Choose a backend: local, ssh, winrm, docker."
40
37
  option :host, type: :string,
41
- desc: 'Specify a remote host which is tested.'
38
+ desc: "Specify a remote host which is tested."
42
39
  option :port, aliases: :p, type: :numeric,
43
- desc: 'Specify the login port for a remote scan.'
40
+ desc: "Specify the login port for a remote scan."
44
41
  option :user, type: :string,
45
- desc: 'The login user for a remote scan.'
42
+ desc: "The login user for a remote scan."
46
43
  option :password, type: :string, lazy_default: -1,
47
- desc: 'Login password for a remote scan, if required.'
44
+ desc: "Login password for a remote scan, if required."
48
45
  option :enable_password, type: :string, lazy_default: -1,
49
- desc: 'Password for enable mode on Cisco IOS devices.'
46
+ desc: "Password for enable mode on Cisco IOS devices."
50
47
  option :key_files, aliases: :i, type: :array,
51
- desc: 'Login key or certificate file for a remote scan.'
48
+ desc: "Login key or certificate file for a remote scan."
52
49
  option :path, type: :string,
53
- desc: 'Login path to use when connecting to the target (WinRM).'
50
+ desc: "Login path to use when connecting to the target (WinRM)."
54
51
  option :sudo, type: :boolean,
55
- desc: 'Run scans with sudo. Only activates on Unix and non-root user.'
52
+ desc: "Run scans with sudo. Only activates on Unix and non-root user."
56
53
  option :sudo_password, type: :string, lazy_default: -1,
57
- desc: 'Specify a sudo password, if it is required.'
54
+ desc: "Specify a sudo password, if it is required."
58
55
  option :sudo_options, type: :string,
59
- desc: 'Additional sudo options for a remote scan.'
56
+ desc: "Additional sudo options for a remote scan."
60
57
  option :sudo_command, type: :string,
61
- desc: 'Alternate command for sudo.'
58
+ desc: "Alternate command for sudo."
62
59
  option :shell, type: :boolean,
63
- desc: 'Run scans in a subshell. Only activates on Unix.'
60
+ desc: "Run scans in a subshell. Only activates on Unix."
64
61
  option :shell_options, type: :string,
65
- desc: 'Additional shell options.'
62
+ desc: "Additional shell options."
66
63
  option :shell_command, type: :string,
67
- desc: 'Specify a particular shell to use.'
64
+ desc: "Specify a particular shell to use."
68
65
  option :ssl, type: :boolean,
69
- desc: 'Use SSL for transport layer encryption (WinRM).'
66
+ desc: "Use SSL for transport layer encryption (WinRM)."
70
67
  option :self_signed, type: :boolean,
71
- desc: 'Allow remote scans with self-signed certificates (WinRM).'
72
- option :winrm_transport, type: :string, default: 'negotiate',
73
- desc: 'Specify which transport to use, defaults to negotiate (WinRM).'
68
+ desc: "Allow remote scans with self-signed certificates (WinRM)."
69
+ option :winrm_transport, type: :string, default: "negotiate",
70
+ desc: "Specify which transport to use, defaults to negotiate (WinRM)."
74
71
  option :winrm_disable_sspi, type: :boolean,
75
- desc: 'Whether to use disable sspi authentication, defaults to false (WinRM).'
72
+ desc: "Whether to use disable sspi authentication, defaults to false (WinRM)."
76
73
  option :winrm_basic_auth, type: :boolean,
77
- desc: 'Whether to use basic authentication, defaults to false (WinRM).'
74
+ desc: "Whether to use basic authentication, defaults to false (WinRM)."
78
75
  option :config, type: :string,
79
- desc: 'Read configuration from JSON file (`-` reads from stdin).'
76
+ desc: "Read configuration from JSON file (`-` reads from stdin)."
80
77
  option :json_config, type: :string, hide: true
81
78
  option :proxy_command, type: :string,
82
- desc: 'Specifies the command to use to connect to the server'
79
+ desc: "Specifies the command to use to connect to the server"
83
80
  option :bastion_host, type: :string,
84
- desc: 'Specifies the bastion host if applicable'
81
+ desc: "Specifies the bastion host if applicable"
85
82
  option :bastion_user, type: :string,
86
- desc: 'Specifies the bastion user if applicable'
83
+ desc: "Specifies the bastion user if applicable"
87
84
  option :bastion_port, type: :string,
88
- desc: 'Specifies the bastion port if applicable'
85
+ desc: "Specifies the bastion port if applicable"
89
86
  option :insecure, type: :boolean, default: false,
90
- desc: 'Disable SSL verification on select targets'
87
+ desc: "Disable SSL verification on select targets"
91
88
  option :target_id, type: :string,
92
- desc: 'Provide a ID which will be included on reports'
89
+ desc: "Provide a ID which will be included on reports"
93
90
  end
94
91
 
95
92
  def self.profile_options
96
93
  option :profiles_path, type: :string,
97
- desc: 'Folder which contains referenced profiles.'
94
+ desc: "Folder which contains referenced profiles."
98
95
  option :vendor_cache, type: :string,
99
- desc: 'Use the given path for caching dependencies. (default: ~/.inspec/cache)'
96
+ desc: "Use the given path for caching dependencies. (default: ~/.inspec/cache)"
100
97
  end
101
98
 
102
99
  def self.exec_options
103
100
  target_options
104
101
  profile_options
105
102
  option :controls, type: :array,
106
- desc: 'A list of control names to run, or a list of /regexes/ to match against control names. Ignore all other tests.'
103
+ desc: "A list of control names to run, or a list of /regexes/ to match against control names. Ignore all other tests."
107
104
  option :reporter, type: :array,
108
- banner: 'one two:/output/file/path',
109
- desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit, yaml'
105
+ banner: "one two:/output/file/path",
106
+ desc: "Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit, yaml"
110
107
  option :input_file, type: :array,
111
- desc: 'Load one or more input files, a YAML file with values for the profile to use'
108
+ desc: "Load one or more input files, a YAML file with values for the profile to use"
112
109
  option :attrs, type: :array,
113
- desc: 'Legacy name for --input-file - deprecated.'
110
+ desc: "Legacy name for --input-file - deprecated."
114
111
  option :create_lockfile, type: :boolean,
115
- desc: 'Write out a lockfile based on this execution (unless one already exists)'
112
+ desc: "Write out a lockfile based on this execution (unless one already exists)"
116
113
  option :backend_cache, type: :boolean,
117
- desc: 'Allow caching for backend command output. (default: true)'
114
+ desc: "Allow caching for backend command output. (default: true)"
118
115
  option :show_progress, type: :boolean,
119
- desc: 'Show progress while executing tests.'
116
+ desc: "Show progress while executing tests."
120
117
  option :distinct_exit, type: :boolean, default: true,
121
- desc: 'Exit with code 101 if any tests fail, and 100 if any are skipped (default). If disabled, exit 0 on skips and 1 for failures.'
118
+ desc: "Exit with code 101 if any tests fail, and 100 if any are skipped (default). If disabled, exit 0 on skips and 1 for failures."
122
119
  end
123
120
 
124
121
  def self.format_platform_info(params: {}, indent: 0, color: 39)
125
- str = ''
126
- params.each { |item, info|
122
+ str = ""
123
+ params.each do |item, info|
127
124
  data = info
128
125
 
129
126
  # Format Array for better output if applicable
130
- data = data.join(', ') if data.is_a?(Array)
127
+ data = data.join(", ") if data.is_a?(Array)
131
128
 
132
129
  # Do not output fields of data is missing ('unknown' is fine)
133
130
  next if data.nil?
134
131
 
135
132
  data = "\e[1m\e[#{color}m#{data}\e[0m"
136
- str << format("#{' ' * indent}%-10s %s\n", item.to_s.capitalize + ':', data)
137
- }
133
+ str << format("#{' ' * indent}%-10s %s\n", item.to_s.capitalize + ":", data)
134
+ end
138
135
  str
139
136
  end
140
137
 
@@ -193,12 +190,12 @@ module Inspec
193
190
  private
194
191
 
195
192
  def suppress_log_output?(opts)
196
- return false if opts['reporter'].nil?
197
- match = %w{json json-min json-rspec json-automate junit html yaml documentation progress} & opts['reporter'].keys
193
+ return false if opts["reporter"].nil?
194
+ match = %w{json json-min json-rspec json-automate junit html yaml documentation progress} & opts["reporter"].keys
198
195
  unless match.empty?
199
196
  match.each do |m|
200
197
  # check to see if we are outputting to stdout
201
- return true if opts['reporter'][m]['stdout'] == true
198
+ return true if opts["reporter"][m]["stdout"] == true
202
199
  end
203
200
  end
204
201
  false
@@ -220,7 +217,7 @@ module Inspec
220
217
  if valid.include?(level)
221
218
  l = level
222
219
  else
223
- l = 'info'
220
+ l = "info"
224
221
  end
225
222
 
226
223
  Logger.const_get(l.upcase)
@@ -237,11 +234,13 @@ module Inspec
237
234
  end
238
235
 
239
236
  def vendor_deps(path, opts)
237
+ require "inspec/profile_vendor"
238
+
240
239
  profile_path = path || Dir.pwd
241
240
  profile_vendor = Inspec::ProfileVendor.new(profile_path)
242
241
 
243
242
  if (profile_vendor.cache_path.exist? || profile_vendor.lockfile.exist?) && !opts[:overwrite]
244
- puts 'Profile is already vendored. Use --overwrite.'
243
+ puts "Profile is already vendored. Use --overwrite."
245
244
  return false
246
245
  end
247
246
 
@@ -257,23 +256,23 @@ module Inspec
257
256
  # logging singleton Inspec::Log. Eventually it would be nice to
258
257
  # move internal debug logging to use this logging singleton.
259
258
  #
260
- loc = if o['log_location']
261
- o['log_location']
259
+ loc = if o["log_location"]
260
+ o["log_location"]
262
261
  elsif suppress_log_output?(o)
263
- STDERR
262
+ $stderr
264
263
  else
265
- STDOUT
264
+ $stdout
266
265
  end
267
266
 
268
267
  Inspec::Log.init(loc)
269
- Inspec::Log.level = get_log_level(o['log_level'])
268
+ Inspec::Log.level = get_log_level(o["log_level"])
270
269
 
271
270
  o[:logger] = Logger.new(loc)
272
271
  # output json if we have activated the json formatter
273
- if o['log-format'] == 'json'
272
+ if o["log-format"] == "json"
274
273
  o[:logger].formatter = Logger::JSONFormatter.new
275
274
  end
276
- o[:logger].level = get_log_level(o['log_level'])
275
+ o[:logger].level = get_log_level(o["log_level"])
277
276
  end
278
277
  end
279
278
  end
@@ -1,6 +1,5 @@
1
- # encoding: utf-8
2
- require 'inspec/fetcher'
3
- require 'forwardable'
1
+ require "inspec/fetcher"
2
+ require "forwardable"
4
3
 
5
4
  module Inspec
6
5
  class CachedFetcher
@@ -1,57 +1,75 @@
1
- # encoding: utf-8
2
1
  # Copyright 2015 Dominik Richter
3
- # author: Dominik Richter
4
- # author: Christoph Hartmann
5
-
6
- require 'logger'
7
- require 'thor'
8
- require 'json'
9
- require 'pp'
10
- require 'utils/json_log'
11
- require 'utils/latest_version'
12
- require 'inspec/base_cli'
13
- require 'inspec/plugin/v1'
14
- require 'inspec/plugin/v2'
15
- require 'inspec/runner_mock'
16
- require 'inspec/env_printer'
17
- require 'inspec/schema'
18
- require 'inspec/config'
2
+
3
+ require "inspec/utils/deprecation/deprecator"
4
+ require "inspec/dist"
5
+ require "inspec/backend"
6
+ require "inspec/dependencies/cache"
7
+
8
+ module Inspec # TODO: move this somewhere "better"?
9
+ autoload :BaseCLI, "inspec/base_cli"
10
+ autoload :Deprecation, "inspec/utils/deprecation"
11
+ autoload :Exceptions, "inspec/exceptions"
12
+ autoload :Fetcher, "inspec/fetcher"
13
+ autoload :Formatters, "inspec/formatters"
14
+ autoload :Globals, "inspec/globals"
15
+ autoload :Impact, "inspec/impact"
16
+ autoload :Impact, "inspec/impact"
17
+ autoload :InputRegistry, "inspec/input_registry"
18
+ autoload :Profile, "inspec/profile"
19
+ autoload :Reporters, "inspec/reporters"
20
+ autoload :Resource, "inspec/resource"
21
+ autoload :Rule, "inspec/rule"
22
+ autoload :Runner, "inspec/runner"
23
+ autoload :Runner, "inspec/runner"
24
+ autoload :Shell, "inspec/shell"
25
+ autoload :SourceReader, "inspec/source_reader"
26
+ autoload :Telemetry, "inspec/utils/telemetry"
27
+ autoload :V1, "inspec/plugin/v1"
28
+ autoload :V2, "inspec/plugin/v2"
29
+ autoload :VERSION, "inspec/version"
30
+ end
19
31
 
20
32
  class Inspec::InspecCLI < Inspec::BaseCLI
21
33
  class_option :log_level, aliases: :l, type: :string,
22
- desc: 'Set the log level: info (default), debug, warn, error'
34
+ desc: "Set the log level: info (default), debug, warn, error"
23
35
 
24
36
  class_option :log_location, type: :string,
25
- desc: 'Location to send diagnostic log messages to. (default: STDOUT or Inspec::Log.error)'
37
+ desc: "Location to send diagnostic log messages to. (default: $stdout or Inspec::Log.error)"
26
38
 
27
39
  class_option :diagnose, type: :boolean,
28
- desc: 'Show diagnostics (versions, configurations)'
40
+ desc: "Show diagnostics (versions, configurations)"
29
41
 
30
42
  class_option :color, type: :boolean,
31
- desc: 'Use colors in output.'
43
+ desc: "Use colors in output."
32
44
 
33
45
  class_option :interactive, type: :boolean,
34
- desc: 'Allow or disable user interaction'
46
+ desc: "Allow or disable user interaction"
35
47
 
36
- class_option :disable_core_plugins, type: :string, banner: '', # Actually a boolean, but this suppresses the creation of a --no-disable...
37
- desc: 'Disable loading all plugins that are shipped in the lib/plugins directory of InSpec. Useful in development.'
48
+ class_option :disable_core_plugins, type: :string, banner: "", # Actually a boolean, but this suppresses the creation of a --no-disable...
49
+ desc: "Disable loading all plugins that are shipped in the lib/plugins directory of InSpec. Useful in development."
38
50
 
39
- class_option :disable_user_plugins, type: :string, banner: '',
40
- desc: 'Disable loading all plugins that the user installed.'
51
+ class_option :disable_user_plugins, type: :string, banner: "",
52
+ desc: "Disable loading all plugins that the user installed."
41
53
 
42
- require 'license_acceptance/cli_flags/thor'
54
+ class_option :enable_telemetry, type: :boolean,
55
+ desc: "Allow or disable telemetry", default: false
56
+
57
+ require "license_acceptance/cli_flags/thor"
43
58
  include LicenseAcceptance::CLIFlags::Thor
44
59
 
45
- desc 'json PATH', 'read all tests in PATH and generate a JSON summary'
60
+ desc "json PATH", "read all tests in PATH and generate a JSON summary"
46
61
  option :output, aliases: :o, type: :string,
47
- desc: 'Save the created profile to a path'
62
+ desc: "Save the created profile to a path"
48
63
  option :controls, type: :array,
49
- desc: 'A list of controls to include. Ignore all other tests.'
64
+ desc: "A list of controls to include. Ignore all other tests."
50
65
  profile_options
51
66
  def json(target)
67
+ require "inspec/resources"
68
+ require "json"
69
+
52
70
  o = config
53
71
  diagnose(o)
54
- o['log_location'] = STDERR
72
+ o["log_location"] = $stderr
55
73
  configure_logger(o)
56
74
 
57
75
  o[:backend] = Inspec::Backend.create(Inspec::Config.mock)
@@ -62,7 +80,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
62
80
  info = profile.info
63
81
  # add in inspec version
64
82
  info[:generator] = {
65
- name: 'inspec',
83
+ name: "inspec",
66
84
  version: Inspec::VERSION,
67
85
  }
68
86
  dst = o[:output].to_s
@@ -81,12 +99,18 @@ class Inspec::InspecCLI < Inspec::BaseCLI
81
99
  pretty_handle_exception(e)
82
100
  end
83
101
 
84
- desc 'check PATH', 'verify all tests at the specified PATH'
102
+ desc "check PATH", "verify all tests at the specified PATH"
85
103
  option :format, type: :string
86
104
  profile_options
87
- def check(path) # rubocop:disable Metrics/AbcSize
105
+ def check(path) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
106
+ require "inspec/resources"
107
+
88
108
  o = config
89
109
  diagnose(o)
110
+ o["log_location"] ||= STDERR if o["format"] == "json"
111
+ o["log_level"] ||= "warn"
112
+ configure_logger(o)
113
+
90
114
  o[:backend] = Inspec::Backend.create(Inspec::Config.mock)
91
115
  o[:check_mode] = true
92
116
  o[:vendor_cache] = Inspec::Cache.new(o[:vendor_cache])
@@ -95,25 +119,25 @@ class Inspec::InspecCLI < Inspec::BaseCLI
95
119
  profile = Inspec::Profile.for_target(path, o)
96
120
  result = profile.check
97
121
 
98
- if o['format'] == 'json'
122
+ if o["format"] == "json"
99
123
  puts JSON.generate(result)
100
124
  else
101
125
  %w{location profile controls timestamp valid}.each do |item|
102
- puts format('%-12s %s', item.to_s.capitalize + ':',
126
+ puts format("%-12s %s", item.to_s.capitalize + ":",
103
127
  mark_text(result[:summary][item.to_sym]))
104
128
  end
105
129
  puts
106
130
 
107
- if result[:errors].empty? and result[:warnings].empty?
108
- puts 'No errors or warnings'
131
+ if result[:errors].empty? && result[:warnings].empty?
132
+ puts "No errors or warnings"
109
133
  else
110
134
  red = "\033[31m"
111
135
  yellow = "\033[33m"
112
136
  rst = "\033[0m"
113
137
 
114
138
  item_msg = lambda { |item|
115
- pos = [item[:file], item[:line], item[:column]].compact.join(':')
116
- pos.empty? ? item[:msg] : pos + ': ' + item[:msg]
139
+ pos = [item[:file], item[:line], item[:column]].compact.join(":")
140
+ pos.empty? ? item[:msg] : pos + ": " + item[:msg]
117
141
  }
118
142
  result[:errors].each do |item|
119
143
  puts "#{red} ✖ #{item_msg.call(item)}#{rst}"
@@ -123,7 +147,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
123
147
  end
124
148
 
125
149
  puts
126
- puts format('Summary: %s%d errors%s, %s%d warnings%s',
150
+ puts format("Summary: %s%d errors%s, %s%d warnings%s",
127
151
  red, result[:errors].length, rst,
128
152
  yellow, result[:warnings].length, rst)
129
153
  end
@@ -133,35 +157,39 @@ class Inspec::InspecCLI < Inspec::BaseCLI
133
157
  pretty_handle_exception(e)
134
158
  end
135
159
 
136
- desc 'vendor PATH', 'Download all dependencies and generate a lockfile in a `vendor` directory'
160
+ desc "vendor PATH", "Download all dependencies and generate a lockfile in a `vendor` directory"
137
161
  option :overwrite, type: :boolean, default: false,
138
- desc: 'Overwrite existing vendored dependencies and lockfile.'
162
+ desc: "Overwrite existing vendored dependencies and lockfile."
139
163
  def vendor(path = nil)
164
+ require "inspec/resources"
165
+
140
166
  o = config
141
167
  configure_logger(o)
142
- o[:logger] = Logger.new(STDOUT)
168
+ o[:logger] = Logger.new($stdout)
143
169
  o[:logger].level = get_log_level(o[:log_level])
144
170
 
145
171
  vendor_deps(path, o)
146
172
  end
147
173
 
148
- desc 'archive PATH', 'archive a profile to tar.gz (default) or zip'
174
+ desc "archive PATH", "archive a profile to tar.gz (default) or zip"
149
175
  profile_options
150
176
  option :output, aliases: :o, type: :string,
151
- desc: 'Save the archive to a path'
177
+ desc: "Save the archive to a path"
152
178
  option :zip, type: :boolean, default: false,
153
- desc: 'Generates a zip archive.'
179
+ desc: "Generates a zip archive."
154
180
  option :tar, type: :boolean, default: false,
155
- desc: 'Generates a tar.gz archive.'
181
+ desc: "Generates a tar.gz archive."
156
182
  option :overwrite, type: :boolean, default: false,
157
- desc: 'Overwrite existing archive.'
183
+ desc: "Overwrite existing archive."
158
184
  option :ignore_errors, type: :boolean, default: false,
159
- desc: 'Ignore profile warnings.'
185
+ desc: "Ignore profile warnings."
160
186
  def archive(path)
187
+ require "inspec/resources"
188
+
161
189
  o = config
162
190
  diagnose(o)
163
191
 
164
- o[:logger] = Logger.new(STDOUT)
192
+ o[:logger] = Logger.new($stdout)
165
193
  o[:logger].level = get_log_level(o[:log_level])
166
194
  o[:backend] = Inspec::Backend.create(Inspec::Config.mock)
167
195
 
@@ -174,7 +202,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
174
202
  result = profile.check
175
203
 
176
204
  if result && !o[:ignore_errors] == false
177
- o[:logger].info 'Profile check failed. Please fix the profile before generating an archive.'
205
+ o[:logger].info "Profile check failed. Please fix the profile before generating an archive."
178
206
  return exit 1
179
207
  end
180
208
 
@@ -184,7 +212,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
184
212
  pretty_handle_exception(e)
185
213
  end
186
214
 
187
- desc 'exec LOCATIONS', 'run all test files at the specified LOCATIONS.'
215
+ desc "exec LOCATIONS", "run all test files at the specified LOCATIONS."
188
216
  # TODO: find a way for Thor not to butcher the formatting of this
189
217
  long_desc <<~EOT
190
218
  Loads the given profile(s) and fetches their dependencies if needed. Then
@@ -206,55 +234,55 @@ class Inspec::InspecCLI < Inspec::BaseCLI
206
234
 
207
235
  Automate:
208
236
  ```
209
- inspec compliance login
210
- inspec exec compliance://username/linux-baseline
237
+ #{Inspec::Dist::EXEC_NAME} compliance login
238
+ #{Inspec::Dist::EXEC_NAME} exec compliance://username/linux-baseline
211
239
  ```
212
240
 
213
241
  Supermarket:
214
242
  ```
215
- inspec exec supermarket://username/linux-baseline
243
+ #{Inspec::Dist::EXEC_NAME} exec supermarket://username/linux-baseline
216
244
  ```
217
245
 
218
246
  Local profile (executes all tests in `controls/`):
219
247
  ```
220
- inspec exec /path/to/profile
248
+ #{Inspec::Dist::EXEC_NAME} exec /path/to/profile
221
249
  ```
222
250
 
223
251
  Local single test (doesn't allow inputs or custom resources)
224
252
  ```
225
- inspec exec /path/to/a_test.rb
253
+ #{Inspec::Dist::EXEC_NAME} exec /path/to/a_test.rb
226
254
  ```
227
255
 
228
256
  Git via SSH
229
257
  ```
230
- inspec exec git@github.com:dev-sec/linux-baseline.git
258
+ #{Inspec::Dist::EXEC_NAME} exec git@github.com:dev-sec/linux-baseline.git
231
259
  ```
232
260
 
233
261
  Git via HTTPS (.git suffix is required):
234
262
  ```
235
- inspec exec https://github.com/dev-sec/linux-baseline.git
263
+ #{Inspec::Dist::EXEC_NAME} exec https://github.com/dev-sec/linux-baseline.git
236
264
  ```
237
265
 
238
266
  Private Git via HTTPS (.git suffix is required):
239
267
  ```
240
- inspec exec https://API_TOKEN@github.com/dev-sec/linux-baseline.git
268
+ #{Inspec::Dist::EXEC_NAME} exec https://API_TOKEN@github.com/dev-sec/linux-baseline.git
241
269
  ```
242
270
 
243
271
  Private Git via HTTPS and cached credentials (.git suffix is required):
244
272
  ```
245
273
  git config credential.helper cache
246
274
  git ls-remote https://github.com/dev-sec/linux-baseline.git
247
- inspec exec https://github.com/dev-sec/linux-baseline.git
275
+ #{Inspec::Dist::EXEC_NAME} exec https://github.com/dev-sec/linux-baseline.git
248
276
  ```
249
277
 
250
278
  Web hosted fileshare (also supports .zip):
251
279
  ```
252
- inspec exec https://webserver/linux-baseline.tar.gz
280
+ #{Inspec::Dist::EXEC_NAME} exec https://webserver/linux-baseline.tar.gz
253
281
  ```
254
282
 
255
283
  Web hosted fileshare with basic authentication (supports .zip):
256
284
  ```
257
- inspec exec https://username:password@webserver/linux-baseline.tar.gz
285
+ #{Inspec::Dist::EXEC_NAME} exec https://username:password@webserver/linux-baseline.tar.gz
258
286
  ```
259
287
  EOT
260
288
  exec_options
@@ -274,17 +302,17 @@ class Inspec::InspecCLI < Inspec::BaseCLI
274
302
  pretty_handle_exception(e)
275
303
  end
276
304
 
277
- desc 'detect', 'detect the target OS'
305
+ desc "detect", "detect the target OS"
278
306
  target_options
279
307
  option :format, type: :string
280
308
  def detect
281
309
  o = config
282
- o[:command] = 'platform.params'
310
+ o[:command] = "platform.params"
283
311
  (_, res) = run_command(o)
284
- if o['format'] == 'json'
312
+ if o["format"] == "json"
285
313
  puts res.to_json
286
314
  else
287
- headline('Platform Details')
315
+ headline("Platform Details")
288
316
  puts Inspec::BaseCLI.format_platform_info(params: res, indent: 0, color: 36)
289
317
  end
290
318
  rescue ArgumentError, RuntimeError, Train::UserError => e
@@ -294,23 +322,23 @@ class Inspec::InspecCLI < Inspec::BaseCLI
294
322
  pretty_handle_exception(e)
295
323
  end
296
324
 
297
- desc 'shell', 'open an interactive debugging shell'
325
+ desc "shell", "open an interactive debugging shell"
298
326
  target_options
299
327
  option :command, aliases: :c,
300
- desc: 'A single command string to run instead of launching the shell'
328
+ desc: "A single command string to run instead of launching the shell"
301
329
  option :reporter, type: :array,
302
- banner: 'one two:/output/file/path',
303
- desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit'
330
+ banner: "one two:/output/file/path",
331
+ desc: "Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit"
304
332
  option :depends, type: :array, default: [],
305
- desc: 'A space-delimited list of local folders containing profiles whose libraries and resources will be loaded into the new shell'
333
+ desc: "A space-delimited list of local folders containing profiles whose libraries and resources will be loaded into the new shell"
306
334
  option :distinct_exit, type: :boolean, default: true,
307
- desc: 'Exit with code 100 if any tests fail, and 101 if any are skipped but none failed (default). If disabled, exit 0 on skips and 1 for failures.'
335
+ desc: "Exit with code 100 if any tests fail, and 101 if any are skipped but none failed (default). If disabled, exit 0 on skips and 1 for failures."
308
336
  def shell_func
309
337
  o = config
310
338
  diagnose(o)
311
339
  o[:debug_shell] = true
312
340
 
313
- log_device = suppress_log_output?(o) ? nil : STDOUT
341
+ log_device = suppress_log_output?(o) ? nil : $stdout
314
342
  o[:logger] = Logger.new(log_device)
315
343
  o[:logger].level = get_log_level(o[:log_level])
316
344
 
@@ -323,7 +351,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
323
351
  exit res unless run_type == :ruby_eval
324
352
 
325
353
  # No InSpec tests - just print evaluation output.
326
- res = (res.respond_to?(:to_json) ? res.to_json : JSON.dump(res)) if o['reporter']&.keys&.include?('json')
354
+ res = (res.respond_to?(:to_json) ? res.to_json : JSON.dump(res)) if o["reporter"]&.keys&.include?("json")
327
355
  puts res
328
356
  exit 0
329
357
  rescue RuntimeError, Train::UserError => e
@@ -332,7 +360,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI
332
360
  pretty_handle_exception(e)
333
361
  end
334
362
 
335
- desc 'env', 'Output shell-appropriate completion configuration'
363
+ desc "env", "Output shell-appropriate completion configuration"
336
364
  def env(shell = nil)
337
365
  p = Inspec::EnvPrinter.new(self.class, shell)
338
366
  p.print_and_exit!
@@ -340,31 +368,40 @@ class Inspec::InspecCLI < Inspec::BaseCLI
340
368
  pretty_handle_exception(e)
341
369
  end
342
370
 
343
- desc 'schema NAME', 'print the JSON schema', hide: true
371
+ desc "schema NAME", "print the JSON schema", hide: true
344
372
  def schema(name)
373
+ require "inspec/schema"
374
+
345
375
  puts Inspec::Schema.json(name)
346
376
  rescue StandardError => e
347
377
  puts e
348
378
  puts "Valid schemas are #{Inspec::Schema.names.join(', ')}"
349
379
  end
350
380
 
351
- desc 'version', 'prints the version of this tool'
381
+ desc "version", "prints the version of this tool"
352
382
  option :format, type: :string
353
383
  def version
354
- if config['format'] == 'json'
384
+ if config["format"] == "json"
355
385
  v = { version: Inspec::VERSION }
356
386
  puts v.to_json
357
387
  else
388
+ require "inspec/utils/latest_version"
358
389
  puts Inspec::VERSION
359
390
  # display outdated version
360
- latest = LatestInSpecVersion.new.latest
391
+ # TODO: remove this. Don't notify of update to a gem when they install omnibus
392
+ latest = LatestInSpecVersion.new.latest || Inspec::VERSION
361
393
  if Gem::Version.new(Inspec::VERSION) < Gem::Version.new(latest)
362
- puts "\nYour version of InSpec is out of date! The latest version is #{latest}."
394
+ puts "\nYour version of #{Inspec::Dist::PRODUCT_NAME} is out of date! The latest version is #{latest}."
363
395
  end
364
396
  end
365
397
  end
366
398
  map %w{-v --version} => :version
367
399
 
400
+ desc "nothing", "does nothing"
401
+ def nothing
402
+ puts "you did nothing"
403
+ end
404
+
368
405
  private
369
406
 
370
407
  def run_command(opts)
@@ -381,25 +418,25 @@ end
381
418
  # Pre-Flight Code
382
419
  #=====================================================================#
383
420
 
384
- help_commands = ['-h', '--help', 'help']
385
- version_commands = ['-v', '--version', 'version']
421
+ help_commands = ["-h", "--help", "help"]
422
+ version_commands = ["-v", "--version", "version"]
386
423
  commands_exempt_from_license_check = help_commands + version_commands
387
424
 
388
425
  #---------------------------------------------------------------------#
389
426
  # EULA acceptance
390
427
  #---------------------------------------------------------------------#
391
- require 'license_acceptance/acceptor'
428
+ require "license_acceptance/acceptor"
392
429
  begin
393
- if (commands_exempt_from_license_check & ARGV.map(&:downcase)).empty? && # Did they use a non-exempt command?
394
- !ARGV.empty? # Did they supply at least one command?
430
+ if (commands_exempt_from_license_check & ARGV.map(&:downcase)).empty? && # Did they use a non-exempt command?
431
+ !ARGV.empty? # Did they supply at least one command?
395
432
  LicenseAcceptance::Acceptor.check_and_persist(
396
- 'inspec',
433
+ "inspec",
397
434
  Inspec::VERSION,
398
- logger: Inspec::Log,
435
+ logger: Inspec::Log
399
436
  )
400
437
  end
401
438
  rescue LicenseAcceptance::LicenseNotAcceptedError
402
- Inspec::Log.error 'InSpec cannot execute without accepting the license'
439
+ Inspec::Log.error "InSpec cannot execute without accepting the license"
403
440
  Inspec::UI.new.exit(:license_not_accepted)
404
441
  end
405
442
 
@@ -418,10 +455,12 @@ end
418
455
  #---------------------------------------------------------------------#
419
456
  # Plugin Loading
420
457
  #---------------------------------------------------------------------#
458
+ require "inspec/plugin/v2"
459
+
421
460
  begin
422
461
  # Load v2 plugins. Manually check for plugin disablement.
423
- omit_core = ARGV.delete('--disable-core-plugins')
424
- omit_user = ARGV.delete('--disable-user-plugins')
462
+ omit_core = ARGV.delete("--disable-core-plugins")
463
+ omit_user = ARGV.delete("--disable-user-plugins")
425
464
  v2_loader = Inspec::Plugin::V2::Loader.new(omit_core_plugins: omit_core, omit_user_plugins: omit_user)
426
465
  v2_loader.load_all
427
466
  v2_loader.exit_on_load_error
@@ -432,23 +471,23 @@ begin
432
471
  ctl.list.each { |x| ctl.load(x) }
433
472
 
434
473
  # load v1 CLI plugins before the InSpec CLI has been started
435
- Inspec::Plugins::CLI.subcommands.each { |_subcommand, params|
474
+ Inspec::Plugins::CLI.subcommands.each do |_subcommand, params|
436
475
  Inspec::InspecCLI.register(
437
476
  params[:klass],
438
477
  params[:subcommand_name],
439
478
  params[:usage],
440
479
  params[:description],
441
- params[:options],
480
+ params[:options]
442
481
  )
443
- }
482
+ end
444
483
  rescue Inspec::Plugin::V2::Exception => v2ex
445
484
  Inspec::Log.error v2ex.message
446
485
 
447
- if ARGV.include?('--debug')
486
+ if ARGV.include?("--debug")
448
487
  Inspec::Log.error v2ex.class.name
449
488
  Inspec::Log.error v2ex.backtrace.join("\n")
450
489
  else
451
- Inspec::Log.error 'Run again with --debug for a stacktrace.'
490
+ Inspec::Log.error "Run again with --debug for a stacktrace."
452
491
  end
453
492
  exit 2
454
493
  end