From c8ac78614dea3b2409f88cf7fb7901cbd78ce23d Mon Sep 17 00:00:00 2001 From: Arnoud de Jonge Date: Mon, 15 Apr 2013 17:56:44 +0200 Subject: 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. --- lib/puppet/provider/vcsrepo/hg.rb | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'lib/puppet/provider/vcsrepo/hg.rb') 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 -- cgit v1.2.3