Class: Nucleon::Action::Node::Revoke

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.describeObject


Info



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

def self.describe
  super(:node, :revoke, 550)
end

Instance Method Details

#argumentsObject




27
28
29
# File 'lib/nucleon/action/node/revoke.rb', line 27

def arguments
  [ :public_key ]
end

#configureObject


Settings



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

def configure
  super do
    codes :key_remove_failure

    register :public_key, :str, nil
  end
end

#executeObject


Operations



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
60
# File 'lib/nucleon/action/node/revoke.rb', line 34

def execute
  super do |node|
    info('corl.actions.revoke.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
      output_keys     = []

      if File.exists?(authorized_keys)
        Util::Disk.read(authorized_keys).split("\n").each do |line|
          if line.strip.include?(public_key)
            key_found = true
          else
            output_keys << line
          end
        end
      end
      unless key_found
        unless Util::Disk.write(authorized_keys, output_keys.join("\n"))
          myself.status = code.key_revoke_failure
        end
      end
    end
  end
end