GRNOC-WebService-Client
view release on metacpan or search on metacpan
* ISSUE=3454 Added the wsutil command line tool for testing and timing webservices.
* ISSUE=3454 Added a timing option to the Client constructor to turn on timing debugging.
GRNOC::WebService::Client v1.1.3 -- Tue Nov 29 2011
===================================================
Features:
* ISSUE=2956 PROJ=102 Added set_credentials to allow the credentials uid, realm, and passwd to be change dynamically.
GRNOC::WebService::Client v1.1.2 -- Tue Jun 28 2011
===================================================
Features:
* ISSUE=2313 PROJ=102 set_raw_output() & get_content_type() methods added, as well as unit tests to verify the ability to receive the raw HTTP response (non-JSON-decoded)
Bug Fixes:
OLD CHANGES
===========
1.1.0 06-07-2011
ISSUE=2342 PROJ=102 Webservice Client follows Cosign redirects properly
ISSUE=2311 PROJ=102 Fully flushed out RemoteMethod information
ISSUE=2349 PROJ=102 Added raw_output to constructor to allow for data to be returned without any decoding or manipulation (before was hard coded for JSON decode)
1.0.5 06-06-2011
ISSUE=2311 PROJ=102 dding ability for WS Client to understand service names and grab urls out of name service config file
dont supply user/pass credentials unless they are given
1.0.4 04-14-2011
ISSUE=2132 PROJ=102 Switched to JSON::XS 2.x
1.0.2 12-13-2010
ISSUE=1135 PROJ=102 HTTP Basic Auth support
1.0.1 11-12-2010
ISSUE=1478 PROJ=102 keep-alive support and fixes when running under mod_perl
1.0.0 06-08-2010
bin/wsutil.pl view on Meta::CPAN
--raw decode it as json This is a boolean field and does not
require an argument.
-l path to cookie file location. If given this will use any
cookies in the file when authenticating to a service and
also save them to this file when done. If not given
cookies are maintained only for the current run.
It is probably prudent to make sure that the cookies that
are generated using your own credentials are cleaned up
afterwards or at least not made publicly available.
-c service cache file (in case of specifying -S Service Name)
--servicecache This file should be in the same format as the grnoc proxy
cronjob creates from the name service.
-n name service lookup URL (in case of specifying -S
--nameservice Service Name)
lib/GRNOC/WebService/Client.pm view on Meta::CPAN
my $realm = $self->{'realm'};
my $cookieJar = $self->{'cookieJar'};
my $ua = $self->{'ua'};
#--- if we did not pass realm explicitly
#--- use realm from the config file
if( !defined( $self->{'realm'} )) {
$self->{'realm'} = $self->{'default_realm'};
}
#--- set credentials for basic auth if given
#--- this does not use LWP::UserAgent->credentials because that appears to do two requests
#--- because it won't send credentials until it gets challenged, so we set the creds
#--- directly on the request
if (defined $self->{'uid'} && defined $self->{'passwd'} && defined $self->{'realm'}){
# --- Is this a Shibboleth ECP realm?
if ($self->{'realm'} =~ m|^https://|){
# Then set PAOS accept/header to tell SP we want to ECP
$request->header('Accept' => "*/*; @{[CONTENT_PAOS]}");
$request->header('PAOS' => PAOS_HEADER);
}
else {
# Otherwise do basic auth
lib/GRNOC/WebService/Client.pm view on Meta::CPAN
}
#--- submit form
my $result2 = $ua->request($request2);
alarm 0;
if($timed_out){
#request2 timed out----> alarm
$self->_set_error("Request timeout while authing to cosign.." . $request2->uri());
return undef;
}
if ($self->{"timing"}) {
$self->_do_timing("Sent credentials to Cosign");
}
#--- Got another 200 back
if ($result2->is_success && !defined($result2->header('x-died'))){
my $content2 = $result2->content;
#--- Are we back at Cosign? If so, we're unauthorized.
if ($content2 =~ /<form action=\".*cosign-bin\/cosign\.cgi\"/mi){
$self->_set_error( "Error: Authorization failed for: " . $request->uri());
lib/GRNOC/WebService/Client.pm view on Meta::CPAN
}
}
else
{
$self->_set_error("Unable to find a usable URL: Neither name_services or service_cache_file were specified\n");
return undef;
}
return 1;
}
=head2 set_credentials
interface to change the username, password, and/or realm of the client
=cut
sub set_credentials {
my $self = shift;
my %args = @_;
$self->{'uid'} = $args{'uid'} if ($args{'uid'});
$self->{'realm'} = $args{'realm'} if ($args{'realm'});
$self->{'passwd'} = $args{'passwd'} if ($args{'passwd'});
return 1;
}
t/ChangeCredentials.t view on Meta::CPAN
#!/usr/bin/perl
use Test::More tests => 14;
use strict;
use warnings;
use GRNOC::WebService::Client;
use Data::Dumper;
# going to test basic auth navigation here and the ability to change our credentials on the fly
my $svc = GRNOC::WebService::Client->new(url => 'http://localhost:8529/protected/protected.cgi');
# should fail since we don't give any info for this basic auth
my $result = $svc->test();
is($result, undef, "successfully failed to get into webservice");
$svc->set_credentials(uid => "dummy",
passwd => "banana",
realm => "The Realm"
);
is($svc->{'uid'}, "dummy", "successfully updated uid");
is($svc->{'passwd'}, "banana", "successfully updated passwd");
is($svc->{'realm'}, "The Realm", "successfully updated realm");
$result = $svc->test();
ok(defined $result, "was able to get a result after setting credentials");
ok($result->{'results'}->{'success'} eq 1, "got expected output");
$svc->set_credentials(passwd => "not_right");
is($svc->{'uid'}, "dummy", "kept previous user");
is($svc->{'passwd'}, "not_right", "successfully updated passwd 2");
is($svc->{'realm'}, "The Realm", "kept previous realm");
$result = $svc->test();
ok(! defined $result, "failed to auth with bad password");
$svc->set_credentials(uid => "dummy",
passwd => "banana",
realm => "The Realm"
);
is($svc->{'uid'}, "dummy", "successfully updated uid 2");
is($svc->{'passwd'}, "banana", "successfully updated passwd 3");
is($svc->{'realm'}, "The Realm", "successfully updated realm 2");
$result = $svc->test();
ok(defined $result, "was able to get a result after resetting credentials");
( run in 0.245 second using v1.01-cache-2.11-cpan-4d50c553e7e )