r10k 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.mkd +150 -0
  3. data/README.mkd +10 -1
  4. data/doc/dynamic-environments/configuration.mkd +31 -0
  5. data/doc/dynamic-environments/quickstart.mkd +33 -79
  6. data/doc/faq.mkd +67 -0
  7. data/doc/git/providers.mkd +37 -0
  8. data/doc/puppetfile.mkd +73 -0
  9. data/integration/lib/r10k_utils.rb +47 -2
  10. data/integration/pre-suite/01_git_config.rb +9 -8
  11. data/integration/pre-suite/02_pe_r10k.rb +5 -8
  12. data/integration/scripts/setup_r10k_env_centos5.sh +1 -1
  13. data/integration/scripts/setup_r10k_env_centos6.sh +1 -1
  14. data/integration/scripts/setup_r10k_env_rhel7.sh +1 -1
  15. data/integration/scripts/setup_r10k_env_sles11.sh +1 -1
  16. data/integration/scripts/setup_r10k_env_sles12.sh +1 -1
  17. data/integration/scripts/setup_r10k_env_ubuntu1004.sh +1 -1
  18. data/integration/scripts/setup_r10k_env_ubuntu1204.sh +1 -1
  19. data/integration/scripts/setup_r10k_env_ubuntu1404.sh +1 -1
  20. data/integration/test_run_scripts/all_tests-rugged-pe-centos6.sh +1 -1
  21. data/integration/test_run_scripts/all_tests-rugged-pe-rhel7.sh +1 -1
  22. data/integration/test_run_scripts/all_tests-rugged-pe-sles11.sh +1 -1
  23. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1204.sh +1 -1
  24. data/integration/test_run_scripts/all_tests-rugged-pe-ubuntu1404.sh +1 -1
  25. data/integration/test_run_scripts/all_tests-shellgit-pe-centos6.sh +1 -1
  26. data/integration/test_run_scripts/all_tests-shellgit-pe-rhel7.sh +1 -1
  27. data/integration/test_run_scripts/all_tests-shellgit-pe-sles11.sh +1 -1
  28. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1204.sh +1 -1
  29. data/integration/test_run_scripts/all_tests-shellgit-pe-ubuntu1404.sh +1 -1
  30. data/integration/test_run_scripts/basic_functionality/all_tests-pe-centos6.sh +1 -1
  31. data/integration/test_run_scripts/command_line/all_tests-pe-centos6.sh +1 -1
  32. data/integration/test_run_scripts/git_source/all_tests-pe-centos6.sh +1 -1
  33. data/integration/test_run_scripts/user_scenario/basic_workflow/all_tests-pe-centos6.sh +1 -1
  34. data/integration/test_run_scripts/user_scenario/complex_workflow/all_tests-pe-centos6.sh +1 -1
  35. data/integration/tests/basic_functionality/install_pe_only_module_with_puppetfile.rb +83 -0
  36. data/integration/tests/basic_functionality/negative/attempt_to_install_peonly_module_without_license.rb +71 -0
  37. data/integration/tests/basic_functionality/negative/neg_deploy_with_invalid_r10k_yaml.rb +7 -2
  38. data/integration/tests/basic_functionality/negative/neg_deploy_with_missing_r10k_yaml.rb +3 -2
  39. data/integration/tests/basic_functionality/negative/neg_invalid_git_provider.rb +3 -2
  40. data/integration/tests/basic_functionality/negative/negative_bad_proxy.rb +56 -0
  41. data/integration/tests/basic_functionality/proxy_specified_in_configuration.rb +103 -0
  42. data/integration/tests/basic_functionality/proxy_with_puppetfile.rb +61 -0
  43. data/integration/tests/basic_functionality/rugged_git_provider_with_ssh.rb +2 -1
  44. data/integration/tests/basic_functionality/rugged_git_provider_without_ssh.rb +2 -1
  45. data/integration/tests/command_line/deploy_env_without_mod_update.rb +3 -2
  46. data/integration/tests/command_line/negative/neg_deploy_env_with_module_update.rb +3 -2
  47. data/integration/tests/command_line/negative/neg_invalid_cli_dep_flag.rb +2 -1
  48. data/integration/tests/command_line/negative/neg_invalid_cli_env_flag.rb +2 -1
  49. data/integration/tests/command_line/negative/neg_invalid_cmd_line_arg.rb +3 -4
  50. data/integration/tests/git_source/git_source_git.rb +7 -2
  51. data/integration/tests/git_source/git_source_ssh.rb +3 -2
  52. data/integration/tests/git_source/git_source_submodule.rb +2 -1
  53. data/integration/tests/git_source/negative/neg_git_broken_remote.rb +2 -1
  54. data/integration/tests/git_source/negative/neg_git_unauthorized_https.rb +2 -1
  55. data/integration/tests/git_source/negative/neg_git_unauthorized_ssh.rb +2 -1
  56. data/integration/tests/git_source/negative/neg_git_unicode_branch.rb +2 -1
  57. data/integration/tests/user_scenario/basic_workflow/multi_env_1000_branches.rb +3 -3
  58. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module.rb +2 -1
  59. data/integration/tests/user_scenario/basic_workflow/multi_env_custom_forge_git_module_static.rb +9 -5
  60. data/integration/tests/user_scenario/basic_workflow/multi_env_hiera.rb +9 -2
  61. data/integration/tests/user_scenario/basic_workflow/multi_env_multi_source.rb +2 -1
  62. data/integration/tests/user_scenario/basic_workflow/multi_source_custom_forge_git_module.rb +2 -1
  63. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_basedir.rb +2 -1
  64. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_forge_module.rb +7 -2
  65. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module.rb +3 -4
  66. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_module_ref.rb +2 -1
  67. data/integration/tests/user_scenario/basic_workflow/negative/neg_bad_git_remote.rb +2 -1
  68. data/integration/tests/user_scenario/basic_workflow/negative/neg_branch_name_collision.rb +2 -1
  69. data/integration/tests/user_scenario/basic_workflow/negative/neg_disk_full.rb +2 -1
  70. data/integration/tests/user_scenario/basic_workflow/negative/neg_duplicate_module_names.rb +10 -4
  71. data/integration/tests/user_scenario/basic_workflow/negative/neg_inaccessible_forge.rb +9 -2
  72. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_env_name.rb +2 -1
  73. data/integration/tests/user_scenario/basic_workflow/negative/neg_invalid_puppet_file.rb +2 -1
  74. data/integration/tests/user_scenario/basic_workflow/negative/neg_module_specified_at_deleted_release.rb +7 -2
  75. data/integration/tests/user_scenario/basic_workflow/negative/neg_read_only.rb +2 -1
  76. data/integration/tests/user_scenario/basic_workflow/negative/neg_specify_deleted_forge_module.rb +9 -2
  77. data/integration/tests/user_scenario/basic_workflow/single_env_10000_files.rb +2 -1
  78. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_git_module.rb +2 -1
  79. data/integration/tests/user_scenario/basic_workflow/single_env_custom_forge_module.rb +2 -1
  80. data/integration/tests/user_scenario/basic_workflow/single_env_custom_module.rb +2 -1
  81. data/integration/tests/user_scenario/basic_workflow/single_env_large_files.rb +2 -1
  82. data/integration/tests/user_scenario/basic_workflow/single_env_module_already_installed.rb +2 -1
  83. data/integration/tests/user_scenario/basic_workflow/single_env_module_last_release_deleted.rb +2 -1
  84. data/integration/tests/user_scenario/basic_workflow/single_env_non-existent_base_dir.rb +2 -1
  85. data/integration/tests/user_scenario/basic_workflow/single_env_purge_unmanaged_modules.rb +3 -2
  86. data/integration/tests/user_scenario/basic_workflow/single_env_switch_forge_git_module.rb +3 -2
  87. data/integration/tests/user_scenario/basic_workflow/single_env_unicode_paths.rb +2 -1
  88. data/integration/tests/user_scenario/basic_workflow/single_env_upgrade_forge_mod_revert_change.rb +4 -3
  89. data/integration/tests/user_scenario/complex_workflow/multi_env_add_change_remove.rb +3 -2
  90. data/integration/tests/user_scenario/complex_workflow/multi_env_remove_re-add.rb +4 -3
  91. data/integration/tests/user_scenario/complex_workflow/multi_env_unamanaged.rb +3 -2
  92. data/integration/tests/user_scenario/complex_workflow/single_env_git_module_update.rb +3 -2
  93. data/lib/r10k/action/base.rb +31 -0
  94. data/lib/r10k/action/deploy/deploy_helpers.rb +34 -0
  95. data/lib/r10k/action/deploy/display.rb +57 -75
  96. data/lib/r10k/action/deploy/environment.rb +52 -15
  97. data/lib/r10k/action/deploy/module.rb +13 -18
  98. data/lib/r10k/action/puppetfile/check.rb +8 -18
  99. data/lib/r10k/action/puppetfile/install.rb +13 -27
  100. data/lib/r10k/action/puppetfile/purge.rb +8 -17
  101. data/lib/r10k/action/runner.rb +39 -3
  102. data/lib/r10k/cli.rb +1 -3
  103. data/lib/r10k/cli/deploy.rb +3 -1
  104. data/lib/r10k/cli/puppetfile.rb +2 -2
  105. data/lib/r10k/deployment.rb +8 -6
  106. data/lib/r10k/deployment/config.rb +18 -65
  107. data/lib/r10k/environment/base.rb +19 -0
  108. data/lib/r10k/environment/git.rb +9 -0
  109. data/lib/r10k/environment/svn.rb +9 -0
  110. data/lib/r10k/forge/module_release.rb +21 -14
  111. data/lib/r10k/git.rb +6 -0
  112. data/lib/r10k/git/alternates.rb +20 -6
  113. data/lib/r10k/git/cache.rb +1 -1
  114. data/lib/r10k/git/rugged/bare_repository.rb +5 -0
  115. data/lib/r10k/git/rugged/base_repository.rb +6 -20
  116. data/lib/r10k/git/rugged/credentials.rb +66 -0
  117. data/lib/r10k/git/rugged/thin_repository.rb +16 -11
  118. data/lib/r10k/git/rugged/working_repository.rb +15 -7
  119. data/lib/r10k/git/shellgit/bare_repository.rb +9 -4
  120. data/lib/r10k/git/shellgit/thin_repository.rb +8 -10
  121. data/lib/r10k/git/stateful_repository.rb +1 -1
  122. data/lib/r10k/initializers.rb +55 -0
  123. data/lib/r10k/module.rb +1 -0
  124. data/lib/r10k/module/base.rb +3 -2
  125. data/lib/r10k/module/forge.rb +14 -6
  126. data/lib/r10k/module/local.rb +36 -0
  127. data/lib/r10k/module/metadata_file.rb +2 -2
  128. data/lib/r10k/puppetfile.rb +1 -1
  129. data/lib/r10k/settings.rb +86 -0
  130. data/lib/r10k/settings/collection.rb +118 -0
  131. data/lib/r10k/settings/definition.rb +112 -0
  132. data/lib/r10k/settings/enum_definition.rb +22 -0
  133. data/lib/r10k/settings/loader.rb +96 -0
  134. data/lib/r10k/settings/uri_definition.rb +19 -0
  135. data/lib/r10k/util/subprocess/runner/windows.rb +4 -4
  136. data/lib/r10k/version.rb +1 -1
  137. data/r10k.gemspec +2 -3
  138. data/spec/fixtures/unit/puppetfile/argument-error/Puppetfile +1 -0
  139. data/spec/fixtures/unit/util/subprocess/{posix/runner → runner}/no-execute.sh +0 -0
  140. data/spec/integration/git/rugged/thin_repository_spec.rb +2 -2
  141. data/spec/integration/git/rugged/working_repository_spec.rb +9 -0
  142. data/spec/integration/git/shellgit/thin_repository_spec.rb +2 -2
  143. data/spec/integration/git/stateful_repository_spec.rb +1 -1
  144. data/spec/r10k-mocks/mock_config.rb +10 -13
  145. data/spec/r10k-mocks/mock_env.rb +8 -0
  146. data/spec/shared-examples/deploy-actions.rb +69 -0
  147. data/spec/shared-examples/puppetfile-action.rb +17 -0
  148. data/spec/unit/action/cri_runner_spec.rb +3 -1
  149. data/spec/unit/action/deploy/deploy_helpers_spec.rb +38 -0
  150. data/spec/unit/action/deploy/display_spec.rb +31 -0
  151. data/spec/unit/action/deploy/environment_spec.rb +56 -0
  152. data/spec/unit/action/deploy/module_spec.rb +17 -0
  153. data/spec/unit/action/puppetfile/check_spec.rb +26 -0
  154. data/spec/unit/action/puppetfile/install_spec.rb +68 -0
  155. data/spec/unit/action/puppetfile/purge_spec.rb +19 -0
  156. data/spec/unit/action/runner_spec.rb +10 -9
  157. data/spec/unit/deployment/config_spec.rb +20 -44
  158. data/spec/unit/deployment_spec.rb +1 -1
  159. data/spec/unit/environment/git_spec.rb +20 -0
  160. data/spec/unit/environment/svn_spec.rb +20 -0
  161. data/spec/unit/forge/module_release_spec.rb +6 -3
  162. data/spec/unit/git/alternates_spec.rb +38 -12
  163. data/spec/unit/git/cache_spec.rb +4 -0
  164. data/spec/unit/git/rugged/credentials_spec.rb +74 -0
  165. data/spec/unit/initializers_spec.rb +68 -0
  166. data/spec/unit/module/base_spec.rb +2 -2
  167. data/spec/unit/module/forge_spec.rb +11 -3
  168. data/spec/unit/module/metadata_file_spec.rb +0 -1
  169. data/spec/unit/puppetfile_spec.rb +11 -0
  170. data/spec/unit/settings/collection_spec.rb +122 -0
  171. data/spec/unit/settings/definition_spec.rb +78 -0
  172. data/spec/unit/settings/enum_definition_spec.rb +20 -0
  173. data/spec/unit/{deployment/config → settings}/loader_spec.rb +50 -2
  174. data/spec/unit/settings/uri_definition_spec.rb +23 -0
  175. data/spec/unit/settings_spec.rb +151 -0
  176. data/spec/unit/util/subprocess/runner/posix_spec.rb +1 -1
  177. data/spec/unit/util/subprocess/runner/windows_spec.rb +7 -0
  178. metadata +53 -90
  179. data/lib/r10k/deployment/config/loader.rb +0 -59
  180. data/lib/shared/puppet/module_tool/metadata.rb +0 -197
  181. data/lib/shared/puppet_forge/connection.rb +0 -64
  182. data/lib/shared/puppet_forge/connection/connection_failure.rb +0 -26
  183. data/lib/shared/puppet_forge/error.rb +0 -41
  184. data/lib/shared/puppet_forge/tar.rb +0 -10
  185. data/lib/shared/puppet_forge/tar/mini.rb +0 -81
  186. data/lib/shared/puppet_forge/unpacker.rb +0 -68
  187. data/lib/shared/puppet_forge/v3.rb +0 -13
  188. data/lib/shared/puppet_forge/v3/module.rb +0 -69
  189. data/lib/shared/puppet_forge/v3/module_release.rb +0 -85
  190. data/lib/shared/puppet_forge/version.rb +0 -3
  191. data/spec/unit/puppet/module_tool/metadata_spec.rb +0 -301
  192. data/spec/unit/puppet_forge/connection/connection_failure_spec.rb +0 -28
  193. data/spec/unit/puppet_forge/connection_spec.rb +0 -41
  194. data/spec/unit/puppet_forge/tar/mini_spec.rb +0 -87
  195. data/spec/unit/puppet_forge/tar_spec.rb +0 -9
  196. data/spec/unit/puppet_forge/unpacker_spec.rb +0 -59
  197. data/spec/unit/puppet_forge/v3/module_release_spec.rb +0 -83
  198. data/spec/unit/puppet_forge/v3/module_spec.rb +0 -75
