Skip to content

Commit

Permalink
set token failure on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-szalwinski-he committed May 5, 2024
1 parent 6244d01 commit 6cb6aa3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
18 changes: 12 additions & 6 deletions examples/rdkafka/oauth_token_refresher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@
class OAuthTokenRefresher
def refresh_token(client_name)
print "refreshing token\n"
client = Producer.from_name(client_name)
signer = AwsMskIamSaslSigner::MSKTokenProvider.new(region: ENV.fetch("AWS_REGION", nil))
token = signer.generate_auth_token

client = Producer.from_name(client_name)
client.oauthbearer_set_token(
token: token.token,
lifetime_ms: token.expiration_time_ms,
principal_name: "kafka-cluster"
)
if token
client.oauthbearer_set_token(
token: token.token,
lifetime_ms: token.expiration_time_ms,
principal_name: "kafka-cluster"
)
else
client.oauthbearer_set_token_failure(
"Failed to generate token."
)
end
end
end

Expand Down
19 changes: 13 additions & 6 deletions examples/waterdrop/oauth_token_refresher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

class OAuthTokenRefresher
def on_oauthbearer_token_refresh(event)
print "refreshing token\n"

signer = AwsMskIamSaslSigner::MSKTokenProvider.new(region: ENV.fetch("AWS_REGION", nil))
token = signer.generate_auth_token

event[:bearer].oauthbearer_set_token(
token: token.token,
lifetime_ms: token.expiration_time_ms,
principal_name: "kafka-cluster"
)
if token
event[:bearer].oauthbearer_set_token(
token: token.token,
lifetime_ms: token.expiration_time_ms,
principal_name: "kafka-cluster"
)
else
event[:bearer].oauthbearer_set_token_failure(
"Failed to generate token."
)
end
end
end

0 comments on commit 6cb6aa3

Please sign in to comment.