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

switch to Syntax::Keyword::Try

parent 3dde0041
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ use DateTime; ...@@ -13,6 +13,7 @@ use DateTime;
use English qw(-no_match_vars); use English qw(-no_match_vars);
use Getopt::Long qw(:config auto_help); use Getopt::Long qw(:config auto_help);
use Pod::Usage; use Pod::Usage;
use Syntax::Keyword::Try;
use AccountManager::Data::Account; use AccountManager::Data::Account;
use AccountManager::Data::Entity; use AccountManager::Data::Entity;
...@@ -151,15 +152,15 @@ sub list_accounts { ...@@ -151,15 +152,15 @@ sub list_accounts {
db => $db db => $db
); );
eval { try {
AccountManager::Tools::update_ssp_authsources( AccountManager::Tools::update_ssp_authsources(
$configuration->{setup}->{templates_dir}, $configuration->{setup}->{templates_dir},
$configuration->{setup}->{accounts_file}, $configuration->{setup}->{accounts_file},
$accounts $accounts
); );
}; } catch ($error) {
die "failed to update simpleSAMLphp configuration file: $EVAL_ERROR" die "failed to update simpleSAMLphp configuration file: $error"
if $EVAL_ERROR; }
printf "Update simpleSamlPhp configuration file...\n"; printf "Update simpleSamlPhp configuration file...\n";
} }
...@@ -169,12 +170,13 @@ sub list_accounts { ...@@ -169,12 +170,13 @@ sub list_accounts {
sub parse_metadata { sub parse_metadata {
my $federation_metadata; my $federation_metadata;
eval { try {
$federation_metadata = AccountManager::Metadata->new( $federation_metadata = AccountManager::Metadata->new(
file => $configuration->{setup}->{federation_metadata_file} file => $configuration->{setup}->{federation_metadata_file}
); );
}; } catch ($error) {
die "unable to load federation metadata: $EVAL_ERROR" if $EVAL_ERROR; die "unable to load federation metadata: $error";
}
my $data = $federation_metadata->parse(id => $options{entityid}); my $data = $federation_metadata->parse(id => $options{entityid});
......
...@@ -13,6 +13,7 @@ use Getopt::Long qw(:config auto_help); ...@@ -13,6 +13,7 @@ use Getopt::Long qw(:config auto_help);
use List::MoreUtils qw(uniq); use List::MoreUtils qw(uniq);
use Mojo::UserAgent; use Mojo::UserAgent;
use Pod::Usage; use Pod::Usage;
use Syntax::Keyword::Try;
use AccountManager::Data::DB; use AccountManager::Data::DB;
use AccountManager::Data::Entity; use AccountManager::Data::Entity;
...@@ -82,24 +83,22 @@ foreach my $id (keys %{$configuration->{federations}}) { ...@@ -82,24 +83,22 @@ foreach my $id (keys %{$configuration->{federations}}) {
$result->save_to($file->filename()); $result->save_to($file->filename());
my $metadata; my $metadata;
eval { try {
$metadata = AccountManager::Metadata->new( $metadata = AccountManager::Metadata->new(
file => $file file => $file
); );
}; } catch ($error) {
if ($EVAL_ERROR) {
$db->rollback(); $db->rollback();
die "failed to load federation metadata: $EVAL_ERROR"; die "failed to load federation metadata: $error";
} }
print "parsing metadata from file $file\n" if $options{verbose}; print "parsing metadata from file $file\n" if $options{verbose};
my $entities; my $entities;
eval { try {
$entities = $metadata->parse(); $entities = $metadata->parse();
}; } catch ($error) {
if ($EVAL_ERROR) {
$db->rollback(); $db->rollback();
die "failed to parse federation metadata: $EVAL_ERROR"; die "failed to parse federation metadata: $error";
} }
foreach my $entry (@$entities) { foreach my $entry (@$entities) {
...@@ -118,28 +117,28 @@ foreach my $id (keys %{$configuration->{federations}}) { ...@@ -118,28 +117,28 @@ foreach my $id (keys %{$configuration->{federations}}) {
); );
$entity->update(); $entity->update();
} else { } else {
eval { $entity = AccountManager::Data::Entity->new(
$entity = AccountManager::Data::Entity->new( db => $db,
db => $db, type => $entry->{type},
type => $entry->{type}, entityid => $entry->{entityid},
entityid => $entry->{entityid}, display_name => $entry->{display_name},
display_name => $entry->{display_name}, information_url => $entry->{information_url},
information_url => $entry->{information_url}, organization_url => $entry->{organization_url},
organization_url => $entry->{organization_url}, );
); if ($entry->{contacts}) {
if ($entry->{contacts}) { my @contacts =
my @contacts = uniq
uniq grep { $_ }
grep { $_ } map { $_->{EmailAddress} }
map { $_->{EmailAddress} } @{$entry->{contacts}};
@{$entry->{contacts}}; $entity->contacts(@contacts);
$entity->contacts(@contacts); }
} $entity->federations($id);
$entity->federations($id);
try {
$entity->save(); $entity->save();
}; } catch ($error) {
if ($EVAL_ERROR) { warn "error while processing entity $entry->{entityid}: $error";
warn "error while processing entity $entry->{entityid}: $EVAL_ERROR";
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment