class Nucleon::Action::Node::Authorize

Public Class Methods

describe() click to toggle source
Calls superclass method
   # File lib/nucleon/action/node/authorize.rb
10 def self.describe
11   super(:node, :authorize, 555)
12 end

Public Instance Methods

arguments() click to toggle source
   # File lib/nucleon/action/node/authorize.rb
29 def arguments
30   [ :public_key, :ssh_user ]
31 end
configure() click to toggle source
Calls superclass method
   # File lib/nucleon/action/node/authorize.rb
17 def configure
18   super do
19     codes :key_store_failure
20 
21     register_bool :reset, false
22     register_str :public_key, nil
23     register_str :ssh_user, ''
24   end
25 end
execute() click to toggle source
Calls superclass method
   # File lib/nucleon/action/node/authorize.rb
36 def execute
37   super do |node|
38     info('start', { :public_key => settings[:public_key] })
39 
40     ensure_node(node) do
41       ssh_user        = settings[:ssh_user].empty? ? nil : settings[:ssh_user]
42       ssh_path        = Util::SSH.key_path(ssh_user)
43       authorized_keys = File.join(ssh_path, 'authorized_keys')
44       public_key      = settings[:public_key].strip
45       key_found       = false
46 
47       File.delete(authorized_keys) if settings[:reset]
48 
49       if File.exists?(authorized_keys)
50         Util::Disk.read(authorized_keys).split("\n").each do |line|
51           if line.strip.include?(public_key)
52             key_found = true
53             break
54           end
55         end
56       end
57       unless key_found
58         unless Util::Disk.write(authorized_keys, "#{public_key}\n", { :mode => 'a' })
59           myself.status = code.key_store_failure
60         end
61       end
62     end
63   end
64 end