Skip to content

Commit

Permalink
Fix some OAuth related issues
Browse files Browse the repository at this point in the history
* Add logging for config issues
* oauth callback expiration should be milliseconds not microseconds
* Return on error early during oauth callback
* Prevent no config from throwing exception constructing string
  • Loading branch information
rockwood-openai authored and alex-q-chen committed Jul 3, 2024
1 parent e9a96ff commit 122678e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/kafka/ClientCommon.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <chrono>
#include <kafka/Project.h>

#include <kafka/Error.h>
Expand Down Expand Up @@ -32,7 +33,7 @@ namespace KAFKA_API { namespace clients {
using KeyValuePairs = std::map<std::string, std::string>;

std::string value;
std::chrono::microseconds mdLifetime{};
std::chrono::milliseconds mdLifetime{};
std::string mdPrincipalName;
KeyValuePairs extensions;
};
Expand Down
5 changes: 3 additions & 2 deletions include/kafka/KafkaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ KafkaClient::KafkaClient(ClientType clientType,
}
else
{
KAFKA_API_DO_LOG(Log::Level::Err, "failed to be initialized with property[%s:%s], result[%d]", k.c_str(), v->c_str(), result);
KAFKA_API_DO_LOG(Log::Level::Err, "failed to be initialized with property[%s:%s], result[%d]: %s", k.c_str(), v->c_str(), result, errInfo.c_str());
}
}

Expand Down Expand Up @@ -570,11 +570,12 @@ KafkaClient::oauthbearerTokenRefreshCallback(rd_kafka_t* rk, const char* oauthbe

try
{
oauthbearerToken = kafkaClient(rk).onOauthbearerTokenRefresh(oauthbearerConfig);
oauthbearerToken = kafkaClient(rk).onOauthbearerTokenRefresh(oauthbearerConfig != nullptr ? oauthbearerConfig : "");
}
catch (const std::exception& e)
{
rd_kafka_oauthbearer_set_token_failure(rk, e.what());
return;
}

LogBuffer<LOG_BUFFER_SIZE> errInfo;
Expand Down

0 comments on commit 122678e

Please sign in to comment.