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($$$$$) ...@@ -1641,6 +1641,28 @@ sub Create($$$$$)
return GeniSlice::ClientSliver->Lookup($idx); 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. # Delete it.
# #
......
...@@ -38,7 +38,7 @@ use Exporter; ...@@ -38,7 +38,7 @@ use Exporter;
use vars qw(@ISA @EXPORT); use vars qw(@ISA @EXPORT);
@ISA = "Exporter"; @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 GeniSA;
use GeniResponse; use GeniResponse;
...@@ -51,6 +51,7 @@ use Data::Dumper; ...@@ -51,6 +51,7 @@ use Data::Dumper;
use Carp qw(cluck carp); use Carp qw(cluck carp);
use POSIX qw(strftime); use POSIX qw(strftime);
use Date::Parse; use Date::Parse;
use Time::Local;
# Filter out any credentials of an uknown type leaving only geni_sfa # Filter out any credentials of an uknown type leaving only geni_sfa
# version 2 and version 3 credentials in a list. Also invokes # version 2 and version 3 credentials in a list. Also invokes
...@@ -373,6 +374,36 @@ sub CheckCredentials($;$) ...@@ -373,6 +374,36 @@ sub CheckCredentials($;$)
return (wantarray() ? ($error) : $error); 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 # Takes a blob and returns a new one with only the fields defined by
# the filter. # the filter.
sub FilterFields($$) sub FilterFields($$)
...@@ -401,22 +432,94 @@ sub FilterFields($$) ...@@ -401,22 +432,94 @@ sub FilterFields($$)
sub GetMatchFilter($) sub GetMatchFilter($)
{ {
my ($options) = @_; my ($options) = @_;
my $match = []; my $match;
my $filter; my $filter;
if (exists($options->{'match'})) { if (exists($options->{'match'})) {
push(@{ $match }, getMaybeArray($options->{'match'}->{'MEMBER_URN'})); $match = {};
push(@{ $match }, getMaybeArray($options->{'match'}->{'MEMBER_UID'})); my $matches = $options->{'match'};
push(@{ $match }, getMaybeArray($options->{'match'}->{'SLICE_URN'})); foreach my $key (keys %$matches) {
my $value = $matches->{$key};
my $valueAr;
if (ref($value) eq 'ARRAY') {
$valueAr = $value;
} else {
$valueAr = [ $value ];
}
$match->{$key} = $valueAr;
}
} }
if (exists($options->{'filter'})) {
$filter = $options->{'filter'} $filter = $options->{'filter'}
if (exists($options->{'filter'})); }
return ($match, $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 # Take a reference that might be an array or might be a scalar or
# might be undefined. Return an array # might be undefined. Return an array
...@@ -454,4 +557,48 @@ sub DateTimeGMT($) ...@@ -454,4 +557,48 @@ sub DateTimeGMT($)
gmtime(str2time($datetime))); 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; 1;
This diff is collapsed.
...@@ -46,18 +46,63 @@ use lib '@prefix@/lib'; ...@@ -46,18 +46,63 @@ use lib '@prefix@/lib';
use GeniMA; use GeniMA;
use GeniResponse; use GeniResponse;
$GENI_METHODS = { GeniMA::SetGeniVersion($GENI_VERSION);
"get_version" => \&GeniMA::GetVersion,
"lookup_public_member_info" => \&GeniMA::LookupPublic, if (defined($GENI_VERSION)) {
"lookup_private_member_info" => \&GeniMA::LookupPrivate, if ($GENI_VERSION != 1) {
"lookup_identifying_member_info" => \&GeniMA::LookupIdentifying, if ($GENI_VERSION != 2) {
"update_member_info" => \&GeniMA::UpdateMember, print STDERR "Invalid API version: $GENI_VERSION\n";
"get_credentials" => \&GeniMA::GetCredentials, print STDERR "Will fall back to API version 2\n";
#fallback to version 2
"create_key" => \&GeniMA::CreateKey, }
"delete_key" => \&GeniMA::DeleteKey, $GENI_METHODS = {
"update_key" => \&GeniMA::UpdateKey, "get_version" => \&GeniMA::GetVersion,
"lookup_keys" => \&GeniMA::LookupKeys,
}; "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; 1;
...@@ -34,7 +34,7 @@ use Frontier::RPC2; ...@@ -34,7 +34,7 @@ use Frontier::RPC2;
# Do this early so that we talk to the right DB. # Do this early so that we talk to the right DB.
use vars qw($GENI_DBNAME $GENI_METHODS $EMULAB_PEMFILE use vars qw($GENI_DBNAME $GENI_METHODS $EMULAB_PEMFILE
$GENI_RESPONSE_CONVERTER); $GENI_RESPONSE_CONVERTER $GENI_VERSION);
BEGIN { $GENI_DBNAME = "geni"; } BEGIN { $GENI_DBNAME = "geni"; }
# Configure variables # Configure variables
...@@ -46,34 +46,127 @@ use lib '@prefix@/lib'; ...@@ -46,34 +46,127 @@ use lib '@prefix@/lib';
use GeniStdSA; use GeniStdSA;
use GeniResponse; use GeniResponse;
$GENI_METHODS = { GeniStdSA::SetGeniVersion($GENI_VERSION);
# SLICE_INFO
"get_version" => \&GeniStdSA::GetVersion,
"create_slice" => \&GeniStdSA::CreateSlice,
"lookup_slices" => \&GeniStdSA::LookupSlices,
"update_slice" => \&GeniStdSA::UpdateSlice,
"get_credentials" => \&GeniStdSA::GetCredentials,
# SLICE_MEMBERS if (defined($GENI_VERSION)) {
"modify_slice_membership" => \&GeniStdSA::ModifySliceMembership, if ($GENI_VERSION != 1) {
"lookup_slice_members" => \&GeniStdSA::LookupSliceMembers, if ($GENI_VERSION != 2) {
"lookup_slices_for_member" => \&GeniStdSA::LookupSlicesForMember, print STDERR "Invalid API version: $GENI_VERSION\n";
print STDERR "Will fall back to API version 2\n";
# SLIVER INFO #fallback to version 2
"create_sliver_info" => \&GeniStdSA::CreateSliverInfo, }
"update_sliver_info" => \&GeniStdSA::UpdateSliverInfo, $GENI_METHODS = {
"delete_sliver_info" => \&GeniStdSA::DeleteSliverInfo, "get_version" => \&GeniStdSA::GetVersion,
"lookup_sliver_info" => \&GeniStdSA::LookupSliverInfo,
"create" => \&GeniStdSA::Create,
# PROJECT_SERVICE "lookup" => \&GeniStdSA::Lookup,
"create_project" => \&GeniStdSA::CreateProject, "update" => \&GeniStdSA::Update,
"lookup_projects" => \&GeniStdSA::LookupProjects, "delete" => \&GeniStdSA::Delete,
"update_project" => \&GeniStdSA::UpdateProject,
"get_credentials" => \&GeniStdSA::GetCredentials,
# PROJECT_SERVICE
"modify_project_membership" => \&GeniStdSA::ModifyProjectMembership, "modify_membership" => \&GeniStdSA::ModifyMembership,
"lookup_project_members" => \&GeniStdSA::LookupProjectMembers, "lookup_for_member" => \&GeniStdSA::LookupForMember,
"lookup_projects_for_member" => \&GeniStdSA::LookupProjectsForMember, "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; 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