diff options
author | Arnoud de Jonge <arnoud@de-jonge.org> | 2013-04-15 17:56:44 +0200 |
---|---|---|
committer | Arnoud de Jonge <arnoud@de-jonge.org> | 2013-07-16 15:43:33 +0200 |
commit | c8ac78614dea3b2409f88cf7fb7901cbd78ce23d (patch) | |
tree | 71b01c117f7db4a62e122c2ce40487395ac08862 | |
parent | 054d16421c782dd76a6990856bb78797abe36750 (diff) | |
download | puppet-vcsrepo-c8ac78614dea3b2409f88cf7fb7901cbd78ce23d.tar.gz puppet-vcsrepo-c8ac78614dea3b2409f88cf7fb7901cbd78ce23d.tar.bz2 |
Added ssh identity
hg_with_identity function renamed to hg_wrapper. Added ability to specify a user and an SSH identity.
Added extra options to the ssh command.
Identity and user fixed
Requirement for pp deleted.
-rw-r--r-- | README.HG.markdown | 22 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/hg.rb | 32 |
2 files changed, 42 insertions, 12 deletions
diff --git a/README.HG.markdown b/README.HG.markdown index b1680c8..55ceef4 100644 --- a/README.HG.markdown +++ b/README.HG.markdown @@ -27,7 +27,7 @@ For a specific changeset, use `revision`: vcsrepo { "/path/to/repo": ensure => present, provider => hg, - source => "http://hg.example.com/myrepo" + source => "http://hg.example.com/myrepo", revision => '21ea4598c962' } @@ -36,10 +36,28 @@ You can also set `revision` to a tag: vcsrepo { "/path/to/repo": ensure => present, provider => hg, - source => "http://hg.example.com/myrepo" + source => "http://hg.example.com/myrepo", revision => '1.1.2' } +Check out as a user: + + vcsrepo { "/path/to/repo": + ensure => present, + provider => hg, + source => "http://hg.example.com/myrepo", + user => 'user' + } + +Specify an SSH identity key: + + vcsrepo { "/path/to/repo": + ensure => present, + provider => hg, + source => "ssh://hg@hg.example.com/myrepo", + identity => "/home/user/.ssh/id_dsa, + } + For sources that use SSH (eg, `ssh://...`) ------------------------------------------ diff --git a/lib/puppet/provider/vcsrepo/hg.rb b/lib/puppet/provider/vcsrepo/hg.rb index 67a2a82..4886b7a 100644 --- a/lib/puppet/provider/vcsrepo/hg.rb +++ b/lib/puppet/provider/vcsrepo/hg.rb @@ -3,8 +3,9 @@ require File.join(File.dirname(__FILE__), '..', 'vcsrepo') Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) do desc "Supports Mercurial repositories" - optional_commands :hg => 'hg' - has_features :reference_tracking + optional_commands :hg => 'hg', + :su => 'su' + has_features :reference_tracking, :ssh_identity, :user def create if !@resource.value(:source) @@ -36,7 +37,7 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d def latest at_path do begin - hg('incoming', '--branch', '.', '--newest-first', '--limit', '1')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + hg_wrapper('incoming', '--branch', '.', '--newest-first', '--limit', '1')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] rescue Puppet::ExecutionFailure # If there are no new changesets, return the current nodeid self.revision @@ -46,11 +47,11 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d def revision at_path do - current = hg('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + current = hg_wrapper('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] desired = @resource.value(:revision) if desired # Return the tag name if it maps to the current nodeid - mapped = hg('tags')[/^#{Regexp.quote(desired)}\s+\d+:(\S+)/m, 1] + mapped = hg_wrapper('tags')[/^#{Regexp.quote(desired)}\s+\d+:(\S+)/m, 1] if current == mapped desired else @@ -65,15 +66,15 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d def revision=(desired) at_path do begin - hg('pull') + hg_wrapper('pull') rescue end begin - hg('merge') + hg_wrapper('merge') rescue Puppet::ExecutionFailure # If there's nothing to merge, just skip end - hg('update', '--clean', '-r', desired) + hg_wrapper('update', '--clean', '-r', desired) end update_owner end @@ -81,7 +82,7 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d private def create_repository(path) - hg('init', path) + hg_wrapper('init', path) end def clone_repository(revision) @@ -91,7 +92,7 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d end args.push(@resource.value(:source), @resource.value(:path)) - hg(*args) + hg_wrapper(*args) end def update_owner @@ -100,4 +101,15 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d end end + def hg_wrapper(*args) + if @resource.value(:identity) + args += ["--ssh", "ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -i #{@resource.value(:identity)}"] + end + if @resource.value(:user) + args.map! { |a| if a =~ /\s/ then "'#{a}'" else a end } # Adds quotes to arguments with whitespaces. + su(@resource.value(:user), '-c', "hg #{args.join(' ')}") + else + hg(*args) + end + end end |