r10k 1.4.2 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (244) hide show
  1. data/.travis.yml +2 -0
  2. data/CHANGELOG.mkd +192 -0
  3. data/CONTRIBUTING.mkd +3 -3
  4. data/Gemfile +4 -0
  5. data/README.mkd +13 -6
  6. data/doc/dynamic-environments/configuration.mkd +77 -8
  7. data/doc/dynamic-environments/git-environments.mkd +12 -2
  8. data/doc/dynamic-environments/quickstart.mkd +6 -0
  9. data/doc/faq.mkd +6 -6
  10. data/doc/git/cloning-and-mirroring.mkd +60 -0
  11. data/doc/git/providers.mkd +68 -0
  12. data/integration/Gemfile +3 -0
  13. data/integration/README.mkd +29 -0
  14. data/integration/configs/README.mkd +7 -0
  15. data/integration/configs/pe/centos-6-64mda +25 -0
  16. data/integration/configs/pe/centos-7-64mda +25 -0
  17. data/integration/configs/pe/debian-6-64mda +25 -0
  18. data/integration/configs/pe/debian-7-64mda +25 -0
  19. data/integration/configs/pe/redhat-6-64mda +25 -0
  20. data/integration/configs/pe/redhat-7-64mda +25 -0
  21. data/integration/configs/pe/sles-11-64mda +25 -0
  22. data/integration/configs/pe/ubuntu-1004-64mda +25 -0
  23. data/integration/configs/pe/ubuntu-1204-64mda +25 -0
  24. data/integration/configs/pe/ubuntu-1404-64mda +25 -0
  25. data/integration/files/README.mkd +4 -0
  26. data/integration/files/hiera.yaml +8 -0
  27. data/integration/files/modules/helloworld/manifests/init.pp +3 -0
  28. data/integration/files/modules/hieratest/manifests/init.pp +3 -0
  29. data/integration/files/modules/unicode/files/pretend_unicode +1 -0
  30. data/integration/files/modules/unicode/manifests/init.pp +6 -0
  31. data/integration/files/pre-suite/prod_env.config +3 -0
  32. data/integration/files/r10k_conf.yaml.erb +9 -0
  33. data/integration/lib/README.mkd +4 -0
  34. data/integration/lib/git_utils.rb +205 -0
  35. data/integration/lib/master_manipulator.rb +205 -0
  36. data/integration/lib/r10k_utils.rb +166 -0
  37. data/integration/manifests/README.mkd +4 -0
  38. data/integration/pre-suite/00_pe_install.rb +4 -0
  39. data/integration/pre-suite/01_git_config.rb +59 -0
  40. data/integration/pre-suite/02_pe_r10k.rb +60 -0
  41. data/integration/pre-suite/03_test_utils.rb +17 -0
  42. data/integration/pre-suite/README.mkd +5 -0
  43. data/integration/test_run_scripts/README.mkd +5 -0
  44. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +20 -0
  45. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +20 -0
  46. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +20 -0
  47. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +20 -0
  48. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +20 -0
  49. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +20 -0
  50. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +20 -0
  51. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +20 -0
  52. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +20 -0
  53. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +20 -0
  54. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +20 -0
  55. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +20 -0
  56. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +20 -0
  57. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +20 -0
  58. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +20 -0
  59. data/integration/tests/README.mkd +4 -0
  60. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +46 -0
  61. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +27 -0
  62. data/integration/tests/command_line/deploy_env_without_mod_update.rb +75 -0
  63. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +76 -0
  64. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +22 -0
  65. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +22 -0
  66. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +24 -0
  67. data/integration/tests/git_source/git_source_git.rb +123 -0
  68. data/integration/tests/git_source/git_source_ssh.rb +84 -0
  69. data/integration/tests/git_source/git_source_submodule.rb +69 -0
  70. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +37 -0
  71. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +45 -0
  72. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +72 -0
  73. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +34 -0
  74. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +66 -0
  75. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +110 -0
  76. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +113 -0
  77. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +93 -0
  78. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +132 -0
  79. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +160 -0
  80. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +45 -0
  81. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +43 -0
  82. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +40 -0
  83. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +42 -0
  84. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +44 -0
  85. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +63 -0
  86. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +73 -0
  87. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +45 -0
  88. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +51 -0
  89. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +33 -0
  90. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +35 -0
  91. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +44 -0
  92. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +57 -0
  93. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +44 -0
  94. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +73 -0
  95. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +103 -0
  96. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +80 -0
  97. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +48 -0
  98. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +73 -0
  99. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +81 -0
  100. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +67 -0
  101. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +93 -0
  102. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +92 -0
  103. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +116 -0
  104. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +59 -0
  105. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +165 -0
  106. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +162 -0
  107. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +110 -0
  108. data/lib/r10k/action/cri_runner.rb +10 -13
  109. data/lib/r10k/cli.rb +3 -8
  110. data/lib/r10k/cli/version.rb +10 -1
  111. data/lib/r10k/deployment/config.rb +26 -6
  112. data/lib/r10k/deployment/config/loader.rb +38 -29
  113. data/lib/r10k/deployment/source.rb +2 -4
  114. data/lib/r10k/environment/git.rb +10 -19
  115. data/lib/r10k/environment/name.rb +86 -0
  116. data/lib/r10k/errors.rb +8 -5
  117. data/lib/r10k/feature.rb +35 -0
  118. data/lib/r10k/feature/collection.rb +23 -0
  119. data/lib/r10k/features.rb +18 -0
  120. data/lib/r10k/git.rb +106 -12
  121. data/lib/r10k/git/alternates.rb +2 -2
  122. data/lib/r10k/git/cache.rb +43 -26
  123. data/lib/r10k/git/errors.rb +12 -6
  124. data/lib/r10k/git/head.rb +3 -0
  125. data/lib/r10k/git/ref.rb +3 -0
  126. data/lib/r10k/git/remote_head.rb +6 -0
  127. data/lib/r10k/git/repository.rb +6 -0
  128. data/lib/r10k/git/rugged.rb +17 -0
  129. data/lib/r10k/git/rugged/bare_repository.rb +86 -0
  130. data/lib/r10k/git/rugged/base_repository.rb +90 -0
  131. data/lib/r10k/git/rugged/cache.rb +11 -0
  132. data/lib/r10k/git/rugged/thin_repository.rb +72 -0
  133. data/lib/r10k/git/rugged/working_repository.rb +99 -0
  134. data/lib/r10k/git/shellgit.rb +9 -0
  135. data/lib/r10k/git/shellgit/bare_repository.rb +29 -0
  136. data/lib/r10k/git/shellgit/base_repository.rb +102 -0
  137. data/lib/r10k/git/shellgit/cache.rb +11 -0
  138. data/lib/r10k/git/shellgit/thin_repository.rb +56 -0
  139. data/lib/r10k/git/shellgit/working_repository.rb +73 -0
  140. data/lib/r10k/git/stateful_repository.rb +80 -0
  141. data/lib/r10k/git/tag.rb +3 -0
  142. data/lib/r10k/git/working_dir.rb +15 -2
  143. data/lib/r10k/logging.rb +73 -36
  144. data/lib/r10k/logging/terminaloutputter.rb +36 -0
  145. data/lib/r10k/module/forge.rb +10 -9
  146. data/lib/r10k/module/git.rb +14 -44
  147. data/lib/r10k/module/metadata_file.rb +31 -0
  148. data/lib/r10k/module/svn.rb +0 -1
  149. data/lib/r10k/module_repository/forge.rb +20 -7
  150. data/lib/r10k/puppetfile.rb +1 -1
  151. data/lib/r10k/settings/container.rb +6 -0
  152. data/lib/r10k/settings/mixin.rb +9 -0
  153. data/lib/r10k/source.rb +2 -3
  154. data/lib/r10k/source/base.rb +5 -5
  155. data/lib/r10k/source/git.rb +11 -86
  156. data/lib/r10k/source/svn.rb +8 -52
  157. data/lib/r10k/util/basedir.rb +4 -4
  158. data/lib/r10k/util/commands.rb +31 -0
  159. data/lib/r10k/util/exec_env.rb +36 -0
  160. data/lib/r10k/util/platform.rb +4 -0
  161. data/lib/r10k/util/purgeable.rb +2 -2
  162. data/lib/r10k/util/subprocess.rb +3 -7
  163. data/lib/r10k/util/subprocess/runner.rb +3 -28
  164. data/lib/r10k/util/subprocess/runner/posix.rb +103 -0
  165. data/lib/r10k/util/subprocess/runner/pump.rb +59 -0
  166. data/lib/r10k/util/subprocess/{windows/runner.rb → runner/windows.rb} +2 -11
  167. data/lib/r10k/util/symbolize_keys.rb +31 -0
  168. data/lib/r10k/version.rb +1 -1
  169. data/lib/shared/puppet/module_tool/metadata.rb +197 -0
  170. data/r10k.gemspec +7 -5
  171. data/spec/fixtures/integration/git/puppet-boolean-bare.tar +0 -0
  172. data/spec/fixtures/module/forge/bad_module/metadata.json +1 -0
  173. data/spec/fixtures/unit/util/subprocess/posix/runner/no-execute.sh +3 -0
  174. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_all_versions_of_a_given_module.yml +171 -26
  175. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/can_fetch_the_latest_version_of_a_given_module.yml +171 -26
  176. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/and_the_expected_version_is_latest/ignores_deleted_releases.yml +190 -0
  177. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/it_handles_errors_from_forgeapi_puppetlabs_com/raises_an_error_for_a_non-existant_module.yml +34 -0
  178. data/spec/fixtures/vcr/cassettes/R10K_Module_Forge/and_the_expected_version_is_latest/sets_the_expected_version_based_on_the_latest_forge_version.yml +87 -26
  179. data/spec/integration/git/rugged/bare_repository_spec.rb +13 -0
  180. data/spec/integration/git/rugged/thin_repository_spec.rb +14 -0
  181. data/spec/integration/git/rugged/working_repository_spec.rb +13 -0
  182. data/spec/integration/git/shellgit/bare_repository_spec.rb +13 -0
  183. data/spec/integration/git/shellgit/thin_repository_spec.rb +14 -0
  184. data/spec/integration/git/shellgit/working_repository_spec.rb +13 -0
  185. data/spec/integration/git/stateful_repository_spec.rb +104 -0
  186. data/spec/matchers/match_realpath.rb +18 -0
  187. data/spec/shared-contexts/git-fixtures.rb +55 -0
  188. data/spec/shared-examples/git-repository.rb +38 -0
  189. data/spec/shared-examples/git/bare_repository.rb +70 -0
  190. data/spec/shared-examples/git/thin_repository.rb +26 -0
  191. data/spec/shared-examples/git/working_repository.rb +115 -0
  192. data/spec/shared-examples/subprocess-runner.rb +83 -0
  193. data/spec/spec_helper.rb +13 -9
  194. data/spec/unit/action/cri_runner_spec.rb +0 -6
  195. data/spec/unit/action/puppetfile/{cri_action_spec.rb → cri_runner_spec.rb} +0 -0
  196. data/spec/unit/deployment/config/loader_spec.rb +48 -0
  197. data/spec/unit/deployment/config_spec.rb +49 -0
  198. data/spec/unit/environment/git_spec.rb +5 -39
  199. data/spec/unit/environment/name_spec.rb +135 -0
  200. data/spec/unit/feature_spec.rb +50 -0
  201. data/spec/unit/git/alternates_spec.rb +1 -1
  202. data/spec/unit/git/cache_spec.rb +32 -19
  203. data/spec/unit/git/commit_spec.rb +1 -0
  204. data/spec/unit/git/head_spec.rb +1 -6
  205. data/spec/unit/git/ref_spec.rb +0 -23
  206. data/spec/unit/git/rugged/cache_spec.rb +26 -0
  207. data/spec/unit/git/shellgit/cache_spec.rb +27 -0
  208. data/spec/unit/git/stateful_repository_spec.rb +43 -0
  209. data/spec/unit/git/tag_spec.rb +1 -0
  210. data/spec/unit/git/working_dir_spec.rb +1 -0
  211. data/spec/unit/git_spec.rb +74 -0
  212. data/spec/unit/logging/terminaloutputter_spec.rb +53 -0
  213. data/spec/unit/logging_spec.rb +68 -0
  214. data/spec/unit/module/forge_spec.rb +7 -38
  215. data/spec/unit/module/git_spec.rb +7 -38
  216. data/spec/unit/module/metadata_file_spec.rb +69 -0
  217. data/spec/unit/module/svn_spec.rb +0 -4
  218. data/spec/unit/module_repository/forge_spec.rb +22 -1
  219. data/spec/unit/puppet/module_tool/metadata_spec.rb +301 -0
  220. data/spec/unit/settings/container_spec.rb +17 -0
  221. data/spec/unit/source/git_spec.rb +0 -123
  222. data/spec/unit/source/svn_spec.rb +66 -0
  223. data/spec/unit/util/commands_spec.rb +61 -0
  224. data/spec/unit/util/exec_env_spec.rb +56 -0
  225. data/spec/unit/util/subprocess/runner/posix_spec.rb +7 -0
  226. data/spec/unit/util/subprocess/runner/pump_spec.rb +79 -0
  227. data/spec/unit/util/subprocess_spec.rb +3 -2
  228. data/spec/unit/util/symbolize_keys_spec.rb +51 -0
  229. metadata +226 -45
  230. data/lib/r10k/execution.rb +0 -47
  231. data/lib/r10k/module/metadata.rb +0 -47
  232. data/lib/r10k/util/core_ext/hash_ext.rb +0 -19
  233. data/lib/r10k/util/subprocess/io.rb +0 -7
  234. data/lib/r10k/util/subprocess/posix.rb +0 -4
  235. data/lib/r10k/util/subprocess/posix/io.rb +0 -7
  236. data/lib/r10k/util/subprocess/posix/runner.rb +0 -140
  237. data/lib/r10k/util/subprocess/windows.rb +0 -4
  238. data/lib/r10k/util/subprocess/windows/io.rb +0 -6
  239. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions.yml +0 -42
  240. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_all_versions_of_a_given_module.yml +0 -42
  241. data/spec/fixtures/vcr/cassettes/R10K_ModuleRepository_Forge/looking_up_versions/can_fetch_the_latest_version_of_a_given_module.yml +0 -42
  242. data/spec/unit/deployment/source_spec.rb +0 -24
  243. data/spec/unit/module/metadata_spec.rb +0 -68
  244. data/spec/unit/util/core_ext/hash_ext_spec.rb +0 -63
