Commit 3d13311a authored by Leigh Stoller's avatar Leigh Stoller

Add more checks in GeniCertificate->Create() to prevent duplicates

(this time for the urn). Also change the protoype to allow an error to
be returned.
parent 5c21fb9c
......@@ -178,7 +178,9 @@ sub Create($$$$$$)
# Create a cert pair, which gives us a new uuid.
my $urn = GeniHRN::Generate( "@OURDOMAIN@", "sliver", $idx );
my $certificate = GeniCertificate->Create("aggregate", $urn, $hrn, $TBOPS);
my $certificate = GeniCertificate->Create({'urn' => $urn,
'hrn' => $hrn,
'email' => $TBOPS});
if (!defined($certificate)) {
print STDERR "GeniAggregate::Create: ".
"Could not generate new certificate and UUID for $hrn\n";
......
......@@ -18,6 +18,7 @@ use vars qw(@ISA @EXPORT);
# Must come after package declaration!
use GeniDB;
use GeniResponse;
use emutil qw(TBGetUniqueIndex);
use English;
use XML::Simple;
......@@ -156,9 +157,15 @@ sub email($)
#
# Create a certificate pair, which gives us a uuid to use for an object.
#
sub Create($$$$$;$$)
sub Create($$;$)
{
my ($class, $what, $urn, $hrn, $email, $uuid, $url) = @_;
my ($class, $argref, $error) = @_;
my $urn = (exists($argref->{'urn'}) ? $argref->{'urn'} : undef);
my $hrn = (exists($argref->{'hrn'}) ? $argref->{'hrn'} : undef);
my $email = (exists($argref->{'email'}) ? $argref->{'email'} : undef);
my $uuid = (exists($argref->{'uuid'}) ? $argref->{'uuid'} : undef);
my $url = (exists($argref->{'url'}) ? $argref->{'url'} : undef);
# Let mkcert generate a new one.
$uuid = ""
if (!defined($uuid));
......@@ -233,6 +240,20 @@ sub Create($$$$$;$$)
my ($ourn) = $query_result->fetchrow_array();
print STDERR "*** Duplicate uuid in geni_certificates table\n";
print STDERR "*** $uuid,$urn : $ourn\n";
$$error = GENIRESPONSE_UNAVAILABLE
if (defined($error));
goto bad;
}
$query_result =
DBQueryWarn("select uuid from geni_certificates where urn='$urn'");
goto bad
if (!$query_result);
if ($query_result->numrows) {
my ($ouuid) = $query_result->fetchrow_array();
print STDERR "*** Duplicate urn in geni_certificates table\n";
print STDERR "*** $uuid,$urn : $ouuid\n";
$$error = GENIRESPONSE_UNAVAILABLE
if (defined($error));
goto bad;
}
if ($certificate->Store() != 0) {
......
......@@ -429,9 +429,16 @@ sub Register($)
#
# Generate a certificate for this new slice.
#
my $certificate = GeniCertificate->Create("slice", $urn, $hrn,
$this_user->email());
my $error;
my $certificate =
GeniCertificate->Create({'urn' => $urn,
'hrn' => $hrn,
'email'=> $this_user->email()}, \$error);
if (!defined($certificate)) {
if (defined($error)) {
return GeniResponse->Create($error, undef,
GENIRESPONSE_STRING($error));
}
print STDERR "Could not create new certificate for slice\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
......
......@@ -277,8 +277,9 @@ sub CreateFromLocal($$$)
#
# Generate a certificate.
#
$certificate = GeniCertificate->Create("slice", $urn, $hrn,
$geniuser->email());
$certificate = GeniCertificate->Create({'urn' => $urn,
'hrn' => $hrn,
'email'=> $geniuser->email()});
if (!defined($certificate)) {
print STDERR "GeniSlice::CreateFromLocal: ".
"Could not generate new certificate $experiment\n";
......
......@@ -189,7 +189,9 @@ sub Create($$$$$$$$)
"Already have a certificate for $hrn/$urn\n";
return undef;
}
$certificate = GeniCertificate->Create("sliver", $urn, $hrn, $TBOPS);
$certificate = GeniCertificate->Create({'urn' => $urn,
'hrn' => $hrn,
'email'=> $TBOPS});
if (!defined($certificate)) {
print STDERR "GeniSliver::Create: ".
"Could not generate new certificate for $hrn/$urn\n";
......
#!/usr/bin/perl -w
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2009 University of Utah and the Flux Group.
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
# All rights reserved.
#
# Perl code to access an XMLRPC server using http. Derived from the
......@@ -21,7 +21,7 @@ use vars qw(@ISA @EXPORT);
GENIRESPONSE_RPCERROR GENIRESPONSE_UNAVAILABLE
GENIRESPONSE_SEARCHFAILED GENIRESPONSE_UNSUPPORTED
GENIRESPONSE_BUSY GENIRESPONSE_EXPIRED GENIRESPONSE_INPROGRESS
GENIRESPONSE);
GENIRESPONSE GENIRESPONSE_STRING);
use overload ('""' => 'Stringify');
my $current_response = undef;
......@@ -68,6 +68,12 @@ my @GENIRESPONSE_STRINGS =
"Expired",
"In Progress",
);
sub GENIRESPONSE_STRING($)
{
my ($error) = @_;
return $GENIRESPONSE_STRINGS[$error] || "Unknown Error $error";
}
#
# This is the (python-style) "structure" we want to return.
......
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