lib/conjur/cli.rb in conjur-cli-4.28.2 vs lib/conjur/cli.rb in conjur-cli-4.29.0
- old
+ new
@@ -47,10 +47,12 @@
end
class CLI
extend GLI::App
+ @current_command = nil
+
class << self
def load_config
Conjur::Config.load
end
@@ -67,12 +69,11 @@
super args
end
def load_plugins
# These used to be plugins but now they are in the core CLI
- plugins = Conjur::Config.plugins - %w(layer pubkeys)
-
+ 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
@@ -90,10 +91,23 @@
load_config
apply_config
load_plugins
commands_from 'conjur/command'
end
+
+ def appliance_version
+ Conjur::API.service_version 'appliance'
+ rescue
+ nil
+ end
+
+ def command_version_compatible? command
+ !command.instance_variable_defined?(:@conjur_min_version) ||
+ (appliance_version &&
+ command.instance_variable_get(:@conjur_min_version) <= appliance_version
+ )
+ end
end
init!
version Conjur::VERSION
@@ -121,16 +135,25 @@
options[:ownerid] = role.roleid
end
true
end
+
+ around do |global,command,options,args,code|
+ @current_command = command
+ code.call
+ @current_command = nil
+ end
on_error do |exception|
require 'rest-client'
require 'patches/conjur/error'
-
+
run_default_handler = true
- if exception.is_a?(RestClient::Exception) && exception.response
+ if @current_command != nil && !command_version_compatible?(@current_command)
+ $stderr.puts "error: this command is not supported by the current Conjur server version"
+ run_default_handler = false
+ elsif exception.is_a?(RestClient::Exception) && exception.response
err = Conjur::Error.create exception.response.body
if err
$stderr.puts "error: " + err.message
run_default_handler = false # suppress default error message
else