Sha256: 88f065d0ce9ad1d1073438bfcbfe4897f0e8f8db15f48caa0bb63fbba0007633

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

module CORL
module Action
class Authorize < Plugin::CloudAction
 
  #-----------------------------------------------------------------------------
  # Settings
  
  def configure
    super do
      codes :key_store_failure
      
      register :public_key, :str, nil
    end
  end
  
  #---
  
  def arguments
    [ :public_key ]
  end

  #-----------------------------------------------------------------------------
  # Operations
   
  def execute
    super do |node, network|
      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
        
        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
end
end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
corl-0.4.26 lib/CORL/action/authorize.rb
corl-0.4.25 lib/CORL/action/authorize.rb
corl-0.4.24 lib/CORL/action/authorize.rb
corl-0.4.23 lib/CORL/action/authorize.rb
corl-0.4.22 lib/CORL/action/authorize.rb
corl-0.4.21 lib/CORL/action/authorize.rb
corl-0.4.20 lib/CORL/action/authorize.rb
corl-0.4.19 lib/CORL/action/authorize.rb
corl-0.4.18 lib/CORL/action/authorize.rb
corl-0.4.17 lib/CORL/action/authorize.rb
corl-0.4.16 lib/CORL/action/authorize.rb