fix(primera-restapi): retry authentication when the token is invalid/expired (#5267)

Co-authored-by: Roman Morandell <46994680+rmorandell-pgum@users.noreply.github.com>

Refs: CTOR-1032
This commit is contained in:
omercier 2024-10-31 17:46:04 +01:00 committed by GitHub
parent fe581afd0b
commit 790c96d3ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

View File

@ -175,6 +175,21 @@ sub request_api {
critical_status => ''
);
# Maybe token is invalid. so we retry
if (!defined($token) || $self->{http}->get_code() >= 400) {
$self->clean_token();
$token = $self->get_token();
$content = $self->{http}->request(
url_path => $options{endpoint},
get_param => $get_param,
header => [ 'X-HP3PAR-WSAPI-SessionKey: ' . $token ],
unknown_status => $self->{unknown_http_status},
warning_status => $self->{warning_http_status},
critical_status => $self->{critical_http_status}
);
}
if (!defined($content) || $content eq '') {
$self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();