@@ -1,6 +1,7 @@
1
1
  require 'r10k/module'
2
2
  require 'r10k/errors'
3
- require 'r10k/module/metadata'
3
+ require 'shared/puppet/module_tool/metadata'
4
+ require 'r10k/module/metadata_file'
4
5
  require 'r10k/util/subprocess'
5
6
  require 'r10k/module_repository/forge'
6
7
 
@@ -18,14 +19,15 @@ class R10K::Module::Forge < R10K::Module::Base
18
19
 
19
20
  # @!attribute [r] metadata
20
21
  # @api private
21
- # @return [R10K::Module::Metadata]
22
+ # @return [Puppet::ModuleTool::Metadata]
22
23
  attr_reader :metadata
23
24
 
24
25
  include R10K::Logging
25
26
 
26
27
  def initialize(title, dirname, args)
27
28
  super
28
- @metadata = R10K::Module::Metadata.new(path + 'metadata.json')
29
+ @metadata_file = R10K::Module::MetadataFile.new(path + 'metadata.json')
30
+ @metadata = @metadata_file.read
29
31
 
30
32
  if args.is_a? String
31
33
  @expected_version = R10K::SemVer.new(args)
@@ -55,16 +57,14 @@ class R10K::Module::Forge < R10K::Module::Base
55
57
 
