Akamai-Edgegrid
view release on metacpan or search on metacpan
lib/Akamai/Edgegrid.pm view on Meta::CPAN
sub _make_data_to_sign {
my ($self, $r, $auth_header) = @_;
my $data_to_sign = join("\t", (
$r->method,
$r->url->scheme,
$r->url->host,
$r->url->path_query,
$self->_canonicalize_headers($r),
$self->_make_content_hash($r),
$auth_header
));
my $display_to_sign = $data_to_sign;
$display_to_sign =~ s/\t/\\t/g;
$self->_debug("data to sign: $display_to_sign");
return $data_to_sign;
}
sub _sign_request {
my ($self, $r, $timestamp, $auth_header) = @_;
return _padded_hmac_sha256_base64(
$self->_make_data_to_sign($r, $auth_header),
$self->_make_signing_key($timestamp)
);
}
sub _make_auth_header {
my ($self, $r, $timestamp, $nonce) = @_;
my @kvps = (
['client_token' => $self->{client_token}],
['access_token' => $self->{access_token}],
['timestamp' => $timestamp],
['nonce' => $nonce]
);
my $auth_header = "EG1-HMAC-SHA256 " . join(';', map {
my ($k,$v) = @$_;
"$k=$v";
} @kvps) . ';';
$self->_debug("unsigned authorization header: $auth_header");
my $signed_auth_header =
$auth_header . 'signature=' . $self->_sign_request($r, $timestamp, $auth_header);
$self->_debug("signed authorization header: $signed_auth_header");
return $signed_auth_header;
}
=head1 CONSTRUCTOR METHOD
=over 2
=item $ua = Akamai::Edgegrid->new( %options )
This method constructs a new C<Akamai::EdgeGrid> object and returns it. This
is a subclass of C<LWP::UserAgent> and accepts all Key/value pair arguments
accepted by the parent class. In addition The following required key/value
pairs must be provided:
KEY SOURCE
------------- -----------------------------------------------
client_token from "Credentials" section of Manage APIs UI
client_secret from "Credentials" section of Manage APIs UI
access_token from "Authorizations" section of Manage APIs UI
The following optional key/value pairs may be provided:
KEY DESCRIPTION
--------------- -------------------------------------------------------
debug if true enables additional logging
headers_to_sign listref of header names to sign (in order) (default [])
max_body maximum body size for POSTS (default 2048)
=cut
sub new {
my $class = shift @_;
my %args = @_;
my @local_args = qw(config_file section client_token client_secret access_token headers_to_sign max_body debug);
my @required_args = qw(client_token client_secret access_token);
my @cred_args = qw(client_token client_secret access_token host);
my %local = ();
for my $arg (@local_args) {
$local{$arg} = delete $args{$arg};
}
my $self = LWP::UserAgent::new($class, %args);
for my $arg (@local_args) {
$self->{$arg} = $local{$arg};
}
# defaults
unless ($self->{config_file}) {
$self->{config_file} = "$ENV{HOME}/.edgerc";
}
if (-f $self->{config_file} and $self->{section} ) {
my $cfg = Config::IniFiles->new( -file => $self->{config_file} );
for my $variable (@cred_args) {
if ($cfg->val($self->{section}, $variable)) {
$self->{$variable} = $cfg->val($self->{section}, $variable);
} else {
die ("Config file " . $self->{config_file} .
" is missing required argument " . $variable .
" in section " . $self->{section} );
}
}
if ( $cfg->val($self->{section}, "max_body") ) {
$self->{max_body} = $cfg->val($self->{section}, "max_body");
}
}
for my $arg (@required_args) {
unless ($self->{$arg}) {
die "missing required argument $arg";
( run in 1.516 second using v1.01-cache-2.11-cpan-2398b32b56e )