Class: ICSP::Commands::Certificate::Install

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/commands/certificate/install.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#arguments, #config, #options, #prompt

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from ICSP::Commands::BaseCommand

Instance Method Details

#available_storesObject



42
43
44
# File 'lib/commands/certificate/install.rb', line 42

def available_stores
  %w[uMy root ca]
end

#certmgrObject



7
8
9
# File 'lib/commands/certificate/install.rb', line 7

def certmgr
  @certmgr ||= @config.certmgr
end

#executeObject



11
12
13
14
15
16
17
18
# File 'lib/commands/certificate/install.rb', line 11

def execute
  unless options[:file]
    install_from_container
    return
  end

  install_from_file
end

#install_from_containerObject



20
21
22
23
24
25
# File 'lib/commands/certificate/install.rb', line 20

def install_from_container
  result = ::ICSP::Shell.new("#{certmgr} -inst -cont '#{selected_container}'", convert_to_utf8: false).execute
  exit(result.exit_code) unless result.ok

  puts result
end

#install_from_fileObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/commands/certificate/install.rb', line 27

def install_from_file
  store = prompt.select('Select store:', available_stores)
  not_crl = prompt.no?('Is it CRL?')
  result = ::ICSP::Shell.new(
    "#{certmgr} -inst -file '#{options[:file]}' -store #{store} #{not_crl ? '' : '-crl'}", convert_to_utf8: false
  ).execute
  exit(result.exit_code) unless result.ok

  puts result
end

#selected_containerObject



38
39
40
# File 'lib/commands/certificate/install.rb', line 38

def selected_container
  ::ICSP::Commands::Container::List.new(config: config, options: options, arguments: arguments).select
end