| 1 | 14 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | 14 | ▶ | use feature 'class'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 14 | ▶ | no warnings 'experimental::class'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use Azure::SDK::Core::Policy; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 14 | class Azure::SDK::Core::Policy::Diagnostics :isa(Azure::SDK::Core::Policy) { | |||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 14 | field $enabled :param :reader = 1; | |||||||||||||||||||||||||||||||||
| 11 | 14 | field $logger :param :reader = undef; | |||||||||||||||||||||||||||||||||
| 12 | 14 | field $id_generator :param = undef; | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 77 | ▶ | ADJUST { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 15 | 77 | ▶ | $id_generator //= \&_default_request_id; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$id_generator //= \&Azure::SDK::Core::Policy::Diagnostics::_default_request_id
MC/DC0%0/1
$id_generator //= \&Azure::SDK::Core::Policy::Diagnostics::_default_request_id
$id_generator
Truth table50%1/2
A
A= $id_generator
| |||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 118 | ▶ | method send ($context, $request, $next) { | ||||||||||||||||||||||||||||||||
|
Subroutine
send: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 19 | 118 | ▶ | my $request_id = $context->request_id | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
($context->request_id // $request->header("x-ms-client-request-id")) // &$id_generator()
$context->request_id // $request->header("x-ms-client-request-id")
MC/DC0%0/3
($context->request_id // $request->header("x-ms-client-request-id")) // &$id_generator()
$context->request_id
$request->header("x-ms-client-request-id")
&$id_generator()
Truth table50%2/4
A // B // C
A= $context->request_idB= $request->header("x-ms-client-request-id")C= &$id_generator()
| |||||||||||||||||||||||||||||||||||
| 20 | // $request->header('x-ms-client-request-id') | ||||||||||||||||||||||||||||||||||
| 21 | // $id_generator->(); | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 118 | $context->set_request_id($request_id); | |||||||||||||||||||||||||||||||||
| 24 | 118 | $request->set_header('x-ms-client-request-id', $request_id); | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 118 | ▶ | $self->_log("request $request_id @{[ $request->method ]} @{[ _redact_url($request->url) ]}") | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 27 | if $enabled; | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 118 | my $response = $next->($context, $request); | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 118 | ▶ | $self->_log("response $request_id status @{[ $response->status ]}") | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | if $enabled; | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | 118 | return $response; | |||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 22 | ▶ | method _log ($line) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_log: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 38 | 22 | ▶ | return unless defined $logger; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 22 | $logger->($line); | |||||||||||||||||||||||||||||||||
| 40 | 22 | return; | |||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 11 | ▶ | sub _redact_url ($url) { | ||||||||||||||||||||||||||||||||
|
Subroutine
_redact_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 44 | 11 | $url =~ s/\?.*\z/?[redacted]/s; | |||||||||||||||||||||||||||||||||
| 45 | 11 | return $url; | |||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | # NOTE (SAST: cryptographically weak PRNG): this UUID-shaped value is a | ||||||||||||||||||||||||||||||||||
| 49 | # correlation id (x-ms-client-request-id) only, never a token, key, nonce, or | ||||||||||||||||||||||||||||||||||
| 50 | # anti-CSRF value, so non-cryptographic rand is intentional. Do not copy this | ||||||||||||||||||||||||||||||||||
| 51 | # generator into a security-sensitive context. If a CSPRNG dependency ever | ||||||||||||||||||||||||||||||||||
| 52 | # arrives for an unrelated need, swap it in via the id_generator parameter. | ||||||||||||||||||||||||||||||||||
| 53 | 116 | ▶ | sub _default_request_id () { | ||||||||||||||||||||||||||||||||
|
Subroutine
_default_request_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 54 | 116 | my @hex = map { sprintf '%04x', int rand 0x10000 } 1 .. 8; | |||||||||||||||||||||||||||||||||
| 55 | 116 | return sprintf '%s%s-%s-4%s-%x%s-%s%s%s', | |||||||||||||||||||||||||||||||||
| 56 | $hex[0], $hex[1], $hex[2], | ||||||||||||||||||||||||||||||||||
| 57 | substr($hex[3], 1), | ||||||||||||||||||||||||||||||||||
| 58 | 8 + int(rand 4), substr($hex[4], 1), | ||||||||||||||||||||||||||||||||||
| 59 | $hex[5], $hex[6], $hex[7]; | ||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 14 | 1; | |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||||||||