#!/usr/bin/perl
use REST::Client;
use XML::LibXML;
my $ssl_cert = 'my-app.cert';
my $ssl_key = 'my-app.key';
my $ssl_ca = '/usr/local/ssl/certs/cacerts.cert';
my $gws_host = 'https://iam-ws.u.washington.edu:7443';
my $rest_timeout = 20;
my $client = REST::Client->new({
host => $gws_host,
cert => $ssl_cert,
key => $ssl_key,
ca => $ssl_ca,
timeout => $rest_timeout,
});
my $group = $ARGV[0];
my $rest_query = '/group/'.$group.'/history?size=999999';
$client->GET($rest_query);
my $rc = $client->responseCode();
my $raw_html = $client->responseContent();
&check_rest($gws_host.$rest_query,$rc,$raw_html,__LINE__);
my $doc_hist = XML::LibXML->new->parse_html_string($raw_html);
my $query = "//*[\@class='history']";
foreach my $node ($doc_hist->findnodes($query)) {
my $activity = $node->getAttribute("activity");
my $unixtime_ms = $node->getAttribute("date");
my $raction = $node->getAttribute("description");
my($action,$user) = $raction =~ /(.+): \'(.+)\'/;
if($activity eq "membership" && $action eq "add member") {
print "$user => $unixtime_ms\n";
}
}
sub check_rest($$$$) {
my($query,$rc,$output,$line) = @_;
if($rc != 200) {
print "Line $line: REST GET ($query) failed: RC $rc\n";
die "$output\n";
}
}