Commit 53499003 authored by Leigh B Stoller's avatar Leigh B Stoller

Switch to using URN objects in the data structures. This is backwards

compat with existing code since the stringify method just returns the
URN. Over time, this will be made more explicit. See previous commit for
how it interacts with XMLRPC and JSON encoding.
parent 9d2cc009
......@@ -165,7 +165,7 @@ sub Lookup($$)
$self->{'DOMAIN'} = $domain;
# Convert URNs to objects.
$self->{'AUTHORITY'}->{'urnOBJ'} = GeniHRN->new($self->urn());
$self->{'AUTHORITY'}->{'urn'} = GeniHRN->new($self->urn());
return $self;
}
......@@ -232,8 +232,7 @@ sub expires($) { return field($_[0], "expires"); }
sub created($) { return field($_[0], "created"); }
sub uuid_prefix($) { return field($_[0], "uuid_prefix"); }
sub urn($) { return field($_[0], "urn"); }
sub urnOBJ($) { return field($_[0], "urnOBJ"); }
sub URN($) { return field($_[0], "urnOBJ"); }
sub URN($) { return field($_[0], "urn"); }
sub url($) { return field($_[0], "url"); }
sub hrn($) { return field($_[0], "hrn"); }
sub type($) { return field($_[0], "type"); }
......
......@@ -4696,7 +4696,7 @@ sub Lockdown($)
#
my $caller = GeniHRN->new($credential->owner_urn());
if (! ($caller->IsSA() &&
$caller->domain() eq $slice->urnOBJ()->domain())) {
$caller->domain() eq $slice->urn()->domain())) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN, undef,
"Not enough permission to set/clr lockdown");
}
......@@ -4750,7 +4750,7 @@ sub Panic($)
#
my $caller = GeniHRN->new($credential->owner_urn());
if (! ($caller->IsSA() &&
$caller->domain() eq $slice->urnOBJ()->domain())) {
$caller->domain() eq $slice->urn()->domain())) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN, undef,
"Not enough permission to turn on/off panic mode");
}
......
......@@ -119,8 +119,8 @@ sub Lookup($$)
bless($self, $class);
my $cert = $self->cert();
# Convert urn to object now.
$self->{'CERT'}->{'urnOBJ'} = GeniHRN->new($self->{'CERT'}->{'urn'})
# Convert urn to object. Stringify overload will allow old code to work.
$self->{'CERT'}->{'urn'} = GeniHRN->new($self->{'CERT'}->{'urn'})
if (defined($self->{'CERT'}->{'urn'}));
# Add to cache.
......@@ -159,7 +159,6 @@ sub certfile($) { return field($_[0], "certfile"); }
sub passphrase($) { return undef; }
sub uri($) { return field($_[0], "uri"); }
sub urn($) { return field($_[0], "urn"); }
sub urnOBJ($) { return field($_[0], "urnOBJ"); }
sub rootcert($) { return $_[0]->{'ROOTCERT'}; }
sub GetCertificate($) { return $_[0]; }
......@@ -656,7 +655,7 @@ sub LoadFromArray($$@)
$self->{'CERT'}->{'enddate'} = undef;
$self->{'CERT'}->{'serial'} = undef;
# Convert URNs to objects.
$self->{'CERT'}->{'urnOBJ'} = GeniHRN->new($urn) if (defined($urn));
$self->{'CERT'}->{'urn'} = GeniHRN->new($urn) if (defined($urn));
return $self;
}
......@@ -768,7 +767,7 @@ sub LoadFromStringFast($$)
$self->{'CERT'}->{'enddate'} = TBDateStringGMT($x509->notAfter());
$self->{'CERT'}->{'serial'} = $x509->serial();
# Convert URNs to objects.
$self->{'CERT'}->{'urnOBJ'} = GeniHRN->new($urn);
$self->{'CERT'}->{'urn'} = GeniHRN->new($urn);
return $self;
}
......@@ -1592,7 +1591,7 @@ sub Create($$)
bless($self, $class);
# Convert URNs to objects.
$self->{'CERT'}->{'urnOBJ'} = GeniHRN->new($self->urn());
$self->{'CERT'}->{'urn'} = GeniHRN->new($self->urn());
return $self;
}
......@@ -1606,7 +1605,6 @@ sub revoked($) { return field($_[0], "revoked"); }
sub passphrase($) { return field($_[0], "password"); }
sub uri($) { return undef; }
sub urn($) { return field($_[0], "urn"); }
sub urnOBJ($) { return field($_[0], "urnOBJ"); }
sub URL($) { return undef; }
sub URN($) { return field($_[0], "urn"); }
sub certfile($) { return undef; }
......
......@@ -1153,7 +1153,7 @@ sub CheckCredential($;$$)
# If an authority is provided, the target must match the authority.
#
if (defined($target)) {
my $target_hrn = $target->urnOBJ();
my $target_hrn = $target->urn();
my $this_hrn = GeniHRN->new($credential->target_urn());
# The point here, is that the subauth is not relevant; we assume that
......
......@@ -134,12 +134,19 @@ sub SendEvent($$)
#
# We fill in the tuple stuff ourself instead.
#
# These options allow encoding of GeniHRN objects via TO_JSON method.
#
my $json = JSON->new;
$json = $json->allow_nonref(1);
$json = $json->allow_blessed(1);
$json = $json->convert_blessed(1);
foreach my $key (keys(%{ $hash })) {
my $val = $hash->{$key};
if (ref($val)) {
$val = eval { encode_json($val); };
if ($@) {
print STDERR "Could not json encode event data:\n";
print STDERR "Could not json encode event data: $@\n";
print STDERR Dumper($hash->{$key});
next;
}
......
......@@ -348,6 +348,7 @@ sub GenerateImage($$$$)
sub new($$)
{
my ($class, $urn) = @_;
my ($project, $group);
return $urn
if (ref($urn) && ref($urn) eq "GeniHRN");
......@@ -362,9 +363,14 @@ sub new($$)
$self->{'type'} = $type;
$self->{'id'} = $id;
$self->{'authority'} = $authority;
my ($domain,$subauth) = split(":", $authority);
my ($domain,$subauth) = split(":", $authority, 2);
$self->{'domain'} = $domain;
$self->{'subauth'} = $subauth;
if (defined($subauth)) {
($project,$group) = split(":", $subauth, 2);
}
$self->{'project'} = $project;
$self->{'group'} = $group;
bless($self, $class);
return $self;
......@@ -376,6 +382,8 @@ sub asString($) { return $_[0]->urn(); }
sub authority($) { return field($_[0], "authority"); }
sub domain($) { return field($_[0], "domain"); }
sub subauth($) { return field($_[0], "subauth"); }
sub project($) { return field($_[0], "project"); }
sub group($) { return field($_[0], "group"); }
sub type($) { return field($_[0], "type"); }
sub id($) { return field($_[0], "id"); }
sub IsAuthority() { return $_[0]->type() =~ /^authority$/i ? 1 : 0; }
......@@ -393,5 +401,15 @@ sub Stringify($)
return $self->{"urn"};
}
#
# For JSON encode.
#
sub TO_JSON($)
{
my ($self) = @_;
return $self->{"urn"};
}
# _Always_ make sure that this 1 is at the end of the file...
1;
......@@ -170,8 +170,8 @@ sub Lookup($$)
$slices{$self->hrn()} = $self;
# Convert URNs to objects.
$self->{'SLICE'}->{'creator_urnOBJ'} = GeniHRN->new($self->creator_urn());
$self->{'SLICE'}->{'speaksfor_urnOBJ'} = GeniHRN->new($self->speaksfor_urn())
$self->{'SLICE'}->{'creator_urn'} = GeniHRN->new($self->creator_urn());
$self->{'SLICE'}->{'speaksfor_urn'} = GeniHRN->new($self->speaksfor_urn())
if (defined($self->speaksfor_urn()));
return $self;
......@@ -310,7 +310,6 @@ sub uuid($) { return field($_[0], "uuid"); }
sub publicid($) { return field($_[0], "publicid"); }
sub creator_uuid($) { return field($_[0], "creator_uuid"); }
sub creator_urn($) { return field($_[0], "creator_urn"); }
sub creator_urnOBJ($) { return field($_[0], "creator_urnOBJ"); }
sub created($) { return field($_[0], "created"); }
sub shutdown($) { return field($_[0], "shutdown"); }
sub isshutdown($) { return field($_[0], "isshutdown"); }
......@@ -325,7 +324,6 @@ sub locked($) { return field($_[0], "locked"); }
sub isplaceholder($) { return field($_[0], "isplaceholder"); }
sub monitor_pid($) { return field($_[0], "monitor_pid"); }
sub speaksfor_urn($) { return field($_[0], "speaksfor_urn"); }
sub speaksfor_urnOBJ($) { return field($_[0], "speaksfor_urnOBJ"); }
sub speaksfor_uuid($) { return field($_[0], "speaksfor_uuid"); }
sub expiration_max($) { return field($_[0], "expiration_max"); }
sub renew_limit($) { return field($_[0], "renew_limit"); }
......@@ -408,13 +406,6 @@ sub urn($)
return $self->uuid();
}
sub urnOBJ($)
{
my ($self) = @_;
return $self->GetCertificate()->urnOBJ();
}
#
# Lookup slice by the experiment it is related to.
#
......
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