inspec 4.18.51 → 4.18.85

Sign up to get free protection for your applications and to get access to all the features.
Files changed (371) hide show
  1. checksums.yaml +4 -4
  2. data/inspec.gemspec +15 -37
  3. data/lib/resource_support/aws/aws_resource_mixin.rb +1 -1
  4. metadata +22 -709
  5. data/Gemfile +0 -61
  6. data/LICENSE +0 -14
  7. data/README.md +0 -474
  8. data/etc/deprecations.json +0 -125
  9. data/etc/plugin_filters.json +0 -45
  10. data/lib/bundles/README.md +0 -3
  11. data/lib/bundles/inspec-compliance/api.rb +0 -7
  12. data/lib/bundles/inspec-compliance/configuration.rb +0 -7
  13. data/lib/bundles/inspec-compliance/http.rb +0 -7
  14. data/lib/bundles/inspec-compliance/support.rb +0 -7
  15. data/lib/bundles/inspec-compliance/target.rb +0 -7
  16. data/lib/bundles/inspec-supermarket.rb +0 -9
  17. data/lib/bundles/inspec-supermarket/README.md +0 -45
  18. data/lib/bundles/inspec-supermarket/api.rb +0 -87
  19. data/lib/bundles/inspec-supermarket/cli.rb +0 -71
  20. data/lib/bundles/inspec-supermarket/target.rb +0 -31
  21. data/lib/inspec.rb +0 -30
  22. data/lib/inspec/archive/tar.rb +0 -25
  23. data/lib/inspec/archive/zip.rb +0 -15
  24. data/lib/inspec/backend.rb +0 -101
  25. data/lib/inspec/base_cli.rb +0 -318
  26. data/lib/inspec/cached_fetcher.rb +0 -65
  27. data/lib/inspec/cli.rb +0 -469
  28. data/lib/inspec/completions/bash.sh.erb +0 -45
  29. data/lib/inspec/completions/fish.sh.erb +0 -34
  30. data/lib/inspec/completions/zsh.sh.erb +0 -61
  31. data/lib/inspec/config.rb +0 -511
  32. data/lib/inspec/control_eval_context.rb +0 -248
  33. data/lib/inspec/dependencies/cache.rb +0 -74
  34. data/lib/inspec/dependencies/dependency_set.rb +0 -93
  35. data/lib/inspec/dependencies/lockfile.rb +0 -115
  36. data/lib/inspec/dependencies/requirement.rb +0 -135
  37. data/lib/inspec/dependencies/resolver.rb +0 -86
  38. data/lib/inspec/describe_base.rb +0 -53
  39. data/lib/inspec/dist.rb +0 -20
  40. data/lib/inspec/dsl.rb +0 -115
  41. data/lib/inspec/dsl_shared.rb +0 -32
  42. data/lib/inspec/env_printer.rb +0 -156
  43. data/lib/inspec/errors.rb +0 -18
  44. data/lib/inspec/exceptions.rb +0 -11
  45. data/lib/inspec/expect.rb +0 -42
  46. data/lib/inspec/fetcher.rb +0 -48
  47. data/lib/inspec/fetcher/git.rb +0 -211
  48. data/lib/inspec/fetcher/local.rb +0 -116
  49. data/lib/inspec/fetcher/mock.rb +0 -34
  50. data/lib/inspec/fetcher/url.rb +0 -281
  51. data/lib/inspec/file_provider.rb +0 -318
  52. data/lib/inspec/formatters.rb +0 -3
  53. data/lib/inspec/formatters/base.rb +0 -269
  54. data/lib/inspec/formatters/json_rspec.rb +0 -20
  55. data/lib/inspec/formatters/show_progress.rb +0 -12
  56. data/lib/inspec/globals.rb +0 -9
  57. data/lib/inspec/impact.rb +0 -36
  58. data/lib/inspec/input.rb +0 -421
  59. data/lib/inspec/input_dsl_helpers.rb +0 -26
  60. data/lib/inspec/input_registry.rb +0 -315
  61. data/lib/inspec/library_eval_context.rb +0 -55
  62. data/lib/inspec/log.rb +0 -7
  63. data/lib/inspec/metadata.rb +0 -253
  64. data/lib/inspec/method_source.rb +0 -20
  65. data/lib/inspec/objects.rb +0 -14
  66. data/lib/inspec/objects/control.rb +0 -85
  67. data/lib/inspec/objects/describe.rb +0 -106
  68. data/lib/inspec/objects/each_loop.rb +0 -41
  69. data/lib/inspec/objects/input.rb +0 -49
  70. data/lib/inspec/objects/list.rb +0 -15
  71. data/lib/inspec/objects/or_test.rb +0 -45
  72. data/lib/inspec/objects/ruby_helper.rb +0 -13
  73. data/lib/inspec/objects/tag.rb +0 -32
  74. data/lib/inspec/objects/test.rb +0 -94
  75. data/lib/inspec/objects/value.rb +0 -32
  76. data/lib/inspec/plugin/v1.rb +0 -2
  77. data/lib/inspec/plugin/v1/plugin_types/cli.rb +0 -22
  78. data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +0 -83
  79. data/lib/inspec/plugin/v1/plugin_types/resource.rb +0 -176
  80. data/lib/inspec/plugin/v1/plugin_types/secret.rb +0 -11
  81. data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +0 -36
  82. data/lib/inspec/plugin/v1/plugins.rb +0 -59
  83. data/lib/inspec/plugin/v1/registry.rb +0 -90
  84. data/lib/inspec/plugin/v2.rb +0 -46
  85. data/lib/inspec/plugin/v2/activator.rb +0 -40
  86. data/lib/inspec/plugin/v2/config_file.rb +0 -151
  87. data/lib/inspec/plugin/v2/filter.rb +0 -96
  88. data/lib/inspec/plugin/v2/installer.rb +0 -512
  89. data/lib/inspec/plugin/v2/loader.rb +0 -321
  90. data/lib/inspec/plugin/v2/plugin_base.rb +0 -112
  91. data/lib/inspec/plugin/v2/plugin_types/cli.rb +0 -49
  92. data/lib/inspec/plugin/v2/plugin_types/dsl.rb +0 -11
  93. data/lib/inspec/plugin/v2/plugin_types/input.rb +0 -34
  94. data/lib/inspec/plugin/v2/plugin_types/mock.rb +0 -12
  95. data/lib/inspec/plugin/v2/registry.rb +0 -98
  96. data/lib/inspec/plugin/v2/status.rb +0 -29
  97. data/lib/inspec/profile.rb +0 -658
  98. data/lib/inspec/profile_context.rb +0 -203
  99. data/lib/inspec/profile_vendor.rb +0 -84
  100. data/lib/inspec/reporters.rb +0 -73
  101. data/lib/inspec/reporters/automate.rb +0 -78
  102. data/lib/inspec/reporters/base.rb +0 -25
  103. data/lib/inspec/reporters/cli.rb +0 -370
  104. data/lib/inspec/reporters/json.rb +0 -113
  105. data/lib/inspec/reporters/json_automate.rb +0 -80
  106. data/lib/inspec/reporters/json_min.rb +0 -48
  107. data/lib/inspec/reporters/junit.rb +0 -77
  108. data/lib/inspec/reporters/yaml.rb +0 -20
  109. data/lib/inspec/require_loader.rb +0 -29
  110. data/lib/inspec/resource.rb +0 -114
  111. data/lib/inspec/resources.rb +0 -130
  112. data/lib/inspec/resources/aide_conf.rb +0 -153
  113. data/lib/inspec/resources/apache.rb +0 -47
  114. data/lib/inspec/resources/apache_conf.rb +0 -156
  115. data/lib/inspec/resources/apt.rb +0 -151
  116. data/lib/inspec/resources/audit_policy.rb +0 -64
  117. data/lib/inspec/resources/auditd.rb +0 -251
  118. data/lib/inspec/resources/auditd_conf.rb +0 -45
  119. data/lib/inspec/resources/bash.rb +0 -33
  120. data/lib/inspec/resources/bond.rb +0 -70
  121. data/lib/inspec/resources/bridge.rb +0 -125
  122. data/lib/inspec/resources/bsd_service.rb +0 -2
  123. data/lib/inspec/resources/chocolatey_package.rb +0 -82
  124. data/lib/inspec/resources/command.rb +0 -91
  125. data/lib/inspec/resources/cpan.rb +0 -58
  126. data/lib/inspec/resources/cran.rb +0 -64
  127. data/lib/inspec/resources/crontab.rb +0 -173
  128. data/lib/inspec/resources/csv.rb +0 -56
  129. data/lib/inspec/resources/dh_params.rb +0 -83
  130. data/lib/inspec/resources/directory.rb +0 -23
  131. data/lib/inspec/resources/docker.rb +0 -274
  132. data/lib/inspec/resources/docker_container.rb +0 -91
  133. data/lib/inspec/resources/docker_image.rb +0 -84
  134. data/lib/inspec/resources/docker_object.rb +0 -52
  135. data/lib/inspec/resources/docker_plugin.rb +0 -64
  136. data/lib/inspec/resources/docker_service.rb +0 -91
  137. data/lib/inspec/resources/elasticsearch.rb +0 -165
  138. data/lib/inspec/resources/etc_fstab.rb +0 -96
  139. data/lib/inspec/resources/etc_group.rb +0 -157
  140. data/lib/inspec/resources/etc_hosts.rb +0 -68
  141. data/lib/inspec/resources/etc_hosts_allow.rb +0 -2
  142. data/lib/inspec/resources/etc_hosts_allow_deny.rb +0 -114
  143. data/lib/inspec/resources/etc_hosts_deny.rb +0 -2
  144. data/lib/inspec/resources/file.rb +0 -339
  145. data/lib/inspec/resources/filesystem.rb +0 -139
  146. data/lib/inspec/resources/firewalld.rb +0 -148
  147. data/lib/inspec/resources/gem.rb +0 -80
  148. data/lib/inspec/resources/group.rb +0 -2
  149. data/lib/inspec/resources/groups.rb +0 -241
  150. data/lib/inspec/resources/grub_conf.rb +0 -230
  151. data/lib/inspec/resources/host.rb +0 -310
  152. data/lib/inspec/resources/http.rb +0 -275
  153. data/lib/inspec/resources/iis_app.rb +0 -101
  154. data/lib/inspec/resources/iis_app_pool.rb +0 -127
  155. data/lib/inspec/resources/iis_site.rb +0 -148
  156. data/lib/inspec/resources/iis_website.rb +0 -2
  157. data/lib/inspec/resources/inetd_conf.rb +0 -53
  158. data/lib/inspec/resources/ini.rb +0 -28
  159. data/lib/inspec/resources/interface.rb +0 -204
  160. data/lib/inspec/resources/ip6tables.rb +0 -79
  161. data/lib/inspec/resources/iptables.rb +0 -80
  162. data/lib/inspec/resources/json.rb +0 -116
  163. data/lib/inspec/resources/kernel_module.rb +0 -106
  164. data/lib/inspec/resources/kernel_parameter.rb +0 -54
  165. data/lib/inspec/resources/key_rsa.rb +0 -66
  166. data/lib/inspec/resources/ksh.rb +0 -33
  167. data/lib/inspec/resources/launchd_service.rb +0 -2
  168. data/lib/inspec/resources/limits_conf.rb +0 -45
  169. data/lib/inspec/resources/linux_kernel_parameter.rb +0 -2
  170. data/lib/inspec/resources/login_defs.rb +0 -56
  171. data/lib/inspec/resources/mount.rb +0 -88
  172. data/lib/inspec/resources/mssql_session.rb +0 -117
  173. data/lib/inspec/resources/mysql.rb +0 -81
  174. data/lib/inspec/resources/mysql_conf.rb +0 -128
  175. data/lib/inspec/resources/mysql_session.rb +0 -88
  176. data/lib/inspec/resources/nginx.rb +0 -96
  177. data/lib/inspec/resources/nginx_conf.rb +0 -232
  178. data/lib/inspec/resources/noop.rb +0 -9
  179. data/lib/inspec/resources/npm.rb +0 -68
  180. data/lib/inspec/resources/ntp_conf.rb +0 -51
  181. data/lib/inspec/resources/oneget.rb +0 -71
  182. data/lib/inspec/resources/oracledb_session.rb +0 -149
  183. data/lib/inspec/resources/os.rb +0 -34
  184. data/lib/inspec/resources/os_env.rb +0 -86
  185. data/lib/inspec/resources/package.rb +0 -391
  186. data/lib/inspec/resources/packages.rb +0 -111
  187. data/lib/inspec/resources/parse_config.rb +0 -112
  188. data/lib/inspec/resources/parse_config_file.rb +0 -2
  189. data/lib/inspec/resources/passwd.rb +0 -73
  190. data/lib/inspec/resources/pip.rb +0 -132
  191. data/lib/inspec/resources/platform.rb +0 -112
  192. data/lib/inspec/resources/port.rb +0 -791
  193. data/lib/inspec/resources/postfix_conf.rb +0 -35
  194. data/lib/inspec/resources/postgres.rb +0 -152
  195. data/lib/inspec/resources/postgres_conf.rb +0 -116
  196. data/lib/inspec/resources/postgres_hba_conf.rb +0 -86
  197. data/lib/inspec/resources/postgres_ident_conf.rb +0 -75
  198. data/lib/inspec/resources/postgres_session.rb +0 -70
  199. data/lib/inspec/resources/powershell.rb +0 -67
  200. data/lib/inspec/resources/ppa.rb +0 -2
  201. data/lib/inspec/resources/processes.rb +0 -219
  202. data/lib/inspec/resources/rabbitmq_conf.rb +0 -2
  203. data/lib/inspec/resources/rabbitmq_config.rb +0 -52
  204. data/lib/inspec/resources/registry_key.rb +0 -296
  205. data/lib/inspec/resources/runit_service.rb +0 -2
  206. data/lib/inspec/resources/script.rb +0 -1
  207. data/lib/inspec/resources/security_identifier.rb +0 -91
  208. data/lib/inspec/resources/security_policy.rb +0 -182
  209. data/lib/inspec/resources/service.rb +0 -820
  210. data/lib/inspec/resources/shadow.rb +0 -150
  211. data/lib/inspec/resources/ssh_config.rb +0 -98
  212. data/lib/inspec/resources/sshd_config.rb +0 -2
  213. data/lib/inspec/resources/ssl.rb +0 -99
  214. data/lib/inspec/resources/sys_info.rb +0 -119
  215. data/lib/inspec/resources/systemd_service.rb +0 -2
  216. data/lib/inspec/resources/sysv_service.rb +0 -2
  217. data/lib/inspec/resources/toml.rb +0 -30
  218. data/lib/inspec/resources/upstart_service.rb +0 -2
  219. data/lib/inspec/resources/user.rb +0 -1
  220. data/lib/inspec/resources/users.rb +0 -742
  221. data/lib/inspec/resources/vbscript.rb +0 -67
  222. data/lib/inspec/resources/virtualization.rb +0 -255
  223. data/lib/inspec/resources/windows_feature.rb +0 -126
  224. data/lib/inspec/resources/windows_hotfix.rb +0 -37
  225. data/lib/inspec/resources/windows_registry_key.rb +0 -2
  226. data/lib/inspec/resources/windows_task.rb +0 -112
  227. data/lib/inspec/resources/wmi.rb +0 -109
  228. data/lib/inspec/resources/x509_certificate.rb +0 -143
  229. data/lib/inspec/resources/xinetd_conf.rb +0 -103
  230. data/lib/inspec/resources/xml.rb +0 -48
  231. data/lib/inspec/resources/yaml.rb +0 -42
  232. data/lib/inspec/resources/yum.rb +0 -162
  233. data/lib/inspec/resources/zfs_dataset.rb +0 -62
  234. data/lib/inspec/resources/zfs_pool.rb +0 -50
  235. data/lib/inspec/rspec_extensions.rb +0 -116
  236. data/lib/inspec/rule.rb +0 -389
  237. data/lib/inspec/runner.rb +0 -333
  238. data/lib/inspec/runner_mock.rb +0 -37
  239. data/lib/inspec/runner_rspec.rb +0 -184
  240. data/lib/inspec/runtime_profile.rb +0 -23
  241. data/lib/inspec/schema.rb +0 -245
  242. data/lib/inspec/secrets.rb +0 -15
  243. data/lib/inspec/secrets/yaml.rb +0 -29
  244. data/lib/inspec/shell.rb +0 -211
  245. data/lib/inspec/shell_detector.rb +0 -89
  246. data/lib/inspec/source_reader.rb +0 -26
  247. data/lib/inspec/ui.rb +0 -213
  248. data/lib/inspec/ui_table_helper.rb +0 -12
  249. data/lib/inspec/utils/command_wrapper.rb +0 -23
  250. data/lib/inspec/utils/convert.rb +0 -8
  251. data/lib/inspec/utils/database_helpers.rb +0 -75
  252. data/lib/inspec/utils/deprecation.rb +0 -6
  253. data/lib/inspec/utils/deprecation/config_file.rb +0 -109
  254. data/lib/inspec/utils/deprecation/deprecator.rb +0 -118
  255. data/lib/inspec/utils/deprecation/errors.rb +0 -14
  256. data/lib/inspec/utils/deprecation/global_method.rb +0 -9
  257. data/lib/inspec/utils/enumerable_delegation.rb +0 -7
  258. data/lib/inspec/utils/erlang_parser.rb +0 -190
  259. data/lib/inspec/utils/file_reader.rb +0 -24
  260. data/lib/inspec/utils/filter.rb +0 -461
  261. data/lib/inspec/utils/filter_array.rb +0 -25
  262. data/lib/inspec/utils/find_files.rb +0 -44
  263. data/lib/inspec/utils/hash.rb +0 -37
  264. data/lib/inspec/utils/json_log.rb +0 -15
  265. data/lib/inspec/utils/modulator.rb +0 -9
  266. data/lib/inspec/utils/nginx_parser.rb +0 -101
  267. data/lib/inspec/utils/object_traversal.rb +0 -47
  268. data/lib/inspec/utils/parser.rb +0 -277
  269. data/lib/inspec/utils/pkey_reader.rb +0 -17
  270. data/lib/inspec/utils/simpleconfig.rb +0 -121
  271. data/lib/inspec/utils/spdx.rb +0 -10
  272. data/lib/inspec/utils/spdx.txt +0 -383
  273. data/lib/inspec/utils/telemetry.rb +0 -3
  274. data/lib/inspec/utils/telemetry/collector.rb +0 -81
  275. data/lib/inspec/utils/telemetry/data_series.rb +0 -44
  276. data/lib/inspec/utils/telemetry/global_methods.rb +0 -22
  277. data/lib/inspec/version.rb +0 -3
  278. data/lib/matchers/matchers.rb +0 -341
  279. data/lib/plugins/README.md +0 -16
  280. data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +0 -12
  281. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +0 -170
  282. data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +0 -116
  283. data/lib/plugins/inspec-artifact/test/functional/inspec_artifact_test.rb +0 -50
  284. data/lib/plugins/inspec-compliance/README.md +0 -207
  285. data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +0 -12
  286. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +0 -362
  287. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +0 -198
  288. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +0 -269
  289. data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +0 -103
  290. data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +0 -117
  291. data/lib/plugins/inspec-compliance/lib/inspec-compliance/images/cc-token.png +0 -0
  292. data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +0 -34
  293. data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +0 -146
  294. data/lib/plugins/inspec-compliance/test/functional/inspec_compliance_test.rb +0 -53
  295. data/lib/plugins/inspec-compliance/test/integration/default/cli.rb +0 -91
  296. data/lib/plugins/inspec-compliance/test/unit/api/login_test.rb +0 -190
  297. data/lib/plugins/inspec-compliance/test/unit/api_test.rb +0 -386
  298. data/lib/plugins/inspec-compliance/test/unit/target_test.rb +0 -155
  299. data/lib/plugins/inspec-habitat/Berksfile +0 -5
  300. data/lib/plugins/inspec-habitat/README.md +0 -150
  301. data/lib/plugins/inspec-habitat/kitchen.yml +0 -28
  302. data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +0 -11
  303. data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +0 -41
  304. data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +0 -265
  305. data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +0 -6
  306. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/Berksfile +0 -2
  307. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/README.md +0 -3
  308. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/files/hab_setup.exp +0 -28
  309. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/metadata.rb +0 -9
  310. data/lib/plugins/inspec-habitat/test/cookbooks/inspec_habitat_fixture/recipes/default.rb +0 -61
  311. data/lib/plugins/inspec-habitat/test/functional/inspec_habitat_test.rb +0 -34
  312. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/README.md +0 -3
  313. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/controls/inspec_habitat.rb +0 -40
  314. data/lib/plugins/inspec-habitat/test/integration/default/inspec_habitat/inspec.yml +0 -10
  315. data/lib/plugins/inspec-habitat/test/support/example_profile/README.md +0 -3
  316. data/lib/plugins/inspec-habitat/test/support/example_profile/controls/example.rb +0 -7
  317. data/lib/plugins/inspec-habitat/test/support/example_profile/inspec.yml +0 -10
  318. data/lib/plugins/inspec-habitat/test/unit/profile_test.rb +0 -242
  319. data/lib/plugins/inspec-init/README.md +0 -31
  320. data/lib/plugins/inspec-init/lib/inspec-init.rb +0 -12
  321. data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +0 -15
  322. data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +0 -243
  323. data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +0 -47
  324. data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +0 -97
  325. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -11
  326. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/LICENSE +0 -2
  327. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/README.md +0 -28
  328. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Rakefile +0 -40
  329. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -14
  330. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -62
  331. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -53
  332. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -8
  333. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/fixtures/README.md +0 -24
  334. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/README.md +0 -12
  335. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/functional/inspec_plugin_template_test.rb +0 -110
  336. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/helper.rb +0 -24
  337. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/README.md +0 -17
  338. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/cli_args_test.rb +0 -67
  339. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/test/unit/plugin_def_test.rb +0 -51
  340. data/lib/plugins/inspec-init/templates/profiles/aws/libraries/.gitkeep +0 -0
  341. data/lib/plugins/inspec-init/templates/profiles/azure/libraries/.gitkeep +0 -0
  342. data/lib/plugins/inspec-init/templates/profiles/gcp/libraries/.gitkeep +0 -0
  343. data/lib/plugins/inspec-init/templates/profiles/os/README.md +0 -3
  344. data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +0 -18
  345. data/lib/plugins/inspec-init/templates/profiles/os/inspec.yml +0 -10
  346. data/lib/plugins/inspec-init/templates/profiles/os/libraries/.gitkeep +0 -0
  347. data/lib/plugins/inspec-init/test/functional/inspec_init_plugin_test.rb +0 -184
  348. data/lib/plugins/inspec-init/test/functional/inspec_init_profile_test.rb +0 -121
  349. data/lib/plugins/inspec-plugin-manager-cli/README.md +0 -6
  350. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +0 -17
  351. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +0 -518
  352. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +0 -12
  353. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep +0 -0
  354. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb +0 -2
  355. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep +0 -0
  356. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep +0 -0
  357. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +0 -1
  358. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep +0 -0
  359. data/lib/plugins/inspec-plugin-manager-cli/test/functional/help_test.rb +0 -23
  360. data/lib/plugins/inspec-plugin-manager-cli/test/functional/helper.rb +0 -62
  361. data/lib/plugins/inspec-plugin-manager-cli/test/functional/install_test.rb +0 -368
  362. data/lib/plugins/inspec-plugin-manager-cli/test/functional/list_test.rb +0 -101
  363. data/lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb +0 -129
  364. data/lib/plugins/inspec-plugin-manager-cli/test/functional/uninstall_test.rb +0 -63
  365. data/lib/plugins/inspec-plugin-manager-cli/test/functional/update_test.rb +0 -84
  366. data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +0 -77
  367. data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +0 -39
  368. data/lib/plugins/shared/core_plugin_test_helper.rb +0 -153
  369. data/lib/plugins/things-for-train-integration.rb +0 -14
  370. data/lib/source_readers/flat.rb +0 -36
  371. data/lib/source_readers/inspec.rb +0 -66
