diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl index 1379207aed90ec2a962eaf29da50cbd68c0cf041..2ae87090e4f3123640c11ae87ec581e62c4d2e38 100755 --- a/bin/account-manager-client.pl +++ b/bin/account-manager-client.pl @@ -11,6 +11,8 @@ use strict; use warnings; use utf8; use lib qw(lib conf); +use feature "switch"; +no warnings 'experimental::smartmatch'; use Getopt::Long qw(:config auto_help); use Pod::Usage; @@ -58,8 +60,25 @@ IdPAccountManager::DB->register_db( my $db = IdPAccountManager::DB->new(); -if ($action eq 'add_test_account') { +for ($action) { + when ('add_test_account') { add_test_account() } + when ('list_test_accounts') { list_test_accounts() } + when ('add_service_provider') { add_service_provider() } + when ('list_service_providers') { list_service_providers() } + when ('add_authentication_token') { add_authentication_token() } + when ('get_authentication_token') { get_authentication_token() } + when ('list_authentication_tokens') { list_authentication_tokens() } + when ('parse_federation_metadata') { parse_federation_metadata() } + when ('send_notice') { send_notice() } + default { + pod2usage( + -message => "invalid action '$action', aborting\n", + -verbose => 0 + ); + } +} +sub add_test_account { pod2usage( -message => "missing account_profile option, aborting\n", -verbose => 0 @@ -87,8 +106,9 @@ if ($action eq 'add_test_account') { printf "Account created:\n\tuserid: user%d\n\tpassword: %s\n", $test_account->id(), $test_account->user_password(); -} elsif ($action eq 'list_test_accounts') { +} +sub list_test_accounts { my %args; if ($options{'sp_entityid'}) { push @{ $args{'query'} }, 'sp_entityid' => $options{'sp_entityid'}; @@ -129,7 +149,9 @@ if ($action eq 'add_test_account') { printf "Update simpleSamlPhp configuration file...\n"; } -} elsif ($action eq 'parse_federation_metadata') { +} + +sub parse_federation_metadata { my $federation_metadata = IdPAccountManager::SAMLMetadata->new(); die "unable to load federation metadata\n" @@ -155,7 +177,9 @@ if ($action eq 'add_test_account') { $federation_metadata->{'federation_metadata_as_hashref'}, 0, \*STDOUT); -} elsif ($action eq 'add_service_provider') { +} + +sub add_service_provider { pod2usage( -message => "missing sp_entityid option, aborting\n", @@ -197,8 +221,9 @@ if ($action eq 'add_test_account') { printf "Service Provider created\n"; -} elsif ($action eq 'list_service_providers') { +} +sub list_service_providers { my %args; my $providers = IdPAccountManager::Data::ServiceProvider::Manager->get_serviceproviders(db => $db, %args); @@ -211,7 +236,9 @@ if ($action eq 'add_test_account') { $provider->print(); } -} elsif ($action eq 'list_authentication_tokens') { +} + +sub list_authentication_tokens { my %args; if ($options{'sp_entityid'}) { @@ -244,7 +271,9 @@ if ($action eq 'add_test_account') { } -} elsif ($action eq 'get_authentication_token') { +} + +sub get_authentication_token { my %args; if ($options{'token'}) { @@ -265,7 +294,9 @@ if ($action eq 'add_test_account') { $authentication_token->print(); -} elsif ($action eq 'add_authentication_token') { +} + +sub add_authentication_token { pod2usage( -message => "missing email_address option, aborting\n", @@ -305,7 +336,9 @@ if ($action eq 'add_test_account') { $authentication_token->print(); -} elsif ($action eq 'send_notice') { +} + +sub send_notice { pod2usage( -message => "missing email_address option, aborting\n", @@ -332,11 +365,6 @@ if ($action eq 'add_test_account') { printf "Mail notice sent to $options{'email_address'}\n"; -} else { - pod2usage( - -message => "invalid action '$action', aborting\n", - -verbose => 0 - ); } __END__