-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
285 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/waterdrop/instrumentation/callbacks/oauthbearer_token_refresh.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module WaterDrop | ||
module Instrumentation | ||
module Callbacks | ||
# Callback that is triggered when oauth token needs to be refreshed. | ||
class OauthbearerTokenRefresh | ||
# @param bearer [Rdkafka::Producer] given rdkafka instance. It is needed as | ||
# we need to have a reference to call `#oauthbearer_set_token` or | ||
# `#oauthbearer_set_token_failure` upon the event. | ||
# @param monitor [WaterDrop::Instrumentation::Monitor] monitor we are using | ||
def initialize(bearer, monitor) | ||
@bearer = bearer | ||
@monitor = monitor | ||
end | ||
|
||
# Upon receiving of this event, user is required to invoke either `#oauthbearer_set_token` | ||
# or `#oauthbearer_set_token_failure` on the `event[:bearer]` depending whether token | ||
# obtaining was successful or not. | ||
# | ||
# Please refer to WaterDrop and Karafka documentation or `Rdkafka::Helpers::OAuth` | ||
# documentation directly for exact parameters of those methods. | ||
# | ||
# @param _rd_config [Rdkafka::Config] | ||
# @param bearer_name [String] name of the bearer for which we refresh | ||
def call(_rd_config, bearer_name) | ||
return unless @bearer.name == bearer_name | ||
|
||
@monitor.instrument( | ||
'oauthbearer.token_refresh', | ||
bearer: @bearer, | ||
caller: self | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.