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,46 +0,0 @@
1
- require "inspec/errors"
2
-
3
- module Inspec
4
- module Plugin
5
- module V2
6
- class Exception < Inspec::Error; end
7
- class ConfigError < Inspec::Plugin::V2::Exception; end
8
- class LoadError < Inspec::Plugin::V2::Exception; end
9
- class GemActionError < Inspec::Plugin::V2::Exception
10
- attr_accessor :plugin_name
11
- attr_accessor :version
12
- end
13
- class InstallError < Inspec::Plugin::V2::GemActionError; end
14
- class PluginExcludedError < Inspec::Plugin::V2::InstallError
15
- attr_accessor :details
16
- end
17
- class UpdateError < Inspec::Plugin::V2::GemActionError
18
- attr_accessor :from_version, :to_version
19
- end
20
- class UnInstallError < Inspec::Plugin::V2::GemActionError; end
21
- class SearchError < Inspec::Plugin::V2::GemActionError; end
22
- end
23
- end
24
- end
25
-
26
- require "inspec/globals"
27
- require "inspec/plugin/v2/config_file"
28
- require "inspec/plugin/v2/registry"
29
- require "inspec/plugin/v2/loader"
30
- require "inspec/plugin/v2/plugin_base"
31
-
32
- # Load all plugin type base classes
33
- Dir.glob(File.join(__dir__, "v2", "plugin_types", "*.rb")).each { |file| require file }
34
-
35
- module Inspec
36
- # Provides the base class that plugin implementors should use.
37
- def self.plugin(version, plugin_type = nil)
38
- unless version == 2
39
- raise "Only plugins version 2 is supported!"
40
- end
41
-
42
- return Inspec::Plugin::V2::PluginBase if plugin_type.nil?
43
-
44
- Inspec::Plugin::V2::PluginBase.base_class_for_type(plugin_type)
45
- end
46
- end
@@ -1,40 +0,0 @@
1
- module Inspec::Plugin::V2
2
- Activator = Struct.new(
3
- :plugin_name,
4
- :plugin_type,
5
- :activator_name,
6
- :activated,
7
- :exception,
8
- :activation_proc,
9
- :implementation_class
10
- ) do
11
- def initialize(*)
12
- super
13
- self[:activated] = false
14
- end
15
-
16
- alias activated? activated
17
-
18
- # Load a plugin, but if an error is encountered, store it and continue
19
- def activate
20
- return if activated?
21
-
22
- # rubocop: disable Lint/RescueException
23
- begin
24
- impl_class = self[:activation_proc].call
25
- self.activated = true
26
- self[:implementation_class] = impl_class
27
- rescue Exception => ex
28
- self[:exception] = ex
29
- Inspec::Log.error "Could not activate #{self[:plugin_type]} hook named '#{self[:activator_name]}' for plugin #{self[:plugin_name]}"
30
- end
31
- # rubocop: enable Lint/RescueException
32
- end
33
-
34
- # Load a plugin, but if an error is encountered, re-throw it
35
- def activate!
36
- activate
37
- raise exception if exception
38
- end
39
- end
40
- end
@@ -1,151 +0,0 @@
1
- require "json"
2
-
3
- module Inspec::Plugin::V2
4
- # Represents the plugin config file on disk.
5
- class ConfigFile
6
- include Enumerable
7
-
8
- attr_reader :path
9
-
10
- def initialize(path = nil)
11
- @path = path || self.class.default_path
12
- @data = blank_structure
13
-
14
- read_and_validate_file if File.exist?(@path)
15
- end
16
-
17
- # Returns the defaut path for a config file.
18
- # This respects ENV['INSPEC_CONFIG_DIR'].
19
- def self.default_path
20
- File.join(Inspec.config_dir, "plugins.json")
21
- end
22
-
23
- # Implement Enumerable. All Enumerable methds act
24
- # on the plugins list, and yield Hashes that represent
25
- # an entry.
26
- def each(&block)
27
- @data[:plugins].each(&block)
28
- end
29
-
30
- # Look for a plugin by name.
31
- def plugin_by_name(name)
32
- detect { |entry| entry[:name] == name.to_sym }
33
- end
34
-
35
- # Check for a plugin
36
- def existing_entry?(name)
37
- !plugin_by_name(name).nil?
38
- end
39
-
40
- # Add an entry with full validation.
41
- def add_entry(proposed_entry)
42
- unless proposed_entry.keys.all? { |field| field.is_a? Symbol }
43
- raise Inspec::Plugin::V2::ConfigError, "All keys to ConfigFile#add_entry must be symbols"
44
- end
45
-
46
- validate_entry(proposed_entry)
47
-
48
- if existing_entry?(proposed_entry[:name])
49
- raise Inspec::Plugin::V2::ConfigError, "Duplicate plugin name in call to ConfigFile#add_entry: '#{proposed_entry[:name]}'"
50
- end
51
-
52
- @data[:plugins] << proposed_entry
53
- end
54
-
55
- # Removes an entry specified by plugin name.
56
- def remove_entry(name)
57
- unless existing_entry?(name)
58
- raise Inspec::Plugin::V2::ConfigError, "No such entry with plugin name '#{name}'"
59
- end
60
-
61
- @data[:plugins].delete_if { |entry| entry[:name] == name.to_sym }
62
- end
63
-
64
- # Save the file to disk as a JSON structure at the path.
65
- def save
66
- dir = File.dirname(path)
67
- FileUtils.mkdir_p(dir)
68
- File.write(path, JSON.pretty_generate(@data))
69
- end
70
-
71
- private
72
-
73
- def blank_structure
74
- {
75
- plugins_config_version: "1.0.0",
76
- plugins: [],
77
- }
78
- end
79
-
80
- def read_and_validate_file
81
- @data = JSON.parse(File.read(path), symbolize_names: true)
82
- validate_file
83
- rescue JSON::ParserError => e
84
- raise Inspec::Plugin::V2::ConfigError, "Failed to load plugins JSON configuration from #{path}:\n#{e}"
85
- end
86
-
87
- def validate_file # rubocop: disable Metrics/AbcSize
88
- unless @data[:plugins_config_version]
89
- raise Inspec::Plugin::V2::ConfigError, "Missing 'plugins_config_version' entry at #{path} - currently support versions: 1.0.0"
90
- end
91
-
92
- unless @data[:plugins_config_version] == "1.0.0"
93
- raise Inspec::Plugin::V2::ConfigError, "Unsupported plugins.json file version #{@data[:plugins_config_version]} at #{path} - currently support versions: 1.0.0"
94
- end
95
-
96
- plugin_entries = @data[:plugins]
97
- if plugin_entries.nil?
98
- raise Inspec::Plugin::V2::ConfigError, "Malformed plugins.json file at #{path} - missing top-level key named 'plugins', whose value should be an array"
99
- end
100
-
101
- unless plugin_entries.is_a?(Array)
102
- raise Inspec::Plugin::V2::ConfigError, "Malformed plugins.json file at #{path} - top-level key named 'plugins' should be an array"
103
- end
104
-
105
- plugin_entries.each_with_index do |plugin_entry, idx|
106
- begin
107
- validate_entry(plugin_entry)
108
- rescue Inspec::Plugin::V2::ConfigError => ex
109
- # append some context to the message
110
- raise Inspec::Plugin::V2::ConfigError, "Malformed plugins.json file - " + ex.message + " at index #{idx}"
111
- end
112
-
113
- # Check for duplicates
114
- plugin_entries.each_with_index do |other_entry, other_idx|
115
- next if idx == other_idx
116
- next unless other_entry.is_a? Hash # We'll catch that invalid entry later
117
- next if plugin_entry[:name] != other_entry[:name]
118
-
119
- indices = [idx, other_idx].sort
120
- raise Inspec::Plugin::V2::ConfigError, "Malformed plugins.json file - duplicate plugin entry '#{plugin_entry[:name]}' detected at index #{indices[0]} and #{indices[1]}"
121
- end
122
- end
123
- end
124
-
125
- def validate_entry(plugin_entry)
126
- unless plugin_entry.is_a? Hash
127
- raise Inspec::Plugin::V2::ConfigError, "each 'plugins' entry should be a Hash / JSON object"
128
- end
129
-
130
- unless plugin_entry.key? :name
131
- raise Inspec::Plugin::V2::ConfigError, "'plugins' entry missing 'name' field"
132
- end
133
-
134
- # Symbolize the name.
135
- plugin_entry[:name] = plugin_entry[:name].to_sym
136
-
137
- if plugin_entry.key? :installation_type
138
- seen_type = plugin_entry[:installation_type]
139
- unless %i{gem path}.include? seen_type.to_sym
140
- raise Inspec::Plugin::V2::ConfigError, "'plugins' entry with unrecognized installation_type (must be one of 'gem' or 'path')"
141
- end
142
-
143
- plugin_entry[:installation_type] = seen_type.to_sym
144
-
145
- if plugin_entry[:installation_type] == :path && !plugin_entry.key?(:installation_path)
146
- raise Inspec::Plugin::V2::ConfigError, "'plugins' entry with a 'path' installation_type missing installation path"
147
- end
148
- end
149
- end
150
- end
151
- end
@@ -1,96 +0,0 @@
1
- require "singleton"
2
- require "json"
3
- require "inspec/globals"
4
-
5
- module Inspec::Plugin; end
6
-
7
- module Inspec::Plugin::V2
8
- Exclusion = Struct.new(:plugin_name, :rationale)
9
-
10
- class PluginFilter
11
- include Singleton
12
- def initialize
13
- read_filter_data
14
- end
15
-
16
- def self.exclude?(plugin_name)
17
- instance.exclude?(plugin_name)
18
- end
19
-
20
- def exclude?(plugin_name)
21
- # Currently, logic is very simple: is there an exact match?
22
- # In the future, we might add regexes on names, or exclude version ranges
23
- return false unless @filter_data[:exclude].detect { |e| e.plugin_name == plugin_name }
24
-
25
- # OK, return entire data structure.
26
- @filter_data[:exclude].detect { |e| e.plugin_name == plugin_name }
27
- end
28
-
29
- private
30
-
31
- def read_filter_data
32
- path = File.join(Inspec.src_root, "etc", "plugin_filters.json")
33
- @filter_data = JSON.parse(File.read(path))
34
-
35
- unless @filter_data["file_version"] == "1.0.0"
36
- raise Inspec::Plugin::V2::ConfigError, "Unknown plugin fillter file format at #{path}"
37
- end
38
-
39
- validate_plugin_filter_file("1.0.0")
40
-
41
- @filter_data[:exclude] = @filter_data["exclude"].map do |entry|
42
- Exclusion.new(entry["plugin_name"], entry["rationale"])
43
- end
44
- @filter_data.delete("exclude")
45
- end
46
-
47
- def validate_plugin_filter_file(_file_version)
48
- unless @filter_data.key?("exclude") && @filter_data["exclude"].is_a?(Array)
49
- raise Inspec::Plugin::V2::ConfigError, 'Unknown plugin fillter file format: expected "exclude" to be an array'
50
- end
51
-
52
- @filter_data["exclude"].each_with_index do |entry, idx|
53
- unless entry.is_a? Hash
54
- raise Inspec::Plugin::V2::ConfigError, "Unknown plugin fillter file format: expected entry #{idx} to be a Hash / JS Object"
55
- end
56
- unless entry.key?("plugin_name")
57
- raise Inspec::Plugin::V2::ConfigError, "Unknown plugin fillter file format: expected entry #{idx} to have a \"plugin_name\" field"
58
- end
59
- unless entry.key?("rationale")
60
- raise Inspec::Plugin::V2::ConfigError, "Unknown plugin fillter file format: expected entry #{idx} to have a \"rationale\" field"
61
- end
62
- end
63
- end
64
- end
65
-
66
- # To be a valid plugin name, the plugin must beign with either
67
- # inspec- or train-, AND ALSO not be on the exclusion list.
68
- # We maintain this exclusion list to avoid confusing users.
69
- # For example, we want to have a real gem named inspec-test-fixture,
70
- # but we don't want the users to see that.
71
- module FilterPredicates
72
- def train_plugin_name?(name)
73
- valid_plugin_name?(name, :train)
74
- end
75
-
76
- def inspec_plugin_name?(name)
77
- valid_plugin_name?(name, :inspec)
78
- end
79
-
80
- def valid_plugin_name?(name, kind = :either)
81
- # Must have a permitted prefix.
82
- return false unless case kind
83
- when :inspec
84
- name.to_s.start_with?("inspec-")
85
- when :train
86
- name.to_s.start_with?("train-")
87
- when :either
88
- name.to_s.match(/^(inspec|train)-/)
89
- else false
90
- end # rubocop: disable Layout/EndAlignment
91
-
92
- # And must not be on the exclusion list.
93
- ! Inspec::Plugin::V2::PluginFilter.exclude?(name)
94
- end
95
- end
96
- end
@@ -1,512 +0,0 @@
1
- # This file is not required by default.
2
-
3
- require "singleton"
4
- require "forwardable"
5
- require "fileutils"
6
-
7
- # Gem extensions for doing unusual things - not loaded by Gem default
8
- require "rubygems/package"
9
- require "rubygems/name_tuple"
10
- require "rubygems/uninstaller"
11
- require "rubygems/remote_fetcher"
12
-
13
- require "inspec/plugin/v2/filter"
14
-
15
- module Inspec::Plugin::V2
16
- # Handles all actions modifying the user's plugin set:
17
- # * Modifying the plugins.json file
18
- # * Installing, updating, and removing gem-based plugins
19
- # Loading plugins is handled by Loader.
20
- # Listing plugins is handled by Loader.
21
- # Searching for plugins is handled by ???
22
- class Installer
23
- include Singleton
24
- extend Forwardable
25
-
26
- Gem.configuration["verbose"] = false
27
-
28
- attr_reader :conf_file, :loader, :registry
29
- def_delegator :loader, :plugin_gem_path, :gem_path
30
- def_delegator :loader, :plugin_conf_file_path
31
- def_delegator :loader, :list_managed_gems
32
- def_delegator :loader, :list_installed_plugin_gems
33
-
34
- def initialize
35
- @loader = Inspec::Plugin::V2::Loader.new
36
- @registry = Inspec::Plugin::V2::Registry.instance
37
- end
38
-
39
- def plugin_installed?(name)
40
- list_installed_plugin_gems.detect { |spec| spec.name == name }
41
- end
42
-
43
- def plugin_version_installed?(name, version)
44
- list_installed_plugin_gems.detect { |spec| spec.name == name && spec.version == Gem::Version.new(version) }
45
- end
46
-
47
- # Installs a plugin. Defaults to assuming the plugin provided is a gem, and will try to install
48
- # from whatever gemsources `rubygems` thinks it should use.
49
- # If it's a gem, installs it and its dependencies to the `gem_path`. The gem is not activated.
50
- # If it's a path, leaves it in place.
51
- # Finally, updates the plugins.json file with the new information.
52
- # No attempt is made to load the plugin.
53
- #
54
- # @param [String] plugin_name
55
- # @param [Hash] opts The installation options
56
- # @option opts [String] :gem_file Path to a local gem file to install from
57
- # @option opts [String] :path Path to a file to be used as the entry point for a path-based plugin
58
- # @option opts [String] :version Version constraint for remote gem installs
59
- def install(plugin_name, opts = {})
60
- # TODO: - check plugins.json for validity before trying anything that needs to modify it.
61
- validate_installation_opts(plugin_name, opts)
62
-
63
- # TODO: return installed thingy
64
- if opts[:path]
65
- install_from_path(plugin_name, opts)
66
- elsif opts[:gem_file]
67
- gem_version = install_from_gem_file(plugin_name, opts)
68
- opts[:version] = gem_version.to_s
69
- else
70
- gem_version = install_from_remote_gems(plugin_name, opts)
71
- opts[:version] = gem_version.to_s
72
- end
73
-
74
- update_plugin_config_file(plugin_name, opts.merge({ action: :install }))
75
- end
76
-
77
- # Updates a plugin. Most options same as install, but will not handle path installs.
78
- # If no :version is provided, updates to the latest.
79
- # If a version is provided, the plugin becomes pinned at that specified version.
80
- #
81
- # @param [String] plugin_name
82
- # @param [Hash] opts The installation options
83
- # @option opts [String] :gem_file Reserved for future use. No effect.
84
- # @option opts [String] :version Version constraint for remote gem updates
85
- def update(plugin_name, opts = {})
86
- # TODO: - check plugins.json for validity before trying anything that needs to modify it.
87
- validate_update_opts(plugin_name, opts)
88
- opts[:update_mode] = true
89
-
90
- # TODO: Handle installing from a local file
91
- # TODO: Perform dependency checks to make sure the new solution is valid
92
- gem_version = install_from_remote_gems(plugin_name, opts)
93
-
94
- update_plugin_config_file(plugin_name, opts.merge({ action: :update, version: gem_version.to_s }))
95
- end
96
-
97
- # Uninstalls (removes) a plugin. Refers to plugin.json to determine if it
98
- # was a gem-based or path-based install.
99
- # If it's a gem, uninstalls it, and all other unused plugins.
100
- # If it's a path, removes the reference from the plugins.json, but does not
101
- # tamper with the plugin source tree.
102
- # Either way, the plugins.json file is updated with the new information.
103
- #
104
- # @param [String] plugin_name
105
- # @param [Hash] opts The uninstallation options. Currently unused.
106
- def uninstall(plugin_name, opts = {})
107
- # TODO: - check plugins.json for validity before trying anything that needs to modify it.
108
- validate_uninstall_opts(plugin_name, opts)
109
-
110
- if registry.path_based_plugin?(plugin_name)
111
- uninstall_via_path(plugin_name, opts)
112
- else
113
- uninstall_via_gem(plugin_name, opts)
114
- end
115
-
116
- update_plugin_config_file(plugin_name, opts.merge({ action: :uninstall }))
117
- end
118
-
119
- # Search rubygems.org for a plugin gem.
120
- #
121
- # @param [String] plugin_seach_term
122
- # @param [Hash] opts Search options
123
- # @option opts [TrueClass, FalseClass] :exact If true, use plugin_search_term exactly. If false (default), append a wildcard.
124
- # @option opts [Symbol] :scope Which versions to search for. :released (default) - all released versions. :prerelease - Also include versioned marked prerelease. :latest - only return one version, the latest one.
125
- # @return [Hash of Arrays] - Keys are String names of gems, arrays contain String versions.
126
- def search(plugin_query, opts = {}) # rubocop: disable Metrics/AbcSize
127
- validate_search_opts(plugin_query, opts)
128
-
129
- fetcher = Gem::SpecFetcher.fetcher
130
- matched_tuples = []
131
- if opts[:exact]
132
- matched_tuples = fetcher.detect(opts[:scope]) { |tuple| tuple.name == plugin_query }
133
- else
134
- regex = Regexp.new("^" + plugin_query + ".*")
135
- matched_tuples = fetcher.detect(opts[:scope]) do |tuple|
136
- tuple.name =~ regex && !Inspec::Plugin::V2::PluginFilter.exclude?(tuple.name)
137
- end
138
- end
139
-
140
- # sort tuples
141
- matched_tuples.sort! { |a, b| b.first.version <=> a.first.version }
142
-
143
- gem_info = {}
144
- matched_tuples.each do |tuple|
145
- gem_info[tuple.first.name] ||= []
146
- gem_info[tuple.first.name] << tuple.first.version.to_s
147
- end
148
- gem_info
149
- end
150
-
151
- # Testing API. Performs a hard reset on the installer and registry, and reloads the loader.
152
- # Not for public use.
153
- # TODO: bad timing coupling in tests
154
- def __reset
155
- registry.__reset
156
- end
157
-
158
- def __reset_loader
159
- @loader = Loader.new
160
- end
161
-
162
- private
163
-
164
- #===================================================================#
165
- # Validation Methods #
166
- #===================================================================#
167
-
168
- # rubocop: disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
169
- # rationale for rubocop exemption: While there are many conditionals, they are all of the same form;
170
- # its goal is to check for several subtle combinations of params, and raise an error if needed. It's
171
- # straightforward to understand, but has to handle many cases.
172
- def validate_installation_opts(plugin_name, opts)
173
- unless plugin_name =~ /^(inspec|train)-/
174
- raise InstallError, "All inspec plugins must begin with either 'inspec-' or 'train-' - refusing to install #{plugin_name}"
175
- end
176
-
177
- if opts.key?(:gem_file) && opts.key?(:path)
178
- raise InstallError, "May not specify both gem_file and a path (for installing from source)"
179
- end
180
-
181
- if opts.key?(:version) && (opts.key?(:gem_file) || opts.key?(:path))
182
- raise InstallError, "May not specify a version when installing from a gem file or source path"
183
- end
184
-
185
- if opts.key?(:gem_file)
186
- unless opts[:gem_file].end_with?(".gem")
187
- raise InstallError, "When installing from a local gem file, gem file must have '.gem' extension - saw #{opts[:gem_file]}"
188
- end
189
- unless File.exist?(opts[:gem_file])
190
- raise InstallError, "Could not find local gem file to install - #{opts[:gem_file]}"
191
- end
192
- elsif opts.key?(:path)
193
- unless File.exist?(opts[:path])
194
- raise InstallError, "Could not find path for install from source path - #{opts[:path]}"
195
- end
196
- end
197
-
198
- if plugin_installed?(plugin_name)
199
- if opts.key?(:version) && plugin_version_installed?(plugin_name, opts[:version])
200
- raise InstallError, "#{plugin_name} version #{opts[:version]} is already installed."
201
- else
202
- raise InstallError, "#{plugin_name} is already installed. Use 'inspec plugin update' to change version."
203
- end
204
- end
205
-
206
- reason = Inspec::Plugin::V2::PluginFilter.exclude?(plugin_name)
207
- if reason
208
- ex = PluginExcludedError.new("Refusing to install #{plugin_name}. It is on the Plugin Exclusion List. Rationale: #{reason.rationale}")
209
- ex.details = reason
210
- raise ex
211
- end
212
- end
213
- # rubocop: enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
214
-
215
- def validate_update_opts(plugin_name, opts)
216
- # Only update plugins we know about
217
- unless plugin_name =~ /^(inspec|train)-/
218
- raise UpdateError, "All inspec plugins must begin with either 'inspec-' or 'train-' - refusing to update #{plugin_name}"
219
- end
220
- unless registry.known_plugin?(plugin_name.to_sym)
221
- raise UpdateError, "'#{plugin_name}' is not installed - use 'inspec plugin install' to install it"
222
- end
223
-
224
- # No local path support for update
225
- if registry[plugin_name.to_sym].installation_type == :path
226
- raise UpdateError, "'inspec plugin update' will not handle path-based plugins like '#{plugin_name}'. Use 'inspec plugin uninstall' to remove the reference, then install as a gem."
227
- end
228
- if opts.key?(:path)
229
- raise UpdateError, "'inspec plugin update' will not install from a path."
230
- end
231
-
232
- if opts.key?(:version) && plugin_version_installed?(plugin_name, opts[:version])
233
- raise UpdateError, "#{plugin_name} version #{opts[:version]} is already installed."
234
- end
235
- end
236
-
237
- def validate_uninstall_opts(plugin_name, _opts)
238
- # Only uninstall plugins we know about
239
- unless plugin_name =~ /^(inspec|train)-/
240
- raise UnInstallError, "All inspec plugins must begin with either 'inspec-' or 'train-' - refusing to uninstall #{plugin_name}"
241
- end
242
- unless registry.known_plugin?(plugin_name.to_sym)
243
- raise UnInstallError, "'#{plugin_name}' is not installed, refusing to uninstall."
244
- end
245
- end
246
-
247
- def validate_search_opts(search_term, opts)
248
- unless search_term =~ /^(inspec|train)-/
249
- raise SearchError, "All inspec plugins must begin with either 'inspec-' or 'train-'."
250
- end
251
-
252
- opts[:scope] ||= :released
253
- unless %i{prerelease released latest}.include?(opts[:scope])
254
- raise SearchError, "Search scope for listing versons must be :prerelease, :released, or :latest."
255
- end
256
- end
257
-
258
- #===================================================================#
259
- # Install / Upgrade Methods #
260
- #===================================================================#
261
-
262
- def install_from_path(requested_plugin_name, opts)
263
- # Nothing to do here; we will later update the plugins file with the path.
264
- end
265
-
266
- def install_from_gem_file(requested_plugin_name, opts)
267
- # Make Set that encompasses just the gemfile that was provided
268
- plugin_local_source = Gem::Source::SpecificFile.new(opts[:gem_file])
269
-
270
- plugin_dependency = Gem::Dependency.new(
271
- requested_plugin_name,
272
- plugin_local_source.spec.version
273
- )
274
-
275
- requested_local_gem_set = Gem::Resolver::InstallerSet.new(:both)
276
- requested_local_gem_set.add_local(
277
- plugin_dependency.name,
278
- plugin_local_source.spec,
279
- plugin_local_source
280
- )
281
-
282
- install_gem_to_plugins_dir(plugin_dependency, [requested_local_gem_set])
283
- end
284
-
285
- def install_from_remote_gems(requested_plugin_name, opts)
286
- plugin_dependency = Gem::Dependency.new(requested_plugin_name, opts[:version] || "> 0")
287
- # BestSet is rubygems.org API + indexing
288
- install_gem_to_plugins_dir(plugin_dependency, [Gem::Resolver::BestSet.new], opts[:update_mode])
289
- end
290
-
291
- def install_gem_to_plugins_dir(new_plugin_dependency, # rubocop: disable Metrics/AbcSize
292
- extra_request_sets = [],
293
- update_mode = false)
294
-
295
- # Get a list of all the gems available to us.
296
- gem_to_force_update = update_mode ? new_plugin_dependency.name : nil
297
- set_available_for_resolution = build_gem_request_universe(extra_request_sets, gem_to_force_update)
298
-
299
- # Solve the dependency (that is, find a way to install the new plugin and anything it needs)
300
- request_set = Gem::RequestSet.new(new_plugin_dependency)
301
-
302
- begin
303
- solution = request_set.resolve(set_available_for_resolution)
304
- rescue Gem::UnsatisfiableDependencyError => gem_ex
305
- # TODO: use search facility to determine if the requested gem exists at all, vs if the constraints are impossible
306
- ex = Inspec::Plugin::V2::InstallError.new(gem_ex.message)
307
- ex.plugin_name = new_plugin_dependency.name
308
- raise ex
309
- end
310
-
311
- # Activate all current plugins before trying to activate the new one
312
- loader.list_managed_gems.each do |spec|
313
- next if spec.name == new_plugin_dependency.name && update_mode
314
-
315
- spec.activate
316
- end
317
-
318
- # Make sure we remove any previously loaded gem on update
319
- Gem.loaded_specs.delete(new_plugin_dependency.name) if update_mode
320
-
321
- # Test activating the solution. This makes sure we do not try to load two different versions
322
- # of the same gem on the stack or a malformed dependency.
323
- begin
324
- solution.each do |activation_request|
325
- unless activation_request.full_spec.activated?
326
- activation_request.full_spec.activate
327
- end
328
- end
329
- rescue Gem::LoadError => gem_ex
330
- ex = Inspec::Plugin::V2::InstallError.new(gem_ex.message)
331
- ex.plugin_name = new_plugin_dependency.name
332
- raise ex
333
- end
334
-
335
- # OK, perform the installation.
336
- # Ignore deps here, because any needed deps should already be baked into new_plugin_dependency
337
- request_set.install_into(gem_path, true, ignore_dependencies: true, document: [])
338
-
339
- # Painful aspect of rubygems: the VendorSet request set type needs to be able to find a gemspec
340
- # file within the source of the gem (and not all gems include it in their source tree; they are
341
- # not obliged to during packaging.)
342
- # So, after each install, run a scan for all gem(specs) we manage, and copy in their gemspec file
343
- # into the exploded gem source area if absent.
344
- loader.list_managed_gems.each do |spec|
345
- path_inside_source = File.join(spec.gem_dir, "#{spec.name}.gemspec")
346
- unless File.exist?(path_inside_source)
347
- File.write(path_inside_source, spec.to_ruby)
348
- end
349
- end
350
-
351
- # Locate the GemVersion for the new dependency and return it
352
- solution.detect { |g| g.name == new_plugin_dependency.name }.version
353
- end
354
-
355
- #===================================================================#
356
- # UnInstall Methods #
357
- #===================================================================#
358
-
359
- def uninstall_via_path(requested_plugin_name, opts)
360
- # Nothing to do here; we will later update the plugins file to remove the plugin entry.
361
- end
362
-
363
- def uninstall_via_gem(plugin_name_to_be_removed, _opts)
364
- # Strategy: excluding the plugin we want to uninstall, determine a gem install solution
365
- # based on gems we already have, then remove anything not needed. This removes 3 kinds
366
- # of cruft:
367
- # 1. All versions of the unwanted plugin gem
368
- # 2. All dependencies of the unwanted plugin gem (that aren't needed by something else)
369
- # 3. All other gems installed under the ~/.inspec/gems area that are not needed
370
- # by a plugin gem. TODO: ideally this would be a separate 'clean' operation.
371
-
372
- # Create a list of plugins dependencies, including any version constraints,
373
- # excluding any that are path-or-core-based, excluding the gem to be removed
374
- plugin_deps_we_still_must_satisfy = registry.plugin_statuses
375
- plugin_deps_we_still_must_satisfy = plugin_deps_we_still_must_satisfy.select do |status|
376
- status.installation_type == :user_gem && status.name != plugin_name_to_be_removed.to_sym
377
- end
378
- plugin_deps_we_still_must_satisfy = plugin_deps_we_still_must_satisfy.map do |status|
379
- constraint = status.version || "> 0"
380
- Gem::Dependency.new(status.name.to_s, constraint)
381
- end
382
-
383
- # Make a Request Set representing the still-needed deps
384
- request_set_we_still_must_satisfy = Gem::RequestSet.new(*plugin_deps_we_still_must_satisfy)
385
- request_set_we_still_must_satisfy.remote = false
386
-
387
- # Find out which gems we still actually need...
388
- names_of_gems_we_actually_need = \
389
- request_set_we_still_must_satisfy.resolve(build_gem_request_universe)
390
- .map(&:full_spec).map(&:full_name)
391
-
392
- # ... vs what we currently have, which should have some cruft
393
- cruft_gem_specs = loader.list_managed_gems.reject do |spec|
394
- names_of_gems_we_actually_need.include?(spec.full_name)
395
- end
396
-
397
- # Ok, delete the unneeded gems
398
- cruft_gem_specs.each do |cruft_spec|
399
- Gem::Uninstaller.new(
400
- cruft_spec.name,
401
- version: cruft_spec.version,
402
- install_dir: gem_path,
403
- # Docs on this class are poor. Next 4 are reasonable, but cargo-culted.
404
- all: true,
405
- executables: true,
406
- force: true,
407
- ignore: true
408
- ).uninstall_gem(cruft_spec)
409
- end
410
- end
411
-
412
- #===================================================================#
413
- # Utilities
414
- #===================================================================#
415
-
416
- # This class allows us to build a Resolver set with the gems that are
417
- # already included either with Ruby or with the InSpec install
418
- #
419
- # This code is heavily based on:
420
- # https://github.com/hashicorp/vagrant/blob/32237377/lib/vagrant/bundler.rb#L400
421
- # https://github.com/hashicorp/vagrant/blob/32237377/lib/vagrant/bundler.rb#L565
422
- class InstalledVendorSet < Gem::Resolver::Set
423
- def initialize
424
- super
425
- @remote = false
426
- @specs = []
427
-
428
- # Grab any pre loaded gems
429
- Gem::Specification.find_all do |spec|
430
- @specs << spec
431
- end
432
-
433
- # find all gem specification directories
434
-
435
- spec_dir = if Gem.respond_to? :default_specifications_dir
436
- Gem.default_specifications_dir
437
- else
438
- Gem::Specification.default_specifications_dir
439
- end
440
- directories = [spec_dir]
441
- unless defined?(::Bundler)
442
- # add in any others that do not start with the user directory
443
- directories += Gem::Specification.dirs.find_all do |path|
444
- !path.start_with?(Gem.user_dir)
445
- end
446
- end
447
-
448
- # add them all to the specs array
449
- Gem::Specification.each_spec(directories) do |spec|
450
- @specs << spec
451
- end
452
-
453
- # resolver expects one of each spec so uniq here.
454
- @specs.uniq!
455
- end
456
-
457
- def find_all(req)
458
- @specs.select { |spec| req.match?(spec) }.map do |spec|
459
- Gem::Resolver::InstalledSpecification.new(self, spec)
460
- end
461
- end
462
- end
463
-
464
- # Provides a RequestSet (a set of gems representing the gems that are available to
465
- # solve a dependency request) that represents a combination of:
466
- # * the gems included in the system
467
- # * the gems included in the inspec install
468
- # * the currently installed gems in the ~/.inspec/gems directory
469
- # * any other sets you provide
470
- def build_gem_request_universe(extra_request_sets = [], gem_to_force_update = nil)
471
- installed_plugins_gem_set = Gem::Resolver::VendorSet.new
472
- loader.list_managed_gems.each do |spec|
473
- next if spec.name == gem_to_force_update
474
-
475
- installed_plugins_gem_set.add_vendor_gem(spec.name, spec.gem_dir)
476
- end
477
-
478
- # Combine the Sets, so the resolver has one composite place to look
479
- Gem::Resolver.compose_sets(
480
- installed_plugins_gem_set, # The gems that are in the plugin gem path directory tree
481
- InstalledVendorSet.new,
482
- *extra_request_sets # Anything else our caller wanted to include
483
- )
484
- end
485
-
486
- #===================================================================#
487
- # plugins.json Maintenance Methods #
488
- #===================================================================#
489
- def update_plugin_config_file(plugin_name, opts)
490
- # Be careful no to initialize this until just before we write.
491
- # Under testing, ENV['INSPEC_CONFIG_DIR'] may have changed.
492
- @conf_file = Inspec::Plugin::V2::ConfigFile.new
493
-
494
- # Remove, then optionally rebuild, the entry for the plugin being modified.
495
- conf_file.remove_entry(plugin_name) if conf_file.existing_entry?(plugin_name)
496
- unless opts[:action] == :uninstall
497
- entry = { name: plugin_name }
498
- # Parsing by Requirement handles lot of awkward formattoes
499
- entry[:version] = Gem::Requirement.new(opts[:version]).to_s if opts.key?(:version)
500
- if opts.key?(:path)
501
- entry[:installation_type] = :path
502
- entry[:installation_path] = opts[:path]
503
- end
504
- conf_file.add_entry(entry)
505
- end
506
-
507
- conf_file.save
508
-
509
- conf_file
510
- end
511
- end
512
- end