-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SASL config properties sugar function to ConsumerSettings
#1226
base: series/3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,23 @@ ConsumerSettings( | |
.withGroupId("group") | ||
``` | ||
|
||
### Sasl setting | ||
|
||
When interacting with a Kafka host requiring authentication via SASL (Confluent Cloud, for example), you can use the `withPlainSasl` sugar function: | ||
|
||
```scala mdoc:silent | ||
ConsumerSettings( | ||
keyDeserializer = Deserializer[IO, String], | ||
valueDeserializer = Deserializer[IO, String] | ||
).withAutoOffsetReset(AutoOffsetReset.Earliest) | ||
.withBootstrapServers("pkc-instanceName.us-west1.gcp.confluent.cloud:9092") | ||
.withGroupId("group") | ||
.withPlainSasl( | ||
<idToken>, | ||
<passwordToken> | ||
Comment on lines
+137
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I don't think mentioning token is needed. Also, here you are using |
||
) | ||
``` | ||
|
||
[`ConsumerSettings`][consumersettings] provides functions for configuring both the Java Kafka consumer and options specific to the library. If functions for configuring certain properties of the Java Kafka consumer is missing, we can instead use `withProperty` or `withProperties` together with constants from [`ConsumerConfig`][consumerconfig]. Available properties for the Java Kafka consumer are described in the [documentation](http://kafka.apache.org/documentation/#consumerconfigs). | ||
|
||
### Default Settings | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -9,7 +9,9 @@ package fs2.kafka | |||||||
import cats.Show | ||||||||
import cats.effect.Resource | ||||||||
import fs2.kafka.security.KafkaCredentialStore | ||||||||
import org.apache.kafka.clients.CommonClientConfigs | ||||||||
import org.apache.kafka.clients.consumer.ConsumerConfig | ||||||||
import org.apache.kafka.common.config.SaslConfigs | ||||||||
import org.apache.kafka.common.requests.OffsetFetchResponse | ||||||||
|
||||||||
import scala.concurrent.ExecutionContext | ||||||||
|
@@ -401,6 +403,12 @@ sealed abstract class ConsumerSettings[F[_], K, V] { | |||||||
* Includes the credentials properties from the provided [[KafkaCredentialStore]] | ||||||||
*/ | ||||||||
def withCredentials(credentialsStore: KafkaCredentialStore): ConsumerSettings[F, K, V] | ||||||||
|
||||||||
/** | ||||||||
* provides SASL credentials to Kafka host. A typical use case for this would be | ||||||||
* interacting with Confluent Cloud. | ||||||||
Comment on lines
+408
to
+409
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel the second sentence is not needed. A user should be aware of what SASL is at this point (either by reading the docs or because he/she knows what's doing).
Suggested change
|
||||||||
*/ | ||||||||
def withPlainSasl(usernameToken: String, passwordToken: String): ConsumerSettings[F, K, V] | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be a new |
||||||||
} | ||||||||
|
||||||||
object ConsumerSettings { | ||||||||
|
@@ -417,6 +425,15 @@ object ConsumerSettings { | |||||||
override val recordMetadata: ConsumerRecord[K, V] => String, | ||||||||
override val maxPrefetchBatches: Int | ||||||||
) extends ConsumerSettings[F, K, V] { | ||||||||
|
||||||||
def withPlainSasl(usernameToken: String, passwordToken: String): ConsumerSettings[F, K, V] = | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've never worked with SASL but from what I can see here in Why not removing that prefix? 👇🏽
Suggested change
|
||||||||
withProperties( | ||||||||
SaslConfigs.SASL_MECHANISM -> "PLAIN", | ||||||||
SaslConfigs.SASL_JAAS_CONFIG -> | ||||||||
s"""org.apache.kafka.common.security.plain.PlainLoginModule required username="${usernameToken}" password="${passwordToken}";""", | ||||||||
CommonClientConfigs.SECURITY_PROTOCOL_CONFIG -> "SASL_SSL" | ||||||||
) | ||||||||
|
||||||||
override def withCustomBlockingContext(ec: ExecutionContext): ConsumerSettings[F, K, V] = | ||||||||
copy(customBlockingContext = Some(ec)) | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.