Commit d92d8cb8 authored by Wim Van de Meerssche's avatar Wim Van de Meerssche Committed by Leigh Stoller

Updated Federation SA an MA API

parent 604f80d6
This diff is collapsed.
This diff is collapsed.
......@@ -1641,6 +1641,28 @@ sub Create($$$$$)
return GeniSlice::ClientSliver->Lookup($idx);
}
sub UpdateExpire($$)
{
my ($self, $new_expires) = @_;
if (! ref($self)) {
print STDERR "UpdateExpire error: self ref error\n";
return -1;
}
my $idx = $self->idx();
my $safe_expires = DBQuoteSpecial($new_expires);
my $query_res = DBQueryWarn("update client_slivers set expires=$safe_expires where idx='$idx'");
if (!$query_res) {
print STDERR "UpdateExpire error: DB error\n";
return -1;
}
return 0;
}
#
# Delete it.
#
......
......@@ -38,7 +38,7 @@ use Exporter;
use vars qw(@ISA @EXPORT);
@ISA = "Exporter";
@EXPORT = qw ( FilterCredentials auto_add_sa CheckCredentials FilterFields );
@EXPORT = qw ( FilterCredentials auto_add_sa CheckCredentials AddUserCredWhenSpeaksForOnly FilterFields WrapResponse CheckMatchAllowed CheckFieldsAllowed GetMatchFilter GetMatchFilterNew CheckFieldsRequired );
use GeniSA;
use GeniResponse;
......@@ -51,6 +51,7 @@ use Data::Dumper;
use Carp qw(cluck carp);
use POSIX qw(strftime);
use Date::Parse;
use Time::Local;
# Filter out any credentials of an uknown type leaving only geni_sfa
# version 2 and version 3 credentials in a list. Also invokes
......@@ -373,6 +374,36 @@ sub CheckCredentials($;$)
return (wantarray() ? ($error) : $error);
}
sub AddUserCredWhenSpeaksForOnly
{
my ($credential, $speaksfor) = @_;
if (!defined($credential) && defined($speaksfor)) {
$credential = GeniSA::GetCredential({
"credential" => $speaksfor->asString()
});
return (WrapResponse($credential, 'Error in AddUserCredWhenSpeaksForOnly: '), $speaksfor) if (GeniResponse::IsError($credential));
$credential = GeniCredential->CreateFromSigned($credential->{"value"});
}
return ($credential, $speaksfor);
}
sub WrapResponse
{
my ($response, $prefix) = @_;
#debug: check if called correctly
if (!GeniResponse::IsResponse($response)) {
use Data::Dumper;
return GeniResponse->Create(GENIRESPONSE_ERROR, undef, "Internal error calling WrapResponse: " . Dumper( $response, @_ ) );
}
my $new_output = $prefix . $response->{'output'};
$response->{'output'} = $new_output;
return $response;
}
# Takes a blob and returns a new one with only the fields defined by
# the filter.
sub FilterFields($$)
......@@ -401,22 +432,94 @@ sub FilterFields($$)
sub GetMatchFilter($)
{
my ($options) = @_;
my $match = [];
my $match;
my $filter;
if (exists($options->{'match'})) {
push(@{ $match }, getMaybeArray($options->{'match'}->{'MEMBER_URN'}));
push(@{ $match }, getMaybeArray($options->{'match'}->{'MEMBER_UID'}));
push(@{ $match }, getMaybeArray($options->{'match'}->{'SLICE_URN'}));
$match = {};
my $matches = $options->{'match'};
foreach my $key (keys %$matches) {
my $value = $matches->{$key};
my $valueAr;
if (ref($value) eq 'ARRAY') {
$valueAr = $value;
} else {
$valueAr = [ $value ];
}
$match->{$key} = $valueAr;
}
}
$filter = $options->{'filter'}
if (exists($options->{'filter'}));
if (exists($options->{'filter'})) {
$filter = $options->{'filter'}
}
return ($match, $filter);
}
sub CheckMatchAllowed($$$$$)
{
my ($methodname, $match, $allowed, $forbidden, $unimplemented) = @_;
return CheckMatchOrFieldAllowed($methodname, 'match', $match, $allowed, $forbidden, $unimplemented);
}
sub CheckFieldsRequired($$$)
{
my ($methodname, $fields, $required) = @_;
for my $req (@$required) {
my $is_present = 0;
foreach my $key (keys %$fields) {
if ($key eq $req) {
$is_present = 1;
}
}
if (! $is_present) {
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef,
$methodname . ' requires field "' . $req . '" to be specified');
}
}
return 1;
}
sub CheckFieldsAllowed($$$$$)
{
my ($methodname, $fields, $allowed, $forbidden, $unimplemented) = @_;
return CheckMatchOrFieldAllowed($methodname, 'field', $fields, $allowed, $forbidden, $unimplemented);
}
sub CheckMatchOrFieldAllowed($$$$$$)
{
my ($methodname, $optionname, $optionval, $allowed, $forbidden, $unimplemented) = @_;
foreach my $key (keys %$optionval) {
for my $uni (@$unimplemented) {
if ($key eq $uni) {
#GENIRESPONSE_NOT_IMPLEMENTED is not really appropriate, since we implement the method, just not this argument
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef,
$methodname . ' does not implement ' . $optionname . ' "' . $key . '"');
}
}
for my $forb (@$forbidden) {
if ($key eq $forb) {
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef,
$methodname . ' does not allow ' . $optionname . ' "' . $key . '"');
}
}
my $is_allowed = 0;
for my $all (@$allowed) {
if ($key eq $all) {
$is_allowed = 1;
}
}
if (! $is_allowed) {
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef,
$methodname . ' does not know ' . $optionname . ' "' . $key . '"');
}
}
return 1;
}
# Take a reference that might be an array or might be a scalar or
# might be undefined. Return an array
......@@ -454,4 +557,48 @@ sub DateTimeGMT($)
gmtime(str2time($datetime)));
}
#
# Return date in RFC3339 time format.
#
sub DateTimeStringToRFC3339String($)
{
my ($datetime) = @_;
return POSIX::strftime("20%y-%m-%dT%H:%M:%SZ",
gmtime(str2time($datetime)));
}
#perl datetime to RFC3339 string
sub DateTimeToRFC3339String($)
{
my ($datetime) = @_;
return POSIX::strftime("20%y-%m-%dT%H:%M:%SZ",
gmtime($datetime));
}
sub RFC3339StringToDateTime($)
{
my ($expiration) = @_;
if (defined($expiration)) {
#code adapted from GeniCM.pm SetSliceExpiration
if (ref($expiration) eq 'Frontier::RPC2::DateTime::ISO8601') {
$expiration = $expiration->value;
}
my $when = eval { timegm(strptime($expiration)); };
if ($@) {
my $message = $@;
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef, "Could not parse date '$expiration': $message");
}
if (!defined($when)) {
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef, "Could not parse date '$expiration'");
}
return $when;
}
return GeniResponse->Create(GENIRESPONSE_BADARGS, undef, "No date found");
}
1;
This diff is collapsed.
......@@ -46,18 +46,63 @@ use lib '@prefix@/lib';
use GeniMA;
use GeniResponse;
$GENI_METHODS = {
"get_version" => \&GeniMA::GetVersion,
"lookup_public_member_info" => \&GeniMA::LookupPublic,
"lookup_private_member_info" => \&GeniMA::LookupPrivate,
"lookup_identifying_member_info" => \&GeniMA::LookupIdentifying,
"update_member_info" => \&GeniMA::UpdateMember,
"get_credentials" => \&GeniMA::GetCredentials,
"create_key" => \&GeniMA::CreateKey,
"delete_key" => \&GeniMA::DeleteKey,
"update_key" => \&GeniMA::UpdateKey,
"lookup_keys" => \&GeniMA::LookupKeys,
};
GeniMA::SetGeniVersion($GENI_VERSION);
if (defined($GENI_VERSION)) {
if ($GENI_VERSION != 1) {
if ($GENI_VERSION != 2) {
print STDERR "Invalid API version: $GENI_VERSION\n";
print STDERR "Will fall back to API version 2\n";
#fallback to version 2
}
$GENI_METHODS = {
"get_version" => \&GeniMA::GetVersion,
"create" => \&GeniMA::Create,
"lookup" => \&GeniMA::Lookup,
"update" => \&GeniMA::Update,
"delete" => \&GeniMA::Delete,
"get_credentials" => \&GeniMA::GetCredentials,
};
} else {
$GENI_METHODS = {
"get_version" => \&GeniMA::GetVersion,
"lookup_public_member_info" => \&GeniMA::LookupPublic,
"lookup_private_member_info" => \&GeniMA::LookupPrivate,
"lookup_identifying_member_info" => \&GeniMA::LookupIdentifying,
"update_member_info" => \&GeniMA::UpdateMember,
"get_credentials" => \&GeniMA::GetCredentials,
"create_key" => \&GeniMA::CreateKey,
"delete_key" => \&GeniMA::DeleteKey,
"update_key" => \&GeniMA::UpdateKey,
"lookup_keys" => \&GeniMA::LookupKeys,
};
}
} else {
print STDERR "No API version specified in URL\n";
print STDERR "Will fall back to supporting both API version 1 and version 2. get_version will fall back to version 2.\n";
$GENI_METHODS = {
"get_version" => \&GeniMA::GetVersion,
"get_credentials" => \&GeniMA::GetCredentials,
"lookup_public_member_info" => \&GeniMA::LookupPublic,
"lookup_private_member_info" => \&GeniMA::LookupPrivate,
"lookup_identifying_member_info" => \&GeniMA::LookupIdentifying,
"update_member_info" => \&GeniMA::UpdateMember,
"create_key" => \&GeniMA::CreateKey,
"delete_key" => \&GeniMA::DeleteKey,
"update_key" => \&GeniMA::UpdateKey,
"lookup_keys" => \&GeniMA::LookupKeys,
"create" => \&GeniMA::Create,
"lookup" => \&GeniMA::Lookup,
"update" => \&GeniMA::Update,
"delete" => \&GeniMA::Delete,
};
}
1;
......@@ -34,7 +34,7 @@ use Frontier::RPC2;
# Do this early so that we talk to the right DB.
use vars qw($GENI_DBNAME $GENI_METHODS $EMULAB_PEMFILE
$GENI_RESPONSE_CONVERTER);
$GENI_RESPONSE_CONVERTER $GENI_VERSION);
BEGIN { $GENI_DBNAME = "geni"; }
# Configure variables
......@@ -46,34 +46,127 @@ use lib '@prefix@/lib';
use GeniStdSA;
use GeniResponse;
$GENI_METHODS = {
# SLICE_INFO
"get_version" => \&GeniStdSA::GetVersion,
"create_slice" => \&GeniStdSA::CreateSlice,
"lookup_slices" => \&GeniStdSA::LookupSlices,
"update_slice" => \&GeniStdSA::UpdateSlice,
"get_credentials" => \&GeniStdSA::GetCredentials,
GeniStdSA::SetGeniVersion($GENI_VERSION);
# SLICE_MEMBERS
"modify_slice_membership" => \&GeniStdSA::ModifySliceMembership,
"lookup_slice_members" => \&GeniStdSA::LookupSliceMembers,
"lookup_slices_for_member" => \&GeniStdSA::LookupSlicesForMember,
# SLIVER INFO
"create_sliver_info" => \&GeniStdSA::CreateSliverInfo,
"update_sliver_info" => \&GeniStdSA::UpdateSliverInfo,
"delete_sliver_info" => \&GeniStdSA::DeleteSliverInfo,
"lookup_sliver_info" => \&GeniStdSA::LookupSliverInfo,
# PROJECT_SERVICE
"create_project" => \&GeniStdSA::CreateProject,
"lookup_projects" => \&GeniStdSA::LookupProjects,
"update_project" => \&GeniStdSA::UpdateProject,
# PROJECT_SERVICE
"modify_project_membership" => \&GeniStdSA::ModifyProjectMembership,
"lookup_project_members" => \&GeniStdSA::LookupProjectMembers,
"lookup_projects_for_member" => \&GeniStdSA::LookupProjectsForMember,
};
if (defined($GENI_VERSION)) {
if ($GENI_VERSION != 1) {
if ($GENI_VERSION != 2) {
print STDERR "Invalid API version: $GENI_VERSION\n";
print STDERR "Will fall back to API version 2\n";
#fallback to version 2
}
$GENI_METHODS = {
"get_version" => \&GeniStdSA::GetVersion,
"create" => \&GeniStdSA::Create,
"lookup" => \&GeniStdSA::Lookup,
"update" => \&GeniStdSA::Update,
"delete" => \&GeniStdSA::Delete,
"get_credentials" => \&GeniStdSA::GetCredentials,
"modify_membership" => \&GeniStdSA::ModifyMembership,
"lookup_for_member" => \&GeniStdSA::LookupForMember,
"lookup_members" => \&GeniStdSA::LookupMembers,
"create_slice" => \&GeniStdSA::InvalidApi1,
"lookup_slices" => \&GeniStdSA::InvalidApi1,
"update_slice" => \&GeniStdSA::InvalidApi1,
"modify_slice_membership" => \&GeniStdSA::InvalidApi1,
"lookup_slice_members" => \&GeniStdSA::InvalidApi1,
"lookup_slices_for_member" => \&GeniStdSA::InvalidApi1,
"create_sliver_info" => \&GeniStdSA::InvalidApi1,
"update_sliver_info" => \&GeniStdSA::InvalidApi1,
"delete_sliver_info" => \&GeniStdSA::InvalidApi1,
"lookup_sliver_info" => \&GeniStdSA::InvalidApi1,
"create_project" => \&GeniStdSA::InvalidApi1,
"lookup_projects" => \&GeniStdSA::InvalidApi1,
"update_project" => \&GeniStdSA::InvalidApi1,
"modify_project_membership" => \&GeniStdSA::InvalidApi1,
"lookup_projects_for_member" => \&GeniStdSA::InvalidApi1,
"lookup_project_members" => \&GeniStdSA::InvalidApi1
};
} else {
$GENI_METHODS = {
# SLICE_INFO
"get_version" => \&GeniStdSA::GetVersion,
"create_slice" => \&GeniStdSA::CreateSlice,
"lookup_slices" => \&GeniStdSA::LookupSlices,
"update_slice" => \&GeniStdSA::UpdateSlice,
"get_credentials" => \&GeniStdSA::GetCredentials,
# SLICE_MEMBERS
"modify_slice_membership" => \&GeniStdSA::ModifySliceMembership,
"lookup_slice_members" => \&GeniStdSA::LookupSliceMembers,
"lookup_slices_for_member" => \&GeniStdSA::LookupSlicesForMember,
# SLIVER INFO
"create_sliver_info" => \&GeniStdSA::CreateSliverInfo,
"update_sliver_info" => \&GeniStdSA::UpdateSliverInfo,
"delete_sliver_info" => \&GeniStdSA::DeleteSliverInfo,
"lookup_sliver_info" => \&GeniStdSA::LookupSliverInfo,
# PROJECT_SERVICE
"create_project" => \&GeniStdSA::CreateProject,
"lookup_projects" => \&GeniStdSA::LookupProjects,
"update_project" => \&GeniStdSA::UpdateProject,
# PROJECT_SERVICE
"modify_project_membership" => \&GeniStdSA::ModifyProjectMembership,
"lookup_project_members" => \&GeniStdSA::LookupProjectMembers,
"lookup_projects_for_member" => \&GeniStdSA::LookupProjectsForMember,
"create" => \&GeniStdSA::InvalidApi2,
"lookup" => \&GeniStdSA::InvalidApi2,
"update" => \&GeniStdSA::InvalidApi2,
"delete" => \&GeniStdSA::InvalidApi2,
"modify_membership" => \&GeniStdSA::InvalidApi2,
"lookup_for_member" => \&GeniStdSA::InvalidApi2,
"lookup_members" => \&GeniStdSA::InvalidApi2
};
}
} else {
print STDERR "No API version specified in URL\n";
print STDERR "Will fall back to supporting both API version 1 and version 2. get_version will fall back to version 2.\n";
$GENI_METHODS = {
# SLICE_INFO
"get_version" => \&GeniStdSA::GetVersion,
"create_slice" => \&GeniStdSA::CreateSlice,
"lookup_slices" => \&GeniStdSA::LookupSlices,
"update_slice" => \&GeniStdSA::UpdateSlice,
"get_credentials" => \&GeniStdSA::GetCredentials,
# SLICE_MEMBERS
"modify_slice_membership" => \&GeniStdSA::ModifySliceMembership,
"lookup_slice_members" => \&GeniStdSA::LookupSliceMembers,
"lookup_slices_for_member" => \&GeniStdSA::LookupSlicesForMember,
# SLIVER INFO
"create_sliver_info" => \&GeniStdSA::CreateSliverInfo,
"update_sliver_info" => \&GeniStdSA::UpdateSliverInfo,
"delete_sliver_info" => \&GeniStdSA::DeleteSliverInfo,
"lookup_sliver_info" => \&GeniStdSA::LookupSliverInfo,
# PROJECT_SERVICE
"create_project" => \&GeniStdSA::CreateProject,
"lookup_projects" => \&GeniStdSA::LookupProjects,
"update_project" => \&GeniStdSA::UpdateProject,
# PROJECT_SERVICE
"modify_project_membership" => \&GeniStdSA::ModifyProjectMembership,
"lookup_project_members" => \&GeniStdSA::LookupProjectMembers,
"lookup_projects_for_member" => \&GeniStdSA::LookupProjectsForMember,
#version 2 support
"create" => \&GeniStdSA::Create,
"lookup" => \&GeniStdSA::Lookup,
"update" => \&GeniStdSA::Update,
"delete" => \&GeniStdSA::Delete,
"modify_membership" => \&GeniStdSA::ModifyMembership,
"lookup_for_member" => \&GeniStdSA::LookupForMember,
"lookup_members" => \&GeniStdSA::LookupMembers,
};
}
1;
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