-
Guillaume ROUSSE authored
use relative location and environment variable to find other components at runtime, avoiding substitution at install time
Guillaume ROUSSE authoreduse relative location and environment variable to find other components at runtime, avoiding substitution at install time
access-check-manager.pl 11.78 KiB
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Mojo::File qw(curfile);
use lib curfile()->dirname()->sibling('lib')->to_string;
use Config::Tiny;
use Data::Dumper;
use DateTime;
use English qw(-no_match_vars);
use Getopt::Long qw(:config auto_help);
use Pod::Usage;
use AccountManager::Account;
use AccountManager::Metadata;
use AccountManager::Entity;
use AccountManager::Token;
use AccountManager::Tools;
my %options;
GetOptions(
\%options,
'profile=s',
'configuration=s',
'contacts=s',
'delete',
'displayname=s',
'email_address=s',
'expired',
'entityid=s',
'token=s',
) or pod2usage(
-message => "unknown option, aborting\n",
-verbose => 0
);
my $action = $ARGV[0];
pod2usage(
-message => "no action given, aborting\n",
-verbose => 0
) unless $action;
my $configuration_file = $ENV{MOJO_CONFIG} || 'conf/manager.conf';
my $configuration = Config::Tiny->read($configuration_file);
if (!$configuration) {
die Config::Tiny->errstr() . "\n";
}
AccountManager::DB->register_db(
driver => $configuration->{database}->{type},
database => $configuration->{database}->{name},
host => $configuration->{database}->{host},
password => $configuration->{database}->{password},
username => $configuration->{database}->{username},
options => [ split(/, */, $configuration->{database}->{options}) ]
);
my $db = AccountManager::DB->new();
SWITCH: {
if ($action eq 'add_account') { add_account(); last SWITCH; }
if ($action eq 'list_accounts') { list_accounts(); last SWITCH; }
if ($action eq 'add_service') { add_service(); last SWITCH; }
if ($action eq 'list_services') { list_services(); last SWITCH; }
if ($action eq 'add_token') { add_token(); last SWITCH; }
if ($action eq 'get_token') { get_token(); last SWITCH; }