Module: CORL::Mixin::Action::Keypair

Defined in:
lib/core/mixin/action/keypair.rb

Instance Method Summary collapse

Instance Method Details

#keypair(reset = false) ⇒ Object




81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/core/mixin/action/keypair.rb', line 81

def keypair(reset = false)
  if reset || ! @keypair
    if settings[:private_key]
      key_options = { :private_key => private_key } 
    else
      key_options = {}
      if settings[:require_password]
        key_password = password('SSH')
        if key_password
          key_options[:passphrase] = key_password
        else
          warn('no_password')
          return nil
        end
      end
    end
    myself.keypair = key_options
  end
  @keypair
end

#keypair=(options) ⇒ Object




69
70
71
72
73
74
75
76
77
# File 'lib/core/mixin/action/keypair.rb', line 69

def keypair=options
  config = Config.ensure(options).defaults({
    :type    => settings[:key_type].to_s.upcase,
    :bits    => settings[:key_bits],
    :comment => settings[:key_comment]
  })
  @keypair = Util::SSH.generate(config)
  settings.import({ :keypair => @keypair })
end

#keypair_cleanObject




58
59
60
# File 'lib/core/mixin/action/keypair.rb', line 58

def keypair_clean
  remove(keypair_ignore)  
end

#keypair_configObject


Options



10
11
12
13
14
15
16
17
18
19
20
21
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
# File 'lib/core/mixin/action/keypair.rb', line 10

def keypair_config
  register_str :private_key, nil, 'corl.core.mixin.action.keypair.options.private_key' do |value|
    success = true
    if value
      file = File.expand_path(value)
      if File.exists?(file)
        unless Util::SSH.generate({ :private_key => file })
          warn('corl.core.mixin.action.keypair.errors.private_key_parse_error', { :value => file })
          success = false
        end
      else
        warn('corl.core.mixin.action.keypair.errors.private_key_not_found', { :value => file })
        success = false  
      end
    end
    success  
  end
  
  register_bool :require_password, false, 'corl.core.mixin.action.keypair.options.require_password'
  
  register_str :key_type, 'RSA', 'corl.core.mixin.action.keypair.options.key_type' do |value|
    key_type_choices = [ 'RSA', 'DSA' ]
    unless key_type_choices.include?(value.to_s.upcase)
      warn('corl.core.mixin.action.keypair.errors.key_type', { :value => value, :choices => key_type_choices })
      next false    
    end
    true
  end
  register_int :key_bits, 2048, 'corl.core.mixin.action.keypair.options.key_bits' do |value|
    unless value >= 2048
      warn('corl.core.mixin.action.keypair.errors.key_bits', { :value => value, :required => 2048 })
      next false 
    end
    true     
  end
  register_str :key_comment, '', 'corl.core.mixin.action.keypair.options.key_comment'
  
  config_subset(keypair_ignore)
end

#keypair_ignoreObject




52
53
54
# File 'lib/core/mixin/action/keypair.rb', line 52

def keypair_ignore
  [ :require_password, :key_type, :key_bits, :key_comment ]
end