akerl-r10k 3.14.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (405) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/pull_request_template.md +4 -0
  4. data/.github/workflows/docker.yml +64 -0
  5. data/.github/workflows/release.yml +37 -0
  6. data/.github/workflows/rspec_tests.yml +81 -0
  7. data/.github/workflows/stale.yml +21 -0
  8. data/.gitignore +10 -0
  9. data/.travis.yml +42 -0
  10. data/CHANGELOG.mkd +1879 -0
  11. data/CODEOWNERS +2 -0
  12. data/CONTRIBUTING.mkd +105 -0
  13. data/Gemfile +15 -0
  14. data/LICENSE +14 -0
  15. data/README.mkd +139 -0
  16. data/Rakefile +3 -0
  17. data/bin/r10k +17 -0
  18. data/doc/common-patterns.mkd +45 -0
  19. data/doc/dynamic-environments/configuration.mkd +850 -0
  20. data/doc/dynamic-environments/git-environments.mkd +75 -0
  21. data/doc/dynamic-environments/introduction.mkd +69 -0
  22. data/doc/dynamic-environments/master-configuration.mkd +40 -0
  23. data/doc/dynamic-environments/quickstart.mkd +201 -0
  24. data/doc/dynamic-environments/svn-environments.mkd +45 -0
  25. data/doc/dynamic-environments/usage.mkd +163 -0
  26. data/doc/dynamic-environments/workflow-guide.mkd +247 -0
  27. data/doc/dynamic-environments.mkd +31 -0
  28. data/doc/faq.mkd +164 -0
  29. data/doc/git/cloning-and-mirroring.mkd +60 -0
  30. data/doc/git/providers.mkd +133 -0
  31. data/doc/puppetfile.mkd +355 -0
  32. data/doc/updating-your-puppetfile.mkd +38 -0
  33. data/docker/.gitignore +1 -0
  34. data/docker/.rspec +4 -0
  35. data/docker/Gemfile +11 -0
  36. data/docker/Makefile +99 -0
  37. data/docker/README.md +28 -0
  38. data/docker/docker-compose.yml +18 -0
  39. data/docker/r10k/Dockerfile +68 -0
  40. data/docker/r10k/adduser.sh +13 -0
  41. data/docker/r10k/docker-entrypoint.d/10-analytics.sh +30 -0
  42. data/docker/r10k/docker-entrypoint.sh +10 -0
  43. data/docker/r10k/release.Dockerfile +55 -0
  44. data/docker/spec/dockerfile_spec.rb +37 -0
  45. data/docker/spec/fixtures/Puppetfile +2 -0
  46. data/integration/Gemfile +19 -0
  47. data/integration/README.mkd +29 -0
  48. data/integration/Rakefile +79 -0
  49. data/integration/component/pre-suite/05_install_dev_r10k.rb +12 -0
  50. data/integration/files/README.mkd +4 -0
  51. data/integration/files/hiera.yaml +8 -0
  52. data/integration/files/modules/helloworld/manifests/init.pp +3 -0
  53. data/integration/files/modules/hieratest/manifests/init.pp +3 -0
  54. data/integration/files/modules/unicode/files/pretend_unicode +1 -0
  55. data/integration/files/modules/unicode/manifests/init.pp +6 -0
  56. data/integration/files/pre-suite/git_config.pp.erb +19 -0
  57. data/integration/files/pre-suite/prod_env.config +3 -0
  58. data/integration/files/r10k_conf.yaml.erb +9 -0
  59. data/integration/lib/README.mkd +4 -0
  60. data/integration/lib/git_utils.rb +205 -0
  61. data/integration/lib/master_manipulator.rb +205 -0
  62. data/integration/lib/r10k_utils.rb +222 -0
  63. data/integration/manifests/README.mkd +4 -0
  64. data/integration/pre-suite/00_pe_install.rb +6 -0
  65. data/integration/pre-suite/10_git_config.rb +48 -0
  66. data/integration/pre-suite/20_pe_r10k.rb +55 -0
  67. data/integration/pre-suite/README.mkd +5 -0
  68. data/integration/tests/Puppetfile/HTTP_PROXY_affects_forge_source.rb +72 -0
  69. data/integration/tests/Puppetfile/HTTP_PROXY_affects_git_source.rb +70 -0
  70. data/integration/tests/README.mkd +4 -0
  71. data/integration/tests/basic_functionality/basic_deployment.rb +176 -0
  72. data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
  73. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +51 -0
  74. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +28 -0
  75. data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +45 -0
  76. data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +34 -0
  77. data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
  78. data/integration/tests/basic_functionality/proxy_with_pe_only_module.rb +128 -0
  79. data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
  80. data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +109 -0
  81. data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +108 -0
  82. data/integration/tests/command_line/deploy_env_without_mod_update.rb +76 -0
  83. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +77 -0
  84. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +23 -0
  85. data/integration/tests/git_source/HTTP_proxy_and_git_source.rb +70 -0
  86. data/integration/tests/git_source/git_source_git.rb +128 -0
  87. data/integration/tests/git_source/git_source_repeated_remote.rb +68 -0
  88. data/integration/tests/git_source/git_source_ssh.rb +87 -0
  89. data/integration/tests/git_source/git_source_submodule.rb +70 -0
  90. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +38 -0
  91. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +46 -0
  92. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +73 -0
  93. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +35 -0
  94. data/integration/tests/i18n/deploy_module_with_unicode_in_file_name.rb +64 -0
  95. data/integration/tests/purging/content_not_purged_at_root.rb +89 -0
  96. data/integration/tests/purging/default_purging.rb +125 -0
  97. data/integration/tests/purging/does_not_purge_files_on_white_list.rb +93 -0
  98. data/integration/tests/purging/invalid_whitelist_types.rb +63 -0
  99. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
  100. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +112 -0
  101. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +118 -0
  102. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +100 -0
  103. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +133 -0
  104. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +161 -0
  105. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +46 -0
  106. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +48 -0
  107. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +45 -0
  108. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +43 -0
  109. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +45 -0
  110. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +64 -0
  111. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +75 -0
  112. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +44 -0
  113. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +58 -0
  114. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +34 -0
  115. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +36 -0
  116. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +49 -0
  117. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +58 -0
  118. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +45 -0
  119. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +75 -0
  120. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +105 -0
  121. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +81 -0
  122. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +49 -0
  123. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +75 -0
  124. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +82 -0
  125. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +68 -0
  126. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +94 -0
  127. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +89 -0
  128. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +117 -0
  129. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +60 -0
  130. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +166 -0
  131. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +163 -0
  132. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +111 -0
  133. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +78 -0
  134. data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +100 -0
  135. data/lib/r10k/action/base.rb +41 -0
  136. data/lib/r10k/action/cri_runner.rb +72 -0
  137. data/lib/r10k/action/deploy/deploy_helpers.rb +38 -0
  138. data/lib/r10k/action/deploy/display.rb +128 -0
  139. data/lib/r10k/action/deploy/environment.rb +260 -0
  140. data/lib/r10k/action/deploy/module.rb +139 -0
  141. data/lib/r10k/action/deploy.rb +9 -0
  142. data/lib/r10k/action/puppetfile/check.rb +35 -0
  143. data/lib/r10k/action/puppetfile/cri_runner.rb +26 -0
  144. data/lib/r10k/action/puppetfile/install.rb +48 -0
  145. data/lib/r10k/action/puppetfile/purge.rb +37 -0
  146. data/lib/r10k/action/puppetfile.rb +10 -0
  147. data/lib/r10k/action/runner.rb +171 -0
  148. data/lib/r10k/action/visitor.rb +34 -0
  149. data/lib/r10k/cli/deploy.rb +126 -0
  150. data/lib/r10k/cli/ext/logging.rb +15 -0
  151. data/lib/r10k/cli/help.rb +7 -0
  152. data/lib/r10k/cli/puppetfile.rb +73 -0
  153. data/lib/r10k/cli/version.rb +31 -0
  154. data/lib/r10k/cli.rb +51 -0
  155. data/lib/r10k/content_synchronizer.rb +95 -0
  156. data/lib/r10k/deployment/config.rb +56 -0
  157. data/lib/r10k/deployment.rb +132 -0
  158. data/lib/r10k/environment/bare.rb +13 -0
  159. data/lib/r10k/environment/base.rb +230 -0
  160. data/lib/r10k/environment/git.rb +93 -0
  161. data/lib/r10k/environment/name.rb +109 -0
  162. data/lib/r10k/environment/plain.rb +16 -0
  163. data/lib/r10k/environment/svn.rb +98 -0
  164. data/lib/r10k/environment/tarball.rb +78 -0
  165. data/lib/r10k/environment/with_modules.rb +174 -0
  166. data/lib/r10k/environment.rb +39 -0
  167. data/lib/r10k/errors/formatting.rb +28 -0
  168. data/lib/r10k/errors.rb +66 -0
  169. data/lib/r10k/feature/collection.rb +23 -0
  170. data/lib/r10k/feature.rb +56 -0
  171. data/lib/r10k/features.rb +20 -0
  172. data/lib/r10k/forge/module_release.rb +229 -0
  173. data/lib/r10k/git/alternates.rb +63 -0
  174. data/lib/r10k/git/cache.rb +107 -0
  175. data/lib/r10k/git/errors.rb +34 -0
  176. data/lib/r10k/git/rugged/bare_repository.rb +85 -0
  177. data/lib/r10k/git/rugged/base_repository.rb +104 -0
  178. data/lib/r10k/git/rugged/cache.rb +19 -0
  179. data/lib/r10k/git/rugged/credentials.rb +205 -0
  180. data/lib/r10k/git/rugged/thin_repository.rb +96 -0
  181. data/lib/r10k/git/rugged/working_repository.rb +149 -0
  182. data/lib/r10k/git/rugged.rb +17 -0
  183. data/lib/r10k/git/shellgit/bare_repository.rb +43 -0
  184. data/lib/r10k/git/shellgit/base_repository.rb +137 -0
  185. data/lib/r10k/git/shellgit/cache.rb +11 -0
  186. data/lib/r10k/git/shellgit/thin_repository.rb +73 -0
  187. data/lib/r10k/git/shellgit/working_repository.rb +112 -0
  188. data/lib/r10k/git/shellgit.rb +9 -0
  189. data/lib/r10k/git/stateful_repository.rb +109 -0
  190. data/lib/r10k/git.rb +200 -0
  191. data/lib/r10k/initializers.rb +93 -0
  192. data/lib/r10k/instance_cache.rb +32 -0
  193. data/lib/r10k/keyed_factory.rb +39 -0
  194. data/lib/r10k/logging/terminaloutputter.rb +36 -0
  195. data/lib/r10k/logging.rb +186 -0
  196. data/lib/r10k/module/base.rb +182 -0
  197. data/lib/r10k/module/definition.rb +64 -0
  198. data/lib/r10k/module/forge.rb +208 -0
  199. data/lib/r10k/module/git.rb +156 -0
  200. data/lib/r10k/module/local.rb +40 -0
  201. data/lib/r10k/module/metadata_file.rb +31 -0
  202. data/lib/r10k/module/svn.rb +129 -0
  203. data/lib/r10k/module/tarball.rb +101 -0
  204. data/lib/r10k/module.rb +57 -0
  205. data/lib/r10k/module_loader/puppetfile/dsl.rb +42 -0
  206. data/lib/r10k/module_loader/puppetfile.rb +290 -0
  207. data/lib/r10k/puppetfile.rb +211 -0
  208. data/lib/r10k/settings/collection.rb +123 -0
  209. data/lib/r10k/settings/container.rb +97 -0
  210. data/lib/r10k/settings/definition.rb +124 -0
  211. data/lib/r10k/settings/enum_definition.rb +30 -0
  212. data/lib/r10k/settings/helpers.rb +38 -0
  213. data/lib/r10k/settings/list.rb +107 -0
  214. data/lib/r10k/settings/loader.rb +99 -0
  215. data/lib/r10k/settings/mixin.rb +54 -0
  216. data/lib/r10k/settings/uri_definition.rb +19 -0
  217. data/lib/r10k/settings.rb +312 -0
  218. data/lib/r10k/source/base.rb +93 -0
  219. data/lib/r10k/source/exec.rb +51 -0
  220. data/lib/r10k/source/git.rb +178 -0
  221. data/lib/r10k/source/hash.rb +182 -0
  222. data/lib/r10k/source/svn.rb +142 -0
  223. data/lib/r10k/source/yaml.rb +20 -0
  224. data/lib/r10k/source/yamldir.rb +32 -0
  225. data/lib/r10k/source.rb +42 -0
  226. data/lib/r10k/svn/remote.rb +68 -0
  227. data/lib/r10k/svn/working_dir.rb +125 -0
  228. data/lib/r10k/svn.rb +6 -0
  229. data/lib/r10k/tarball.rb +183 -0
  230. data/lib/r10k/util/attempt.rb +84 -0
  231. data/lib/r10k/util/basedir.rb +65 -0
  232. data/lib/r10k/util/cacheable.rb +31 -0
  233. data/lib/r10k/util/cleaner.rb +21 -0
  234. data/lib/r10k/util/commands.rb +31 -0
  235. data/lib/r10k/util/downloader.rb +134 -0
  236. data/lib/r10k/util/exec_env.rb +36 -0
  237. data/lib/r10k/util/license.rb +24 -0
  238. data/lib/r10k/util/platform.rb +42 -0
  239. data/lib/r10k/util/purgeable.rb +154 -0
  240. data/lib/r10k/util/setopts.rb +78 -0
  241. data/lib/r10k/util/subprocess/result.rb +56 -0
  242. data/lib/r10k/util/subprocess/runner/jruby.rb +23 -0
  243. data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
  244. data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
  245. data/lib/r10k/util/subprocess/runner/windows.rb +23 -0
  246. data/lib/r10k/util/subprocess/runner.rb +26 -0
  247. data/lib/r10k/util/subprocess/subprocess_error.rb +24 -0
  248. data/lib/r10k/util/subprocess.rb +85 -0
  249. data/lib/r10k/util/symbolize_keys.rb +35 -0
  250. data/lib/r10k/version.rb +6 -0
  251. data/lib/r10k.rb +11 -0
  252. data/locales/config.yaml +21 -0
  253. data/locales/r10k.pot +693 -0
  254. data/r10k.gemspec +52 -0
  255. data/r10k.yaml.example +140 -0
  256. data/spec/fixtures/empty/.empty +0 -0
  257. data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
  258. data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
  259. data/spec/fixtures/module/forge/eight_hundred/Modulefile +8 -0
  260. data/spec/fixtures/module/forge/eight_hundred/metadata.json +19 -0
  261. data/spec/fixtures/tarball/tarball.tar.gz +0 -0
  262. data/spec/fixtures/unit/action/r10k.yaml +5 -0
  263. data/spec/fixtures/unit/action/r10k_cachedir.yaml +2 -0
  264. data/spec/fixtures/unit/action/r10k_creds.yaml +9 -0
  265. data/spec/fixtures/unit/action/r10k_forge_auth.yaml +4 -0
  266. data/spec/fixtures/unit/action/r10k_forge_auth_no_url.yaml +3 -0
  267. data/spec/fixtures/unit/action/r10k_generate_types.yaml +3 -0
  268. data/spec/fixtures/unit/action/r10k_logging.yaml +12 -0
  269. data/spec/fixtures/unit/action/r10k_puppet_path.yaml +3 -0
  270. data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
  271. data/spec/fixtures/unit/puppetfile/default-branch-override/Puppetfile +5 -0
  272. data/spec/fixtures/unit/puppetfile/duplicate-module-error/Puppetfile +10 -0
  273. data/spec/fixtures/unit/puppetfile/forge-override/Puppetfile +8 -0
  274. data/spec/fixtures/unit/puppetfile/invalid-syntax/Puppetfile +1 -0
  275. data/spec/fixtures/unit/puppetfile/load-error/Puppetfile +1 -0
  276. data/spec/fixtures/unit/puppetfile/name-error/Puppetfile +1 -0
  277. data/spec/fixtures/unit/puppetfile/valid-forge-with-version/Puppetfile +1 -0
  278. data/spec/fixtures/unit/puppetfile/valid-forge-without-version/Puppetfile +1 -0
  279. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile +10 -0
  280. data/spec/fixtures/unit/puppetfile/various-modules/Puppetfile.new +10 -0
  281. data/spec/fixtures/unit/puppetfile/various-modules/modules/apt/.gitkeep +1 -0
  282. data/spec/fixtures/unit/puppetfile/various-modules/modules/baz/.gitkeep +1 -0
  283. data/spec/fixtures/unit/puppetfile/various-modules/modules/buzz/.gitkeep +1 -0
  284. data/spec/fixtures/unit/puppetfile/various-modules/modules/canary/.gitkeep +1 -0
  285. data/spec/fixtures/unit/puppetfile/various-modules/modules/fizz/.gitkeep +1 -0
  286. data/spec/fixtures/unit/puppetfile/various-modules/modules/rpm/.gitkeep +1 -0
  287. data/spec/fixtures/unit/util/purgeable/managed_one/expected_1 +0 -0
  288. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/managed_symlink_file +1 -0
  289. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_allowlisted_2/ignored_1 +0 -0
  290. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_expected_1 +0 -0
  291. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/subdir_unmanaged_1 +0 -0
  292. data/spec/fixtures/unit/util/purgeable/managed_one/managed_subdir_1/unmanaged_symlink_dir +1 -0
  293. data/spec/fixtures/unit/util/purgeable/managed_one/managed_symlink_dir +1 -0
  294. data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_1 +0 -0
  295. data/spec/fixtures/unit/util/purgeable/managed_one/unmanaged_symlink_file +1 -0
  296. data/spec/fixtures/unit/util/purgeable/managed_two/.hidden/unmanaged_3 +0 -0
  297. data/spec/fixtures/unit/util/purgeable/managed_two/expected_2 +0 -0
  298. data/spec/fixtures/unit/util/purgeable/managed_two/unmanaged_2 +0 -0
  299. data/spec/fixtures/unit/util/subprocess/runner/no-execute.sh +3 -0
  300. data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
  301. data/spec/integration/git/rugged/cache_spec.rb +33 -0
  302. data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
  303. data/spec/integration/git/rugged/working_repository_spec.rb +48 -0
  304. data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
  305. data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
  306. data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
  307. data/spec/integration/git/stateful_repository_spec.rb +175 -0
  308. data/spec/integration/util/purageable_spec.rb +41 -0
  309. data/spec/matchers/exit_with.rb +28 -0
  310. data/spec/matchers/match_realpath.rb +18 -0
  311. data/spec/r10k-mocks/mock_config.rb +33 -0
  312. data/spec/r10k-mocks/mock_env.rb +18 -0
  313. data/spec/r10k-mocks/mock_source.rb +17 -0
  314. data/spec/r10k-mocks.rb +3 -0
  315. data/spec/shared-contexts/git-fixtures.rb +55 -0
  316. data/spec/shared-contexts/tarball.rb +32 -0
  317. data/spec/shared-examples/deploy-actions.rb +69 -0
  318. data/spec/shared-examples/git/bare_repository.rb +132 -0
  319. data/spec/shared-examples/git/thin_repository.rb +26 -0
  320. data/spec/shared-examples/git/working_repository.rb +207 -0
  321. data/spec/shared-examples/git-repository.rb +38 -0
  322. data/spec/shared-examples/puppetfile-action.rb +39 -0
  323. data/spec/shared-examples/settings/ancestry.rb +44 -0
  324. data/spec/shared-examples/subprocess-runner.rb +89 -0
  325. data/spec/spec_helper.rb +41 -0
  326. data/spec/unit/action/cri_runner_spec.rb +72 -0
  327. data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
  328. data/spec/unit/action/deploy/display_spec.rb +61 -0
  329. data/spec/unit/action/deploy/environment_spec.rb +640 -0
  330. data/spec/unit/action/deploy/module_spec.rb +476 -0
  331. data/spec/unit/action/puppetfile/check_spec.rb +53 -0
  332. data/spec/unit/action/puppetfile/cri_runner_spec.rb +47 -0
  333. data/spec/unit/action/puppetfile/install_spec.rb +112 -0
  334. data/spec/unit/action/puppetfile/purge_spec.rb +60 -0
  335. data/spec/unit/action/runner_spec.rb +407 -0
  336. data/spec/unit/action/visitor_spec.rb +39 -0
  337. data/spec/unit/cli_spec.rb +9 -0
  338. data/spec/unit/deployment/config_spec.rb +33 -0
  339. data/spec/unit/deployment_spec.rb +162 -0
  340. data/spec/unit/environment/bare_spec.rb +13 -0
  341. data/spec/unit/environment/base_spec.rb +122 -0
  342. data/spec/unit/environment/git_spec.rb +114 -0
  343. data/spec/unit/environment/name_spec.rb +181 -0
  344. data/spec/unit/environment/plain_spec.rb +8 -0
  345. data/spec/unit/environment/svn_spec.rb +146 -0
  346. data/spec/unit/environment/tarball_spec.rb +45 -0
  347. data/spec/unit/environment/with_modules_spec.rb +122 -0
  348. data/spec/unit/errors/formatting_spec.rb +84 -0
  349. data/spec/unit/feature_spec.rb +50 -0
  350. data/spec/unit/forge/module_release_spec.rb +213 -0
  351. data/spec/unit/git/alternates_spec.rb +116 -0
  352. data/spec/unit/git/cache_spec.rb +66 -0
  353. data/spec/unit/git/rugged/cache_spec.rb +48 -0
  354. data/spec/unit/git/rugged/credentials_spec.rb +215 -0
  355. data/spec/unit/git/shellgit/cache_spec.rb +27 -0
  356. data/spec/unit/git/stateful_repository_spec.rb +45 -0
  357. data/spec/unit/git_spec.rb +102 -0
  358. data/spec/unit/initializers_spec.rb +68 -0
  359. data/spec/unit/instance_cache_spec.rb +78 -0
  360. data/spec/unit/keyed_factory_spec.rb +51 -0
  361. data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
  362. data/spec/unit/logging_spec.rb +68 -0
  363. data/spec/unit/module/base_spec.rb +118 -0
  364. data/spec/unit/module/forge_spec.rb +271 -0
  365. data/spec/unit/module/git_spec.rb +387 -0
  366. data/spec/unit/module/metadata_file_spec.rb +68 -0
  367. data/spec/unit/module/svn_spec.rb +208 -0
  368. data/spec/unit/module/tarball_spec.rb +70 -0
  369. data/spec/unit/module_loader/puppetfile_spec.rb +421 -0
  370. data/spec/unit/module_spec.rb +114 -0
  371. data/spec/unit/puppetfile_spec.rb +304 -0
  372. data/spec/unit/settings/collection_spec.rb +123 -0
  373. data/spec/unit/settings/container_spec.rb +92 -0
  374. data/spec/unit/settings/definition_spec.rb +79 -0
  375. data/spec/unit/settings/enum_definition_spec.rb +20 -0
  376. data/spec/unit/settings/inheritance_spec.rb +38 -0
  377. data/spec/unit/settings/list_spec.rb +88 -0
  378. data/spec/unit/settings/loader_spec.rb +110 -0
  379. data/spec/unit/settings/uri_definition_spec.rb +23 -0
  380. data/spec/unit/settings_spec.rb +303 -0
  381. data/spec/unit/source/base_spec.rb +31 -0
  382. data/spec/unit/source/exec_spec.rb +81 -0
  383. data/spec/unit/source/git_spec.rb +233 -0
  384. data/spec/unit/source/hash_spec.rb +54 -0
  385. data/spec/unit/source/svn_spec.rb +196 -0
  386. data/spec/unit/source/yaml_spec.rb +42 -0
  387. data/spec/unit/source_spec.rb +10 -0
  388. data/spec/unit/svn/remote_spec.rb +21 -0
  389. data/spec/unit/svn/working_dir_spec.rb +56 -0
  390. data/spec/unit/tarball_spec.rb +57 -0
  391. data/spec/unit/util/attempt_spec.rb +82 -0
  392. data/spec/unit/util/cacheable_spec.rb +23 -0
  393. data/spec/unit/util/commands_spec.rb +61 -0
  394. data/spec/unit/util/downloader_spec.rb +98 -0
  395. data/spec/unit/util/exec_env_spec.rb +56 -0
  396. data/spec/unit/util/purgeable_spec.rb +267 -0
  397. data/spec/unit/util/setopts_spec.rb +83 -0
  398. data/spec/unit/util/subprocess/result_spec.rb +36 -0
  399. data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
  400. data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
  401. data/spec/unit/util/subprocess/runner/windows_spec.rb +7 -0
  402. data/spec/unit/util/subprocess/subprocess_error_spec.rb +26 -0
  403. data/spec/unit/util/subprocess_spec.rb +65 -0
  404. data/spec/unit/util/symbolize_keys_spec.rb +67 -0
  405. metadata +637 -0
