Class: Scro::Auth::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/scro/auth/key.rb

Instance Method Summary collapse

Constructor Details

#initialize(keygen = 'ssh-keygen') ⇒ Key

Returns a new instance of Key.



4
5
6
7
8
9
# File 'lib/scro/auth/key.rb', line 4

def initialize(keygen = 'ssh-keygen')
  @keygen   =  keygen
  @filename = Digest::SHA1.hexdigest(Time.now.to_f.to_s)

  generate
end

Instance Method Details

#ensure_ssh_keygen_presentObject

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/scro/auth/key.rb', line 16

def ensure_ssh_keygen_present
  `which #{@keygen}`
  raise ArgumentError, "Unable to find the ssh-keygen executable" unless $?.success?
end

#generateObject



11
12
13
14
# File 'lib/scro/auth/key.rb', line 11

def generate
  ensure_ssh_keygen_present
  `#{@keygen} -f #{private_key} -P '' > #{stdout} 2>#{stderr}`
end

#private_keyObject



21
22
23
# File 'lib/scro/auth/key.rb', line 21

def private_key
  "#{Dir.tmpdir}/#{@filename}"
end

#public_keyObject



25
26
27
# File 'lib/scro/auth/key.rb', line 25

def public_key
  "#{private_key}.pub"
end

#stderrObject



29
30
31
# File 'lib/scro/auth/key.rb', line 29

def stderr
  stdout('error')
end

#stdout(suffix = 'out') ⇒ Object



33
34
35
# File 'lib/scro/auth/key.rb', line 33

def stdout(suffix = 'out')
  "#{private_key}.#{suffix}.log"
end