From ef9f66ed755b0e60e3a0f8799359f9be4a476b76 Mon Sep 17 00:00:00 2001 From: "renater.salaun" <renater.salaun@047e039d-479c-447e-8a29-aa6bf4a09bab> Date: Thu, 30 Oct 2014 15:32:09 +0000 Subject: [PATCH] Moved account expiration code to account-manager-client.pl git-svn-id: https://svn.geant.net/GEANT/edugain_testidp_account_manager/trunk@58 047e039d-479c-447e-8a29-aa6bf4a09bab --- bin/account-manager-client.pl | 26 ++++++++++++++++-- bin/expire-test-accounts.pl | 52 ----------------------------------- 2 files changed, 24 insertions(+), 54 deletions(-) delete mode 100755 bin/expire-test-accounts.pl diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl index fb8c0c0..9590cd5 100755 --- a/bin/account-manager-client.pl +++ b/bin/account-manager-client.pl @@ -19,7 +19,7 @@ use IdPAccountManager::AuthenticationToken; my %options; unless (&GetOptions(\%options, 'help', 'add_test_account', 'account_profile=s', 'sp_entityid=s', 'list_test_accounts', 'parse_federation_metadata', 'list_service_providers','list_authentication_tokens', 'get_authentication_token', 'add_authentication_token','email_address=s', - 'token=s','send_notice')) { + 'token=s','send_notice','filter_expired','delete')) { die "Unknown options."; } @@ -62,16 +62,30 @@ if ($options{'add_test_account'}) { push @{$args{'query'}}, 'account_profile' => $options{'account_profile'}; } + if ($options{'filter_expired'}) { + push @{$args{'query'}}, 'expiration_date' => {lt => time}; + } my $all = IdPAccountManager::TestAccount::list_test_accounts(%args); if ($#{$all} < 0) { - printf "No test account in DB\n"; + printf "No matching test account in DB\n"; } foreach my $test_account (@$all) { $test_account->print(); + $test_account->delete || die if ($options{'delete'}); } + + if ($options{'delete'}) { + printf "%d accounts removed\n", $#{$all}+1; + + ## Update simpleSamlPhp configuration file + printf "Update simpleSamlPhp configuration file...\n"; + IdPAccountManager::Tools::update_ssp_authsources(); + } + + }elsif ($options{'parse_federation_metadata'}) { my $federation_metadata = new IdPAccountManager::SAMLMetadata; unless ($federation_metadata->load(federation_metadata_file_path => $Conf::global{'federation_metadata_file_path'})) { @@ -222,6 +236,14 @@ Adds a new test account. List all test accounts. Criterias can be added to filter test accounts. +=item C<account-manager-client.pl --list_test_accounts --filter_expired> + +List all expired test accounts. + +=item C<account-manager-client.pl --list_test_accounts --filter_expired --delete> + +Remove all expired test accounts from DB. + =item C<account-manager-client.pl --parse_federation_metadata> Parses the SAML metadata file, as defined by the C<federation_metadata_file_path> configuration parameter. diff --git a/bin/expire-test-accounts.pl b/bin/expire-test-accounts.pl deleted file mode 100755 index cba9519..0000000 --- a/bin/expire-test-accounts.pl +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl - -## 09/09/2014, Olivier Salaün -## Command-line script to remove expired test accounts -## The script also updates the simpleSamlPhp config file - -use strict; -use utf8; -use lib "/opt/testidp/IdPAccountManager/lib"; -use lib "/opt/testidp/IdPAccountManager/conf"; - -use Getopt::Long; -use POSIX; - -use IdPAccountManager::TestAccount; - -my %options; -unless (&GetOptions(\%options, 'help', 'list_only')) { - die "Unknown options."; -} - -if ($options{'help'}) { - printf "$0 --list_only\n"; -} - -if ($options {'list_only'}) { - my $all = IdPAccountManager::TestAccount::list_test_accounts('query' => ['expiration_date' => {lt => time}]); - - foreach my $test_account (@$all) { - $test_account->print(); - } - -}else { - ## Remove expired test accounts - my $all = IdPAccountManager::TestAccount::list_test_accounts('query' => ['expiration_date' => {lt => time}]); - - printf "Removing expired test accounts...\n"; - foreach my $test_account (@$all) { - $test_account->print(); - $test_account->delete || die; - } - printf "%d accounts removed\n", $#{$all}+1; - - #&IdPAccountManager::Tools::dump_var(\%Conf::global, 0, \*STDOUT); - - ## Update simpleSamlPhp configuration file - printf "Update simpleSamlPhp configuration file...\n"; - - IdPAccountManager::Tools::update_ssp_authsources(); -} - - -- GitLab