Skip to content
Snippets Groups Projects
Commit b65a48b3 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

use a dedicated function for each action

parent 8ee1cff7
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,8 @@ use strict; ...@@ -11,6 +11,8 @@ use strict;
use warnings; use warnings;
use utf8; use utf8;
use lib qw(lib conf); use lib qw(lib conf);
use feature "switch";
no warnings 'experimental::smartmatch';
use Getopt::Long qw(:config auto_help); use Getopt::Long qw(:config auto_help);
use Pod::Usage; use Pod::Usage;
...@@ -58,8 +60,25 @@ IdPAccountManager::DB->register_db( ...@@ -58,8 +60,25 @@ IdPAccountManager::DB->register_db(
my $db = IdPAccountManager::DB->new(); 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( pod2usage(
-message => "missing account_profile option, aborting\n", -message => "missing account_profile option, aborting\n",
-verbose => 0 -verbose => 0
...@@ -87,8 +106,9 @@ if ($action eq 'add_test_account') { ...@@ -87,8 +106,9 @@ if ($action eq 'add_test_account') {
printf "Account created:\n\tuserid: user%d\n\tpassword: %s\n", printf "Account created:\n\tuserid: user%d\n\tpassword: %s\n",
$test_account->id(), $test_account->user_password(); $test_account->id(), $test_account->user_password();
} elsif ($action eq 'list_test_accounts') { }
sub list_test_accounts {
my %args; my %args;
if ($options{'sp_entityid'}) { if ($options{'sp_entityid'}) {
push @{ $args{'query'} }, 'sp_entityid' => $options{'sp_entityid'}; push @{ $args{'query'} }, 'sp_entityid' => $options{'sp_entityid'};
...@@ -129,7 +149,9 @@ if ($action eq 'add_test_account') { ...@@ -129,7 +149,9 @@ if ($action eq 'add_test_account') {
printf "Update simpleSamlPhp configuration file...\n"; printf "Update simpleSamlPhp configuration file...\n";
} }
} elsif ($action eq 'parse_federation_metadata') { }
sub parse_federation_metadata {
my $federation_metadata = IdPAccountManager::SAMLMetadata->new(); my $federation_metadata = IdPAccountManager::SAMLMetadata->new();
die "unable to load federation metadata\n" die "unable to load federation metadata\n"
...@@ -155,7 +177,9 @@ if ($action eq 'add_test_account') { ...@@ -155,7 +177,9 @@ if ($action eq 'add_test_account') {
$federation_metadata->{'federation_metadata_as_hashref'}, $federation_metadata->{'federation_metadata_as_hashref'},
0, \*STDOUT); 0, \*STDOUT);
} elsif ($action eq 'add_service_provider') { }
sub add_service_provider {
pod2usage( pod2usage(
-message => "missing sp_entityid option, aborting\n", -message => "missing sp_entityid option, aborting\n",
...@@ -197,8 +221,9 @@ if ($action eq 'add_test_account') { ...@@ -197,8 +221,9 @@ if ($action eq 'add_test_account') {
printf "Service Provider created\n"; printf "Service Provider created\n";
} elsif ($action eq 'list_service_providers') { }
sub list_service_providers {
my %args; my %args;
my $providers = IdPAccountManager::Data::ServiceProvider::Manager->get_serviceproviders(db => $db, %args); my $providers = IdPAccountManager::Data::ServiceProvider::Manager->get_serviceproviders(db => $db, %args);
...@@ -211,7 +236,9 @@ if ($action eq 'add_test_account') { ...@@ -211,7 +236,9 @@ if ($action eq 'add_test_account') {
$provider->print(); $provider->print();
} }
} elsif ($action eq 'list_authentication_tokens') { }
sub list_authentication_tokens {
my %args; my %args;
if ($options{'sp_entityid'}) { if ($options{'sp_entityid'}) {
...@@ -244,7 +271,9 @@ if ($action eq 'add_test_account') { ...@@ -244,7 +271,9 @@ if ($action eq 'add_test_account') {
} }
} elsif ($action eq 'get_authentication_token') { }
sub get_authentication_token {
my %args; my %args;
if ($options{'token'}) { if ($options{'token'}) {
...@@ -265,7 +294,9 @@ if ($action eq 'add_test_account') { ...@@ -265,7 +294,9 @@ if ($action eq 'add_test_account') {
$authentication_token->print(); $authentication_token->print();
} elsif ($action eq 'add_authentication_token') { }
sub add_authentication_token {
pod2usage( pod2usage(
-message => "missing email_address option, aborting\n", -message => "missing email_address option, aborting\n",
...@@ -305,7 +336,9 @@ if ($action eq 'add_test_account') { ...@@ -305,7 +336,9 @@ if ($action eq 'add_test_account') {
$authentication_token->print(); $authentication_token->print();
} elsif ($action eq 'send_notice') { }
sub send_notice {
pod2usage( pod2usage(
-message => "missing email_address option, aborting\n", -message => "missing email_address option, aborting\n",
...@@ -332,11 +365,6 @@ if ($action eq 'add_test_account') { ...@@ -332,11 +365,6 @@ if ($action eq 'add_test_account') {
printf "Mail notice sent to $options{'email_address'}\n"; printf "Mail notice sent to $options{'email_address'}\n";
} else {
pod2usage(
-message => "invalid action '$action', aborting\n",
-verbose => 0
);
} }
__END__ __END__
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment