Skip to content

Commit

Permalink
refactor(rdkafka): make ENABLE_REFRESH_OAUTH_TOKEN a function (#207)
Browse files Browse the repository at this point in the history
* make `ENABLE_REFRESH_OAUTH_TOKEN` a function

Signed-off-by: Runji Wang <[email protected]>

* ci: update setup-protoc to v3

Signed-off-by: Runji Wang <[email protected]>

* fix clippy on the latest stable toolchain

Signed-off-by: Runji Wang <[email protected]>

---------

Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 authored May 7, 2024
1 parent cccdc33 commit e1f6d8b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/toolchain@v1
Expand All @@ -71,7 +71,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/toolchain@v1
Expand All @@ -93,7 +93,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/toolchain@v1
Expand All @@ -114,7 +114,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/toolchain@v1
Expand All @@ -132,7 +132,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/toolchain@v1
Expand Down
2 changes: 1 addition & 1 deletion madsim-etcd-client/src/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl ProclaimOptions {
}

/// Leader key of election
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct LeaderKey {
pub(crate) name: Bytes,
pub(crate) key: Bytes,
Expand Down
2 changes: 1 addition & 1 deletion madsim-rdkafka/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim-rdkafka"
version = "0.3.4+0.34.0"
version = "0.4.0+0.34.0"
edition = "2021"
authors = ["Runji Wang <[email protected]>"]
description = "The rdkafka simulator on madsim."
Expand Down
4 changes: 3 additions & 1 deletion madsim-rdkafka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Replace all `rdkafka` entries in your Cargo.toml:

```toml
[dependencies]
rdkafka = { version = "0.3", package = "madsim-rdkafka" }
rdkafka = { version = "0.4", package = "madsim-rdkafka" }
```

## API Modification
Expand Down Expand Up @@ -47,6 +47,8 @@ The following functions are modified to be `async`:

[^1]: wrapped in `tokio::task::spawn_blocking`

The associated constant `ClientContext::ENABLE_REFRESH_OAUTH_TOKEN` is changed to a function in order to make the trait object-safe.

## DNS Resolution

This crate has cherry-picked [a commit] from Materialize to support rewriting broker addresses.
Expand Down
8 changes: 5 additions & 3 deletions madsim-rdkafka/src/std/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ pub trait ClientContext: Send + Sync + 'static {
///
/// This parameter is only relevant when using the `OAUTHBEARER` SASL
/// mechanism.
const ENABLE_REFRESH_OAUTH_TOKEN: bool = false;
fn enable_refresh_oauth_token(&self) -> bool {
false
}

/// Receives log lines from librdkafka.
///
Expand Down Expand Up @@ -134,7 +136,7 @@ pub trait ClientContext: Send + Sync + 'static {
///
/// Override with an appropriate implementation when using the `OAUTHBEARER`
/// SASL authentication mechanism. For this method to be called, you must
/// also set [`ClientContext::ENABLE_REFRESH_OAUTH_TOKEN`] to true.
/// also set [`ClientContext::enable_refresh_oauth_token`] to true.
///
/// The `fmt::Display` implementation of the returned error must not
/// generate a message with an embedded null character.
Expand Down Expand Up @@ -275,7 +277,7 @@ impl<C: ClientContext> Client<C> {
>,
);
}
if C::ENABLE_REFRESH_OAUTH_TOKEN {
if context.enable_refresh_oauth_token() {
unsafe {
rdsys::rd_kafka_conf_set_oauthbearer_token_refresh_cb(
native_config.ptr(),
Expand Down
4 changes: 3 additions & 1 deletion madsim-rdkafka/src/std/producer/future_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ pub type OwnedDeliveryResult = Result<(i32, i64), (KafkaError, OwnedMessage)>;

// Delegates all the methods calls to the wrapped context.
impl<C: ClientContext + 'static> ClientContext for FutureProducerContext<C> {
const ENABLE_REFRESH_OAUTH_TOKEN: bool = C::ENABLE_REFRESH_OAUTH_TOKEN;
fn enable_refresh_oauth_token(&self) -> bool {
self.wrapped_context.enable_refresh_oauth_token()
}

fn log(&self, level: RDKafkaLogLevel, fac: &str, log_message: &str) {
self.wrapped_context.log(level, fac, log_message);
Expand Down
2 changes: 2 additions & 0 deletions madsim-rdkafka/src/std/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ impl fmt::Display for ErrBuf {
}
}

#[allow(dead_code)]
pub(crate) trait WrappedCPointer {
type Target;

Expand Down Expand Up @@ -324,6 +325,7 @@ where
}
}

#[allow(dead_code)]
pub(crate) struct OnDrop<F>(pub F)
where
F: Fn();
Expand Down
6 changes: 3 additions & 3 deletions madsim/src/sim/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl FromStr for Config {
}

/// Print the config into TOML.
impl ToString for Config {
fn to_string(&self) -> String {
toml::to_string_pretty(self).unwrap()
impl std::fmt::Display for Config {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", toml::to_string_pretty(self).unwrap())
}
}

Expand Down

0 comments on commit e1f6d8b

Please sign in to comment.