@@ -666,26 +666,60 @@ def git_with_identity(*args)
666
666
end
667
667
668
668
if @resource . value ( :identity )
669
- ssh_opts = {
670
- IgnoreUnknown : 'IdentityAgent' ,
671
- IdentitiesOnly : 'yes' ,
672
- IdentityAgent : 'none' ,
673
- PasswordAuthentication : 'no' ,
674
- KbdInteractiveAuthentication : 'no' ,
675
- }
676
- ssh_command = "ssh -i #{ @resource . value ( :identity ) } "
677
- ssh_command += ssh_opts . map { |option , value | "-o \" #{ option } #{ value } \" " } . join ' '
678
-
679
- env_git_ssh_command_save = ENV [ 'GIT_SSH_COMMAND' ]
680
- ENV [ 'GIT_SSH_COMMAND' ] = ssh_command
669
+ git_ver = git_version
670
+ if Gem ::Version . new ( git_ver ) >= Gem ::Version . new ( '2.3.0' )
671
+ # GIT_SSH_COMMAND was introduced in version 2.3.0.
672
+ git_ssh_with_identity_ssh_command ( *args )
673
+ else
674
+ git_ssh_with_identity_ssh_file ( *args )
675
+ end
676
+ else
677
+ exec_git ( *args )
678
+ end
679
+ end
680
+
681
+ # @!visibility private
682
+ def git_ssh_with_identity_ssh_command ( *args )
683
+ ssh_opts = {
684
+ IgnoreUnknown : 'IdentityAgent' ,
685
+ IdentitiesOnly : 'yes' ,
686
+ IdentityAgent : 'none' ,
687
+ PasswordAuthentication : 'no' ,
688
+ KbdInteractiveAuthentication : 'no' ,
689
+ }
690
+ ssh_command = "ssh -i #{ @resource . value ( :identity ) } "
691
+ ssh_command += ssh_opts . map { |option , value | "-o \" #{ option } #{ value } \" " } . join ' '
692
+
693
+ env_git_ssh_command_save = ENV [ 'GIT_SSH_COMMAND' ]
694
+ ENV [ 'GIT_SSH_COMMAND' ] = ssh_command
695
+
696
+ ret = exec_git ( *args )
697
+
698
+ ENV [ 'GIT_SSH_COMMAND' ] = env_git_ssh_command_save
699
+
700
+ ret
701
+ end
702
+
703
+ # @!visiblity private
704
+ def git_ssh_with_identity_ssh_file ( *args )
705
+ Tempfile . open ( 'git-helper' , Puppet [ :statedir ] ) do |f |
706
+ f . puts '#!/bin/sh'
707
+ f . puts 'SSH_AUTH_SOCKET='
708
+ f . puts 'export SSH_AUTH_SOCKET'
709
+ f . puts 'exec ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no ' \
710
+ "-oChallengeResponseAuthentication=no -oConnectTimeout=120 -i #{ @resource . value ( :identity ) } $*"
711
+ f . close
712
+
713
+ FileUtils . chmod ( 0o755 , f . path )
714
+
715
+ env_git_ssh_save = ENV [ 'GIT_SSH' ]
716
+ ENV [ 'GIT_SSH' ] = f . path
681
717
682
718
ret = exec_git ( *args )
683
719
684
- ENV [ 'GIT_SSH_COMMAND ' ] = env_git_ssh_command_save
720
+ ENV [ 'GIT_SSH ' ] = env_git_ssh_save
685
721
686
722
ret
687
- else
688
- exec_git ( *args )
689
723
end
690
724
end
691
725
0 commit comments