Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN Access Check - Account manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
edugain
eduGAIN Access Check - Account manager
Commits
e709ff8c
Commit
e709ff8c
authored
7 years ago
by
Guillaume ROUSSE
Browse files
Options
Downloads
Patches
Plain Diff
rationalize error reporting
Exit with die() for processing errors, exit with pod2usage() for usage errors.
parent
3082b9ad
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/account-manager-client.pl
+77
-108
77 additions, 108 deletions
bin/account-manager-client.pl
with
77 additions
and
108 deletions
bin/account-manager-client.pl
+
77
−
108
View file @
e709ff8c
...
...
@@ -47,43 +47,32 @@ unless (
if
(
$options
{'
add_test_account
'})
{
my
$logger
=
IdPAccountManager::
Logger
->
new
(
file
=>
$
Conf::
global
{'
log_file
'},
verbosity
=>
$
Conf::
global
{'
log_level
'}
);
unless
(
$options
{'
account_profile
'})
{
die
"
Missing account_profile option
";
}
pod2usage
(
-
message
=>
"
missing account_profile option, aborting
\n
",
-
verbose
=>
0
)
unless
$options
{'
account_profile
'};
unless
(
$options
{'
sp_entityid
'})
{
die
"
Missing sp_entityid option
";
}
pod2usage
(
-
message
=>
"
missing sp_entityid option, aborting
\n
",
-
verbose
=>
0
)
unless
$options
{'
sp_entityid
'};
my
$test_account
=
IdPAccountManager::
TestAccount
->
new
(
account_profile
=>
$options
{'
account_profile
'},
sp_entityid
=>
$options
{'
sp_entityid
'}
);
unless
(
defined
$test_account
)
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create test account
");
exit
-
1
;
}
unless
(
$test_account
->
save
())
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create test account
");
exit
-
1
;
}
die
"
Failed to create test account
\n
"
unless
$test_account
;
die
"
Failed to save test account
\n
"
unless
$test_account
->
save
();
printf
"
Account created:
\n\t
userid: user%d
\n\t
password: %s
\n
",
$test_account
->
get
('
id
'),
$test_account
->
get
('
user_password
');
}
elsif
(
$options
{'
list_test_accounts
'})
{
my
$logger
=
IdPAccountManager::
Logger
->
new
(
file
=>
$
Conf::
global
{'
log_file
'},
verbosity
=>
$
Conf::
global
{'
log_level
'}
);
my
%args
;
if
(
$options
{'
sp_entityid
'})
{
push
@
{
$args
{'
query
'}
},
'
sp_entityid
'
=>
$options
{'
sp_entityid
'};
...
...
@@ -106,42 +95,36 @@ if ($options{'add_test_account'}) {
foreach
my
$test_account
(
@$all
)
{
$test_account
->
print
();
$test_account
->
delete
||
die
if
(
$options
{'
delete
'});
next
unless
$options
{'
delete
'};
die
"
failed to delete test account
\n
"
unless
$test_account
->
delete
();
}
if
(
$options
{'
delete
'})
{
printf
"
%d accounts removed
\n
",
$#
{
$all
}
+
1
;
## Update simpleSamlPhp configuration file
die
"
failed to update simpleSAMLphp configuration file
\n
"
unless
IdPAccountManager::Tools::
update_ssp_authsources
();
printf
"
Update simpleSamlPhp configuration file...
\n
";
unless
(
IdPAccountManager::Tools::
update_ssp_authsources
())
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create simpleSAMLphp configuration file
"
);
}
}
}
elsif
(
$options
{'
parse_federation_metadata
'})
{
my
$federation_metadata
=
IdPAccountManager::
SAMLMetadata
->
new
();
unless
(
$federation_metadata
->
load
(
die
"
unable to load federation metadata
\n
"
unless
$federation_metadata
->
load
(
federation_metadata_file_path
=>
$
Conf::
global
{'
federation_metadata_file_path
'}
)
)
{
die
;
}
);
my
%args
;
if
(
$options
{'
sp_entityid
'})
{
$args
{'
filter_entity_id
'}
=
$options
{'
sp_entityid
'};
}
unless
(
$federation_metadata
->
parse
(
%args
))
{
die
;
}
die
"
unable to parse federation metadata
\n
"
unless
$federation_metadata
->
parse
(
%args
);
printf
"
Document %s parsed
\n
",
$
Conf::
global
{'
federation_metadata_file_path
'};
...
...
@@ -154,18 +137,15 @@ if ($options{'add_test_account'}) {
}
elsif
(
$options
{'
add_service_provider
'})
{
my
$logger
=
IdPAccountManager::
Logger
->
new
(
file
=>
$
Conf::
global
{'
log_file
'},
verbosity
=>
$
Conf::
global
{'
log_level
'}
);
unless
(
$options
{'
sp_entityid
'})
{
die
"
Missing sp_entityid option
";
}
pod2usage
(
-
message
=>
"
missing sp_entityid option, aborting
\n
",
-
verbose
=>
0
)
unless
$options
{'
sp_entityid
'};
unless
(
$options
{'
contacts
'})
{
die
"
Missing contacts option
";
}
pod2usage
(
-
message
=>
"
missing contacts option, aborting
\n
",
-
verbose
=>
0
)
unless
$options
{'
contacts
'};
## Check if entry already exists in DB first
my
$service_provider
=
...
...
@@ -185,18 +165,14 @@ if ($options{'add_test_account'}) {
contacts
=>
$options
{'
contacts
'},
displayname
=>
$options
{'
displayname
'}
);
unless
(
defined
$service_provider
)
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create service provider
");
exit
-
1
;
}
die
"
failed to create service provider
\n
"
unless
$service_provider
;
}
unless
(
$service_provider
->
save
())
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create service provider
");
exit
-
1
;
}
die
"
failed to save service provider
"
unless
$service_provider
->
save
();
printf
"
Service Provider created
:
\n
";
printf
"
Service Provider created
\n
";
}
elsif
(
$options
{'
list_service_providers
'})
{
...
...
@@ -235,7 +211,9 @@ if ($options{'add_test_account'}) {
foreach
my
$authentication_token
(
@$all
)
{
$authentication_token
->
print
();
$authentication_token
->
delete
||
die
if
(
$options
{'
delete
'});
next
unless
options
{'
delete
'};
die
"
failed to delete authentication token
\n
"
unless
$authentication_token
->
delete
();
}
if
(
$options
{'
delete
'})
{
...
...
@@ -253,84 +231,75 @@ if ($options{'add_test_account'}) {
my
$authentication_token
=
IdPAccountManager::
AuthenticationToken
->
new
(
%args
);
unless
(
$authentication_token
->
load
())
{
die
"
No corresponding token found in DB
\n
";
}
die
"
No corresponding token found in DB
\n
"
unless
$authentication_token
->
load
();
if
(
$options
{'
sp_entityid
'})
{
unless
(
$authentication_token
->
get
('
sp_entityid
')
eq
$options
{'
sp_entityid
'})
{
die
"
Authentication token cannot be used for this SP
\n
";
}
die
"
Authentication token cannot be used for this SP
\n
"
unless
$authentication_token
->
get
('
sp_entityid
')
eq
$options
{'
sp_entityid
'};
}
$authentication_token
->
print
();
}
elsif
(
$options
{'
add_authentication_token
'})
{
my
$logger
=
IdPAccountManager::
Logger
->
new
(
file
=>
$
Conf::
global
{'
log_file
'},
verbosity
=>
$
Conf::
global
{'
log_level
'}
);
unless
(
$options
{'
email_address
'})
{
die
"
Missing email_address option
";
}
pod2usage
(
-
message
=>
"
missing email_address option, aborting
\n
",
-
verbose
=>
0
)
unless
$options
{'
email_address
'};
unless
(
$options
{'
sp_entityid
'})
{
die
"
Missing sp_entityid option
";
}
pod2usage
(
-
message
=>
"
missing sp_entityid option, aborting
\n
",
-
verbose
=>
0
)
unless
$options
{'
sp_entityid
'};
my
$authentication_token
=
IdPAccountManager::
AuthenticationToken
->
new
(
'
email_address
'
=>
$options
{'
email_address
'},
'
sp_entityid
'
=>
$options
{'
sp_entityid
'}
);
unless
(
defined
$authentication_token
)
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create token object
");
exit
-
1
;
}
die
"
failed to create authentication token
\n
"
unless
$authentication_token
;
## First remove token if on exist for this email+SP
if
(
$authentication_token
->
load
())
{
unless
(
$authentication_token
->
delete
())
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to delete token
");
exit
-
1
;
}
die
"
failed to delete authentication token
\n
"
unless
$authentication_token
->
delete
();
$authentication_token
=
IdPAccountManager::
AuthenticationToken
->
new
(
'
email_address
'
=>
$options
{'
email_address
'},
'
sp_entityid
'
=>
$options
{'
sp_entityid
'}
);
unless
(
defined
$authentication_token
)
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create token object
");
exit
-
1
;
}
die
"
failed to create authentication token
\n
"
unless
$authentication_token
;
}
unless
(
$authentication_token
->
save
())
{
$logger
->
log
(
level
=>
LOG_ERROR
,
message
=>
"
Failed to create token
");
exit
-
1
;
}
die
"
failed to save authentication token
\n
"
unless
$authentication_token
->
save
();
$authentication_token
->
print
();
}
elsif
(
$options
{'
send_notice
'})
{
unless
(
$options
{'
email_address
'})
{
die
"
Missing email_address option
";
}
unless
(
IdPAccountManager::Tools::
mail_notice
(
pod2usage
(
-
message
=>
"
missing email_address option, aborting
\n
",
-
verbose
=>
0
)
unless
$options
{'
email_address
'};
my
$logger
=
IdPAccountManager::
Logger
->
new
(
file
=>
$
Conf::
global
{'
log_file
'},
verbosity
=>
$
Conf::
global
{'
log_level
'}
);
die
"
Failed to send mail notice to
$options
{'email_address'}
\n
"
unless
IdPAccountManager::Tools::
mail_notice
(
'
template
'
=>
'
templates/mail/notification_generic_error.tt2.eml
',
'
data
'
=>
{},
'
to
'
=>
$options
{'
email_address
'}
'
to
'
=>
$options
{'
email_address
'}
,
'
logger
'
=>
$logger
)
)
{
die
"
Failed to send mail notice to
$options
{'email_address'}
\n
";
}
);
printf
"
Mail notice sent to
$options
{'email_address'}
\n
";
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment