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

Commit

Permalink
Archive tools used to inject orgID values
Browse files Browse the repository at this point in the history
  • Loading branch information
iay committed Sep 19, 2016
1 parent 741920e commit 37d0bdf
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
42 changes: 42 additions & 0 deletions utilities/2016-09-16/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# `utilities/2016-09-16`

These transforms and scripts were used to add an `orgID` attribute to the
`UKFederationMember` elements on all currently registered entities.

## Step 1

Generate `id-to-name.txt` as follows:

xsltproc --output=id-to-name.txt gen-id-to-name.xsl members/members.xml

This file contains a mapping between organization IDs and canonical
organization names, like this:

ukforg4590 Ian A. Young

The first field is separated from the second by a single tab character.

## Step 2

Generate `ukid-to-name.txt` as follows:

xsltproc gen-ukid-to-name.xsl entities/uk*.xml >ukid-to-name.txt

This file contains a mapping between entity `ID` attributes and canonical
organization names, like this:

uk000006 Ian A. Young

Again, the separator between the first and second fields is a single tab character.

## Step 3

Combining the results of steps 1 and 2, we can generate a list of all entity
files (named after entity `ID` values as in `ukid-to-name.txt`), via
the canonical organization name, to the organization ID values found in
`members.xml`.

This is then applied to all entity fragment files by executing `./doall.pl`.

`doall` reads both data files, then iterates across all fragment files calling
`patch.pl` to inject the appropriate `orgID` value.
26 changes: 26 additions & 0 deletions utilities/2016-09-16/doall.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env perl -W

open(F, "id-to-name.txt") || die "could not open id-to-name map";
while (<F>) {
my ($orgid, $name) = split /[\t\n]/;
# print "name='$name' --> orgid='$orgid'\n";
$name_to_orgid{$name} = $orgid;
}
close(F);

open(F, "ukid-to-name.txt") || die "could not open ukid-to-name map";
while (<F>) {
my ($ukid, $name) = split /[\t\n]/;
# print "ukid='$ukid' --> name='$name'\n";
if (defined $name_to_orgid{$name}) {
# print " --> orgid='$name_to_orgid{$name}'\n"
my $orgid = $name_to_orgid{$name};
$command = "perl -i patch.pl $orgid entities/$ukid.xml";
print "$ukid --> $orgid $command\n";
system($command);
} else {
die "'$name' unmapped";
# print " --> undefined\n";
}
}
close(F);
19 changes: 19 additions & 0 deletions utilities/2016-09-16/gen-id-to-name.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:members="http://ukfederation.org.uk/2007/01/members"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="members:Member">
<xsl:value-of select="@ID"/>
<xsl:text>&#9;</xsl:text>
<xsl:value-of select="members:Name"/>
<xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="text()">
<!-- do nothing -->
</xsl:template>
</xsl:stylesheet>
19 changes: 19 additions & 0 deletions utilities/2016-09-16/gen-ukid-to-name.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="md:EntityDescriptor">
<xsl:value-of select="@ID"/>
<xsl:text>&#9;</xsl:text>
<xsl:value-of select="md:Organization/md:OrganizationName"/>
<xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="text()">
<!-- do nothing -->
</xsl:template>
</xsl:stylesheet>
10 changes: 10 additions & 0 deletions utilities/2016-09-16/patch.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env perl -W

my $orgID = shift @ARGV;

while (<>) {
if (/UKFederationMember/ && !/orgID/) {
s/UKFederationMember/UKFederationMember orgID="$orgID"/;
}
print $_;
}

0 comments on commit 37d0bdf

Please sign in to comment.