First Cli : get base keys only for now
This commit is contained in:
parent
2b35cb6e04
commit
2c512dbcfa
75
lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm
Normal file
75
lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
package Lemonldap::NG::Manager::Cli;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Mouse;
|
||||||
|
use 5.14.0;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
extends('Lemonldap::NG::Manager::Cli::Lib');
|
||||||
|
|
||||||
|
has cfgNum => (
|
||||||
|
is => 'rw',
|
||||||
|
isa => 'Int',
|
||||||
|
trigger => sub {
|
||||||
|
$_[0]->{req} =
|
||||||
|
Lemonldap::NG::Manager::Cli::Request->new(
|
||||||
|
cfgNum => $_[0]->{cfgNum} );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
has req => ( is => 'ro' );
|
||||||
|
|
||||||
|
sub get {
|
||||||
|
my ( $self, @values ) = @_;
|
||||||
|
$self->cfgNum( $self->lastCfg ) unless ( $self->cfgNum );
|
||||||
|
die 'get requires at least one key' unless (@values);
|
||||||
|
L: foreach my $key (@values) {
|
||||||
|
unless ( $key =~ /^\w+(?:\/[\w\.]+)*$/ ) {
|
||||||
|
warn "Unknown key $key";
|
||||||
|
next L;
|
||||||
|
}
|
||||||
|
my $value = $self->mgr->getConfKey( $self->req, $key );
|
||||||
|
#$value = Dumper($value);
|
||||||
|
#$value =~ s/\$VAR1/$key/;
|
||||||
|
#print $value;
|
||||||
|
if(ref $value eq 'HASH') {
|
||||||
|
print "$key has the following keys:\n";
|
||||||
|
print " $_\n" foreach(sort keys %$value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "$key = $value\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub lastCfg {
|
||||||
|
my ($self) = @_;
|
||||||
|
return $self->jsonResponse('/confs/latest')->{cfgNum};
|
||||||
|
}
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my $self = shift;
|
||||||
|
unless (@_) {
|
||||||
|
die 'nothing to do, aborting';
|
||||||
|
}
|
||||||
|
my $action = shift;
|
||||||
|
unless ( $action =~ /^(?:get|set)$/ ) {
|
||||||
|
die "unknown action $action";
|
||||||
|
}
|
||||||
|
$self->$action(@_);
|
||||||
|
}
|
||||||
|
|
||||||
|
package Lemonldap::NG::Manager::Cli::Request;
|
||||||
|
|
||||||
|
use Mouse;
|
||||||
|
|
||||||
|
has cfgNum => ( is => 'rw' );
|
||||||
|
|
||||||
|
has error => ( is => 'rw' );
|
||||||
|
|
||||||
|
sub params {
|
||||||
|
my ( $self, $key ) = @_;
|
||||||
|
return $self->{$key};
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -4,18 +4,20 @@ use JSON::MaybeXS;
|
||||||
use Mouse;
|
use Mouse;
|
||||||
use Lemonldap::NG::Manager;
|
use Lemonldap::NG::Manager;
|
||||||
|
|
||||||
has iniFile => ( is => 'ro', isa => 'Str', required => 1 );
|
has iniFile => ( is => 'ro', isa => 'Str' );
|
||||||
|
|
||||||
|
has mgr => ( is => 'ro', isa => 'Lemonldap::NG::Manager' );
|
||||||
|
|
||||||
has app => (
|
has app => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
isa => 'CodeRef',
|
isa => 'CodeRef',
|
||||||
builder => sub {
|
builder => sub {
|
||||||
return Lemonldap::NG::Manager->run(
|
my $args = { protection => 'none' };
|
||||||
{
|
$args->{configStorage} = { confFile => $_[0]->{iniFile} }
|
||||||
configStorage => { confFile => $_[0]->{iniFile} },
|
if ( $_[0]->{iniFile} );
|
||||||
protection => 'none',
|
$_[0]->{mgr} = Lemonldap::NG::Manager->new($args);
|
||||||
}
|
$_[0]->{mgr}->init($args);
|
||||||
);
|
return $_[0]->{mgr}->run();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
9
lemonldap-ng-manager/scripts/llng-manager-cli
Executable file
9
lemonldap-ng-manager/scripts/llng-manager-cli
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use warnings;
|
||||||
|
use strict;
|
||||||
|
use Lemonldap::NG::Manager::Cli;
|
||||||
|
|
||||||
|
my $cli = Lemonldap::NG::Manager::Cli->new(iniFile=>'t/lemonldap-ng.ini');
|
||||||
|
|
||||||
|
$cli->run(@ARGV);
|
Loading…
Reference in New Issue
Block a user