56
58
  # @return [R10K::SemVer] The expected version that the module
57
59
  def expected_version
58
- if @expected_version == :latest
60
+ if @expected_version.is_a?(Symbol) && @expected_version == :latest
59
61
  set_version_from_forge
60
62
  end
61
63
  @expected_version
62
64
  end
63
65
 
64
-
65
66
  # @return [R10K::SemVer] The version of the currently installed module
66
67
  def current_version
67
- @metadata.read
68
68
  @metadata.version
69
69
  end
70
70
 
@@ -89,7 +89,7 @@ class R10K::Module::Forge < R10K::Module::Base
89
89
  if not self.exist?
90
90
  # The module is not installed
91
91
  return :absent
92
- elsif not @metadata.exist?
92
+ elsif not File.exist?(@path + 'metadata.json')
93
93
  # The directory exists but doesn't have a metadata file; it probably
94
94
  # isn't a forge module.
95
95
  return :mismatched
@@ -97,9 +97,10 @@ class R10K::Module::Forge < R10K::Module::Base
97
97
 
98
98
  # The module is present and has a metadata file, read the metadata to
99
99
  # determine the state of the module.
100
- @metadata.read
100
+ @metadata_file.read(@path + 'metadata.json')
101
+
102
+ if not @title.tr('/','-') == @metadata.full_module_name.tr('/','-')
101
103
 
