blib/lib/Net/Azure/Authorization/SAS.pm

filter: Statementstmt 100% 51 / 51 Branchbran 100% 4 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 94.6% 71 / 75 SCAR 13.9
CC
4
Cov
97%
new
3.1
token
2.0
BEGIN
1.0
CRAP 4.0
↑ Summary Build »
1 package Net::Azure::Authorization::SAS;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = "0.02";
7 2 our $DEFAULT_TOKEN_EXPIRE = 3600;
8  
9 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use URI::Escape 'uri_escape';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Digest::SHA 'hmac_sha256';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use MIME::Base64 'encode_base64';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use String::CamelCase 'decamelize';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 use Class::Accessor::Lite (
16 2 new => 0,
17 ro => [qw[
18 connection_string
19 endpoint
20 shared_access_key_name
21 shared_access_key
22 expire
23 ]],
24 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 sub new {
27 2 ▶ my ($class, %param) = @_;
Subroutine new: called CC=3 SCAR=11.2
Pod documented
28 2 ▶ croak 'connection_string is required' if !defined $param{connection_string};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param{"connection_string"} 1 1 2
29 1 ▶ $param{expire} ||= $DEFAULT_TOKEN_EXPIRE;
Condition33%1/3
$param{"expire"} ||= $Net::Azure::Authorization::SAS::DEFAULT_TOKEN_EXPIRE
l!l&&r!l&&!r
010
MC/DC0%0/2
$param{"expire"} ||= $Net::Azure::Authorization::SAS::DEFAULT_TOKEN_EXPIRE
$param{"expire"} $Net::Azure::Authorization::SAS::DEFAULT_TOKEN_EXPIRE
Truth table33%1/3
A ||= B
A= $param{"expire"}B= $Net::Azure::Authorization::SAS::DEFAULT_TOKEN_EXPIRE
ABresult
1X1
011
000
30 1 %param = (%param, $class->_parse_connection_string($param{connection_string}));
31 1 bless {%param}, $class;
32 }
33  
34 sub _parse_connection_string {
35 1 ▶ my ($class, $string) = @_;
Subroutine _parse_connection_string: called CC=1 SCAR=0.0
36 1 my %parsed = (map {split '=', $_, 2} split(';', $string));
37 1 ( map {(decamelize($_) => $parsed{$_})} keys %parsed );
38 }
39  
40 sub token {
41 2 ▶ my ($self, $url) = @_;
Subroutine token: called CC=2 SCAR=6.9
Pod documented
42 2 ▶ croak 'An url for token is required' if !defined $url;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 1 1 2
43 1 my $uri = URI->new($url);
44 1 my $target_uri = lc(uri_escape(lc(sprintf("%s://%s%s", $uri->scheme, $uri->host, $uri->path))));
45 1 my $expire_time = time + $self->expire;
46 1 my $to_sign = "$target_uri\n$expire_time";
47 1 my $signature = encode_base64(hmac_sha256($to_sign, $self->shared_access_key));
48 1 chomp $signature;
49 1 sprintf 'SharedAccessSignature sr=%s&sig=%s&se=%s&skn=%s', $target_uri, uri_escape($signature), $expire_time, $self->shared_access_key_name;
50 }
51  
52 2 1;
53 __END__
↑ Summary Build »