Class: GitSafe::SshTempfile

Inherits:
Object
  • Object
show all
Defined in:
lib/git-safe/ssh_tempfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key_string) ⇒ SshTempfile

Returns a new instance of SshTempfile.



5
6
7
8
# File 'lib/git-safe/ssh_tempfile.rb', line 5

def initialize(private_key_string)
  @private_key_string    = private_key_string
  @private_key_temp_file = create_private_key_tmp_file
end

Instance Attribute Details

#private_key_stringObject (readonly)

Returns the value of attribute private_key_string.



3
4
5
# File 'lib/git-safe/ssh_tempfile.rb', line 3

def private_key_string
  @private_key_string
end

#private_key_temp_fileObject (readonly)

Returns the value of attribute private_key_temp_file.



3
4
5
# File 'lib/git-safe/ssh_tempfile.rb', line 3

def private_key_temp_file
  @private_key_temp_file
end

Instance Method Details

#create_private_key_tmp_fileObject



14
15
16
17
18
19
20
21
22
# File 'lib/git-safe/ssh_tempfile.rb', line 14

def create_private_key_tmp_file
  tf = Tempfile.new('git-ssh-wrapper')
  tf << private_key_string
  tf.puts('') # required for openssh keys
  tf.chmod(0600)
  tf.flush
  tf.close
  tf
end


10
11
12
# File 'lib/git-safe/ssh_tempfile.rb', line 10

def safe_unlink_private_key_tmp_file
  private_key_temp_file&.unlink
end