@@ -67,6 +67,25 @@ class R10K::Environment::Base
67
67
  raise NotImplementedError, "#{self.class} has not implemented method #{__method__}"
68
68
  end
69
69
 
70
+ # Returns a unique identifier for the environment's current state.
71
+ #
72
+ # @api public
73
+ # @abstract
74
+ # @return [String]
75
+ def signature
76
+ raise NotImplementedError, "#{self.class} has not implemented method #{__method__}"
77
+ end
78
+
79
+ # Returns a hash describing the current state of the environment.
80
+ #
81
+ # @return [Hash]
82
+ def info
83
+ {
84
+ :name => self.name,
85
+ :signature => self.signature,
86
+ }
87
+ end
88
+
70
89
  # @return [Array<R10K::Module::Base>] All modules defined in the Puppetfile
71
90
  # associated with this environment.
72
91
  def modules
@@ -52,6 +52,15 @@ class R10K::Environment::Git < R10K::Environment::Base
52
52
  @synced = true
53
53
  end
54
54
 
55
+ # Return a sting which uniquely identifies (per source) the current state of the
56
+ # environment.
57
+ #
58
+ # @api public
59
+ # @return [String]
60
+ def signature
61
+ @repo.head
62
+ end
63
+
55
64
  extend Forwardable
