diff --git a/lib/perl/OVH/Bastion/configuration.inc b/lib/perl/OVH/Bastion/configuration.inc index d8ace0d..ac44c9a 100644 --- a/lib/perl/OVH/Bastion/configuration.inc +++ b/lib/perl/OVH/Bastion/configuration.inc @@ -782,7 +782,7 @@ sub json_load { my %params = @_; # Check params - my $file = $params{'file'}; + my $file = $params{'file'}; if (!$file) { return R('KO_MISSING_PARAMETER', msg => "Missing 'file' parameter"); diff --git a/lib/perl/OVH/Bastion/interactive.inc b/lib/perl/OVH/Bastion/interactive.inc index 062a5a9..8ff1e83 100644 --- a/lib/perl/OVH/Bastion/interactive.inc +++ b/lib/perl/OVH/Bastion/interactive.inc @@ -3,7 +3,6 @@ package OVH::Bastion; use common::sense; use Term::ReadLine; -use JSON; use POSIX (); # autocompletion rules @@ -60,16 +59,16 @@ EOM push @cmdlist, $plugin; # also load autocompletion rules for this plugin - if (open(my $jsonFd, '<', $pluginList->{$plugin}->{'dir'} . '/' . $plugin . '.json')) { - local $/ = undef; - my $jsonPayload = <$jsonFd>; - close($jsonFd); - my $jsonData; - eval { $jsonData = decode_json($jsonPayload); }; + $fnret = OVH::Bastion::load_configuration_file(secure => 1, file => $pluginList->{$plugin}->{'dir'} . '/' . $plugin . '.json'); + if ($fnret) { + my $jsonData = $fnret->value; if (ref $jsonData eq 'HASH' && ref $jsonData->{'interactive'} eq 'ARRAY') { push @rules, @{$jsonData->{'interactive'}}; } } + elsif ($fnret->err ne 'KO_NO_SUCH_FILE') { + warn_syslog("Interactive mode: error reading configuration for plugin '$plugin': " . $fnret->msg); + } } print scalar(@cmdlist) . " commands and " . (@rules / 2) . " autocompletion rules loaded.\n\n";