mirror of
https://github.com/ovh/the-bastion.git
synced 2025-01-01 13:01:53 +08:00
fix: interactive: use load_configuration_file() to handle comments in JSON files
This commit is contained in:
parent
17a38ff960
commit
4ad41712fd
2 changed files with 7 additions and 8 deletions
|
@ -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");
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
Loading…
Reference in a new issue