56
65
 
57
66
  def_delegators :@repo, :status
@@ -64,6 +64,15 @@ class R10K::Environment::SVN < R10K::Environment::Base
64
64
  @synced = true
65
65
  end
66
66
 
67
+ # Return a sting which uniquely identifies (per source) the current state of the
68
+ # environment.
69
+ #
70
+ # @api public
71
+ # @return [String]
72
+ def signature
73
+ @working_dir.revision
74
+ end
75
+
67
76
  def status
68
77
  if !@path.exist?
69
78
  :absent
@@ -1,10 +1,8 @@
1
- require 'shared/puppet_forge/v3/module_release'
2
- require 'shared/puppet_forge/unpacker'
3
1
  require 'r10k/logging'
4
2
  require 'r10k/settings/mixin'
5
3
  require 'fileutils'
6
- require 'forwardable'
7
4
  require 'tmpdir'
5
+ require 'puppet_forge'
8
6
 
9
7
  module R10K
10
8
  module Forge
@@ -14,6 +12,7 @@ module R10K
14
12
  include R10K::Settings::Mixin
15
13
 
16
14
  def_setting_attr :proxy
15
+ def_setting_attr :baseurl
17
16
 
18
17
  include R10K::Logging
19
18
 
@@ -24,10 +23,6 @@ module R10K
24
23
  # release.