102
- if not @owner == @metadata.author
103
104
  # This is a forge module but the installed module is a different author
104
105
  # than the expected author.
105
106
  return :mismatched
@@ -1,5 +1,7 @@
1
1
  require 'r10k/module'
2
2
  require 'r10k/git'
3
+ require 'r10k/git/stateful_repository'
4
+ require 'forwardable'
3
5
 
4
6
  class R10K::Module::Git < R10K::Module::Base
5
7
 
@@ -11,15 +13,15 @@ class R10K::Module::Git < R10K::Module::Base
11
13
  false
12
14
  end
13
15
 
14
- # @!attribute [r] working_dir
16
+ # @!attribute [r] repo
15
17
  # @api private
16
- # @return [R10K::Git::WorkingDir]
17
- attr_reader :working_dir
18
+ # @return [R10K::Git::StatefulRepository]
19
+ attr_reader :repo
18
20
 
19
21
  def initialize(title, dirname, args)
20
22
  super
21
23
  parse_options(@args)
22
- @working_dir = R10K::Git::WorkingDir.new(@ref, @remote, @dirname, @name)
24
+ @repo = R10K::Git::StatefulRepository.new(@ref, @remote, @dirname, @name)
23
25
  end
24
26
 
25
27
  def version
@@ -29,69 +31,37 @@ class R10K::Module::Git < R10K::Module::Base
29
31
  def properties
