Class: Arver::InfoAction

Inherits:
Action
  • Object
show all
Defined in:
lib/arver/info_action.rb

Instance Attribute Summary

Attributes inherited from Action

#generator, #key, #keystore, #slot_of_target_user, #target_list, #target_user

Instance Method Summary collapse

Methods inherited from Action

#load_key, #needs_target_user?, #new_key_generator, #on_user, #open_keystore, #post_action, #post_host, #post_partition, #pre_action, #pre_partition, #run_on, #verify?, #verify_key_on_target

Constructor Details

#initialize(target_list) ⇒ InfoAction

Returns a new instance of InfoAction.



3
4
5
6
7
# File 'lib/arver/info_action.rb', line 3

def initialize( target_list )
  super( target_list )
  self.open_keystore
  Arver::Log.info("Warning: existence of a keyslot is not a guarantee that the user can access it")
end

Instance Method Details

#execute_partition(partition) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/arver/info_action.rb', line 13

def execute_partition(partition)
  cmd = Arver::LuksWrapper.dump(partition)
  cmd.execute
  info = cmd.output
  info =~ /Version:[\s]+(\d)/
  version = $1
  slots = []

  head = " #{sprintf("%0-10s",partition.name[0...10])} :"+
         " #{sprintf("%0-30s",partition.device_path[0...30])}"

  if version != '1' && version != '2'
    Arver::Log.info("#{head} : Unsupported luks version")
    return
  end

  if version == '1'
    info.each_line do |line|
      if line =~ /Key Slot (\d): ENABLED/
        slots << Integer($1)
      end
    end
  else
    keyslots = []
    start = false
    info.each_line do |line|
      if line =~ /Keyslots:/
        start = true
        next
      end
      next unless start
      break unless line =~ /^\s/
      if line =~ /[\s]+(\d): luks2/
        slots << Integer($1)
      end
    end
  end
  slots = slots.map{|s| "#{Config.instance.user_at(s)}(#{s})"}.join(",")
  Arver::Log.info("#{head} : #{slots}")
end

#pre_host(host) ⇒ Object



9
10
11
# File 'lib/arver/info_action.rb', line 9

def pre_host( host )
  Arver::Log.info( "\n-- "+host.path+":" )
end