25
24
  attr_reader :forge_release
26
25
 
27
- extend Forwardable
28
-
29
- def_delegators :@forge_release, :slug, :data
30
-
31
26
  # @!attribute [rw] download_path
32
27
  # @return [Pathname] Where the module tarball will be downloaded to.
33
28
  attr_accessor :download_path
@@ -42,11 +37,11 @@ module R10K
42
37
  @full_name = PuppetForge::V3.normalize_name(full_name)
43
38
  @version = version
44
39
 
45
- @forge_release = PuppetForge::V3::ModuleRelease.new(@full_name, @version)
46
- @forge_release.conn.proxy(proxy)
40
+ PuppetForge::V3::Release.conn = conn
41
+ @forge_release = PuppetForge::V3::Release.new({ :name => @full_name, :version => @version, :slug => "#{@full_name}-#{@version}" })
47
42
 
48
- @download_path = Pathname.new(Dir.mktmpdir) + (slug + '.tar.gz')
49
- @unpack_path = Pathname.new(Dir.mktmpdir) + slug
43
+ @download_path = Pathname.new(Dir.mktmpdir) + (@forge_release.slug + '.tar.gz')
44
+ @unpack_path = Pathname.new(Dir.mktmpdir) + @forge_release.slug
50
45
  end
51
46
 