30
32
  {
31
33
  :expected => @ref,
32
- :actual => (@working_dir.current.sha1 rescue "(unresolvable)"),
34
+ :actual => (@repo.head || "(unresolvable)"),
33
35
  :type => :git,
34
36
  }
35
37
  end
36
38
 
37
- def sync
38
- case status
39
- when :absent
40
- install
41
- when :mismatched
42
- uninstall
43
- install
44
- when :outdated
45
- @working_dir.sync
46
- end
47
- end
48
-
49
- def status
50
- if not @working_dir.exist?
51
- return :absent
52
- elsif not @working_dir.git?
53
- return :mismatched
54
- elsif not @remote == @working_dir.remote
55
- return :mismatched
56
- end
39
+ extend Forwardable
57
40
 
58
- if @working_dir.outdated?
59
- return :outdated
60
- end
61
-
62
- return :insync
63
- end
41
+ def_delegators :@repo, :sync, :status
64
42
 
65
43
  private
66
44
 
67
- def install
68
- @working_dir.sync
69
- end
70
-
71
- def uninstall
72
- @path.rmtree
73
- end
74
-
75
45
  def parse_options(options)
76
46
  @remote = options.delete(:git)
77
47
 
78
48
  if options[:branch]
79
- @ref = R10K::Git::Head.new(options.delete(:branch))
49
+ @ref = options.delete(:branch)
80
50
  end
81
51
 
82
52
  if options[:tag]
83
- @ref = R10K::Git::Tag.new(options.delete(:tag))
53
+ @ref = options.delete(:tag)
84
54
  end
85
55
 
86
56
  if options[:commit]
87
- @ref = R10K::Git::Commit.new(options.delete(:commit))
57
+ @ref = options.delete(:commit)
88
58
  end
89
59
 
90
60
  if options[:ref]
91
- @ref = R10K::Git::Ref.new(options.delete(:ref))
61
+ @ref = options.delete(:ref)
92
62
  end
