Commit 7e1fa44c authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add List() to ClearingHouse.

Add a demonstration of getting lists from the ClearingHouse.
parent 08a4b8e6
......@@ -291,6 +291,36 @@ sub LookupByPrefix($$)
return GeniAuthority->Lookup($uuid);
}
#
# List all authorities.
#
sub ListAll($$)
{
my ($class, $pref) = @_;
my @result = ();
@$pref = ();
my $query = "select uuid from geni_authorities";
my $query_result = DBQueryWarn($query);
return -1
if (! $query_result);
return 0
if (!$query_result->numrows);
while (my ($uuid) = $query_result->fetchrow_array()) {
my $authority = GeniAuthority->Lookup($uuid);
if (!defined($authority)) {
print STDERR "Could not lookup authority $uuid\n";
return -1;
}
push(@result, $authority);
}
@$pref = @result;
return 0;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
#!/usr/bin/perl -wT
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2009 University of Utah and the Flux Group.
......@@ -817,3 +818,86 @@ sub PostCRL($)
"$cert");
return GeniResponse->Create(GENIRESPONSE_SUCCESS);
}
##
# Lookup a UUID and return a blob of stuff. We allow lookups of both
# users and slices, which is what we allow clients to register.
#
sub List($)
{
my ($argref) = @_;
my $cred = $argref->{'credential'};
my $type = $argref->{'type'};
my @results = ();
if (! (defined($type) && ($type =~ /^(Authorities|Components|Slices)$/i))){
return GeniResponse->MalformedArgsResponse();
}
$type = lc($type);
if (! defined($cred)) {
return GeniResponse->MalformedArgsResponse();
}
my $credential = GeniCredential->CreateFromSigned($cred);
if (!defined($credential)) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"Could not create GeniCredential object");
}
#
# Make sure the credential was issued to the caller.
#
if ($credential->owner_uuid() ne $ENV{'GENIUUID'}) {
return GeniResponse->Create(GENIRESPONSE_ERROR, undef,
"This is not your credential!");
}
#
# And that the target of the credential is this registry.
#
my $authority = GeniAuthority->Lookup($ENV{'MYUUID'});
if (!defined($authority)) {
print STDERR "Could not find local authority object\n";
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
if ($credential->target_uuid() ne $authority->uuid()) {
return GeniResponse->Create(GENIRESPONSE_FORBIDDEN,
undef, "This is not your registry!");
}
$credential->HasPrivilege( "authority" ) or
$credential->HasPrivilege( "resolve" ) or
return GeniResponse->Create( GENIRESPONSE_FORBIDDEN, undef,
"Insufficient privilege" );
if ($type eq "slices") {
my @slices;
if (GeniRegistry::GeniSlice->ListAll(\@slices) != 0) {
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
foreach my $slice (@slices) {
my $blob = {"gid" => $slice->cert(),
"hrn" => $slice->hrn(),
"uuid" => $slice->uuid() };
push(@results, $blob);
}
}
elsif ($type eq "authorities") {
my @authorities;
if (GeniAuthority->ListAll(\@authorities) != 0) {
return GeniResponse->Create(GENIRESPONSE_ERROR);
}
foreach my $authority (@authorities) {
my $blob = {"gid" => $authority->cert(),
"hrn" => $authority->hrn(),
"uuid" => $authority->uuid() };
push(@results, $blob);
}
}
else {
return GeniResponse->Create(GENIRESPONSE_UNSUPPORTED);
}
return GeniResponse->Create(GENIRESPONSE_SUCCESS, \@results);
}
......@@ -193,6 +193,35 @@ sub CheckExisting($$$)
return $query_result->numrows;
}
#
# List all slices.
#
sub ListAll($$)
{
my ($class, $pref) = @_;
my @result = ();
@$pref = ();
my $query = "select uuid from geni_slices ";
my $query_result = DBQueryWarn($query);
return -1
if (! $query_result);
return 0
if (!$query_result->numrows);
while (my ($uuid) = $query_result->fetchrow_array()) {
my $slice = GeniRegistry::GeniSlice->Lookup($uuid);
if (!defined($slice)) {
print STDERR "Could not lookup slice $uuid\n";
return -1;
}
push(@result, $slice);
}
@$pref = @result;
return 0;
}
#
# Stringify for output.
#
......
#! /usr/bin/env python
#
# GENIPUBLIC-COPYRIGHT
# Copyright (c) 2008-2009 University of Utah and the Flux Group.
# All rights reserved.
#
# Permission to use, copy, modify and distribute this software is hereby
# granted provided that (1) source code retains these copyright, permission,
# and disclaimer notices, and (2) redistributions including binaries
# reproduce the notices in supporting documentation.
#
# THE UNIVERSITY OF UTAH ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
# CONDITION. THE UNIVERSITY OF UTAH DISCLAIMS ANY LIABILITY OF ANY KIND
# FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
#
#
#
import sys
import pwd
import getopt
import os
import re
import xmlrpclib
from M2Crypto import X509
execfile( "test-common.py" )
#
# Get a credential for myself, that allows me to do things at the SA.
#
mycredential = get_self_credential()
#
# Ask the clearinghouse for a list of slices
#
params = {}
params["credential"] = mycredential
params["type"] = "slices"
rval,response = do_method("ch", "List", params)
if rval:
Fatal("Could not get the list from the ClearingHouse")
pass
print str(response["value"])
#
# Ask the clearinghouse for a list of authorities
#
params = {}
params["credential"] = mycredential
params["type"] = "authorities"
rval,response = do_method("ch", "List", params)
if rval:
Fatal("Could not get the list from the ClearingHouse")
pass
print str(response["value"])
......@@ -125,6 +125,7 @@ my $responder = Frontier::Responder->new( "methods" => {
"ListComponents" => \&GeniCH::ListComponents,
"PostCRL" => \&GeniCH::PostCRL,
"Shutdown" => \&GeniCH::Shutdown,
"List" => \&GeniCH::List,
},
);
......
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