Class: Nucleon::Action::Node::Authorize

Inherits:
Object
  • Object
show all
Defined in:
lib/nucleon/action/node/authorize.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.describeObject


Info



10
11
12
# File 'lib/nucleon/action/node/authorize.rb', line 10

def self.describe
  super(:node, :authorize, 555)
end

Instance Method Details

#argumentsObject




28
29
30
# File 'lib/nucleon/action/node/authorize.rb', line 28

def arguments
  [ :public_key ]
end

#configureObject


Settings



17
18
19
20
21
22
23
24
# File 'lib/nucleon/action/node/authorize.rb', line 17

def configure
  super do
    codes :key_store_failure
    
    register :reset, :bool, false
    register :public_key, :str, nil
  end
end

#executeObject


Operations



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
60
61
62
# File 'lib/nucleon/action/node/authorize.rb', line 35

def execute
  super do |node|
    info('corl.actions.authorize.start')
    
    ensure_node(node) do
      ssh_path        = Util::SSH.key_path
      authorized_keys = File.join(ssh_path, 'authorized_keys')        
      public_key      = settings[:public_key].strip
      key_found       = false
      
      File.delete(authorized_keys) if settings[:reset]
              
      if File.exists?(authorized_keys)
        Util::Disk.read(authorized_keys).split("\n").each do |line|
          if line.strip.include?(public_key)
            key_found = true
            break  
          end            
        end
      end
      unless key_found
        unless Util::Disk.write(authorized_keys, "#{public_key}\n", { :mode => 'a' })
          myself.status = code.key_store_failure
        end
      end
    end
  end
end