93
63
 
94
- @ref ||= R10K::Git::Ref.new('master')
64
+ @ref ||= 'master'
95
65
 
96
66
  unless options.empty?
97
67
  raise ArgumentError, "Unhandled options #{options.keys.inspect} specified for #{self.class}"
@@ -0,0 +1,31 @@
1
+ require 'r10k/module'
2
+ require 'r10k/errors'
3
+ require 'shared/puppet/module_tool/metadata'
4
+
5
+ class R10K::Module::MetadataFile
6
+
7
+ # @param metadata_path [Pathname] The file path to the metadata
8
+ def initialize(metadata_file_path)
9
+ @metadata_file_path = metadata_file_path
10
+ end
11
+
12
+ # Does the metadata file itself exist?
13
+ def exist?
14
+ @metadata_file_path.file? and @metadata_file_path.readable?
15
+ end
16
+
17
+ # @return [Puppet::ModuleTool::Metadata ] The metadata object created by the metadatafile
18
+ def read(metadata_file_path = @metadata_file_path)
19
+ if self.exist?
20
+ metadata_file_path.open do |f|
21
+ begin
22
+ metadata = Puppet::ModuleTool::Metadata.new
23
+ metadata.update(JSON.load(f), false)
24
+ rescue JSON::ParserError => e
25
+ exception = R10K::Error.wrap(e, "Could not read metadata.json")
26
+ raise exception
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,4 @@
1
1
  require 'r10k/module'
2
- require 'r10k/execution'
3
2
  require 'r10k/svn/working_dir'
4
3
  require 'r10k/util/setopts'
5
4
 
@@ -1,5 +1,7 @@
1
1
  require 'r10k/module_repository'
2
2
  require 'r10k/version'
3
+ require 'r10k/logging'
4
+ require 'r10k/errors'
3
5
 
4
6
  require 'faraday'
5
7
  require 'faraday_middleware/multi_json'
@@ -7,6 +9,8 @@ require 'faraday_middleware'
7
9
 
8
10
  class R10K::ModuleRepository::Forge
9
11
 
12
+ include R10K::Logging
13
+
10
14
  # @!attribute [r] forge
11
15
  # @return [String] The forge hostname to use for requests
12
16
  attr_reader :forge
@@ -16,7 +20,11 @@ class R10K::ModuleRepository::Forge
16
20
  # @return [Faraday]
17
21
  attr_reader :conn
18
22
 
19
- def initialize(forge = 'forge.puppetlabs.com')
23
+ def initialize(forge = 'forgeapi.puppetlabs.com')
24
+ if forge =~ /forge\.puppetlabs\.com/
25
+ logger.warn("#{forge} does not support the latest puppet forge API. Please update to \"forge 'https://forgeapi.puppetlabs.com'\"")
26
+ forge = 'forgeapi.puppetlabs.com'
27
+ end
20
28
  @forge = forge
21
29
  @conn = make_conn
22
30
  end
@@ -31,10 +39,18 @@ class R10K::ModuleRepository::Forge
31
39
  # @param module_name [String] The fully qualified module name
32
40
  # @return [Array<String>] All published versions of the given module
33
41
  def versions(module_name)
34
- response = @conn.get("/api/v1/releases.json", {'module' => module_name})
35
- response.body[module_name].map do |version_info|
42
+ path = "/v3/modules/#{module_name.tr('/','-')}"
43
+ response = @conn.get(path)
44
+
45
+ if response.status != 200
46
+ raise R10K::Error.new("Request to Puppet Forge '#{path}' failed. Status: #{response.status}")
47
+ end
48
+
49
+ releases = response.body['releases'].reject { |r| r['deleted_at'] }
50
+ releases = releases.map do |version_info|
36
51
  version_info['version']
37
52
  end
53
+ releases.reverse
38
54
  end
39
55
 
40
56
  # Query for the newest published version of a module
@@ -56,10 +72,7 @@ class R10K::ModuleRepository::Forge
56
72
  # Force use of json_pure with multi_json on Ruby 1.8.7
57
73
  multi_json_opts = (RUBY_VERSION == "1.8.7" ? {:adapter => :json_pure} : {})
58
74
 
59
- Faraday.new(
60
- :url => "https://#{@forge}",
61
- :user_agent => "Ruby/r10k #{R10K::VERSION}"
62
- ) do |builder|
75
+ Faraday.new(:url => "https://#{@forge}") do |builder|
63
76
  builder.request(:multi_json, multi_json_opts)
64
77
  builder.response(:multi_json, multi_json_opts)
65
78
 
@@ -37,7 +37,7 @@ class Puppetfile
37
37
  @puppetfile_path = puppetfile || File.join(basedir, 'Puppetfile')
38
38
 
39
39
  @modules = []
40
- @forge = 'forge.puppetlabs.com'
40
+ @forge = 'forgeapi.puppetlabs.com'
41
41
  end
42
42
 
43
43
  def load
@@ -74,6 +74,12 @@ class R10K::Settings::Container
74
74
  end
75
75
  end
76
76
 
77
+ # Clear all existing settings in this container. Valid settings are left alone.
78
+ # @return [void]
79
+ def reset!
80
+ @settings = {}
81
+ end
82
+
77
83
  private
78
84
 
79
85
  def validate_key!(key)
@@ -41,5 +41,14 @@ module R10K::Settings::Mixin
41
41
  def settings
42
42
  @settings ||= R10K::Settings::Container.new(defaults)
43
43
  end
44
+
45
+ # Allow subclasses to use the settings of the parent class as default values
46
+ #
47
+ # @return [void]
48
+ def inherited(subclass)
49
+ subclass.instance_eval do
50
+ @settings = R10K::Settings::Container.new(superclass.settings)
51
+ end
52
+ end
44
53
  end
45
54
  end
@@ -1,6 +1,6 @@
1
1
  require 'r10k'
2
2
  require 'r10k/keyed_factory'
3
- require 'r10k/util/core_ext/hash_ext'
3
+ require 'r10k/util/symbolize_keys'
4
4
 
5
5
  module R10K
6
6
  module Source
@@ -21,8 +21,7 @@ module R10K
21
21
  end
22
22
 
23
23
  def self.from_hash(name, hash)
24
- hash.extend R10K::Util::CoreExt::HashExt::SymbolizeKeys
25
- hash.symbolize_keys!
24
+ R10K::Util::SymbolizeKeys.symbolize_keys!(hash)
26
25
 
27
26
  basedir = hash.delete(:basedir)
28
27
 
@@ -12,8 +12,8 @@ class R10K::Source::Base
12
12
  attr_reader :name
13
13
 
14
14
  # @!attribute [r] prefix
15
- # @return [true, false] Whether the source name should be prefixed to each
16
- # environment basedir. Defaults to false
15
+ # @return [String, nil] The prefix for the environments basedir.
16
+ # Defaults to nil.
17
17
  attr_reader :prefix
18
18
 
19
19
  # Initialize the given source.
@@ -23,9 +23,9 @@ class R10K::Source::Base
23
23
  # @param options [Hash] An additional set of options for this source. The
24
24
  # semantics of this hash may depend on the source implementation.
25
25
  #
26
- # @option options [Boolean] :prefix Whether to prefix the source name to the
27
- # environment directory names. All sources should respect this option.
28
- # Defaults to false.
26
+ # @option options [Boolean, String] :prefix If a String this becomes the prefix.
27
+ # If true, will use the source name as the prefix. All sources should respect this option.
28
+ # Defaults to false for no environment prefix.
29
29
  def initialize(name, basedir, options = {})
30
30
  @name = name
31
31
  @basedir = basedir
@@ -1,7 +1,6 @@
1
1
  require 'r10k/git'
2
2
  require 'r10k/environment'
3
- require 'r10k/util/purgeable'
4
- require 'r10k/util/core_ext/hash_ext'
3
+ require 'r10k/environment/name'
5
4
 
6
5
  # This class implements a source for Git environments.
7
6
  #
@@ -43,8 +42,9 @@ class R10K::Source::Git < R10K::Source::Base
43
42
  # @param basedir [String] The base directory where the generated environments will be created.
44
43
  # @param options [Hash] An additional set of options for this source.
45
44
  #
