diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl index 21074214c7abf9bdce94c40c8b84c5c547787f33..bd57933e17d1d68299824e8684d78931babb3c31 100755 --- a/bin/account-manager-client.pl +++ b/bin/account-manager-client.pl @@ -23,29 +23,30 @@ use IdPAccountManager::AuthenticationToken; use IdPAccountManager::Logger; my %options; -unless ( - GetOptions( - \%options, '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', 'filter_expired', - 'delete', 'add_service_provider', - 'contacts=s', 'displayname=s' - ) - ) -{ - pod2usage( - -message => "unknown option, aborting\n", - -verbose => 0 - ); -} - - - -if ($options{'add_test_account'}) { +GetOptions( + \%options, + 'account_profile=s', + 'contacts=s', + 'delete', + 'displayname=s', + 'email_address=s', + 'filter_expired', + 'sp_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; + + +if ($action eq 'add_test_account') { pod2usage( -message => "missing account_profile option, aborting\n", @@ -71,7 +72,7 @@ if ($options{'add_test_account'}) { printf "Account created:\n\tuserid: user%d\n\tpassword: %s\n", $test_account->get('id'), $test_account->get('user_password'); -} elsif ($options{'list_test_accounts'}) { +} elsif ($action eq 'list_test_accounts') { my %args; if ($options{'sp_entityid'}) { @@ -109,7 +110,7 @@ if ($options{'add_test_account'}) { printf "Update simpleSamlPhp configuration file...\n"; } -} elsif ($options{'parse_federation_metadata'}) { +} elsif ($action eq 'parse_federation_metadata') { my $federation_metadata = IdPAccountManager::SAMLMetadata->new(); die "unable to load federation metadata\n" @@ -135,7 +136,7 @@ if ($options{'add_test_account'}) { $federation_metadata->{'federation_metadata_as_hashref'}, 0, \*STDOUT); -} elsif ($options{'add_service_provider'}) { +} elsif ($action eq 'add_service_provider') { pod2usage( -message => "missing sp_entityid option, aborting\n", @@ -174,7 +175,7 @@ if ($options{'add_test_account'}) { printf "Service Provider created\n"; -} elsif ($options{'list_service_providers'}) { +} elsif ($action eq 'list_service_providers') { my %args; @@ -188,7 +189,7 @@ if ($options{'add_test_account'}) { $service_provider->print(); } -} elsif ($options{'list_authentication_tokens'}) { +} elsif ($action eq 'list_authentication_tokens') { my %args; if ($options{'sp_entityid'}) { @@ -221,7 +222,7 @@ if ($options{'add_test_account'}) { } -} elsif ($options{'get_authentication_token'}) { +} elsif ($action eq 'get_authentication_token') { my %args; if ($options{'token'}) { @@ -242,8 +243,7 @@ if ($options{'add_test_account'}) { $authentication_token->print(); -} elsif ($options{'add_authentication_token'}) { - +} elsif ($action eq 'add_authentication_token') { pod2usage( -message => "missing email_address option, aborting\n", @@ -281,7 +281,7 @@ if ($options{'add_test_account'}) { $authentication_token->print(); -} elsif ($options{'send_notice'}) { +} elsif ($action eq 'send_notice') { pod2usage( -message => "missing email_address option, aborting\n", @@ -305,10 +305,9 @@ if ($options{'add_test_account'}) { } else { pod2usage( - -message => "missing argument, aborting\n", + -message => "invalid action '$action', aborting\n", -verbose => 0 ); - } __END__ @@ -319,41 +318,41 @@ account-manager-client.pl - Command line client to the Test Account manager =head1 SYNOPSIS -B<account-manager-client.pl> B<--add_test_account> +B<account-manager-client.pl> B<add_test_account> S<B<--account_profile> I<string>> S<B<--sp_entityid> I<string>> -B<account-manager-client.pl> B<--list_test_accounts> +B<account-manager-client.pl> B<list_test_accounts> S<[B<--account_profile> I<string>]> S<[B<--sp_entityid> I<string>]> [B<--filter_expired>] [B<--delete>] -B<account-manager-client.pl> B<--parse_federation_metadata> +B<account-manager-client.pl> B<parse_federation_metadata> S<[B<--sp_entityid> I<string>]> -B<account-manager-client.pl> B<--add_service_provider> +B<account-manager-client.pl> B<add_service_provider> S<B<--sp_entityid> I<string>> S<B<--contact> I<string>> S<[B<--displayname> I<string>]> -B<account-manager-client.pl> B<--list_service_providers> +B<account-manager-client.pl> B<list_service_providers> -B<account-manager-client.pl> B<--list_authentication_tokens> +B<account-manager-client.pl> B<list_authentication_tokens> S<B<--sp_entityid> I<string>> S<[B<--token> I<string>]> [B<--filter_expired>] [B<--delete>] -B<account-manager-client.pl> B<--get_authentication_token> +B<account-manager-client.pl> B<get_authentication_token> S<B<--sp_entityid> I<string>> S<[B<--token> I<string>]> -B<account-manager-client.pl> B<--add_authentication_token> +B<account-manager-client.pl> B<add_authentication_token> S<B<--sp_entityid> I<string>> S<B<--email_address> I<string>> -B<account-manager-client.pl> B<--send_notice> +B<account-manager-client.pl> B<send_notice> S<B<--email_address> I<string>> =head1 DESCRIPTION @@ -364,64 +363,64 @@ functions. =head1 EXAMPLES - $> account-manager-client.pl --add_test_account \ + $> account-manager-client.pl add_test_account \ --sp_entityid=https://test.federation.renater.fr/test/ressource --account_profile=student1 \ Adds a new test account. - $> account-manager-client.pl --list_test_accounts \ + $> account-manager-client.pl list_test_accounts \ --sp_entityid=https://test.federation.renater.fr/test/ressource \ --account_profile=student1 List all test accounts. Criterias can be added to filter test accounts. - $> account-manager-client.pl --list_test_accounts --filter_expired + $> account-manager-client.pl list_test_accounts --filter_expired List all expired test accounts. - $> account-manager-client.pl --list_test_accounts --filter_expired \ + $> account-manager-client.pl list_test_accounts --filter_expired \ --delete Remove all expired test accounts from DB. - $> account-manager-client.pl --parse_federation_metadata + $> account-manager-client.pl parse_federation_metadata Parses the SAML metadata file, as defined by the C<federation_metadata_file_path> configuration parameter. - $> account-manager-client.pl --list_authentication_tokens \ + $> account-manager-client.pl list_authentication_tokens \ --sp_entityid=https://test.federation.renater.fr/test/ressource \ --token=dhj67sjJ List all authentication tokens. Criterias can be added to filter tokens. - $> account-manager-client.pl --list_authentication_tokens \ + $> account-manager-client.pl list_authentication_tokens \ --filter_expired List all expired authentication tokens. - $> account-manager-client.pl --list_authentication_tokens \ + $> account-manager-client.pl list_authentication_tokens \ --filter_expired --delete Remove all expired authentication tokens from DB. - $> account-manager-client.pl --get_authentication_token \ + $> account-manager-client.pl get_authentication_token \ --token=dhj67sjJ Get informations on a token. - $> account-manager-client.pl --add_authentication_token \ + $> account-manager-client.pl add_authentication_token \ --email_address=john@my.fqdn \ --sp_entityid=https://test.federation.renater.fr/test/ressource Adds a new test account. - $> account-manager-client.pl --send_notice --email_address=john@my.fqdn + $> account-manager-client.pl send_notice --email_address=john@my.fqdn Sends a mail notice to the specified email address. - $> account-manager-client.pl --add_service_provider \ + $> account-manager-client.pl add_service_provider \ --sp_entityid=='https://test.federation.renater.fr/test/ressource _ --displayname='Test SP' --contacts=email1@dom,email2@dom