Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Added --head option to output header, added examples in help text, an…
Browse files Browse the repository at this point in the history
…d tidying up
  • Loading branch information
Alex Stuart authored and Alex Stuart committed Jan 16, 2014
1 parent b961c37 commit 01b0cef
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions build/query-entities.pl
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,31 @@
sub help {
print<<'EOF';
usage: entities.pl [--help] [--idp] [--sp] [--reg <registrationAuthority>] [--notreg <registrationAuthority>] <file>
usage: query-entities.pl [--help] [--head] [--idp] [--sp] [--reg <registrationAuthority>] [--notreg <registrationAuthority>] <file>
Outputs the entityID and display name(s) of a entities in the supplied file.
Outputs the entityID, display name(s) and other information about entities in the given SAML metadata aggregate file.
--help - prints this help and exits
--head - prints out a header for the CSV file
--idp - only outputs IdPs
--sp - only outputs SPs
(By default the script outputs all IdP and SP entities)
--reg <registrationAuthority> - outputs entities registered by registrationAuthority
--notreg <registrationAuthority> - outputs those entities NOT registered by registrationAuthority
(By default the script outputs all entities; can only have one of -reg or -notreg)
Example 1:
To output all SPs in the UK federation metadata which have been imported (i.e. are not registered by the UKAMF registrationAuthority http://ukfederation.org.uk), and to include a header on the CSV file:
query-entities.pl --head --sp --notreg http://ukfederation.org.uk ukfederation-metadata.xml
Example 2:
To output all IdPs exported by the UK federation, and include a header
query-entities.pl --head --idp -reg http://ukfederation.org.uk ukfederation-export.xml
EOF
}
Expand All @@ -36,13 +48,15 @@ sub help {
my $reg;
my $notreg;
my $help;
my $head;

my $result = GetOptions(
"idp" => \$idp,
"sp" => \$sp,
"reg=s" => \$reg,
"notreg=s" => \$notreg,
"help=s" => \$help,
"help" => \$help,
"head" => \$head
);

if ($help) {
Expand All @@ -68,7 +82,7 @@ sub help {

my $infile = $ARGV[0];

# If no IdP/SP descriminator set,
# If no IdP/SP discriminator set,
if ( ! $idp && ! $sp ) { $idp = 1; $sp = 1; }

# Can only have one of -reg and -notreg set
Expand Down Expand Up @@ -101,6 +115,14 @@ sub help {
exit 4;
}

#
# print header
#
if ($head) { print "# type, entityID, registrationAuthority, OrganizationDisplayName, OrganizationURL\n"; }

#
# Workhorse
#
my $twig = XML::Twig->new(
pretty_print => "indented",
twig_handlers =>
Expand All @@ -112,7 +134,7 @@ sub help {

sub is_entity () {
my ($t, $section)= @_;
my ($entityID, $ODN, $MDUI, $URL, $registrationAuthority, $type, $temp);
my ($entityID, $ODN, $URL, $registrationAuthority, $type, $temp);

$entityID = "No entityID found";
$entityID = $section->{'att'}->{'entityID'};
Expand All @@ -133,8 +155,6 @@ ()
}
}

$MDUI = "No MDUI display name found";

$registrationAuthority = "No registrationAuthority found";
if ( $temp = $section->first_child('Extensions')->first_child('mdrpi:RegistrationInfo')->{'att'}->{'registrationAuthority'} ) {
$registrationAuthority = $temp;
Expand All @@ -148,18 +168,6 @@ ()
if ( $section->first_child('SPSSODescriptor') ) { $type = "SP"; }

if ( ($sp && $type eq "SP") || ($idp && $type eq "IdP") ) {

# This is crying out for object-orientation and/or a MVC framework
# print "---------------------------------\n";
# print "entityID: $entityID\n";
# print "OrganzationDisplayName: $ODN\n";
## print "MDUI display name: $MDUI\n";
# print "OrganizationURL: $URL\n";
# print "registrationAuthority: $registrationAuthority\n";
# print "type: $type\n";

# ... however CSV is the file format of the future :)
print "$type, $entityID, $registrationAuthority, \"$ODN\", $URL\n"

print "$type, $entityID, $registrationAuthority, \"$ODN\", $URL\n"
}
}

0 comments on commit 01b0cef

Please sign in to comment.