« blib/lib/Google/Auth/Stores/FileTokenStore.pm
↑ Summary
blib/lib/Google/Auth/ServiceAccountCredentials.pm »
| 1 | # Copyright 2026 Google LLC and contributors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | package Google::Auth::RetryHelper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 15 | ▶ | use Google::Auth::Exceptions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 15 | ▶ | use Log::Any qw($log); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | sub execute_with_retry { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute_with_retry: called CC=10 SCAR=23.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | my ($class, $code, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | my $max_retries = $options{max_retries} // 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"max_retries"} // 3
MC/DC100%1/1
$options{"max_retries"} // 3
$options{"max_retries"}
Truth table100%2/2
A
A= $options{"max_retries"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | my $initial_delay = $options{initial_delay} // 1.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"initial_delay"} // 1
MC/DC100%1/1
$options{"initial_delay"} // 1
$options{"initial_delay"}
Truth table100%2/2
A
A= $options{"initial_delay"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | my $backoff_factor = $options{backoff_factor} // 2.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options{"backoff_factor"} // 2
MC/DC100%1/1
$options{"backoff_factor"} // 2
$options{"backoff_factor"}
Truth table100%2/2
A
A= $options{"backoff_factor"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | my $attempt = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | my $delay = $initial_delay; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | $attempt++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | my $res = eval { $code->() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | if ($attempt >= $max_retries) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | $log->errorf('Max retry attempts (%d/%d) reached. Throwing error: %s', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | $attempt, $max_retries, $err); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | die $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | if ( $err =~ /Credential file.*does not exist/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i or $err =~ /Invalid credential_source/i
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i
MC/DC0%0/4
$err =~ /Credential file.*does not exist/i or $err =~ /Missing required/i or $err =~ /Ambiguous/i or $err =~ /Invalid credential_source/i
$err =~ /Credential file.*does not exist/i
$err =~ /Missing required/i
$err =~ /Ambiguous/i
$err =~ /Invalid credential_source/i
Truth table20%1/5
A or B or C or D
A= $err =~ /Credential file.*does not exist/iB= $err =~ /Missing required/iC= $err =~ /Ambiguous/iD= $err =~ /Invalid credential_source/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | || $err =~ /Missing required/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | || $err =~ /Ambiguous/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | || $err =~ /Invalid credential_source/i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $log->errorf('Fatal un-retryable error encountered: %s. Propagating...', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | $err); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | die $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | $log->warnf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | 'Transient error on attempt %d/%d: %s. Retrying in %s seconds...', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | $attempt, $max_retries, $err, $delay); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | Time::HiRes::sleep($delay); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | $delay *= $backoff_factor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||