Class: OsCtld::Commands::Send::KeyGen

Inherits:
Logged
  • Object
show all
Includes:
OsCtl::Lib::Utils::Log, OsCtl::Lib::Utils::System
Defined in:
lib/osctld/commands/send/key_gen.rb

Instance Attribute Summary

Attributes inherited from Base

#client, #client_handler, #id, #opts

Instance Method Summary collapse

Methods inherited from Logged

#base_execute

Methods inherited from Base

#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!

Constructor Details

This class inherits a constructor from OsCtld::Commands::Base

Instance Method Details

#execute(pool) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/osctld/commands/send/key_gen.rb', line 22

def execute(pool)
  privkey = pool.send_receive_key_chain.private_key_path
  pubkey = pool.send_receive_key_chain.public_key_path

  [privkey, pubkey].each do |v|
    FileUtils.rm_f(v)
  end

  type = opts[:type] || 'rsa'

  bits = if opts[:bits]
           opts[:bits]

         elsif type == 'ecdsa'
           521

         else
           4096
         end

  args = [
    'ssh-keygen',
    '-q',
    '-t', type,
    '-b', bits.to_s,
    '-N', "''",
    '-C', "'#{pool.name}@#{Socket.gethostname}'",
    '-f', privkey
  ]

  syscmd(args.join(' '))

  [privkey, pubkey].each do |v|
    File.chmod(0o400, v)
  end

  ok
end

#findObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/osctld/commands/send/key_gen.rb', line 11

def find
  pool = if opts[:pool]
           DB::Pools.find(opts[:pool])

         else
           DB::Pools.get_or_default(nil)
         end

  pool || error!('pool not found')
end