From 00852d1a66a8cb4caf708801747b0ab137d71012 Mon Sep 17 00:00:00 2001 From: Xavier Date: Thu, 30 May 2019 09:39:36 +0200 Subject: [PATCH] Add dump() command in cli Closes: #1770 --- lemonldap-ng-common/scripts/lemonldap-ng-cli | 2 +- lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lemonldap-ng-common/scripts/lemonldap-ng-cli b/lemonldap-ng-common/scripts/lemonldap-ng-cli index 834c773c9..f4f43de8d 100755 --- a/lemonldap-ng-common/scripts/lemonldap-ng-cli +++ b/lemonldap-ng-common/scripts/lemonldap-ng-cli @@ -22,7 +22,7 @@ for ( my $i = 0 ; $i < @ARGV ; $i++ ) { $action ||= "help"; -if ( $action =~ /^(?:[gs]et|(?:add|del)Key)$/ ) { +if ( $action =~ /^(?:[gs]et|(?:add|del)Key|dump)$/ ) { eval { require Lemonldap::NG::Manager::Cli; }; die "Manager libraries not available, aborting ($@)" if ($@); Lemonldap::NG::Manager::Cli->run(@ARGV); diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm index 73673b43a..a9f847753 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm @@ -194,6 +194,13 @@ sub lastCfg { return $self->jsonResponse('/confs/latest')->{cfgNum}; } +sub dump { + my ($self) = @_; + my $conf = $self->jsonResponse( '/confs/latest', 'full=1' ); + my $json = JSON->new->indent->canonical; + print $json->encode($conf); +} + sub _getKey { my ( $self, $key ) = @_; my $sep = $self->sep; @@ -304,7 +311,7 @@ sub run { } $self->cfgNum( $self->lastCfg ) unless ( $self->cfgNum ); my $action = shift; - unless ( $action =~ /^(?:get|set|addKey|delKey)$/ ) { + unless ( $action =~ /^(?:get|set|addKey|delKey|dump)$/ ) { die "unknown action $action. Only get, set, addKey or delKey are accepted"; }