Newer
Older
#!/usr/bin/perl
## 18/07/2014, Olivier Salaün
## Command-line client for the Test IdP Account Manager
use strict;
use utf8;
use lib "/opt/testidp/IdPAccountManager/lib";
use Getopt::Long;
use IdPAccountManager::TestAccount;
my %options;
unless (&GetOptions(\%options, 'help', 'create_test_account', 'account_profile=s', 'sp_entityid=s', 'list_test_accounts')) {
die "Unknown options.";
}
if ($options{'help'}) {
printf "$0 --create_test_account --account_profile=<profile_id> --sp_entityid=<entityid>\n";
}
if ($options{'create_test_account'}) {
unless ($options{'account_profile'}) {
die "Missing account_profile option";
}
unless ($options{'sp_entityid'}) {
die "Missing sp_entityid option";
}
my $test_account = new IdPAccountManager::TestAccount(account_profile => $options{'account_profile'},
sp_entityid => $options{'sp_entityid'});
unless (defined $test_account) {
die "Failed to create test account";
}
printf "Account created:\n\tuserid: user%d\n\tpassword: %s\n", $test_account->id, $test_account->user_password;
}elsif ($options{'list_test_accounts'}) {
my %args;
if ($options{'sp_entityid'}) {
push @{$args{'query'}}, 'sp_entityid' => $options{'sp_entityid'};
}
if ($options{'account_profile'}) {
push @{$args{'query'}}, 'account_profile' => $options{'account_profile'};
}
my $all = IdPAccountManager::TestAccount::list_test_accounts(%args);
foreach my $test_account (@$all) {
printf "Account ID=%s; password=%s; sp_entityid=%s; account_profile=%s; creation_date=%s; expiration_date=%s\n",
$test_account->id, $test_account->user_password, $test_account->sp_entityid, $test_account->account_profile,
&POSIX::strftime('%Y:%m:%d', localtime($test_account->creation_date)), &POSIX::strftime('%Y:%m:%d', localtime($test_account->expiration_date));
}