@@ -0,0 +1,186 @@
1
+ require 'r10k'
2
+ require 'forwardable'
3
+
4
+ require 'log4r'
5
+ require 'log4r/configurator'
6
+ require 'r10k/logging/terminaloutputter'
7
+
8
+ module R10K::Logging
9
+
10
+ LOG_LEVELS = %w{DEBUG2 DEBUG1 DEBUG INFO NOTICE WARN ERROR FATAL}
11
+ SYSLOG_LEVELS_MAP = {
12
+ 'DEBUG2' => 'DEBUG',
13
+ 'DEBUG1' => 'DEBUG',
14
+ 'DEBUG' => 'DEBUG',
15
+ 'INFO' => 'INFO',
16
+ 'NOTICE' => 'INFO',
17
+ 'WARN' => 'WARN',
18
+ 'ERROR' => 'ERROR',
19
+ 'FATAL' => 'FATAL',
20
+ }.freeze
21
+
22
+ def logger_name
23
+ self.class.to_s
24
+ end
25
+
26
+ def logger
27
+ if @logger.nil?
28
+ name = logger_name
29
+ if Log4r::Logger[name]
30
+ @logger = Log4r::Logger[name]
31
+ else
32
+ @logger = Log4r::Logger.new(name)
33
+ @logger.add(R10K::Logging.outputter)
34
+ R10K::Logging.outputters.each do |output|
35
+ @logger.add(output)
36
+ end
37
+ end
38
+ end
39
+ @logger
40
+ end
41
+
42
+ class << self
43
+
44
+ # Convert the input to a valid Log4r log level
45
+ #
46
+ # @param input [String, TrueClass] The level to parse. If TrueClass then
47
+ # Log4r::INFO will be returned (indicating a generic raised verbosity),
48
+ # if a string it will be parsed either as a numeric value or a textual
49
+ # log level.
50
+ # @api private
51
+ # @return [Integer, NilClass] The numeric log level, or nil if the log
52
+ # level is invalid.
53
+ def parse_level(input)
54
+ case input
55
+ when TrueClass
56
+ Log4r::INFO
57
+ when /\A\d+\Z/
58
+ Integer(input)
59
+ when String
60
+ const_name = input.upcase
61
+ if LOG_LEVELS.include?(const_name)
62
+ begin
63
+ Log4r.const_get(const_name.to_sym)
64
+ rescue NameError
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def level=(val)
71
+ level = parse_level(val)
72
+ if level.nil?
73
+ raise ArgumentError, _("Invalid log level '%{val}'. Valid levels are %{log_levels}") % {val: val, log_levels: LOG_LEVELS.map(&:downcase).inspect}
74
+ end
75
+ outputter.level = level unless @disable_default_stderr
76
+ @level = level
77
+
78
+ if level < Log4r::INFO
79
+ outputter.formatter = debug_formatter
80
+ else
81
+ outputter.formatter = default_formatter
82
+ end
83
+ end
84
+
85
+ def disable_default_stderr=(val)
86
+ @disable_default_stderr = val
87
+ outputter.level = val ? Log4r::OFF : @level
88
+ end
89
+
90
+ def add_outputters(outputs)
91
+ outputs.each do |output|
92
+ type = output.fetch(:type)
93
+ # Support specifying both short as well as full names
94
+ type = type.to_s[0..-10] if type.to_s.downcase.end_with? 'outputter'
95
+
96
+ name = output.fetch(:name, 'r10k')
97
+ if output[:level]
98
+ level = parse_level(output[:level])
99
+ if level.nil?
100
+ raise ArgumentError, _("Invalid log level '%{val}'. Valid levels are %{log_levels}") % { val: output[:level], log_levels: LOG_LEVELS.map(&:downcase).inspect }
101
+ end
102
+ else
103
+ level = self.level
104
+ end
105
+ only_at = output[:only_at]
106
+ only_at&.map! do |val|
107
+ lv = parse_level(val)
108
+ if lv.nil?
109
+ raise ArgumentError, _("Invalid log level '%{val}'. Valid levels are %{log_levels}") % { val: val, log_levels: LOG_LEVELS.map(&:downcase).inspect }
110
+ end
111
+
112
+ lv
113
+ end
114
+ parameters = output.fetch(:parameters, {}).merge({ level: level })
115
+
116
+ begin
117
+ # Try to load the outputter file if possible
118
+ require "log4r/outputter/#{type.to_s.downcase}outputter"
119
+ rescue LoadError
120
+ false
121
+ end
122
+ outputtertype = Log4r.constants
123
+ .select { |klass| klass.to_s.end_with? 'Outputter' }
124
+ .find { |klass| klass.to_s.downcase == "#{type.to_s.downcase}outputter" }
125
+ raise ArgumentError, "Unable to find a #{output[:type]} outputter." unless outputtertype
126
+
127
+ outputter = Log4r.const_get(outputtertype).new(name, parameters)
128
+ outputter.only_at(*only_at) if only_at
129
+ # Handle log4r's syslog mapping correctly
130
+ outputter.map_levels_by_name_to_syslog(SYSLOG_LEVELS_MAP) if outputter.respond_to? :map_levels_by_name_to_syslog
131
+
132
+ @outputters << outputter
133
+ Log4r::Logger.global.add outputter
134
+ end
135
+ end
136
+
137
+ extend Forwardable
138
+ def_delegators :@outputter, :use_color, :use_color=
139
+
140
+ # @!attribute [r] level
141
+ # @return [Integer] The current log level. Lower numbers correspond
142
+ # to more verbose log levels.
143
+ attr_reader :level
144
+
145
+ # @!attribute [r] formatter
146
+ # @api private
147
+ # @return [Log4r::Formatter]
148
+ attr_reader :formatter
149
+
150
+ # @!attribute [r] outputter
151
+ # @api private
152
+ # @return [Log4r::Outputter]
153
+ attr_reader :outputter
154
+
155
+ # @!attribute [r] outputters
156
+ # @api private
157
+ # @return [Array[Log4r::Outputter]]
158
+ attr_reader :outputters
159
+
160
+ # @!attribute [r] disable_default_stderr
161
+ # @api private
162
+ # @return [Boolean]
163
+ attr_reader :disable_default_stderr
164
+
165
+ def default_formatter
166
+ Log4r::PatternFormatter.new(:pattern => '%l\t -> %m')
167
+ end
168
+
169
+ def debug_formatter
170
+ Log4r::PatternFormatter.new(:pattern => '[%d - %l] %m')
171
+ end
172
+
173
+ def default_outputter
174
+ R10K::Logging::TerminalOutputter.new('terminal', $stderr, :level => self.level, :formatter => formatter)
175
+ end
176
+ end
177
+
178
+ Log4r::Configurator.custom_levels(*LOG_LEVELS)
179
+ Log4r::Logger.global.level = Log4r::ALL
180
+
181
+ @level = Log4r::WARN
182
+ @formatter = default_formatter
183
+ @outputter = default_outputter
184
+ @outputters = []
185
+ @disable_default_stderr = false
186
+ end
@@ -0,0 +1,182 @@
1
+ require 'r10k/module'
2
+ require 'r10k/logging'
3
+ require 'puppet_forge'
4
+
5
+ # This class defines a common interface for module implementations.
6
+ class R10K::Module::Base
7
+
8
+ include R10K::Logging
9
+
10
+ # @!attribute [r] title
11
+ # @return [String] The forward slash separated owner and name of the module
12
+ attr_reader :title
13
+
14
+ # @!attribute [r] name
15
+ # @return [String] The name of the module
16
+ attr_reader :name
17
+
18
+ # @param [r] dirname
19
+ # @return [String] The name of the directory containing this module
20
+ attr_reader :dirname
21
+
22
+ # @deprecated
23
+ alias :basedir :dirname
24
+
25
+ # @!attribute [r] owner
26
+ # @return [String, nil] The owner of the module if one is specified
27
+ attr_reader :owner
28
+
29
+ # @!attribute [r] path
30
+ # @return [Pathname] The full path of the module
31
+ attr_reader :path
32
+
33
+ # @!attribute [r] environment
34
+ # @return [R10K::Environment, nil] The parent environment of the module
35
+ attr_reader :environment
36
+
37
+ # @!attribute [rw] origin
38
+ # @return [String] Where the module was sourced from. E.g., "Puppetfile"
39
+ attr_accessor :origin
40
+
41
+ # @!attribute [rw] spec_deletable
42
+ # @return [Boolean] set this to true if the spec dir can be safely removed, ie in the moduledir
43
+ attr_accessor :spec_deletable
44
+
45
+ # There's been some churn over `author` vs `owner` and `full_name` over
46
+ # `title`, so in the short run it's easier to support both and deprecate one
47
+ # later.
48
+ alias :author :owner
49
+ alias :full_name :title
50
+
51
+ # @param title [String]
52
+ # @param dirname [String]
53
+ # @param args [Hash]
54
+ def initialize(title, dirname, args, environment=nil)
55
+ @title = PuppetForge::V3.normalize_name(title)
56
+ @dirname = dirname
57
+ @args = args
58
+ @owner, @name = parse_title(@title)
59
+ @path = Pathname.new(File.join(@dirname, @name))
60
+ @environment = environment
61
+ @overrides = args.delete(:overrides) || {}
62
+ @spec_deletable = true
63
+ @exclude_spec = false
64
+ @exclude_spec = @overrides.dig(:modules, :exclude_spec) if @overrides.dig(:modules, :exclude_spec)
65
+ if args.has_key?(:exclude_spec)
66
+ logger.debug2 _("Overriding :exclude_spec setting with per module setting for #{@title}")
67
+ @exclude_spec = args.delete(:exclude_spec)
68
+ end
69
+ @origin = 'external' # Expect Puppetfile or R10k::Environment to set this to a specific value
70
+
71
+ @requested_modules = @overrides.dig(:modules, :requested_modules) || []
72
+ @should_sync = (@requested_modules.empty? || @requested_modules.include?(@name))
73
+ end
74
+
75
+ # @deprecated
76
+ # @return [String] The full filesystem path to the module.
77
+ def full_path
78
+ path.to_s
79
+ end
80
+
81
+ # Delete the spec dir if @exclude_spec has been set to true and @spec_deletable is also true
82
+ def maybe_delete_spec_dir
83
+ if @exclude_spec
84
+ if @spec_deletable
85
+ delete_spec_dir
86
+ else
87
+ logger.info _("Spec dir for #{@title} will not be deleted because it is not in the moduledir")
88
+ end
89
+ end
90
+ end
91
+
92
+ # Actually remove the spec dir
93
+ def delete_spec_dir
94
+ spec_path = @path + 'spec'
95
+ if spec_path.symlink?
96
+ spec_path = spec_path.realpath
97
+ end
98
+ if spec_path.directory?
99
+ logger.debug2 _("Deleting spec data at #{spec_path}")
100
+ # Use the secure flag for the #rm_rf method to avoid security issues
101
+ # involving TOCTTOU(time of check to time of use); more details here:
102
+ # https://ruby-doc.org/stdlib-2.7.0/libdoc/fileutils/rdoc/FileUtils.html#method-c-rm_rf
103
+ # Additionally, #rm_rf also has problems in windows with with symlink targets
104
+ # also being deleted; this should be revisted if Windows becomes higher priority.
105
+ FileUtils.rm_rf(spec_path, secure: true)
106
+ else
107
+ logger.debug2 _("No spec dir detected at #{spec_path}, skipping deletion")
108
+ end
109
+ end
110
+
111
+ # Synchronize this module with the indicated state.
112
+ # @param [Hash] opts Deprecated
113
+ # @return [Boolean] true if the module was updated, false otherwise
114
+ def sync(opts={})
115
+ raise NotImplementedError
116
+ end
117
+
118
+ def should_sync?
119
+ if @should_sync
120
+ logger.info _("Deploying module to %{path}") % {path: path}
121
+ true
122
+ else
123
+ logger.debug1(_("Only updating modules %{modules}, skipping module %{name}") % {modules: @requested_modules.inspect, name: name})
124
+ false
125
+ end
126
+ end
127
+
128
+
129
+ # Return the desired version of this module
130
+ # @abstract
131
+ def version
132
+ raise NotImplementedError
133
+ end
134
+
135
+ # Return the status of the currently installed module.
136
+ #
137
+ # This can return the following values:
138
+ #
139
+ # * :absent - there is no module installed
140
+ # * :mismatched - there is a module installed but it must be removed and reinstalled
141
+ # * :outdated - the correct module is installed but it needs to be updated
142
+ # * :insync - the correct module is installed and up to date, or the module is actually a boy band.
143
+ #
144
+ # @return [Symbol]
145
+ # @abstract
146
+ def status
147
+ raise NotImplementedError
148
+ end
149
+
150
+ # Deprecated
151
+ def accept(visitor)
152
+ visitor.visit(:module, self)
153
+ end
154
+
155
+ # Return the properties of the module
156
+ #
157
+ # @return [Hash]
158
+ # @abstract
159
+ def properties
160
+ raise NotImplementedError
161
+ end
162
+
163
+ # Return the module's cachedir. Subclasses that implement a cache
164
+ # will override this to return a real directory location.
165
+ #
166
+ # @return [String, :none]
167
+ def cachedir
168
+ :none
169
+ end
170
+
171
+ private
172
+
173
+ def parse_title(title)
174
+ if (match = title.match(/\A(\w+)\Z/))
175
+ [nil, match[1]]
176
+ elsif (match = title.match(/\A(\w+)[-\/](\w+)\Z/))
177
+ [match[1], match[2]]
178
+ else
179
+ raise ArgumentError, _("Module name (%{title}) must match either 'modulename' or 'owner/modulename'") % {title: title}
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,64 @@
1
+ require 'r10k/module'
2
+
3
+ class R10K::Module::Definition < R10K::Module::Base
4
+
5
+ attr_reader :version
6
+
7
+ def initialize(name, dirname:, args:, implementation:, environment: nil)
8
+ @original_name = name
9
+ @original_args = args.dup
10
+ @implementation = implementation
11
+ @version = implementation.statically_defined_version(name, args)
12
+
13
+ super(name, dirname, args, environment)
14
+ end
15
+
16
+ def to_implementation
17
+ mod = @implementation.new(@title, @dirname, @original_args, @environment)
18
+
19
+ mod.origin = origin
20
+ mod.spec_deletable = spec_deletable
21
+
22
+ mod
23
+ end
24
+
25
+ # syncing is a noop for module definitions
26
+ # Returns false to inidicate the module was not updated
27
+ def sync(args = {})
28
+ logger.debug1(_("Not updating module %{name}, assuming content unchanged") % {name: name})
29
+ false
30
+ end
31
+
32
+ def status
33
+ :insync
34
+ end
35
+
36
+ def properties
37
+ type = nil
38
+
39
+ if @args[:type]
40
+ type = @args[:type]
41
+ elsif @args[:ref] || @args[:commit] || @args[:branch] || @args[:tag]
42
+ type = 'git'
43
+ elsif @args[:svn]
44
+ # This logic is clear and included for completeness sake, though at
45
+ # this time module definitions do not support SVN versions.
46
+ type = 'svn'
47
+ else
48
+ type = 'forge'
49
+ end
50
+
51
+ {
52
+ expected: version,
53
+ # We can't get the value for `actual` here because that requires the
54
+ # implementation (and potentially expensive operations by the
55
+ # implementation). Some consumers will check this value, if it exists
56
+ # and if not, fall back to the expected version. That is the correct
57
+ # behavior when assuming modules are unchanged, and why `actual` is set
58
+ # to `nil` here.
59
+ actual: nil,
60
+ type: type
61
+ }
62
+ end
63
+ end
64
+
@@ -0,0 +1,208 @@
1
+ require 'r10k/module'
2
+ require 'r10k/errors'
3
+ require 'r10k/module/metadata_file'
4
+
5
+ require 'r10k/forge/module_release'
6
+
7
+ require 'pathname'
8
+ require 'fileutils'
9
+ require 'puppet_forge/util'
10
+
11
+ class R10K::Module::Forge < R10K::Module::Base
12
+
13
+ R10K::Module.register(self)
14
+
15
+ def self.implement?(name, args)
16
+ args[:type].to_s == 'forge'
17
+ end
18
+
19
+ def self.statically_defined_version(name, args)
20
+ args[:version] if args[:version].is_a?(String)
21
+ end
22
+
23
+ # @!attribute [r] metadata
24
+ # @api private
25
+ # @return [PuppetForge::Metadata]
26
+ attr_reader :metadata
27
+
28
+ # @!attribute [r] v3_module
29
+ # @api private
30
+ # @return [PuppetForge::V3::Module] The Puppet Forge module metadata
31
+ attr_reader :v3_module
32
+
33
+ include R10K::Util::Setopts
34
+
35
+ def initialize(title, dirname, opts, environment=nil)
36
+ super
37
+
38
+ @metadata_file = R10K::Module::MetadataFile.new(path + 'metadata.json')
39
+ @metadata = @metadata_file.read
40
+
41
+ setopts(opts, {
42
+ # Standard option interface
43
+ :version => :expected_version,
44
+ :source => ::R10K::Util::Setopts::Ignore,
45
+ :type => ::R10K::Util::Setopts::Ignore,
46
+ }, :raise_on_unhandled => false)
47
+
48
+ # Validate version and raise on issue. Title is validated by base class.
49
+ unless valid_version?(@expected_version)
50
+ raise ArgumentError, _("Module version %{ver} is not a valid Forge module version") % {ver: @expected_version}
51
+ end
52
+
53
+ @expected_version ||= current_version || :latest
54
+
55
+ @v3_module = PuppetForge::V3::Module.new(:slug => @title)
56
+ end
57
+
58
+ def valid_version?(version)
59
+ version == :latest || version.nil? || PuppetForge::Util.version_valid?(version)
60
+ end
61
+
62
+ # @param [Hash] opts Deprecated
63
+ # @return [Boolean] true if the module was updated, false otherwise
64
+ def sync(opts={})
65
+ updated = false
66
+ if should_sync?
67
+ case status
68
+ when :absent
69
+ install
70
+ updated = true
71
+ when :outdated
72
+ upgrade
73
+ updated = true
74
+ when :mismatched
75
+ reinstall
76
+ updated = true
77
+ end
78
+ maybe_delete_spec_dir
79
+ end
80
+ updated
81
+ end
82
+
83
+ def properties
84
+ {
85
+ :expected => expected_version,
86
+ :actual => current_version,
87
+ :type => :forge,
88
+ }
89
+ end
90
+
91
+ # @return [String] The expected version that the module
92
+ def expected_version
93
+ if @expected_version == :latest
94
+ begin
95
+ if @v3_module.current_release
96
+ @expected_version = @v3_module.current_release.version
97
+ else
98
+ raise PuppetForge::ReleaseNotFound, _("The module %{title} does not appear to have any published releases, cannot determine latest version.") % { title: @title }
99
+ end
100
+ rescue Faraday::ResourceNotFound => e
101
+ raise PuppetForge::ReleaseNotFound, _("The module %{title} does not exist on %{url}.") % {title: @title, url: PuppetForge::V3::Release.conn.url_prefix}, e.backtrace
102
+ end
103
+ end
104
+ @expected_version
105
+ end
106
+
107
+ # @return [String] The version of the currently installed module
108
+ def current_version
109
+ if insync?
110
+ (@metadata ||= @metadata_file.read).nil? ? nil : @metadata.version
111
+ else
112
+ nil
113
+ end
114
+ end
115
+
116
+ alias version current_version
117
+
118
+ def exist?
119
+ path.exist?
120
+ end
121
+
122
+ def insync?
123
+ status == :insync
124
+ end
125
+
126
+ def deprecated?
127
+ begin
128
+ @v3_module.fetch && @v3_module.has_attribute?('deprecated_at') && !@v3_module.deprecated_at.nil?
129
+ rescue Faraday::ResourceNotFound => e
130
+ raise PuppetForge::ReleaseNotFound, _("The module %{title} does not exist on %{url}.") % {title: @title, url: PuppetForge::V3::Release.conn.url_prefix}, e.backtrace
131
+ end
132
+ end
133
+
134
+ # Determine the status of the forge module.
135
+ #
136
+ # @return [Symbol] :absent If the directory doesn't exist
137
+ # @return [Symbol] :mismatched If the module is not a forge module, or
138
+ # isn't the right forge module
139
+ # @return [Symbol] :mismatched If the module was previously a git checkout
140
+ # @return [Symbol] :outdated If the installed module is older than expected
141
+ # @return [Symbol] :insync If the module is in the desired state
142
+ def status
143
+ if not self.exist?
144
+ # The module is not installed
145
+ return :absent
146
+ elsif not File.exist?(@path + 'metadata.json')
147
+ # The directory exists but doesn't have a metadata file; it probably
148
+ # isn't a forge module.
149
+ return :mismatched
150
+ end
151
+
152
+ if File.directory?(@path + '.git')
153
+ return :mismatched
154
+ end
155
+
156
+ # The module is present and has a metadata file, read the metadata to
157
+ # determine the state of the module.
158
+ @metadata = @metadata_file.read(@path + 'metadata.json')
159
+
160
+ if not @title.tr('/','-') == @metadata.full_module_name.tr('/','-')
161
+
162
+ # This is a forge module but the installed module is a different author
163
+ # than the expected author.
164
+ return :mismatched
165
+ end
166
+
167
+ if expected_version && (expected_version != @metadata.version)
168
+ return :outdated
169
+ end
170
+
171
+ return :insync
172
+ end
173
+
174
+ def install
175
+ if deprecated?
176
+ logger.warn "Puppet Forge module '#{@v3_module.slug}' has been deprecated, visit https://forge.puppet.com/#{@v3_module.slug.tr('-','/')} for more information."
177
+ end
178
+
179
+ parent_path = @path.parent
180
+ if !parent_path.exist?
181
+ parent_path.mkpath
182
+ end
183
+ module_release = R10K::Forge::ModuleRelease.new(@title, expected_version)
184
+ module_release.install(@path)
185
+ end
186
+
187
+ alias upgrade install
188
+
189
+ def uninstall
190
+ FileUtils.rm_rf full_path
191
+ end
192
+
193
+ def reinstall
194
+ uninstall
195
+ install
196
+ end
197
+
198
+ private
199
+
200
+ # Override the base #parse_title to ensure we have a fully qualified name
201
+ def parse_title(title)
202
+ if (match = title.match(/\A(\w+)[-\/](\w+)\Z/))
203
+ [match[1], match[2]]
204
+ else
205
+ raise ArgumentError, _("Forge module names must match 'owner/modulename', instead got #{title}")
206
+ end
207
+ end
208
+ end