Class: SSHKit::CommandSudoSshForward
- Inherits:
-
Command
- Object
- Command
- SSHKit::CommandSudoSshForward
- Defined in:
- lib/sshkit/command_sudo_ssh_forward.rb
Instance Method Summary collapse
- #environment_hash ⇒ Object
- #ssh_agent(&block) ⇒ Object
- #to_command ⇒ Object
- #user(&block) ⇒ Object
- #with(&block) ⇒ Object
Instance Method Details
#environment_hash ⇒ Object
25 26 27 |
# File 'lib/sshkit/command_sudo_ssh_forward.rb', line 25 def environment_hash default_env.merge() end |
#ssh_agent(&block) ⇒ Object
29 30 31 32 |
# File 'lib/sshkit/command_sudo_ssh_forward.rb', line 29 def ssh_agent(&block) return yield unless ssh_forwarding_required? "setfacl -m #{[:user]}:x $(dirname $SSH_AUTH_SOCK) && setfacl -m #{[:user]}:rw $SSH_AUTH_SOCK && %s" % yield end |
#to_command ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sshkit/command_sudo_ssh_forward.rb', line 5 def to_command return command.to_s unless should_map? within do ssh_agent do umask do with do user do in_background do group do to_s end end end end end end end end |
#user(&block) ⇒ Object
34 35 36 37 38 |
# File 'lib/sshkit/command_sudo_ssh_forward.rb', line 34 def user(&block) return yield unless [:user] shell = [:shell] || 'sh' "sudo -u #{[:user]} #{environment_string + " " unless environment_string.empty?}-- #{shell} -c '%s'" % %Q{#{yield}} end |
#with(&block) ⇒ Object
40 41 42 43 |
# File 'lib/sshkit/command_sudo_ssh_forward.rb', line 40 def with(&block) return yield if environment_hash.empty? || sudo_command? "( #{environment_string} %s )" % yield end |