Commit d472df8a authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Lookup Authority by URN using proper regexp pattern.

Moved this in from the Resolve() function in the CH
module.
parent 2e7be2ea
......@@ -19,6 +19,7 @@ use vars qw(@ISA @EXPORT);
# Must come after package declaration!
use GeniDB;
use GeniRegistry;
use GeniHRN;
use emutil qw(TBGetUniqueIndex);
use English;
use overload ('""' => 'Stringify');
......@@ -47,7 +48,21 @@ sub Lookup($$)
my $query_result;
my $uuid;
if ($token =~ /^\w+\-\w+\-\w+\-\w+\-\w+$/) {
if (GeniHRN::IsValid($token)) {
my ($auth,$t,$id) = GeniHRN::Parse($token);
my $regexp = "/.[-[:alnum:]]+.${auth}";
$regexp =~ s/\./\\\./g;
$query_result =
DBQueryWarn("select uuid from geni_authorities ".
"where url regexp '$regexp' and ".
" type='$id'");
return undef
if (! $query_result || !$query_result->numrows);
($uuid) = $query_result->fetchrow_array();
}
elsif ($token =~ /^\w+\-\w+\-\w+\-\w+\-\w+$/) {
$uuid = $token;
}
elsif ($token =~ /^P([\w]+)$/) {
......
......@@ -187,19 +187,28 @@ sub Resolve($)
$urn = $hrn if (defined($hrn) && GeniHRN::IsValid( $hrn ));
if (defined($urn)) {
my ($auth,$t,$id) = GeniHRN::Parse( $urn );
my $authority = GeniAuthority->Lookup($urn);
my $result = DBQueryWarn( "SELECT hrn FROM geni_authorities WHERE ".
"url LIKE '%" . $auth . "%' LIMIT 1;" );
# print STDERR "$authority, $urn\n";
return GeniResponse->Create(GENIRESPONSE_DBERROR)
if (!defined($result));
my ($translated) = $result->fetchrow_array() =~ /^([-\w]+)\..*/;
if (!defined($authority));
my ($translated) = $authority->hrn() =~ /^([-\w]+)\..*/;
# print STDERR "$auth, $t, $id, $translated\n";
$type = $t;
$type = "Component"
if ($type eq "node");
if ($t eq "node") {
$type = "Component";
}
elsif ($t eq "authority") {
$type = $id;
}
else {
$type = $t;
}
$hrn = $translated . "." . $id;
# print STDERR "$auth, $t, $id, $hrn, $type\n";
$uuid = undef;
}
if (defined($uuid) && !($uuid =~ /^[-\w]*$/)) {
......@@ -302,6 +311,7 @@ sub Resolve($)
# Return a blob.
my $blob = { "gid" => $manager->cert(),
"url" => $manager->url(),
"type" => $manager->type(),
};
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $blob);
}
......@@ -312,6 +322,7 @@ sub Resolve($)
# Return a blob.
my $blob = { "gid" => $authority->cert(),
"url" => $authority->url(),
"type" => $authority->type(),
};
return GeniResponse->Create(GENIRESPONSE_SUCCESS, $blob);
}
......
Supports Markdown
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