Skip Menu |

This queue is for tickets about the Net-Amazon-AWIS CPAN distribution.

Report information
The Basics
Id: 18237
Status: resolved
Priority: 0/
Queue: Net-Amazon-AWIS

People
Owner: Nobody in particular
Requestors: keith [...] iveys.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.31
Fixed in: (no value)



Subject: AWIS now requires signature
AWIS now requires using an AWS Access Key ID and a Secret Access Key to calculate a signature, and the web service URL and namespace URI have changed. I've attached a patch. There have also been some changes in the results returned for the sites in the test -- not sure what the best stable solution is for that, but the changes I've made work for now.
Subject: diff.txt
diff -ur Net-Amazon-AWIS-0.31/lib/Net/Amazon/AWIS.pm Net-Amazon-AWIS-new/lib/Net/Amazon/AWIS.pm --- Net-Amazon-AWIS-0.31/lib/Net/Amazon/AWIS.pm 2005-07-07 04:35:21.000000000 -0400 +++ Net-Amazon-AWIS-new/lib/Net/Amazon/AWIS.pm 2006-03-18 20:17:33.000000000 -0500 @@ -6,12 +6,14 @@ use URI::QueryParam; use XML::LibXML; use XML::LibXML::XPathContext; +use Digest::HMAC_SHA1; +use POSIX qw( strftime ); our $VERSION = "0.31"; use base qw(Class::Accessor::Fast); -__PACKAGE__->mk_accessors(qw(libxml subscription_id ua)); +__PACKAGE__->mk_accessors(qw(libxml aws_access_key_id secret_access_key ua)); sub new { - my($class, $subscription_id) = @_; + my($class, $aws_access_key_id, $secret_access_key) = @_; my $self = {}; bless $self, $class; @@ -19,7 +21,8 @@ $ua->timeout(30); $self->ua($ua); $self->libxml(XML::LibXML->new); - $self->subscription_id($subscription_id); + $self->aws_access_key_id($aws_access_key_id); + $self->secret_access_key($secret_access_key); return $self; } @@ -75,7 +78,7 @@ Operation => 'WebMap', Url => $options{url}, ResponseGroup => 'LinksIn,LinksOut', - Count => $options{count} || 100, + Count => $options{count} || 20, Start => $options{start} || 0, }; @@ -188,9 +191,14 @@ my($self, $parms) = @_; # sleep 1; - $parms->{SubscriptionId} = $self->subscription_id; + $parms->{Service} = 'AlexaWebInfoService'; + $parms->{AWSAccessKeyId} = $self->aws_access_key_id; + $parms->{Timestamp} = strftime '%Y-%m-%dT%H:%M:%S.000Z', gmtime; + my $hmac = Digest::HMAC_SHA1->new($self->secret_access_key); + $hmac->add( $parms->{Service} . $parms->{Operation} . $parms->{Timestamp} ); + $parms->{Signature} = $hmac->b64digest . '='; - my $url = "http://aws-beta.amazon.com/onca/xml?Service=AlexaWebInfoService"; + my $url = 'http://awis.amazonaws.com/onca/xml'; my $uri = URI->new($url); $uri->query_param($_, $parms->{$_}) foreach keys %$parms; @@ -204,7 +212,7 @@ my $doc = $self->libxml->parse_string($xml); my $xpc = XML::LibXML::XPathContext->new($doc); - $xpc->registerNs('awis', 'http://webservices.amazon.com/AWSAlexa/2005-02-01'); + $xpc->registerNs('awis', 'http://webservices.amazon.com/AWSAlexa/2005-07-11'); # warn $doc->toString(1); @@ -264,10 +272,11 @@ =head2 new The constructor method creates a new Net::Amazon::AWIS -object. You must pass in an Amazon Web Services Subscription ID. See +object. You must pass in an Amazon Web Services Access Key ID +and a Secret Access Key. See http://www.amazon.com/gp/aws/landing.html: - my $sq = Net::Amazon::AWIS->new($subscription_id); + my $sq = Net::Amazon::AWIS->new($aws_access_key_id, $secret_access_key); =head2 url_info @@ -426,4 +435,4 @@ Copyright (c) 2005, Leon Brocard C<acme@astray.com>. All rights reserved. This module is free software; you can redistribute it and/or -modify it under the same terms as Perl itself. \ No newline at end of file +modify it under the same terms as Perl itself. diff -ur Net-Amazon-AWIS-0.31/Makefile.PL Net-Amazon-AWIS-new/Makefile.PL --- Net-Amazon-AWIS-0.31/Makefile.PL 2005-07-07 04:35:21.000000000 -0400 +++ Net-Amazon-AWIS-new/Makefile.PL 2006-03-18 19:02:25.000000000 -0500 @@ -7,6 +7,7 @@ 'PREREQ_PM' => { 'Class::Accessor::Fast' => '0', 'DateTime::Format::Strptime' => '0', + 'Digest::HMAC_SHA1' => '0', 'IO::Prompt' => '0', 'LWP::UserAgent' => '0', 'Module::Build' => '0', diff -ur Net-Amazon-AWIS-0.31/t/simple.t Net-Amazon-AWIS-new/t/simple.t --- Net-Amazon-AWIS-0.31/t/simple.t 2005-07-07 04:35:21.000000000 -0400 +++ Net-Amazon-AWIS-new/t/simple.t 2006-03-18 19:59:54.000000000 -0500 @@ -5,24 +5,26 @@ use Test::More; use Test::Exception; -my $subscription_id; +my($aws_access_key_id, $secret_access_key); eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 60; - $subscription_id = prompt("Please enter an AWS subscription ID for testing: "); + $aws_access_key_id = prompt("Please enter an AWS access key ID for testing: "); + alarm 60; + $secret_access_key = prompt("Please enter a secret access key for testing: "); alarm 0; }; -if ($subscription_id && length($subscription_id) == 20) { - eval 'use Test::More tests => 133;'; +if ($aws_access_key_id && $secret_access_key) { + eval 'use Test::More tests => 63;'; } else { - eval 'use Test::More plan skip_all => "Need AWS subscription ID for testing, skipping"'; + eval 'use Test::More plan skip_all => "Need AWS access key ID and secret access key for testing, skipping"'; } use_ok("Net::Amazon::AWIS"); -my $awis = Net::Amazon::AWIS->new($subscription_id); +my $awis = Net::Amazon::AWIS->new($aws_access_key_id, $secret_access_key); isa_ok($awis, "Net::Amazon::AWIS", "Have an object back"); my $data = $awis->url_info(url => "http://use.perl.org/"); @@ -30,7 +32,6 @@ ok(!$data->{adult_content}, "not porn"); is_deeply($data->{categories}, [ { path => 'Top/Computers/Programming/Languages/Perl', title => 'Languages/Perl' }, - { path => 'Top/Computers/Programming/Languages/Perl/Directories', title => 'Perl/Directories' }, ], "categories fine"); is($data->{encoding}, "us-ascii", "encoding is us-ascii"); is($data->{locale}, "en", "locale is en"); @@ -44,9 +45,9 @@ ok(scalar(@{$data->{links_out}}) > 5, "links_out"); my @results = $awis->crawl(url => "http://www.cpan.org", count => 10); -cmp_ok(scalar(@results), '==', 10, "At least ten results"); +cmp_ok(scalar(@results), '>=', 5, "At least five results"); -foreach my $result (@results) { +foreach my $result (@results[0..4]) { like($result->{url}, qr{http://(www\.)?cpan\.org:80/}, "url"); is($result->{ip}, "66.39.76.93", "ip"); isa_ok($result->{date}, 'DateTime', "date"); @@ -56,7 +57,7 @@ is($result->{language}, "en.us-ascii", "language is en.us-ascii"); cmp_ok(scalar(@{$result->{other_urls}}), '==', 0, "0 other urls"); - cmp_ok(scalar(@{$result->{images}}), '>=', 2, ">= 2 images"); + cmp_ok(scalar(@{$result->{images}}), '>=', 1, ">= 1 images"); cmp_ok(scalar(@{$result->{links}}), '>=', 15, ">= 15 links"); };
Thanks, applied. I've just uploaded Net-Amazon-AWIS-0.32.tar.gz to CPAN which contains your patch. Cheers! Leon