52
47
  # Download, unpack, and install this module release to the target directory.
@@ -71,19 +66,19 @@ module R10K
71
66
  #
72
67
  # @return [void]
73
68
  def download
74
- logger.debug1 "Downloading #{@forge_release.slug} from #{@forge_release.conn.url_prefix} to #{@download_path}"
69
+ logger.debug1 "Downloading #{@forge_release.slug} from #{PuppetForge::Release.conn.url_prefix} to #{@download_path}"
75
70
  @forge_release.download(download_path)
76
71
  end
77
72
 
78
73
  # Verify the module release downloaded to {#download_path} against the
79
74
  # module release checksum given by the Puppet Forge
80
75
  #
81
- # @raise [PuppetForge::V3::ModuleRelease::ChecksumMismatch] The
76
+ # @raise [PuppetForge::V3::Release::ChecksumMismatch] The
82
77
  # downloaded module release checksum doesn't match the expected Forge
83
78
  # module release checksum.
84
79
  # @return [void]
85
80
  def verify
86
- logger.debug1 "Verifying that #{download_path} matches checksum #{data['file_md5']}"
81
+ logger.debug1 "Verifying that #{download_path} matches checksum #{@forge_release.file_md5}"
87
82
  @forge_release.verify(download_path)
88
83
  end
89
84
 
