Class: Evrone::CI::CSM::Git::GitSSH

Inherits:
Object
  • Object
show all
Includes:
Evrone::CI::Common::Helper::Shell
Defined in:
lib/evrone/ci/csm/git/git_ssh.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deploy_key) ⇒ GitSSH

Returns a new instance of GitSSH.



13
14
15
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 13

def initialize(deploy_key)
  @deploy_key = deploy_key
end

Instance Attribute Details

#deploy_keyObject (readonly)

Returns the value of attribute deploy_key.



11
12
13
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 11

def deploy_key
  @deploy_key
end

Instance Method Details

#createObject



25
26
27
28
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 25

def create
  key_location
  location
end

#destroyObject



30
31
32
33
34
35
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 30

def destroy
  key_location.unlink if key_location
  location.unlink
  @location     = nil
  @key_location = nil
end

#key_locationObject



41
42
43
44
45
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 41

def key_location
  if deploy_key
    @key_location ||= write_tmp_file 'key', deploy_key, 0600
  end
end

#locationObject



37
38
39
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 37

def location
  @location ||= write_tmp_file 'git', template, 0700
end

#openObject



17
18
19
20
21
22
23
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 17

def open
  begin
    yield create
  ensure
    destroy
  end
end

#templateObject



47
48
49
50
51
52
# File 'lib/evrone/ci/csm/git/git_ssh.rb', line 47

def template
  key = key_location ? "-i #{key_location.path}" : ""
  out = ['#!/bin/sh']
  out << "exec /usr/bin/ssh -A -o StrictHostKeyChecking=no #{key} $@"
  out.join "\n"
end