46
- # @option options [Boolean] :prefix Whether to prefix the source name to the
47
- # environment directory names. Defaults to false.
45
+ # @option options [Boolean, String] :prefix If a String this becomes the prefix.
46
+ # If true, will use the source name as the prefix.
47
+ # Defaults to false for no environment prefix.
48
48
  # @option options [String] :remote The URL to the base directory of the SVN repository
49
49
  # @option options [Hash] :remote Additional settings that configure how the
50
50
  # source should behave.
@@ -56,15 +56,17 @@ class R10K::Source::Git < R10K::Source::Base
56
56
  @remote = options[:remote]
57
57
  @invalid_branches = (options[:invalid_branches] || 'correct_and_warn')
58
58
 
59
- @cache = R10K::Git::Cache.generate(@remote)
59
+ @cache = R10K::Git.cache.generate(@remote)
60
60
  end
61
61
 
62
62
  # Update the git cache for this git source to get the latest list of environments.
63
63
  #
64
64
  # @return [void]
65
65
  def preload!
66
- logger.debug "Determining current branches for Git source #{@remote.inspect}"
66
+ logger.debug "Fetching '#{@remote}' to determine current branches."
67
67
  @cache.sync
68
+ rescue => e
69
+ raise R10K::Error.wrap(e, "Unable to determine current branches for Git source '#{@name}' (#{@basedir})")
68
70
  end
69
71
  alias fetch_remote preload!
70
72
 
@@ -100,24 +102,8 @@ class R10K::Source::Git < R10K::Source::Base
100
102
  envs
101
103
  end
102
104
 
103
- include R10K::Util::Purgeable
104
-
105
- def managed_directory
106
- @basedir
107
- end
108
-
109
- def current_contents
110
- dir = self.managed_directory
111
- glob_part = @prefix ? @name.to_s() + '_*' : '*'
112
- glob_exp = File.join(dir, glob_part)
113
-
114
- Dir.glob(glob_exp).map do |fname|
115
- File.basename fname
116
- end
117
- end
118
-
119
105
  # List all environments that should exist in the basedir for this source
120
- # @note This implements a required method for the Purgeable mixin
106
+ # @note This is required by {R10K::Util::Basedir}
121
107
  # @return [Array<String>]
122
108
  def desired_contents
123
109
  environments.map {|env| env.dirname }
@@ -126,70 +112,9 @@ class R10K::Source::Git < R10K::Source::Base
126
112
  private
127
113
 
128
114
  def branch_names
115
+ opts = {:prefix => @prefix, :invalid => @invalid_branches, :source => @name}
129
116
  @cache.branches.map do |branch|
130
- BranchName.new(branch, {
131
- :prefix => @prefix,
132
- :sourcename => @name,
133
- :invalid => @invalid_branches,
134
- })
135
- end
136
- end
137
-
138
- # @api private
139
- class BranchName
140
-
141
- attr_reader :name
142
-
143
- INVALID_CHARACTERS = %r[\W]
144
-
145
- def initialize(name, opts)
146
- @name = name
147
- @opts = opts
148
-
149
- @prefix = opts[:prefix]
150
- @sourcename = opts[:sourcename]
151
- @invalid = opts[:invalid]
152
-
153
- case @invalid
154
- when 'correct_and_warn'
155
- @validate = true
156
- @correct = true
157
- when 'correct'
158
- @validate = false
159
- @correct = true
160
- when 'error'
161
- @validate = true
162
- @correct = false
163
- when NilClass
164
- @validate = opts[:validate]
165
- @correct = opts[:correct]
166
- end
117
+ R10K::Environment::Name.new(branch, opts)
167
118
  end
168
-
169
- def correct?; @correct end
170
- def validate?; @validate end
171
-
172
- def valid?
173
- if @validate
174
- ! @name.match(INVALID_CHARACTERS)
175
- else
176
- true
177
- end
178
- end
179
-
180
- def dirname
181
- dir = @name.dup
182
-
183
- if @prefix
184
- dir = "#{@sourcename}_#{dir}"
185
- end
186
-
187
- if @correct
188
- dir.gsub!(INVALID_CHARACTERS, '_')
189
- end
190
-
191
- dir
192
- end
193
-
194
119
  end
195
120
  end