@@ -128,6 +123,18 @@ module R10K
128
123
 
129
124
  private
130
125
 
126
+ def conn
127
+ if settings[:baseurl]
128
+ PuppetForge.host = settings[:baseurl]
129
+ conn = PuppetForge::Connection.make_connection(settings[:baseurl])
130
+ else
131
+ PuppetForge.host = "https://forgeapi.puppetlabs.com"
132
+ conn = PuppetForge::Connection.default_connection
133
+ end
134
+ conn.proxy(proxy)
135
+ conn
136
+ end
137
+
131
138
  def proxy
132
139
  [
133
140
  settings[:proxy],
@@ -68,6 +68,8 @@ module R10K
68
68
  name
69
69
  end
70
70
 
71
+ extend R10K::Logging
72
+
71
73
  # Manually set the Git provider by name.
72
74
  #
73
75
  # @param name [Symbol] The name of the Git provider to use.
@@ -87,7 +89,9 @@ module R10K
87
89
  if attrs[:on_set]
88
90
  attrs[:on_set].call
89
91
  end
92
+
90
93
  @provider = attrs[:module]
94
+ logger.debug1 { "Setting Git provider to #{@provider.name}" }
91
95
  end
92
96
 
93
97
  # @return [Module] The namespace of the first available Git implementation.
@@ -98,7 +102,9 @@ module R10K
98
102
  raise R10K::Error, "No Git provider set."
99
103
  when UNSET_PROVIDER
100
104
  self.provider = default_name
105
+ logger.debug1 { "Setting Git provider to default provider #{default_name}" }
101
106
  end
107
+
102
108
  @provider
103
109
  end
104
110
 
@@ -12,22 +12,35 @@ class R10K::Git::Alternates
12
12
  # @param git_dir [Pathname] The path to the git repository
13
13
  def initialize(git_dir)
14
14
  @file = git_dir + File.join('objects', 'info', 'alternates')
15
+ @entries = []
15
16
  end
16
17
 
17
- def to_a
18
- read()
18
+ def add(path)
19
+ write(to_a << path)
19
20
  end
21
+ alias << add
20
22
 
21
- def <<(path)
22
- write(to_a << path)
23
+ # Conditionally add path to the alternates file
24
+ #
25
+ # @param path [String] The file path to add to the file if not already present
26
+ # @return [true, false] If the entry was added.
27
+ def add?(path)
28
+ paths = read()
29
+
30
+ add_entry = !paths.include?(path)
31
+
32
+ if add_entry
33
+ paths << path
34
+ write(paths)
35
+ end
36
+
37
+ add_entry
23
38
  end
24
39
 
25
40
  def include?(path)
26
41
  to_a.include?(path)
27
42
  end
28
43
 
29
- private
30
-
31
44
  def write(entries)
32
45
  if ! @file.parent.directory?
33
46
  raise R10K::Git::GitError, "Cannot write #{@file}; parent directory does not exist"
@@ -46,4 +59,5 @@ class R10K::Git::Alternates
46
59
  end
47
60
  entries
48
61
  end
62
+ alias to_a read
49
63
  end
@@ -46,7 +46,7 @@ class R10K::Git::Cache
46
46
 
47
47
  extend Forwardable
48
48
 
49
- def_delegators :@repo, :git_dir, :branches, :tags, :exist?, :resolve, :ref_type
49
+ def_delegators :@repo, :git_dir, :objects_dir, :branches, :tags, :exist?, :resolve, :ref_type
50
50
 
51
51
  # @!attribute [r] path
52
52
  # @deprecated
@@ -19,6 +19,11 @@ class R10K::Git::Rugged::BareRepository < R10K::Git::Rugged::BaseRepository
19
19
  @path
20
20
  end
21
21
 
22
+ # @return [Pathname] The path to the objects directory in this Git repository
23
+ def objects_dir
24
+ @path + "objects"
25
+ end
26
+
22
27
  # Clone the given remote.
23
28
  #
24
29
  # This should only be called if the repository does not exist.
@@ -1,10 +1,15 @@
1
1
  require 'r10k/git/rugged'
2
+ require 'r10k/git/rugged/credentials'
2
3
  require 'r10k/logging'
3
4
 
4
5
  class R10K::Git::Rugged::BaseRepository
5
6
 
6
7
  include R10K::Logging
7
8
 
9
+ # @return [Pathname] The path to this repository.
10
+ # @note The `@path` instance variable must be set by inheriting classes on instantiation.
11
+ attr_reader :path
12
+
8
13
  def resolve(pattern)
9
14
  object = with_repo { |repo| repo.rev_parse(pattern) }
10
15
  case object
@@ -61,26 +66,7 @@ class R10K::Git::Rugged::BaseRepository
61
66
  #
62
67
  # @return [Proc]
63
68
  def credentials
64
- Proc.new do |url, username_from_url, allowed_types|
65
- private_key = R10K::Git.settings[:private_key]
66
- git_user = R10K::Git.settings[:username]
67
-
68
- if private_key.nil?
69
- raise R10K::Git::GitError.new("Git remote #{url.inspect} uses the SSH protocol but no private key was given", :git_dir => @path.to_s)
70
- end
71
-
72
- if !username_from_url.nil?
73
- user = username_from_url
74
- elsif git_user
75
- user = git_user
76
- logger.debug1 "URL #{url.inspect} did not specify an SSH user, using #{user.inspect} from configuration"
77
- else
78
- user = Etc.getlogin
79
- logger.debug1 "URL #{url.inspect} did not specify an SSH user, using current user #{user.inspect}"
80
- end
81
-
82
- Rugged::Credentials::SshKey.new(:username => user, :privatekey => private_key)
83
- end
69
+ R10K::Git::Rugged::Credentials.new(self)
84
70
  end
85
71
 
86
72
  def report_transfer(results, remote)
@@ -0,0 +1,66 @@
1
+ require 'r10k/git/rugged'
2
+ require 'r10k/git/errors'
3
+ require 'r10k/logging'
4
+
5
+ # Generate credentials for secured remote connections.
6
+ #
7
+ # @api private
8
+ class R10K::Git::Rugged::Credentials
9
+
10
+ include R10K::Logging
11
+
12
+ # @param repository [R10K::Git::Rugged::BaseRepository]
13
+ def initialize(repository)
14
+ @repository = repository
15
+ end
16
+
17
+ def call(url, username_from_url, allowed_types)
18
+ if allowed_types.include?(:ssh_key)
19
+ get_ssh_key_credentials(url, username_from_url)
20
+ elsif allowed_types.include?(:plaintext)
21
+ get_plaintext_credentials(url, username_from_url)
22
+ else
23
+ get_default_credentials(url, username_from_url)
24
+ end
25
+ end
26
+
27
+ def get_ssh_key_credentials(url, username_from_url)
28
+ user = get_git_username(url, username_from_url)
29
+ private_key = R10K::Git.settings[:private_key]
30
+
31
+ if private_key.nil?
32
+ raise R10K::Git::GitError.new("Git remote #{url.inspect} uses the SSH protocol but no private key was given", :git_dir => @repository.path.to_s)
33
+ end
34
+
35
+ Rugged::Credentials::SshKey.new(:username => user, :privatekey => private_key)
36
+ end
37
+
38
+ def get_plaintext_credentials(url, username_from_url)
39
+ user = get_git_username(url, username_from_url)
40
+ password = URI.parse(url).password || ''
41
+ Rugged::Credentials::UserPassword.new(username: user, password: password)
42
+ end
43
+
44
+ def get_default_credentials(url, username_from_url)
45
+ Rugged::Credentials::Default.new
46
+ end
47
+
48
+ def get_git_username(url, username_from_url)
49
+ git_user = R10K::Git.settings[:username]
50
+
51
+ user = nil
52
+
53
+ if !username_from_url.nil?
54
+ user = username_from_url
55
+ logger.debug2 "URL #{url.inspect} includes the username #{username_from_url}, using that user for authentication."
56
+ elsif git_user
57
+ user = git_user
58
+ logger.debug2 "URL #{url.inspect} did not specify a user, using #{user.inspect} from configuration"
59
+ else
60
+ user = Etc.getlogin
61
+ logger.debug2 "URL #{url.inspect} did not specify a user, using current user #{user.inspect}"
62
+ end
63
+
64
+ user
65
+ end
66
+ end
@@ -3,12 +3,10 @@ require 'r10k/git/rugged/working_repository'
3
3
  require 'r10k/git/rugged/cache'
4
4
 
5
5
  class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
6
- def initialize(basedir, dirname)
7
- super
6
+ def initialize(basedir, dirname, cache_repo)
7
+ @cache_repo = cache_repo
8
8
 
9
- if exist? && origin
10
- set_cache(origin)
11
- end
9
+ super(basedir, dirname)
12
10
  end
13
11
 
14
12
  # Clone this git repository
@@ -21,10 +19,9 @@ class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
21
19
  # @return [void]
22
20
  def clone(remote, opts = {})
23
21
  logger.debug1 { "Cloning '#{remote}' into #{@path}" }
24
- set_cache(remote)
25
22
  @cache_repo.sync
26
23
 
27
- objectpath = (@cache_repo.git_dir + 'objects').to_s
24
+ cache_objects_dir = @cache_repo.objects_dir.to_s
28
25
 
29
26
  # {Rugged::Repository.clone_at} doesn't support :alternates, which
30
27
  # completely breaks how thin repositories need to work. To circumvent
@@ -33,8 +30,8 @@ class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
33
30
  # fetch any objects because we don't need them, and we don't actually
34
31
  # use any refs in this repository so we skip all those steps.
35
32
  ::Rugged::Repository.init_at(@path.to_s, false)
36
- @_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => [objectpath])
37
- alternates << objectpath
33
+ @_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => [cache_objects_dir])
34
+ alternates << cache_objects_dir
38
35
 
