Akamai-Open-Client
view release on metacpan or search on metacpan
lib/Akamai/Open/Debug.pm view on Meta::CPAN
# ABSTRACT: Debugging interface for the Akamai Open API Perl clients
$Akamai::Open::Debug::VERSION = '0.03';
use strict;
use warnings;
use MooseX::Singleton;
use Data::Dumper qw/Dumper/;
use Log::Log4perl;
our $default_conf = q/
log4perl.category.Akamai.Open.Debug = ERROR, Screen
log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 1
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern = %p - %C - %m%n
/;
has 'config' => (is => 'rw');
has 'logger' => (is => 'rw', default => sub{return(Log::Log4perl::get_logger('Akamai::Open::Debug'));});
# is called after Moose has builded the object
sub BUILD {
my $self = shift;
$self->config($default_conf) unless($self->config);
Log::Log4perl::init_once(\$self->config);
return;
}
sub dump_obj {
my $self = shift;
my $ref = shift;
$self->logger->info('Dumping object: ', Dumper($ref));
return;
}
sub debugger {
my $self = shift;
my $new = shift;
my $prev = shift;
my $sub = (caller(1))[3];
$self->debug->logger->debug(sprintf('setting %s to %s (%s before)', $sub, $new, $prev ? $prev : 'undef'));
return;
}
1;
__END__
=pod
=encoding utf-8
lib/Akamai/Open/Debug.pm view on Meta::CPAN
=head1 VERSION
version 0.03
=head1 SYNOPSIS
use Akamai::Open::Debug;
use Akamai::Open::Client;
my $log_conf = q/
log4perl.category.Akamai.Open.Debug = DEBUG, Screen
log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 1
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern = %p - %C - %m%n
/;
my $debug = Akamai::Open::Debug->initialize(config => $log_conf);
my $client = Akamai::Open::Client->new(debug => $debug);
I<Akamai::Open::Debug> uses L<Log::Log4perl|http://search.cpan.org/perldoc?Log::Log4perl> for logging purposes and thus is
very flexible and easy configurable.
=head1 ABOUT
I<Akamai::Open::Debug> provides the debugging and logging functionality
for the I<Akamai::Open> API client and uses uses L<MooseX::Singleton|http://search.cpan.org/perldoc?MooseX::Singleton>
to provide a single instance based logging solution.
=head1 USAGE
If you want to configure your own logging, just initialize your
L<Akamai::Open> API client, with an I<Akamai::Open::Debug> object.
To do this, instantiate an object with your own I<Log::Log4perl>
configuration (see I<Log::Log4perl> for example configurations):
my $debug = Akamai::Open::Debug->initialize(config => $log_conf);
The only thing you've to consider is, that the I<Log::Log4perl> category
has to be named I<log4perl.category.Akamai.Open.Debug>, as written in
the example.
After that you can pass your object to your client:
my $client = Akamai::Open::Client->new(debug => $debug);
=head1 AUTHOR
Martin Probst <internet+cpan@megamaddin.org>
lib/Akamai/Open/Request/EdgeGridV1.pm view on Meta::CPAN
extends 'Akamai::Open::Request';
has 'client' => (is => 'rw', trigger => \&Akamai::Open::Debug::debugger);
has 'signed_headers' => (is => 'rw', trigger => \&Akamai::Open::Debug::debugger);
has 'signature' => (is => 'rw', trigger => \&Akamai::Open::Debug::debugger);
has 'signing_key' => (is => 'rw', isa => 'Str', trigger => \&Akamai::Open::Debug::debugger);
before 'sign_request' => sub {
my $self = shift;
my $tmp_key;
$self->debug->logger->debug(sprintf('Calculating signing key from %s and %s', $self->timestamp(),$self->client->client_secret()));
$tmp_key = encode_base64(hmac_sha256($self->timestamp(),$self->client->client_secret()));
chomp($tmp_key);
$self->signing_key($tmp_key);
return;
};
after 'sign_request' => sub {
my $self = shift;
if(defined($self->signature)) {
my $header_name = HEADER_NAME;
my $auth_header = sprintf('%s %s', EDGEGRIDV1ALGO,
join(';', CLIENT_TOKEN . $self->client->client_token(),
ACCESS_TOKEN . $self->client->access_token(),
TIMESTAMP_TOKEN . $self->timestamp(),
NONCE_TOKEN . $self->nonce(),
SIGNATURE_TOKEN . $self->signature()));
$self->debug->logger->debug("Setting Authorization header to $auth_header");
$self->request->header($header_name => $auth_header);
}
if(defined($self->signed_headers)) {
my $headers = $self->signed_headers;
$self->request->header($_ => $headers->{$_}) foreach(keys(%{$headers}));
}
};
lib/Akamai/Open/Request/EdgeGridV1.pm view on Meta::CPAN
my $content_hash = $self->content_hash;
# and the authorization header content
my $auth_header = sprintf('%s %s;', EDGEGRIDV1ALGO,
join(';', CLIENT_TOKEN . $self->client->client_token,
ACCESS_TOKEN . $self->client->access_token,
TIMESTAMP_TOKEN . $self->timestamp,
NONCE_TOKEN . $self->nonce));
# now create the token to sign
my $token = join("\t", $http_method, $http_scheme, $http_host, $http_uri, $http_headers, $content_hash, $auth_header);
$self->debug->logger->info("Signing token is $token");
if($self->debug->logger->is_debug()) {
my $dbg = $token;
$dbg =~ s#\t#\\t#g;
$self->debug->logger->debug("Quoted sigining token is $dbg");
}
# and sign the token
$self->debug->logger->info(sprintf('signing with key %s', $self->signing_key()));
my $tmp_stoken = encode_base64(hmac_sha256($token, $self->signing_key()));
chomp($tmp_stoken);
$self->signature($tmp_stoken);
return;
}
sub content_hash {
my $self = shift;
my $content_hash = '';
t/0002-debug.t view on Meta::CPAN
use Test::More;
BEGIN {
use_ok('Akamai::Open::Debug');
}
require_ok('Akamai::Open::Debug');
my $log_conf = q/
log4perl.category.Akamai.Open.Debug = DEBUG, Screen
log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 1
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern = %p %m
/;
my $debug = Akamai::Open::Debug->initialize(config => $log_conf);
my $clone = Akamai::Open::Debug->instance();
my @array = (1, 2, 'a', 'b');
# object tests
isa_ok($debug, 'Akamai::Open::Debug');
isa_ok($clone, 'Akamai::Open::Debug');
# functional tests
is($debug, $clone, 'test for a singleton object');
ok($debug->logger->debug('foo'), 'print a message of priority DEBUG');
ok($debug->logger->info('foo'), 'print a message of priority INFO');
ok($debug->logger->warn('foo'), 'print a message of priority WARN');
ok($debug->logger->error('foo'), 'print a message of priority ERROR');
ok($debug->logger->fatal('foo'), 'print a message of priority FATAL');
done_testing;
t/0007-signedrequest-extended.t view on Meta::CPAN
my $numtests = scalar @{$testdata->{tests}};
for my $test (@{$testdata->{tests}}) {
run_test($testdata, $test);
}
done_testing;
=head1 LICENSE AND COPYRIGHT
Copyright 2014 Akamai Technologies, Inc. All rights reserved
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
L<http://www.apache.org/licenses/LICENSE-2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
( run in 2.243 seconds using v1.01-cache-2.11-cpan-0371d4a6215 )