Class: GitSSHWrapper
- Inherits:
-
Object
show all
- Defined in:
- lib/git-ssh-wrapper.rb
Defined Under Namespace
Classes: PrivateKeyRequired
Constant Summary
collapse
- SAFE_MODE =
0600
- EXEC_MODE =
0700
- SSH_CONFIG =
<<-CONFIG
Host *
PasswordAuthentication no
StrictHostKeyChecking no
RSAAuthentication yes
ConnectTimeout 5
IdentityFile %s
CheckHostIP no
CONFIG
- SCRIPT =
<<-SCRIPT
#!/bin/bash
unset SSH_AUTH_SOCK
ssh -F %s $*
SCRIPT
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GitSSHWrapper.
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/git-ssh-wrapper.rb', line 49
def initialize(options)
if options[:private_key_path].to_s.empty? && options[:private_key].to_s.empty?
raise PrivateKeyRequired
end
@tempfiles = []
@key_path = options[:private_key_path] || tempfile(options[:private_key])
@ssh_config = ssh_config(@key_path)
@path = script(@ssh_config)
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
47
48
49
|
# File 'lib/git-ssh-wrapper.rb', line 47
def path
@path
end
|
Class Method Details
.tempfile(content, mode = SAFE_MODE) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/git-ssh-wrapper.rb', line 31
def self.tempfile(content, mode=SAFE_MODE)
file = Tempfile.new("git-ssh-wrapper")
file << content
file.chmod(mode)
file.flush
file.close
file
end
|
.with_wrapper(options) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/git-ssh-wrapper.rb', line 40
def self.with_wrapper(options)
wrapper = new(options)
yield wrapper
ensure
wrapper.unlink
end
|
Instance Method Details
#git_ssh ⇒ Object
64
65
66
|
# File 'lib/git-ssh-wrapper.rb', line 64
def git_ssh
"GIT_SSH='#{path}'"
end
|
#pathname ⇒ Object
60
61
62
|
# File 'lib/git-ssh-wrapper.rb', line 60
def pathname
Pathname.new(path)
end
|
#set_env ⇒ Object
68
69
70
|
# File 'lib/git-ssh-wrapper.rb', line 68
def set_env
ENV['GIT_SSH'] = path
end
|
#unlink ⇒ Object
72
73
74
|
# File 'lib/git-ssh-wrapper.rb', line 72
def unlink
@tempfiles.each { |file| file.unlink }.clear
end
|