Skip to content

Commit

Permalink
Merge pull request #71 from dw-kihara/fix/keep_prev_when_refresh_fails
Browse files Browse the repository at this point in the history
Keep previous credentials when refresh fails
  • Loading branch information
onno-vos-dev authored May 22, 2024
2 parents 09634b5 + 5947c04 commit 62247a3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/aws_credentials.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ handle_cast(Message, State) ->
-spec handle_info(any(), state()) -> {'noreply', state()}.
handle_info(refresh_credentials, State) ->
ProviderOptions = application:get_env(aws_credentials, provider_options, #{}),
{ok, C, T} = fetch_credentials(ProviderOptions),
{noreply, State#state{credentials=C, tref=T}};
case fetch_credentials(ProviderOptions) of
{ok, undefined, T} -> {noreply, State#state{tref=T}};
{ok, C, T} -> {noreply, State#state{credentials=C, tref=T}}
end;
handle_info(Message, State) ->
?LOG_WARNING("Unknown message: ~p~n", [Message], #{domain => [aws_credentials]}),
{noreply, State}.
Expand Down Expand Up @@ -193,7 +195,8 @@ fetch_credentials(Options) ->
{ok, undefined, setup_callback(?RETRY_DELAY)}
end.

undefined_or_fail(true) -> true;
-spec undefined_or_fail(boolean()) -> undefined | no_return().
undefined_or_fail(true) -> undefined;
undefined_or_fail(false) -> error(no_credentials).

-spec setup_update_callback('infinity' | binary() | integer()) -> reference().
Expand Down

0 comments on commit 62247a3

Please sign in to comment.