@@ -1,3 +0,0 @@
1
- require "inspec/formatters/base"
2
- require "inspec/formatters/json_rspec"
3
- require "inspec/formatters/show_progress"
@@ -1,269 +0,0 @@
1
- require "rspec/core"
2
- require "rspec/core/formatters/base_formatter"
3
-
4
- module Inspec::Formatters
5
- class Base < RSpec::Core::Formatters::BaseFormatter
6
- RSpec::Core::Formatters.register self, :close, :dump_summary, :stop
7
-
8
- attr_accessor :backend, :run_data
9
-
10
- def initialize(output)
11
- super(output)
12
-
13
- @run_data = {}
14
- @profiles = []
15
- @profiles_info = nil
16
- @backend = nil
17
- end
18
-
19
- # RSpec Override: #dump_summary
20
- #
21
- # Supply run summary data, such as the InSpec version and the total duration.
22
- def dump_summary(summary)
23
- run_data[:version] = Inspec::VERSION
24
- run_data[:statistics] = {
25
- duration: summary.duration,
26
- controls: statistics,
27
- }
28
- end
29
-
30
- # RSpec Override: #stop
31
- #
32
- # Called at the end of a complete RSpec run.
33
- # We use this to map tests to controls and flesh out the rest of the run_data
34
- # hash to include details about the run, the platform, etc.
35
- def stop(notification)
36
- # This might be a bit confusing. The results are not actually organized
37
- # by control. It is organized by test. So if a control has 3 tests, the
38
- # output will have 3 control entries, each one with the same control id
39
- # and different test results. An rspec example maps to an inspec test.
40
- run_data[:controls] = notification.examples.map do |example|
41
- format_example(example).tap do |hash|
42
- e = example.exception
43
- next unless e
44
-
45
- if example.metadata[:sensitive]
46
- hash[:message] = "*** sensitive output suppressed ***"
47
- else
48
- hash[:message] = exception_message(e)
49
- end
50
-
51
- next if e.is_a? RSpec::Expectations::ExpectationNotMetError
52
-
53
- hash[:exception] = e.class.name
54
- hash[:backtrace] = e.backtrace
55
- end
56
- end
57
-
58
- # include any tests that were run that were not part of a control
59
- run_data[:other_checks] = examples_without_controls
60
- examples_with_controls.each do |example|
61
- control = example2control(example)
62
- move_example_into_control(example, control)
63
- end
64
-
65
- # flesh out the profiles key with additional profile information
66
- run_data[:profiles] = profiles_info
67
-
68
- # add the platform information for this particular target
69
- run_data[:platform] = {
70
- name: platform(:name),
71
- release: platform(:release),
72
- target: backend_target,
73
- }
74
- end
75
-
76
- # Add the current profile to the list of executed profiles.
77
- # Called by the runner during example collection.
78
- def add_profile(profile)
79
- @profiles.push(profile)
80
- end
81
-
82
- # Return all the collected output to the caller
83
- def results
84
- run_data
85
- end
86
-
87
- private
88
-
89
- def all_unique_controls
90
- unique_controls = Set.new
91
- run_data[:profiles].each do |profile|
92
- profile[:controls].map { |control| unique_controls.add(control) }
93
- end
94
-
95
- unique_controls
96
- end
97
-
98
- def statistics
99
- failed = 0
100
- skipped = 0
101
- passed = 0
102
-
103
- all_unique_controls.each do |control|
104
- next unless control[:results]
105
-
106
- if control[:results].any? { |r| r[:status] == "failed" }
107
- failed += 1
108
- elsif control[:results].any? { |r| r[:status] == "skipped" }
109
- skipped += 1
110
- else
111
- passed += 1
112
- end
113
- end
114
-
115
- total = failed + passed + skipped
116
-
117
- {
118
- total: total,
119
- passed: {
120
- total: passed,
121
- },
122
- skipped: {
123
- total: skipped,
124
- },
125
- failed: {
126
- total: failed,
127
- },
128
- }
129
- end
130
-
131
- def exception_message(exception)
132
- if exception.is_a?(RSpec::Core::MultipleExceptionError)
133
- exception.all_exceptions.map(&:message).uniq.join("\n\n")
134
- else
135
- exception.message
136
- end
137
- end
138
-
139
- # RSpec Override: #format_example
140
- #
141
- # Called after test execution, this allows us to populate our own hash with data
142
- # for this test that is necessary for the rest of our reports.
143
- def format_example(example) # rubocop:disable Metrics/AbcSize
144
- if !example.metadata[:description_args].empty? && example.metadata[:skip]
145
- # For skipped profiles, rspec returns in full_description the skip_message as well. We don't want
146
- # to mix the two, so we pick the full_description from the example.metadata[:example_group] hash.
147
- code_description = example.metadata[:example_group][:description]
148
- else
149
- code_description = example.metadata[:full_description]
150
- end
151
-
152
- res = {
153
- id: example.metadata[:id],
154
- profile_id: example.metadata[:profile_id],
155
- status: example.execution_result.status.to_s,
156
- code_desc: code_description,
157
- run_time: example.execution_result.run_time,
158
- start_time: example.execution_result.started_at.to_datetime.rfc3339.to_s,
159
- resource_title: example.metadata[:described_class] || example.metadata[:example_group][:description],
160
- expectation_message: format_expectation_message(example),
161
- waiver_data: example.metadata[:waiver_data],
162
- }
163
-
164
- unless (pid = example.metadata[:profile_id]).nil?
165
- res[:profile_id] = pid
166
- end
167
-
168
- if res[:status] == "pending"
169
- res[:status] = "skipped"
170
- res[:skip_message] = example.metadata[:description]
171
- res[:resource] = example.metadata[:described_class].to_s
172
- end
173
-
174
- res
175
- end
176
-
177
- def format_expectation_message(example)
178
- if (example.metadata[:example_group][:description_args].first == example.metadata[:example_group][:described_class]) ||
179
- example.metadata[:example_group][:described_class].nil?
180
- example.metadata[:description]
181
- else
182
- "#{example.metadata[:example_group][:description]} #{example.metadata[:description]}"
183
- end
184
- end
185
-
186
- # This formatter runs for all reports and we cannot error on missing fields.
187
- # Return nil if not found or Train error. If needed, we will raise an error inside
188
- # the proper report.
189
- def platform(field)
190
- return nil if @backend.nil?
191
-
192
- begin
193
- @backend.platform[field]
194
- rescue Train::Error => e
195
- Inspec::Log.warn(e.message)
196
- nil
197
- end
198
- end
199
-
200
- def backend_target
201
- return nil if @backend.nil?
202
-
203
- connection = @backend.backend
204
- connection.respond_to?(:uri) ? connection.uri : nil
205
- end
206
-
207
- def examples
208
- run_data[:controls]
209
- end
210
-
211
- def examples_without_controls
212
- examples.find_all { |example| example2control(example).nil? }
213
- end
214
-
215
- def examples_with_controls
216
- examples.find_all { |example| !example2control(example).nil? }
217
- end
218
-
219
- def profiles_info
220
- @profiles_info ||= @profiles.map(&:info!).map(&:dup)
221
- end
222
-
223
- def example2control(example)
224
- profile = profile_from_example(example)
225
- return nil unless profile&.[](:controls)
226
-
227
- profile[:controls].find { |x| x[:id] == example[:id] }
228
- end
229
-
230
- def profile_from_example(example)
231
- profiles_info.find { |p| profile_contains_example?(p, example) }
232
- end
233
-
234
- def profile_contains_example?(profile, example)
235
- profile_name = profile[:name]
236
- example_profile_id = example[:profile_id]
237
-
238
- # if either the profile name is nil or the profile in the given example
239
- # is nil, assume the profile doesn't contain the example and default
240
- # to creating a new profile. Otherwise, for profiles that have no
241
- # metadata, this may incorrectly match a profile that does not contain
242
- # this example, leading to Ruby exceptions.
243
- return false if profile_name.nil? || example_profile_id.nil?
244
-
245
- # The correct profile is one where the name of the profile, and the profile
246
- # name in the example match. Additionally, the list of controls in the
247
- # profile must contain the example in question (which we match by ID).
248
- #
249
- # While the profile name match is usually good enough, we must also match by
250
- # the control ID in the case where an InSpec runner has multiple profiles of
251
- # the same name (i.e. when Test Kitchen is running concurrently using a
252
- # single test suite that uses the Flat source reader, in which case InSpec
253
- # creates a fake profile with a name like "tests from /path/to/tests")
254
- profile_name == example_profile_id && profile[:controls].any? { |control| control[:id] == example[:id] }
255
- end
256
-
257
- def move_example_into_control(example, control)
258
- control[:results] ||= []
259
- example.delete(:id)
260
- example.delete(:profile_id)
261
- control[:results].push(example)
262
-
263
- # Waiver data, if available, is internally stored on a per-result
264
- # (that is, per-describe-block) basis, because that is the only granularity
265
- # available to us in the RSpec report data structure which we use as a vehicle.
266
- control[:waiver_data] ||= example[:waiver_data] || {}
267
- end
268
- end
269
- end
@@ -1,20 +0,0 @@
1
- module Inspec::Formatters
2
- class RspecJson < RSpec::Core::Formatters::JsonFormatter
3
- RSpec::Core::Formatters.register self
4
-
5
- private
6
-
7
- # We are cheating and overriding a private method in RSpec's core JsonFormatter.
8
- # This is to avoid having to repeat this id functionality in both dump_summary
9
- # and dump_profile (both of which call format_example).
10
- # See https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/json_formatter.rb
11
- #
12
- # rspec's example id here corresponds to an inspec test's control name -
13
- # either explicitly specified or auto-generated by rspec itself.
14
- def format_example(example)
15
- res = super(example)
16
- res[:id] = example.metadata[:id]
17
- res
18
- end
19
- end
20
- end
@@ -1,12 +0,0 @@
1
- module Inspec::Formatters
2
- class ShowProgress < RSpec::Core::Formatters::ProgressFormatter
3
- RSpec::Core::Formatters.register self
4
-
5
- # remove summary output from progress
6
- %w{dump_summary dump_failures dump_pending message seed start_dump}.each do |m|
7
- define_method(m) do |*args|
8
- # override
9
- end
10
- end
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- module Inspec
2
- def self.config_dir
3
- ENV["INSPEC_CONFIG_DIR"] ? ENV["INSPEC_CONFIG_DIR"] : File.join(Dir.home, ".inspec")
4
- end
5
-
6
- def self.src_root
7
- File.expand_path(File.join(__FILE__, "..", "..", ".."))
8
- end
9
- end
@@ -1,36 +0,0 @@
1
- require "inspec/errors"
2
-
3
- # Impact scores based off CVSS 3.0
4
- module Inspec::Impact
5
- IMPACT_SCORES = {
6
- "none" => 0.0,
7
- "low" => 0.1,
8
- "medium" => 0.4,
9
- "high" => 0.7,
10
- "critical" => 0.9,
11
- }.freeze
12
-
13
- def self.impact_from_string(value)
14
- # return if its a number
15
- return value if is_number?(value)
16
- raise Inspec::ImpactError, "'#{value}' is not a valid impact name. Valid impact names: none, low, medium, high, critical." unless IMPACT_SCORES.key?(value.downcase)
17
-
18
- IMPACT_SCORES[value]
19
- end
20
-
21
- def self.is_number?(value)
22
- Float(value)
23
- true
24
- rescue
25
- false
26
- end
27
-
28
- def self.string_from_impact(value)
29
- value = value.to_f
30
- raise Inspec::ImpactError, "'#{value}' is not a valid impact score. Valid impact scores: [0.0 - 1.0]." if value < 0 || value > 1
31
-
32
- IMPACT_SCORES.reverse_each do |name, impact|
33
- return name if value >= impact
34
- end
35
- end
36
- end
@@ -1,421 +0,0 @@
1
- require "inspec/utils/deprecation"
2
-
3
- # For backwards compatibility during the rename (see #3802),
4
- # maintain the Inspec::Attribute namespace for people checking for
5
- # Inspec::Attribute::DEFAULT_ATTRIBUTE
6
- module Inspec
7
- class Attribute
8
- # This only exists to create the Inspec::Attribute::DEFAULT_ATTRIBUTE symbol with a class
9
- class DEFAULT_ATTRIBUTE; end # rubocop: disable Naming/ClassAndModuleCamelCase
10
- end
11
- end
12
-
13
- module Inspec
14
- class Input
15
-
16
- class Error < Inspec::Error; end
17
- class ValidationError < Error
18
- attr_accessor :input_name
19
- attr_accessor :input_value
20
- attr_accessor :input_type
21
- end
22
- class TypeError < Error
23
- attr_accessor :input_type
24
- end
25
- class RequiredError < Error
26
- attr_accessor :input_name
27
- end
28
-
29
- #===========================================================================#
30
- # Class Input::Event
31
- #===========================================================================#
32
-
33
- # TODO: break this out to its own file under inspec/input?
34
- # Information about how the input obtained its value.
35
- # Each time it changes, an Input::Event is added to the #events array.
36
- class Event
37
- EVENT_PROPERTIES = [
38
- :action, # :create, :set, :fetch
39
- :provider, # Name of the plugin
40
- :priority, # Priority of this plugin for resolving conflicts. 1-100, higher numbers win.
41
- :value, # New value, if provided.
42
- :file, # File containing the input-changing action, if known
43
- :line, # Line in file containing the input-changing action, if known
44
- :hit, # if action is :fetch, true if the remote source had the input
45
- ].freeze
46
-
47
- # Value has a special handler
48
- EVENT_PROPERTIES.reject { |p| p == :value }.each do |prop|
49
- attr_accessor prop
50
- end
51
-
52
- attr_reader :value
53
-
54
- def initialize(properties = {})
55
- @value_has_been_set = false
56
-
57
- properties.each do |prop_name, prop_value|
58
- if EVENT_PROPERTIES.include? prop_name
59
- # OK, save the property
60
- send((prop_name.to_s + "=").to_sym, prop_value)
61
- else
62
- raise "Unrecognized property to Input::Event: #{prop_name}"
63
- end
64
- end
65
- end
66
-
67
- def value=(the_val)
68
- # Even if set to nil or false, it has indeed been set; note that fact.
69
- @value_has_been_set = true
70
- @value = the_val
71
- end
72
-
73
- def value_has_been_set?
74
- @value_has_been_set
75
- end
76
-
77
- def diagnostic_string
78
- to_h.reject { |_, val| val.nil? }.to_a.map { |pair| "#{pair[0]}: '#{pair[1]}'" }.join(", ")
79
- end
80
-
81
- def to_h
82
- EVENT_PROPERTIES.each_with_object({}) do |prop, hash|
83
- hash[prop] = send(prop)
84
- end
85
- end
86
-
87
- def self.probe_stack
88
- frames = caller_locations(2, 40)
89
- frames.reject! { |f| f.path && f.path.include?("/lib/inspec/") }
90
- frames.first
91
- end
92
- end # class Event
93
-
94
- #===========================================================================#
95
- # Class NO_VALUE_SET
96
- #===========================================================================#
97
- # This special class is used to represent the value when an input has
98
- # not been assigned a value. This allows a user to explicitly assign nil
99
- # to an input.
100
- class NO_VALUE_SET # rubocop: disable Naming/ClassAndModuleCamelCase
101
- def initialize(name)
102
- @name = name
103
-
104
- # output warn message if we are in a exec call
105
- if Inspec::BaseCLI.inspec_cli_command == :exec
106
- Inspec::Log.warn(
107
- "Input '#{@name}' does not have a value. "\
108
- "Use --input-file to provide a value for '#{@name}' or specify a "\
109
- "value with `attribute('#{@name}', value: 'somevalue', ...)`."
110
- )
111
- end
112
- end
113
-
114
- def method_missing(*_)
115
- self
116
- end
117
-
118
- def respond_to_missing?(_, _)
119
- true
120
- end
121
-
122
- def to_s
123
- "Input '#{@name}' does not have a value. Skipping test."
124
- end
125
-
126
- def is_a?(klass)
127
- if klass == Inspec::Attribute::DEFAULT_ATTRIBUTE
128
- Inspec.deprecate(:rename_attributes_to_inputs, "Don't check for `is_a?(Inspec::Attribute::DEFAULT_ATTRIBUTE)`, check for `Inspec::Input::NO_VALUE_SET")
129
- true # lie for backward compatibility
130
- else
131
- super(klass)
132
- end
133
- end
134
-
135
- def kind_of?(klass)
136
- if klass == Inspec::Attribute::DEFAULT_ATTRIBUTE
137
- Inspec.deprecate(:rename_attributes_to_inputs, "Don't check for `kind_of?(Inspec::Attribute::DEFAULT_ATTRIBUTE)`, check for `Inspec::Input::NO_VALUE_SET")
138
- true # lie for backward compatibility
139
- else
140
- super(klass)
141
- end
142
- end
143
- end # class NO_VALUE_SET
144
-
145
- #===========================================================================#
146
- # Class Inspec::Input
147
- #===========================================================================#
148
-
149
- # Validation types for input values
150
- VALID_TYPES = %w{
151
- String
152
- Numeric
153
- Regexp
154
- Array
155
- Hash
156
- Boolean
157
- Any
158
- }.freeze
159
-
160
- # TODO: this is not used anywhere?
161
- # If you call `input` in a control file, the input will receive this priority.
162
- # You can override that with a :priority option.
163
- DEFAULT_PRIORITY_FOR_DSL_ATTRIBUTES = 20
164
-
165
- # If you somehow manage to initialize an Input outside of the DSL,
166
- # AND you don't provide an Input::Event, this is the priority you get.
167
- DEFAULT_PRIORITY_FOR_UNKNOWN_CALLER = 10
168
-
169
- # If you directly call value=, this is the priority assigned.
170
- # This is the highest priority within InSpec core; though plugins
171
- # are free to go higher.
172
- DEFAULT_PRIORITY_FOR_VALUE_SET = 60
173
-
174
- attr_reader :description, :events, :identifier, :name, :required, :title, :type
175
-
176
- def initialize(name, options = {})
177
- @name = name
178
- @opts = options
179
- if @opts.key?(:default)
180
- Inspec.deprecate(:attrs_value_replaces_default, "input name: '#{name}'")
181
- if @opts.key?(:value)
182
- Inspec::Log.warn "Input #{@name} created using both :default and :value options - ignoring :default"
183
- @opts.delete(:default)
184
- end
185
- end
186
-
187
- # Array of Input::Event objects. These compete with one another to determine
188
- # the value of the input when value() is called, as well as providing a
189
- # debugging record of when and how the value changed.
190
- @events = []
191
- events.push make_creation_event(options)
192
-
193
- update(options)
194
- end
195
-
196
- # TODO: is this here just for testing?
197
- def set_events
198
- events.select { |e| e.action == :set }
199
- end
200
-
201
- def diagnostic_string
202
- "Input #{name}, with history:\n" +
203
- events.map(&:diagnostic_string).map { |line| " #{line}" }.join("\n")
204
- end
205
-
206
- #--------------------------------------------------------------------------#
207
- # Managing Value
208
- #--------------------------------------------------------------------------#
209
-
210
- def update(options)
211
- _update_set_metadata(options)
212
- normalize_type_restriction!
213
-
214
- # Values are set by passing events in; but we can also infer an event.
215
- if options.key?(:value) || options.key?(:default)
216
- if options.key?(:event)
217
- if options.key?(:value) || options.key?(:default)
218
- Inspec::Log.warn "Do not provide both an Event and a value as an option to attribute('#{name}') - using value from event"
219
- end
220
- else
221
- self.class.infer_event(options) # Sets options[:event]
222
- end
223
- end
224
- events << options[:event] if options.key? :event
225
-
226
- enforce_type_restriction!
227
- end
228
-
229
- # We can determine a value:
230
- # 1. By event.value (preferred)
231
- # 2. By options[:value]
232
- # 3. By options[:default] (deprecated)
233
- def self.infer_event(options)
234
- # Don't rely on this working; you really should be passing a proper Input::Event
235
- # with the context information you have.
236
- location = Input::Event.probe_stack
237
- event = Input::Event.new(
238
- action: :set,
239
- provider: options[:provider] || :unknown,
240
- priority: options[:priority] || Inspec::Input::DEFAULT_PRIORITY_FOR_UNKNOWN_CALLER,
241
- file: location.path,
242
- line: location.lineno
243
- )
244
-
245
- if options.key?(:default)
246
- Inspec.deprecate(:attrs_value_replaces_default, "attribute name: '#{name}'")
247
- if options.key?(:value)
248
- Inspec::Log.warn "Input #{@name} created using both :default and :value options - ignoring :default"
249
- options.delete(:default)
250
- else
251
- options[:value] = options.delete(:default)
252
- end
253
- end
254
- event.value = options[:value] if options.key?(:value)
255
- options[:event] = event
256
- end
257
-
258
- private
259
-
260
- def _update_set_metadata(options)
261
- # Basic metadata
262
- @title = options[:title] if options.key?(:title)
263
- @description = options[:description] if options.key?(:description)
264
- @required = options[:required] if options.key?(:required)
265
- @identifier = options[:identifier] if options.key?(:identifier) # TODO: determine if this is ever used
266
- @type = options[:type] if options.key?(:type)
267
- end
268
-
269
- def make_creation_event(options)
270
- loc = options[:location] || Event.probe_stack
271
- Input::Event.new(
272
- action: :create,
273
- provider: options[:provider],
274
- file: loc.path,
275
- line: loc.lineno
276
- )
277
- end
278
-
279
- # Determine the current winning value, but don't validate it
280
- def current_value
281
- # Examine the events to determine highest-priority value. Tie-break
282
- # by using the last one set.
283
- events_that_set_a_value = events.select(&:value_has_been_set?)
284
- winning_priority = events_that_set_a_value.map(&:priority).max
285
- winning_events = events_that_set_a_value.select { |e| e.priority == winning_priority }
286
- winning_event = winning_events.last # Last for tie-break
287
-
288
- if winning_event.nil?
289
- # No value has been set - return special no value object
290
- NO_VALUE_SET.new(name)
291
- else
292
- winning_event.value # May still be nil
293
- end
294
- end
295
-
296
- public
297
-
298
- def value=(new_value, priority = DEFAULT_PRIORITY_FOR_VALUE_SET)
299
- # Inject a new Event with the new value.
300
- location = Event.probe_stack
301
- events << Event.new(
302
- action: :set,
303
- provider: :value_setter,
304
- priority: priority,
305
- value: new_value,
306
- file: location.path,
307
- line: location.lineno
308
- )
309
- enforce_type_restriction!
310
- end
311
-
312
- def value
313
- enforce_required_validation!
314
- current_value
315
- end
316
-
317
- def has_value?
318
- !current_value.is_a? NO_VALUE_SET
319
- end
320
-
321
- def to_hash
322
- as_hash = { name: name, options: {} }
323
- %i{description title identifier type required value}.each do |field|
324
- val = send(field)
325
- next if val.nil?
326
-
327
- as_hash[:options][field] = val
328
- end
329
- as_hash
330
- end
331
-
332
- #--------------------------------------------------------------------------#
333
- # Value Type Coercion
334
- #--------------------------------------------------------------------------#
335
-
336
- def to_s
337
- "Input #{name} with #{current_value}"
338
- end
339
-
340
- #--------------------------------------------------------------------------#
341
- # Validation
342
- #--------------------------------------------------------------------------#
343
-
344
- private
345
-
346
- def enforce_required_validation!
347
- return unless required
348
- # skip if we are not doing an exec call (archive/vendor/check)
349
- return unless Inspec::BaseCLI.inspec_cli_command == :exec
350
-
351
- proposed_value = current_value
352
- if proposed_value.nil? || proposed_value.is_a?(NO_VALUE_SET)
353
- error = Inspec::Input::RequiredError.new
354
- error.input_name = name
355
- raise error, "Input '#{error.input_name}' is required and does not have a value."
356
- end
357
- end
358
-
359
- def enforce_type_restriction! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
360
- return unless type
361
- return unless has_value?
362
-
363
- type_req = type
364
- return if type_req == "Any"
365
-
366
- proposed_value = current_value
367
-
368
- invalid_type = false
369
- if type_req == "Regexp"
370
- invalid_type = true unless valid_regexp?(proposed_value)
371
- elsif type_req == "Numeric"
372
- invalid_type = true unless valid_numeric?(proposed_value)
373
- elsif type_req == "Boolean"
374
- invalid_type = true unless [true, false].include?(proposed_value)
375
- elsif proposed_value.is_a?(Module.const_get(type_req)) == false
376
- # TODO: why is this case here?
377
- invalid_type = true
378
- end
379
-
380
- if invalid_type == true
381
- error = Inspec::Input::ValidationError.new
382
- error.input_name = @name
383
- error.input_value = proposed_value
384
- error.input_type = type_req
385
- raise error, "Input '#{error.input_name}' with value '#{error.input_value}' does not validate to type '#{error.input_type}'."
386
- end
387
- end
388
-
389
- def normalize_type_restriction!
390
- return unless type
391
-
392
- type_req = type.capitalize
393
- abbreviations = {
394
- "Num" => "Numeric",
395
- "Regex" => "Regexp",
396
- }
397
- type_req = abbreviations[type_req] if abbreviations.key?(type_req)
398
- unless VALID_TYPES.include?(type_req)
399
- error = Inspec::Input::TypeError.new
400
- error.input_type = type_req
401
- raise error, "Type '#{error.input_type}' is not a valid input type."
402
- end
403
- @type = type_req
404
- end
405
-
406
- def valid_numeric?(value)
407
- Float(value)
408
- true
409
- rescue
410
- false
411
- end
412
-
413
- def valid_regexp?(value)
414
- # check for invalid regex syntax
415
- Regexp.new(value)
416
- true
417
- rescue
418
- false
419
- end
420
- end
421
- end