diff options
author | Aaron Stone <aaron@serendipity.cx> | 2013-07-16 10:39:01 -0700 |
---|---|---|
committer | Aaron Stone <aaron@serendipity.cx> | 2013-07-16 10:39:01 -0700 |
commit | 827cfaa7715c03589cbfda0fc7fe79239859b216 (patch) | |
tree | 71b01c117f7db4a62e122c2ce40487395ac08862 /lib/puppet/provider/vcsrepo/hg.rb | |
parent | 054d16421c782dd76a6990856bb78797abe36750 (diff) | |
parent | c8ac78614dea3b2409f88cf7fb7901cbd78ce23d (diff) | |
download | puppet-vcsrepo-827cfaa7715c03589cbfda0fc7fe79239859b216.tar.gz puppet-vcsrepo-827cfaa7715c03589cbfda0fc7fe79239859b216.tar.bz2 |
Merge pull request #77 from arnoudj/hg_identity
Add user and ssh identity to the Mercurial provider.
Diffstat (limited to 'lib/puppet/provider/vcsrepo/hg.rb')
-rw-r--r-- | lib/puppet/provider/vcsrepo/hg.rb | 32 |
1 files changed, 22 insertions, 10 deletions
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 |