Commit be514979 authored by Leigh Stoller's avatar Leigh Stoller

Get rid of more uses of MYUUID from the environment; must have a rpc

context instead.
parent c7bbc0d6
...@@ -64,7 +64,7 @@ sub Create($$;$$) ...@@ -64,7 +64,7 @@ sub Create($$;$$)
my ($class, $authority, $context, $credential) = @_; my ($class, $authority, $context, $credential) = @_;
if (!defined($credential)) { if (!defined($credential)) {
$credential = GeniRegistry::Client->GetCredential($authority); $credential = GeniRegistry::Client->GetCredential($authority, $context);
return undef return undef
if (!defined($credential)); if (!defined($credential));
} }
...@@ -85,29 +85,31 @@ sub GetCredential($;$$) ...@@ -85,29 +85,31 @@ sub GetCredential($;$$)
{ {
my ($class, $authority, $context) = @_; my ($class, $authority, $context) = @_;
$context = Genixmlrpc->GetContext()
if (!defined($context));
if (!defined($context)) {
print STDERR "Need a context to create a registry credential\n";
return undef;
}
my $credential = my $credential =
GeniCredential->Lookup($authority->uuid(), $ENV{'MYUUID'}); GeniCredential->Lookup($authority->uuid(),
$context->certificate()->uuid());
if (defined($credential) && if (defined($credential) &&
defined($credential->expires())) { defined($credential->expires())) {
my $expires = str2time($credential->expires()); my $expires = str2time($credential->expires());
# Some buffer. # Some buffer.
if ($expires > time() + 3600) { if (time() > $expires - 3600) {
#print STDERR "Reusing clearinghouse credential\n"; $credential->Delete();
}
else {
print STDERR "Reusing $authority credential $credential\n";
return $credential; return $credential;
} }
$credential->Delete();
}
#print STDERR "Getting new clearinghouse credential\n";
$context = Genixmlrpc->GetContext()
if (!defined($context));
if (!defined($context)) {
print STDERR "Need a context to create a registry credential\n";
return undef;
} }
print STDERR "Getting new credential for $authority\n";
my $url = $authority->url(); my $url = $authority->url();
if (!defined($url)) { if (!defined($url)) {
...@@ -132,7 +134,7 @@ sub GetCredential($;$$) ...@@ -132,7 +134,7 @@ sub GetCredential($;$$)
return undef; return undef;
} }
$credential->Store(); $credential->Store();
print STDERR "Got new credential for $authority: $credential\n";
return $credential; return $credential;
} }
...@@ -452,6 +454,14 @@ use Time::Local; ...@@ -452,6 +454,14 @@ use Time::Local;
sub Create($;$$) sub Create($;$$)
{ {
my ($class, $context, $credential) = @_; my ($class, $context, $credential) = @_;
$context = Genixmlrpc->GetContext()
if (!defined($context));
if (!defined($context)) {
print STDERR "Need a context to create clearinghouse credential\n";
return undef;
}
if (!defined($credential)) { if (!defined($credential)) {
$credential = GeniRegistry::ClearingHouse->GetCredential($context); $credential = GeniRegistry::ClearingHouse->GetCredential($context);
...@@ -460,13 +470,6 @@ sub Create($;$$) ...@@ -460,13 +470,6 @@ sub Create($;$$)
return undef; return undef;
} }
} }
$context = Genixmlrpc->GetContext()
if (!defined($context));
if (!defined($context)) {
print STDERR "Need a context to create clearinghouse credential\n";
return undef;
}
return GeniRegistry::Client->Create($credential->target_cert(), return GeniRegistry::Client->Create($credential->target_cert(),
$context, $credential); $context, $credential);
} }
...@@ -503,41 +506,34 @@ sub GetCredential($;$$) ...@@ -503,41 +506,34 @@ sub GetCredential($;$$)
$context = Genixmlrpc->GetContext() $context = Genixmlrpc->GetContext()
if (!defined($context)); if (!defined($context));
# if (!defined($context)) {
# If there is no UUID in the environment, then try to figure it print STDERR "Need a context to create a registry credential\n";
# out from the context.
#
my $myuuid = (exists($ENV{'MYUUID'}) ? $ENV{'MYUUID'} : undef);
if (!defined($myuuid) && defined($context)) {
$myuuid = $context->certificate()->uuid();
}
if (!defined($myuuid)) {
print STDERR "*** GeniRegistry::ClearingHouse::GetCredential: ".
"No context or MYUUID for RPC\n";
return undef; return undef;
} }
my $clearinghousecert = GeniRegistry::ClearingHouse->GetCertificate(); my $clearinghousecert = GeniRegistry::ClearingHouse->GetCertificate();
if (!defined($clearinghousecert)) { if (!defined($clearinghousecert)) {
return undef; return undef;
} }
my $clearinghousecred = my $clearinghousecred =
GeniCredential->Lookup($clearinghousecert->uuid(), $myuuid); GeniCredential->Lookup($clearinghousecert->uuid(),
$context->certificate()->uuid());
#print "$clearinghousecred\n" if (defined($clearinghousecred)); print "$clearinghousecred\n" if (defined($clearinghousecred));
if (defined($clearinghousecred) && if (defined($clearinghousecred) &&
defined($clearinghousecred->expires())) { defined($clearinghousecred->expires())) {
my $expires = str2time($clearinghousecred->expires()); my $expires = str2time($clearinghousecred->expires());
# Some buffer. # Some buffer.
if ($expires > time() + 3600) { if (time() > $expires - 3600) {
#print STDERR "Reusing clearinghouse credential\n"; $clearinghousecred->Delete();
}
else {
print STDERR "Reusing clearinghouse credential\n";
return $clearinghousecred; return $clearinghousecred;
} }
$clearinghousecred->Delete();
} }
#print STDERR "Getting new clearinghouse credential\n"; print STDERR "Getting new clearinghouse credential\n";
my $url = $clearinghousecert->URL(); my $url = $clearinghousecert->URL();
if (!defined($url)) { if (!defined($url)) {
......
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