39
36
  with_repo do |repo|
40
37
  config = repo.config
@@ -66,7 +63,15 @@ class R10K::Git::Rugged::ThinRepository < R10K::Git::Rugged::WorkingRepository
66
63
 
67
64
  private
68
65
 
69
- def set_cache(remote)
70
- @cache_repo = R10K::Git::Rugged::Cache.generate(remote)
66
+ # Override the parent class repo setup so that we can make sure the alternates file is up to date
67
+ # before we create the Rugged::Repository object, which reads from the alternates file.
68
+ def setup_rugged_repo
69
+ if git_dir.exist?
70
+ entry_added = alternates.add?(@cache_repo.objects_dir.to_s)
71
+ if entry_added
72
+ logger.debug2 { "Updated repo #{@path} to include alternate object db path #{@cache_repo.objects_dir}" }
73
+ end
74
+ end
75
+ super
71
76
  end
72
77
  end
@@ -4,9 +4,6 @@ require 'r10k/git/errors'
4
4
 
5
5
  class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
6
6
 
7
- # @return [Pathname] The path to this directory
8
- attr_reader :path
9
-
10
7
  # @return [Pathname] The path to the Git repository inside of this directory
11
8
  def git_dir
12
9
  @path + '.git'
@@ -16,9 +13,7 @@ class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
16
13
  # @param dirname [String] The directory name of the Git repository
