Sha256: 83bfe27e3572f409b5512214c02170ddfe9ba7fd56ff4d207de9eb505065aa14

Contents?: true

Size: 1.32 KB

Versions: 14

Compression:

Stored size: 1.32 KB

Contents

module CORL
module Action
class Authorize < Plugin::CloudAction
 
  #-----------------------------------------------------------------------------
  # Settings
  
  def configure
    super do
      codes :network_failure,
            :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')
      
      if network && node
        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
      else
        myself.status = code.network_failure
      end
    end
  end
end
end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
corl-0.4.15 lib/CORL/action/authorize.rb
corl-0.4.14 lib/CORL/action/authorize.rb
corl-0.4.13 lib/CORL/action/authorize.rb
corl-0.4.12 lib/CORL/action/authorize.rb
corl-0.4.11 lib/CORL/action/authorize.rb
corl-0.4.10 lib/CORL/action/authorize.rb
corl-0.4.9 lib/CORL/action/authorize.rb
corl-0.4.8 lib/CORL/action/authorize.rb
corl-0.4.7 lib/CORL/action/authorize.rb
corl-0.4.6 lib/CORL/action/authorize.rb
corl-0.4.5 lib/CORL/action/authorize.rb
corl-0.4.4 lib/CORL/action/authorize.rb
corl-0.4.3 lib/CORL/action/authorize.rb
corl-0.4.2 lib/CORL/action/authorize.rb