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,11 +0,0 @@
1
- # All DSL plugin types are defined here.
2
-
3
- module Inspec::Plugin::V2::PluginType
4
- class Dsl < Inspec::Plugin::V2::PluginBase
5
- register_plugin_type(:outer_profile_dsl)
6
- register_plugin_type(:control_dsl)
7
- register_plugin_type(:describe_dsl)
8
- register_plugin_type(:test_dsl)
9
- register_plugin_type(:resource_dsl)
10
- end
11
- end
@@ -1,34 +0,0 @@
1
- module Inspec::Plugin::V2::PluginType
2
- class Input < Inspec::Plugin::V2::PluginBase
3
- register_plugin_type(:input)
4
-
5
- #====================================================================#
6
- # Input plugin type API
7
- #====================================================================#
8
- # Implementation classes must implement these methods.
9
-
10
- # When an input is obtained from the plugin, this number determines what
11
- # precedence to assign to the input.
12
- # @return Integer range 0-100. Higher priority means higher precedence
13
- def default_priority
14
- 60
15
- end
16
-
17
- # Indicates an attempt is being made to read the value for an input.
18
- # Return nil if the input is not supplied by the plugin, otherwise
19
- # return the value.
20
- # @return Object or nil
21
- def fetch(_profile_name, _input_name)
22
- raise NotImplementedError, "Plugin #{plugin_name} must implement the #fetch method"
23
- end
24
-
25
- # Given a profile name, list all input names for which the plugin
26
- # would offer a response.
27
- # @param String profile_name Name of the profile
28
- # @return Array[String] List of input names for which the plugin
29
- # would offer a response.
30
- def list_inputs(_profile)
31
- raise NotImplementedError, "Plugin #{plugin_name} must implement the #list_inputs method"
32
- end
33
- end
34
- end
@@ -1,12 +0,0 @@
1
- module Inspec::Plugin::V2::PluginType
2
- # Test plugin type
3
- class Mock < Inspec::Plugin::V2::PluginBase
4
- register_plugin_type(:mock_plugin_type)
5
-
6
- # This is the API for the mock plugin type: when a mock plugin is
7
- # activated, it is expected to be able to respond to this, and "do something"
8
- def mock_hook
9
- raise NotImplementedError, "Mock plugins must implement mock_hook"
10
- end
11
- end
12
- end
@@ -1,98 +0,0 @@
1
- require "forwardable"
2
- require "singleton"
3
- require "train"
4
-
5
- require_relative "status"
6
- require_relative "activator"
7
-
8
- module Inspec::Plugin::V2
9
- class Registry
10
- include Singleton
11
- extend Forwardable
12
-
13
- attr_reader :registry
14
- def_delegator :registry, :each
15
- def_delegator :registry, :[]
16
- def_delegator :registry, :key?, :known_plugin?
17
- def_delegator :registry, :keys, :plugin_names
18
- def_delegator :registry, :values, :plugin_statuses
19
- def_delegator :registry, :select
20
-
21
- def initialize
22
- @registry = {}
23
- end
24
-
25
- def any_load_failures?
26
- !plugin_statuses.select(&:load_exception).empty?
27
- end
28
-
29
- def loaded_plugin?(name)
30
- # HACK: Status is normally the source of truth for loadedness, unless it is a train plugin; then the Train::Registry is the source of truth.
31
- # Also, InSpec registry is keyed on Symbols; Train is keyed on Strings.
32
- return registry.dig(name.to_sym, :loaded) unless name.to_s.start_with?("train-")
33
-
34
- Train::Plugins.registry.key?(name.to_s.sub(/^train-/, ""))
35
- end
36
-
37
- def loaded_count
38
- loaded_plugin_names.count
39
- end
40
-
41
- def known_count
42
- registry.values.count
43
- end
44
-
45
- def loaded_plugin_names
46
- registry.keys.select { |name| loaded_plugin?(name) }
47
- end
48
-
49
- def path_based_plugin?(name)
50
- known_plugin?(name.to_sym) && registry[name.to_sym].installation_type == :path
51
- end
52
-
53
- def find_status_by_class(klass)
54
- registry.values.detect { |status| status.plugin_class == klass }
55
- end
56
-
57
- # Finds Activators matching criteria (all optional) you specify as a Hash.
58
- # @param [Symbol] plugin_name Restricts the search to the given plugin
59
- # @param [Symbol] plugin_type Restricts the search to the given plugin type
60
- # @param [Symbol] activator_name Name of the activator
61
- # @param [Class] implementation_class Implementation class returned by an already-actived plugin type
62
- # @returns [Array] Possibly empty array of Activators
63
- def find_activators(filters = {})
64
- plugin_statuses.map(&:activators).flatten.select do |act|
65
- %i{plugin_name plugin_type activator_name implementation_class}.all? do |criteria|
66
- !filters.key?(criteria) || act[criteria] == filters[criteria]
67
- end
68
- end
69
- end
70
-
71
- # Convenience method for when you expect exactly one
72
- def find_activator(filters = {})
73
- matched_plugins = find_activators(filters)
74
- if matched_plugins.count > 1
75
- raise Inspec::Plugin::V2::LoadError, "Plugin hooks search returned multiple results for filter #{filters.inspect} - use more filters, or use find_activators (plural)"
76
- elsif matched_plugins.empty?
77
- raise Inspec::Plugin::V2::LoadError, "Plugin hooks search returned zero results for filter #{filters.inspect}"
78
- end
79
-
80
- matched_plugins.first
81
- end
82
-
83
- def register(name, status)
84
- if known_plugin? name
85
- Inspec::Log.debug "PluginLoader: refusing to re-register plugin '#{name}': an existing plugin with that name was loaded via #{registry[name].installation_type}-loading from #{registry[name].entry_point}"
86
- else
87
- registry[name.to_sym] = status
88
- end
89
- end
90
-
91
- alias []= register
92
-
93
- # Provided for test support. Purges the registry.
94
- def __reset
95
- @registry.clear
96
- end
97
- end
98
- end
@@ -1,29 +0,0 @@
1
- module Inspec::Plugin::V2
2
- # Track loading status of each plugin. These are the elements of the Registry.
3
- #
4
- # Lifecycle of an installed plugin:
5
- # If present in the config file, bundled, or core, it is "known"
6
- # All known plugins are loaded. v1 plugins auto-activate. All loaded plugins know their version.
7
- # v2 plugins activate when they are used. All activated plugins know their implementation class.
8
- Status = Struct.new(
9
- :activators, # Array of Activators - where plugin_type info gets stored
10
- :api_generation, # 0,1,2 # TODO: convert all bundled (v0) to v2
11
- :plugin_class, # Plugin class
12
- :entry_point, # a gem name or filesystem path
13
- :installation_type, # :gem, :path, :core, bundle # TODO: combine core and bundle
14
- :loaded, # true, false False could mean not attempted or failed
15
- :load_exception, # Exception class if it failed to load
16
- :name, # String name
17
- :version # three-digit version. Core / bundled plugins use InSpec version here.
18
- ) do
19
- def initialize(*)
20
- super
21
- self[:activators] = []
22
- self[:loaded] = false
23
- end
24
-
25
- def plugin_types
26
- activators.map(&:plugin_type).uniq.sort
27
- end
28
- end
29
- end
@@ -1,658 +0,0 @@
1
- # Copyright 2015 Dominik Richter
2
-
3
- require "forwardable"
4
- require "openssl"
5
- require "pathname"
6
- require "inspec/input_registry"
7
- require "inspec/cached_fetcher" # TODO: split or rename
8
- require "inspec/source_reader"
9
- require "inspec/profile_context"
10
- require "inspec/runtime_profile"
11
- require "inspec/method_source"
12
- require "inspec/dependencies/cache"
13
- require "inspec/dependencies/lockfile"
14
- require "inspec/dependencies/dependency_set"
15
-
16
- module Inspec
17
- class Profile
18
- extend Forwardable
19
-
20
- def self.resolve_target(target, cache)
21
- Inspec::Log.debug "Resolve #{target} into cache #{cache.path}"
22
- Inspec::CachedFetcher.new(target, cache)
23
- end
24
-
25
- # Check if the profile contains a vendored cache, move content into global cache
26
- # TODO: use relative file provider
27
- # TODO: use source reader for Cache as well
28
- def self.copy_deps_into_cache(file_provider, opts)
29
- # filter content
30
- cache = file_provider.files.find_all do |entry|
31
- entry.start_with?("vendor")
32
- end
33
- content = Hash[cache.map { |x| [x, file_provider.binread(x)] }]
34
- keys = content.keys
35
- keys.each do |key|
36
- next if content[key].nil?
37
-
38
- # remove prefix
39
- rel = Pathname.new(key).relative_path_from(Pathname.new("vendor")).to_s
40
- tar = Pathname.new(opts[:vendor_cache].path).join(rel)
41
-
42
- FileUtils.mkdir_p tar.dirname.to_s
43
- Inspec::Log.debug "Copy #{tar} to cache directory"
44
- File.binwrite(tar.to_s, content[key])
45
- end
46
- end
47
-
48
- def self.for_path(path, opts)
49
- file_provider = FileProvider.for_path(path)
50
- rp = file_provider.relative_provider
51
-
52
- # copy embedded dependencies into global cache
53
- copy_deps_into_cache(rp, opts) unless opts[:vendor_cache].nil?
54
-
55
- reader = Inspec::SourceReader.resolve(rp)
56
- if reader.nil?
57
- raise("Don't understand inspec profile in #{path}, it " \
58
- "doesn't look like a supported profile structure.")
59
- end
60
- new(reader, opts)
61
- end
62
-
63
- def self.for_fetcher(fetcher, config)
64
- opts = config.respond_to?(:final_options) ? config.final_options : config
65
- opts[:vendor_cache] = opts[:vendor_cache] || Cache.new
66
- path, writable = fetcher.fetch
67
- for_path(path, opts.merge(target: fetcher.target, writable: writable))
68
- end
69
-
70
- def self.for_target(target, opts = {})
71
- opts[:vendor_cache] ||= Cache.new
72
- fetcher = resolve_target(target, opts[:vendor_cache])
73
- for_fetcher(fetcher, opts)
74
- end
75
-
76
- attr_reader :source_reader, :backend, :runner_context, :check_mode
77
- attr_accessor :parent_profile, :profile_id, :profile_name
78
- def_delegator :@source_reader, :tests
79
- def_delegator :@source_reader, :libraries
80
- def_delegator :@source_reader, :metadata
81
-
82
- # rubocop:disable Metrics/AbcSize
83
- def initialize(source_reader, options = {})
84
- @source_reader = source_reader
85
- @target = options[:target]
86
- @logger = options[:logger] || Logger.new(nil)
87
- @locked_dependencies = options[:dependencies]
88
- @controls = options[:controls] || []
89
- @writable = options[:writable] || false
90
- @profile_id = options[:id]
91
- @profile_name = options[:profile_name]
92
- @cache = options[:vendor_cache] || Cache.new
93
- @input_values = options[:inputs]
94
- @tests_collected = false
95
- @libraries_loaded = false
96
- @check_mode = options[:check_mode] || false
97
- @parent_profile = options[:parent_profile]
98
- @legacy_profile_path = options[:profiles_path] || false
99
- Metadata.finalize(@source_reader.metadata, @profile_id, options)
100
-
101
- # if a backend has already been created, clone it so each profile has its own unique backend object
102
- # otherwise, create a new backend object
103
- #
104
- # This is necessary since we store the RuntimeProfile on the backend object. If a user runs `inspec exec`
105
- # with multiple profiles, only the RuntimeProfile for the last-loaded profile will be available if
106
- # we share the backend between profiles.
107
- #
108
- # This will cause issues if a profile attempts to load a file via `inspec.profile.file`
109
- train_options = options.reject { |k, _| k == "target" } # See https://github.com/chef/inspec/pull/1646
110
- @backend = options[:backend].nil? ? Inspec::Backend.create(Inspec::Config.new(train_options)) : options[:backend].dup
111
- @runtime_profile = RuntimeProfile.new(self)
112
- @backend.profile = @runtime_profile
113
-
114
- # The AttributeRegistry is in charge of keeping track of inputs;
115
- # it is the single source of truth. Now that we have a profile object,
116
- # we can create any inputs that were provided by various mechanisms.
117
- options[:runner_conf] ||= Inspec::Config.cached
118
-
119
- # Catch legacy CLI input option usage
120
- if options[:runner_conf].key?(:attrs)
121
- Inspec.deprecate(:rename_attributes_to_inputs, "Use --input-file on the command line instead of --attrs.")
122
- options[:runner_conf][:input_file] = options[:runner_conf].delete(:attrs)
123
- elsif options[:runner_conf].key?(:input_files)
124
- # The kitchen-inspec docs say to use plural. Our CLI and internal expectations are singular.
125
- options[:runner_conf][:input_file] = options[:runner_conf].delete(:input_files)
126
- end
127
-
128
- # Catch legacy kitchen-inspec input usage
129
- if options[:runner_conf].key?(:attributes)
130
- Inspec.deprecate(:rename_attributes_to_inputs, "Use :inputs in your kitchen.yml verifier config instead of :attributes.")
131
- options[:runner_conf][:inputs] = options[:runner_conf].delete(:attributes)
132
- end
133
-
134
- Inspec::InputRegistry.bind_profile_inputs(
135
- # Every input only exists in the context of a profile
136
- metadata.params[:name], # TODO: test this with profile aliasing
137
- # Remaining args are possible sources of inputs
138
- cli_input_files: options[:runner_conf][:input_file], # From CLI --input-file
139
- profile_metadata: metadata,
140
- runner_api: options[:runner_conf][:inputs], # This is the route the audit_cookbook and kitchen-inspec take
141
- cli_input_arg: options[:runner_conf][:input] # The --input name=value CLI option
142
- )
143
-
144
- @runner_context =
145
- options[:profile_context] ||
146
- Inspec::ProfileContext.for_profile(self, @backend)
147
-
148
- @supports_platform = metadata.supports_platform?(@backend)
149
- @supports_runtime = metadata.supports_runtime?
150
- end
151
-
152
- def name
153
- metadata.params[:name]
154
- end
155
-
156
- def version
157
- metadata.params[:version]
158
- end
159
-
160
- def writable?
161
- @writable
162
- end
163
-
164
- #
165
- # Is this profile is supported on the current platform of the
166
- # backend machine and the current inspec version.
167
- #
168
- # @returns [TrueClass, FalseClass]
169
- #
170
- def supported?
171
- supports_platform? && supports_runtime?
172
- end
173
-
174
- # We need to check if we're using a Mock'd backend for tests to function.
175
- # @returns [TrueClass, FalseClass]
176
- def supports_platform?
177
- if @supports_platform.nil?
178
- @supports_platform = metadata.supports_platform?(@backend)
179
- end
180
- if @backend.backend.class.to_s == "Train::Transports::Mock::Connection"
181
- @supports_platform = true
182
- end
183
-
184
- @supports_platform
185
- end
186
-
187
- def supports_runtime?
188
- if @supports_runtime.nil?
189
- @supports_runtime = metadata.supports_runtime?
190
- end
191
- @supports_runtime
192
- end
193
-
194
- def params
195
- @params ||= load_params
196
- end
197
-
198
- def collect_tests(include_list = @controls)
199
- unless @tests_collected
200
- return unless supports_platform?
201
-
202
- locked_dependencies.each(&:collect_tests)
203
-
204
- tests.each do |path, content|
205
- next if content.nil? || content.empty?
206
-
207
- abs_path = source_reader.target.abs_path(path)
208
- @runner_context.load_control_file(content, abs_path, nil)
209
- end
210
- @tests_collected = true
211
- end
212
- filter_controls(@runner_context.all_rules, include_list)
213
- end
214
-
215
- def filter_controls(controls_array, include_list)
216
- return controls_array if include_list.nil? || include_list.empty?
217
-
218
- # Check for anything that might be a regex in the list, and make it official
219
- include_list.each_with_index do |inclusion, index|
220
- next if inclusion.is_a?(Regexp)
221
- # Insist the user wrap the regex in slashes to demarcate it as a regex
222
- next unless inclusion.start_with?("/") && inclusion.end_with?("/")
223
-
224
- inclusion = inclusion[1..-2] # Trim slashes
225
- begin
226
- re = Regexp.new(inclusion)
227
- include_list[index] = re
228
- rescue RegexpError => e
229
- warn "Ignoring unparseable regex '/#{inclusion}/' in --control CLI option: #{e.message}"
230
- include_list[index] = nil
231
- end
232
- end
233
- include_list.compact!
234
-
235
- controls_array.select do |c|
236
- id = ::Inspec::Rule.rule_id(c)
237
- include_list.any? do |inclusion|
238
- # Try to see if the inclusion is a regex, and if it matches
239
- inclusion == id || (inclusion.is_a?(Regexp) && inclusion =~ id)
240
- end
241
- end
242
- end
243
-
244
- def load_libraries
245
- return @runner_context if @libraries_loaded
246
-
247
- locked_dependencies.dep_list.each_with_index do |(_name, dep), i|
248
- d = dep.profile
249
- # this will force a dependent profile load so we are only going to add
250
- # this metadata if the parent profile is supported.
251
- if supports_platform? && !d.supports_platform?
252
- # since ruby 1.9 hashes are ordered so we can just use index values here
253
- metadata.dependencies[i][:status] = "skipped"
254
- msg = "Skipping profile: '#{d.name}' on unsupported platform: '#{d.backend.platform.name}/#{d.backend.platform.release}'."
255
- metadata.dependencies[i][:skip_message] = msg
256
- next
257
- elsif metadata.dependencies[i]
258
- # Currently wrapper profiles will load all dependencies, and then we
259
- # load them again when we dive down. This needs to be re-done.
260
- metadata.dependencies[i][:status] = "loaded"
261
- end
262
- c = d.load_libraries
263
- @runner_context.add_resources(c)
264
- end
265
-
266
- libs = libraries.map do |path, content|
267
- [content, path]
268
- end
269
-
270
- @runner_context.load_libraries(libs)
271
- @libraries_loaded = true
272
- @runner_context
273
- end
274
-
275
- def to_s
276
- "Inspec::Profile<#{name}>"
277
- end
278
-
279
- # return info using uncached params
280
- def info!
281
- info(load_params.dup)
282
- end
283
-
284
- def info(res = params.dup) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
285
- # add information about the controls
286
- res[:controls] = res[:controls].map do |id, rule|
287
- next if id.to_s.empty?
288
-
289
- data = rule.dup
290
- data.delete(:checks)
291
- data[:impact] ||= 0.5
292
- data[:impact] = 1.0 if data[:impact] > 1.0
293
- data[:impact] = 0.0 if data[:impact] < 0.0
294
- data[:id] = id
295
-
296
- # if the code field is empty try and pull info from dependencies
297
- if data[:code].empty? && parent_profile.nil?
298
- locked_dependencies.dep_list.each do |_name, dep|
299
- profile = dep.profile
300
- code = Inspec::MethodSource.code_at(data[:source_location], profile.source_reader)
301
- data[:code] = code unless code.nil? || code.empty?
302
- break unless data[:code].empty?
303
- end
304
- end
305
- data
306
- end.compact
307
-
308
- # resolve hash structure in groups
309
- res[:groups] = res[:groups].map do |id, group|
310
- group[:id] = id
311
- group
312
- end
313
-
314
- # add information about the required inputs
315
- if res[:inputs].nil? || res[:inputs].empty?
316
- # convert to array for backwards compatability
317
- res[:inputs] = []
318
- else
319
- res[:inputs] = res[:inputs].values.map(&:to_hash)
320
- end
321
- res[:sha256] = sha256
322
- res[:parent_profile] = parent_profile unless parent_profile.nil?
323
-
324
- if !supports_platform?
325
- res[:status] = "skipped"
326
- msg = "Skipping profile: '#{name}' on unsupported platform: '#{backend.platform.name}/#{backend.platform.release}'."
327
- res[:skip_message] = msg
328
- else
329
- res[:status] = "loaded"
330
- end
331
-
332
- # convert legacy os-* supports to their platform counterpart
333
- if res[:supports] && !res[:supports].empty?
334
- res[:supports].each do |support|
335
- # TODO: deprecate
336
- support[:"platform-family"] = support.delete(:"os-family") if support.key?(:"os-family")
337
- support[:"platform-name"] = support.delete(:"os-name") if support.key?(:"os-name")
338
- end
339
- end
340
-
341
- res
342
- end
343
-
344
- # Check if the profile is internally well-structured. The logger will be
345
- # used to print information on errors and warnings which are found.
346
- #
347
- # @return [Boolean] true if no errors were found, false otherwise
348
- def check # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
349
- # initial values for response object
350
- result = {
351
- summary: {
352
- valid: false,
353
- timestamp: Time.now.iso8601,
354
- location: @target,
355
- profile: nil,
356
- controls: 0,
357
- },
358
- errors: [],
359
- warnings: [],
360
- }
361
-
362
- entry = lambda { |file, line, column, control, msg|
363
- {
364
- file: file,
365
- line: line,
366
- column: column,
367
- control_id: control,
368
- msg: msg,
369
- }
370
- }
371
-
372
- warn = lambda { |file, line, column, control, msg|
373
- @logger.warn(msg)
374
- result[:warnings].push(entry.call(file, line, column, control, msg))
375
- }
376
-
377
- error = lambda { |file, line, column, control, msg|
378
- @logger.error(msg)
379
- result[:errors].push(entry.call(file, line, column, control, msg))
380
- }
381
-
382
- @logger.info "Checking profile in #{@target}"
383
- meta_path = @source_reader.target.abs_path(@source_reader.metadata.ref)
384
-
385
- # verify metadata
386
- m_errors, m_warnings = metadata.valid
387
- m_errors.each { |msg| error.call(meta_path, 0, 0, nil, msg) }
388
- m_warnings.each { |msg| warn.call(meta_path, 0, 0, nil, msg) }
389
- m_unsupported = metadata.unsupported
390
- m_unsupported.each { |u| warn.call(meta_path, 0, 0, nil, "doesn't support: #{u}") }
391
- @logger.info "Metadata OK." if m_errors.empty? && m_unsupported.empty?
392
-
393
- # only run the vendor check if the legacy profile-path is not used as argument
394
- if @legacy_profile_path == false
395
- # verify that a lockfile is present if we have dependencies
396
- unless metadata.dependencies.empty?
397
- error.call(meta_path, 0, 0, nil, "Your profile needs to be vendored with `inspec vendor`.") unless lockfile_exists?
398
- end
399
-
400
- if lockfile_exists?
401
- # verify if metadata and lockfile are out of sync
402
- if lockfile.deps.size != metadata.dependencies.size
403
- error.call(meta_path, 0, 0, nil, "inspec.yml and inspec.lock are out-of-sync. Please re-vendor with `inspec vendor`.")
404
- end
405
-
406
- # verify if metadata and lockfile have the same dependency names
407
- metadata.dependencies.each do |dep|
408
- # Skip if the dependency does not specify a name
409
- next if dep[:name].nil?
410
-
411
- # TODO: should we also verify that the soure is the same?
412
- unless lockfile.deps.map { |x| x[:name] }.include? dep[:name]
413
- error.call(meta_path, 0, 0, nil, "Cannot find #{dep[:name]} in lockfile. Please re-vendor with `inspec vendor`.")
414
- end
415
- end
416
- end
417
- end
418
-
419
- # extract profile name
420
- result[:summary][:profile] = metadata.params[:name]
421
-
422
- count = controls_count
423
- result[:summary][:controls] = count
424
- if count == 0
425
- warn.call(nil, nil, nil, nil, "No controls or tests were defined.")
426
- else
427
- @logger.info("Found #{count} controls.")
428
- end
429
-
430
- # iterate over hash of groups
431
- params[:controls].each do |id, control|
432
- sfile = control[:source_location][:ref]
433
- sline = control[:source_location][:line]
434
- error.call(sfile, sline, nil, id, "Avoid controls with empty IDs") if id.nil? || id.empty?
435
- next if id.start_with? "(generated "
436
-
437
- warn.call(sfile, sline, nil, id, "Control #{id} has no title") if control[:title].to_s.empty?
438
- warn.call(sfile, sline, nil, id, "Control #{id} has no descriptions") if control[:descriptions][:default].to_s.empty?
439
- warn.call(sfile, sline, nil, id, "Control #{id} has impact > 1.0") if control[:impact].to_f > 1.0
440
- warn.call(sfile, sline, nil, id, "Control #{id} has impact < 0.0") if control[:impact].to_f < 0.0
441
- warn.call(sfile, sline, nil, id, "Control #{id} has no tests defined") if control[:checks].nil? || control[:checks].empty?
442
- end
443
-
444
- # profile is valid if we could not find any error
445
- result[:summary][:valid] = result[:errors].empty?
446
-
447
- @logger.info "Control definitions OK." if result[:warnings].empty?
448
- result
449
- end
450
-
451
- def controls_count
452
- params[:controls].values.length
453
- end
454
-
455
- # generates a archive of a folder profile
456
- # assumes that the profile was checked before
457
- def archive(opts)
458
- # check if file exists otherwise overwrite the archive
459
- dst = archive_name(opts)
460
- if dst.exist? && !opts[:overwrite]
461
- @logger.info "Archive #{dst} exists already. Use --overwrite."
462
- return false
463
- end
464
-
465
- # remove existing archive
466
- File.delete(dst) if dst.exist?
467
- @logger.info "Generate archive #{dst}."
468
-
469
- # filter files that should not be part of the profile
470
- # TODO ignore all .files, but add the files to debug output
471
-
472
- # display all files that will be part of the archive
473
- @logger.debug "Add the following files to archive:"
474
- files.each { |f| @logger.debug " " + f }
475
-
476
- if opts[:zip]
477
- # generate zip archive
478
- require "inspec/archive/zip"
479
- zag = Inspec::Archive::ZipArchiveGenerator.new
480
- zag.archive(root_path, files, dst)
481
- else
482
- # generate tar archive
483
- require "inspec/archive/tar"
484
- tag = Inspec::Archive::TarArchiveGenerator.new
485
- tag.archive(root_path, files, dst)
486
- end
487
-
488
- @logger.info "Finished archive generation."
489
- true
490
- end
491
-
492
- def locked_dependencies
493
- @locked_dependencies ||= load_dependencies
494
- end
495
-
496
- def lockfile_exists?
497
- @source_reader.target.files.include?("inspec.lock")
498
- end
499
-
500
- def lockfile_path
501
- File.join(cwd, "inspec.lock")
502
- end
503
-
504
- def root_path
505
- @source_reader.target.prefix
506
- end
507
-
508
- def files
509
- @source_reader.target.files
510
- end
511
-
512
- #
513
- # TODO(ssd): Relative path handling really needs to be carefully
514
- # thought through, especially with respect to relative paths in
515
- # tarballs.
516
- #
517
- def cwd
518
- @target.is_a?(String) && File.directory?(@target) ? @target : "./"
519
- end
520
-
521
- def lockfile
522
- @lockfile ||= if lockfile_exists?
523
- Inspec::Lockfile.from_content(@source_reader.target.read("inspec.lock"))
524
- else
525
- generate_lockfile
526
- end
527
- end
528
-
529
- #
530
- # Generate an in-memory lockfile. This won't render the lock file
531
- # to disk, it must be explicitly written to disk by the caller.
532
- #
533
- # @param vendor_path [String] Path to the on-disk vendor dir
534
- # @return [Inspec::Lockfile]
535
- #
536
- def generate_lockfile
537
- res = Inspec::DependencySet.new(cwd, @cache, nil, @backend)
538
- res.vendor(metadata.dependencies)
539
- Inspec::Lockfile.from_dependency_set(res)
540
- end
541
-
542
- def load_dependencies
543
- config = {
544
- cwd: cwd,
545
- cache: @cache,
546
- backend: @backend,
547
- parent_profile: name,
548
- }
549
- Inspec::DependencySet.from_lockfile(lockfile, config, { inputs: @input_values })
550
- end
551
-
552
- # Calculate this profile's SHA256 checksum. Includes metadata, dependencies,
553
- # libraries, data files, and controls.
554
- #
555
- # @return [Type] description of returned object
556
- def sha256
557
- # get all dependency checksums
558
- deps = Hash[locked_dependencies.list.map { |k, v| [k, v.profile.sha256] }]
559
-
560
- res = OpenSSL::Digest::SHA256.new
561
- files = source_reader.tests.to_a + source_reader.libraries.to_a +
562
- source_reader.data_files.to_a +
563
- [["inspec.yml", source_reader.metadata.content]] +
564
- [["inspec.lock.deps", YAML.dump(deps)]]
565
-
566
- files.sort_by { |a| a[0] }
567
- .map { |f| res << f[0] << "\0" << f[1] << "\0" }
568
-
569
- res.digest.unpack("H*")[0]
570
- end
571
-
572
- private
573
-
574
- # Create an archive name for this profile and an additional options
575
- # configuration. Either use :output or generate the name from metadata.
576
- #
577
- # @param [Hash] configuration options
578
- # @return [Pathname] path for the archive
579
- def archive_name(opts)
580
- if (name = opts[:output])
581
- return Pathname.new(name)
582
- end
583
-
584
- name = params[:name] ||
585
- raise("Cannot create an archive without a profile name! Please "\
586
- "specify the name in metadata or use --output to create the archive.")
587
- version = params[:version] ||
588
- raise("Cannot create an archive without a profile version! Please "\
589
- "specify the version in metadata or use --output to create the archive.")
590
- ext = opts[:zip] ? "zip" : "tar.gz"
591
- slug = name.downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "_")
592
- Pathname.new(Dir.pwd).join("#{slug}-#{version}.#{ext}")
593
- end
594
-
595
- def load_params
596
- params = @source_reader.metadata.params
597
- params[:name] = @profile_id unless @profile_id.nil?
598
- load_checks_params(params)
599
- @profile_id ||= params[:name]
600
- params
601
- end
602
-
603
- def load_checks_params(params)
604
- load_libraries
605
- tests = collect_tests
606
- params[:controls] = controls = {}
607
- params[:groups] = groups = {}
608
- prefix = @source_reader.target.prefix || ""
609
- tests&.each do |rule|
610
- next if rule.nil?
611
-
612
- f = load_rule_filepath(prefix, rule)
613
- load_rule(rule, f, controls, groups)
614
- end
615
- params[:inputs] = Inspec::InputRegistry.list_inputs_for_profile(@profile_id)
616
- params
617
- end
618
-
619
- def load_rule_filepath(prefix, rule)
620
- file = rule.instance_variable_get(:@__file)
621
- file = file[prefix.length..-1] if file.start_with?(prefix)
622
- file
623
- end
624
-
625
- def load_rule(rule, file, controls, groups)
626
- id = Inspec::Rule.rule_id(rule)
627
- location = rule.instance_variable_get(:@__source_location)
628
- controls[id] = {
629
- title: rule.title,
630
- desc: rule.desc,
631
- descriptions: rule.descriptions,
632
- impact: rule.impact,
633
- refs: rule.ref,
634
- tags: rule.tag,
635
- checks: Inspec::Rule.checks(rule),
636
- code: Inspec::MethodSource.code_at(location, source_reader),
637
- source_location: location,
638
- }
639
-
640
- # try and grab code text from merge locations
641
- if controls[id][:code].empty? && Inspec::Rule.merge_count(rule) > 0
642
- Inspec::Rule.merge_changes(rule).each do |merge_location|
643
- code = Inspec::MethodSource.code_at(merge_location, source_reader)
644
- unless code.empty?
645
- controls[id][:code] = code
646
- break
647
- end
648
- end
649
- end
650
-
651
- groups[file] ||= {
652
- title: rule.instance_variable_get(:@__group_title),
653
- controls: [],
654
- }
655
- groups[file][:controls].push(id)
656
- end
657
- end
658
- end