17
14
  def initialize(basedir, dirname)
18
15
  @path = Pathname.new(File.join(basedir, dirname))
19
- if exist? && git_dir.exist?
20
- @_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => alternates.to_a)
21
- end
16
+ setup_rugged_repo
22
17
  end
23
18
 
24
19
  # Clone this git repository
@@ -62,9 +57,14 @@ class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
62
57
  # @param ref [String] The git reference to check out
63
58
  # @return [void]
64
59
  def checkout(ref)
65
- logger.debug1 { "Checking out ref '#{ref}' at #{@path}" }
66
60
  sha = resolve(ref)
67
61
 
62
+ if sha
63
+ logger.debug2 { "Checking out ref '#{ref}' (resolved to SHA '#{sha}') in repository #{@path}" }
64
+ else
65
+ raise R10K::Git::GitError.new("Unable to check out unresolvable ref '#{ref}'", git_dir: git_dir)
66
+ end
67
+
68
68
  with_repo do |repo|
69
69
  repo.checkout(sha)
70
70
  repo.reset(sha, :hard)
@@ -96,4 +96,12 @@ class R10K::Git::Rugged::WorkingRepository < R10K::Git::Rugged::BaseRepository
96
96
  def origin
97
97
  with_repo { |repo| repo.config['remote.origin.url'] }
98
98
  end
99
+
100
+ private
101
+
102
+ def setup_rugged_repo
103
+ if exist? && git_dir.exist?
104
+ @_rugged_repo = ::Rugged::Repository.new(@path.to_s, :alternates => alternates.to_a)
105
+ end
106
+ end
99
107
  end