Commit 5fbcaba1 authored by Leigh B Stoller's avatar Leigh B Stoller

Add utility functions to map URNs to local users and projects.

parent 35891d8f
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# Copyright (c) 2007-2016 University of Utah and the Flux Group. # Copyright (c) 2007-2016, 2018 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -42,11 +42,14 @@ use libtestbed; ...@@ -42,11 +42,14 @@ use libtestbed;
use APT_Instance; use APT_Instance;
use Project; use Project;
use Group; use Group;
use GeniHRN;
use GeniUser;
# Configure variables # Configure variables
my $TB = "@prefix@"; my $TB = "@prefix@";
my $MAINSITE = @TBMAINSITE@; my $MAINSITE = @TBMAINSITE@;
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $OURDOMAIN = "@OURDOMAIN@";
# #
# Find all of the instances a user has (should have) an account on, and # Find all of the instances a user has (should have) an account on, and
...@@ -86,3 +89,40 @@ sub UpdateInstancesByUser($) ...@@ -86,3 +89,40 @@ sub UpdateInstancesByUser($)
} }
return 0; return 0;
} }
#
# Map project urn to local project. Since these URNs are coming from
# remote clusters, it might not actually refer to a local
#
sub MapProjectURN($)
{
my ($urn) = @_;
my $hrn = GeniHRN->new($urn);
if (!defined($hrn)) {
print STDERR "MapProjectURN: Could not parse $urn\n";
return undef;
}
if ($hrn->domain() eq $OURDOMAIN && defined($hrn->project())) {
my $project = Project->Lookup($hrn->project());
return $project
if (defined($project));
}
return undef;
}
#
# Same as above, but for users.
#
sub MapUserURN($)
{
my ($urn) = @_;
my $hrn = GeniHRN->new($urn);
if (!defined($hrn)) {
print STDERR "MapUserURN: Could not parse $urn\n";
return undef;
}
my $geniuser = GeniUser->Lookup($urn, 1);
return $geniuser
if (defined($geniuser) && $geniuser->IsLocal());
return undef;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment