class Nucleon::Action::Node::Keypair

Public Class Methods

describe() click to toggle source
# File lib/nucleon/action/node/keypair.rb, line 12
def self.describe
  super(:node, :keypair, 545)
end

Public Instance Methods

configure() click to toggle source
# File lib/nucleon/action/node/keypair.rb, line 19
def configure
  super do
    codes :key_failure
    
    register :json, :bool, true
    register :both, :bool, false
    keypair_config
  end
end
execute() click to toggle source
# File lib/nucleon/action/node/keypair.rb, line 38
def execute
  super do |node, network|
    if keys = keypair
      ui.info("\n", { :prefix => false })
      ui_group(Util::Console.cyan("#{keys.type.upcase} SSH keypair")) do |ui|          
        render_json = lambda do 
          private_key = Util::Console.blue(Util::Data.to_json(keys.encrypted_key, true))
          ssh_key     = keys.ssh_key.gsub(/^ssh\-[a-z]+\s+/, '')           
          ssh_key     = Util::Console.green(Util::Data.to_json(ssh_key, true))
          
          ui.info("-----------------------------------------------------")
          ui.info(yellow("SSH JSON string"))
          ui.info("SSH private key:\n#{private_key}")
          ui.info("SSH public key:\n#{ssh_key}")
          ui.info("\n", { :prefix => false })  
        end
        
        render_file = lambda do
          private_key = Util::Console.blue(keys.encrypted_key)
          ssh_key     = Util::Console.green(keys.ssh_key)
          
          ui.info("-----------------------------------------------------")
          ui.info(yellow("SSH file rendering"))
          ui.info("SSH private key:\n#{private_key}")
          ui.info("SSH public key:\n#{ssh_key}")
          ui.info("\n", { :prefix => false })  
        end
      
        if settings[:both]
          render_json.call
          render_file.call  
        else
          if settings[:json]
            render_json.call
          else
            render_file.call      
          end
        end
      end          
    else
      myself.status = code.key_failure  
    end
  end
end
ignore() click to toggle source
# File lib/nucleon/action/node/keypair.rb, line 31
def ignore
  node_ignore
end