Class: Conjur::CLI

Inherits:
Object
  • Object
show all
Extended by:
GLI::App
Defined in:
lib/conjur/cli.rb

Defined Under Namespace

Classes: Complete

Class Method Summary collapse

Class Method Details

.appliance_versionObject



97
98
99
100
101
# File 'lib/conjur/cli.rb', line 97

def appliance_version
  Conjur::API.service_version 'appliance'
rescue
  nil
end

.apply_configObject



59
60
61
# File 'lib/conjur/cli.rb', line 59

def apply_config
  Conjur::Config.apply
end

.command_version_compatible?(command) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
107
108
# File 'lib/conjur/cli.rb', line 103

def command_version_compatible? command
  !command.instance_variable_defined?(:@conjur_min_version) ||
    (appliance_version &&
     command.instance_variable_get(:@conjur_min_version) <= appliance_version
    )
end

.init!Object

This makes our generate-commands script a little bit cleaner. We can call this from that script to ensure that commands for all plugins are loaded.



89
90
91
92
93
94
95
# File 'lib/conjur/cli.rb', line 89

def init!
  subcommand_option_handling :normal
  load_config
  apply_config
  load_plugins
  commands_from 'conjur/command'
end

.load_configObject



55
56
57
# File 'lib/conjur/cli.rb', line 55

def load_config
  Conjur::Config.load
end

.load_pluginsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/conjur/cli.rb', line 72

def load_plugins
  # These used to be plugins but now they are in the core CLI
  plugins = Conjur::Config.plugins - %w(audit-send host-factory layer pubkeys)
  plugins.each do |plugin|
    begin
      filename = "conjur-asset-#{plugin}"
      require filename
    rescue LoadError => err
      warn "WARNING: #{err.message}\n" \
        "Could not load plugin '#{plugin}' specified in your config file.\n"\
        "Make sure you have the #{filename} gem installed."
    end
  end
end

.run(args) ⇒ Object

Horible hack! We want to support legacy commands like host:list, but we don’t want to do too much effort, and GLIs support for aliasing doesn’t work out so well with subcommands.



67
68
69
70
# File 'lib/conjur/cli.rb', line 67

def run args
  args = args.shift.split(':') + args unless args.empty?
  super args
end