Skip to content

Commit

Permalink
Merge pull request #369 from RADAR-base/fix_schema_registry_basicauth
Browse files Browse the repository at this point in the history
Fix basic authentication during schema registry init
  • Loading branch information
Bdegraaf1234 authored Mar 20, 2024
2 parents bdc4a4f + e2a0174 commit d3b07b2
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.radarbase.schema.registration
import io.ktor.client.plugins.auth.Auth
import io.ktor.client.plugins.auth.providers.BasicAuthCredentials
import io.ktor.client.plugins.auth.providers.basic
import io.ktor.client.request.basicAuth
import io.ktor.client.request.setBody
import io.ktor.client.request.url
import io.ktor.http.ContentType
Expand Down Expand Up @@ -56,8 +57,8 @@ import kotlin.time.toKotlinDuration
*/
class SchemaRegistry(
private val baseUrl: String,
apiKey: String? = null,
apiSecret: String? = null,
private val apiKey: String? = null,
private val apiSecret: String? = null,
private val topicConfiguration: Map<String, TopicConfig> = emptyMap(),
) {
private val schemaClient: SchemaRetriever = schemaRetriever(baseUrl) {
Expand All @@ -66,6 +67,7 @@ class SchemaRegistry(
if (apiKey != null && apiSecret != null) {
install(Auth) {
basic {
sendWithoutRequest { true }
credentials {
BasicAuthCredentials(username = apiKey, password = apiSecret)
}
Expand Down Expand Up @@ -93,6 +95,9 @@ class SchemaRegistry(
try {
httpClient.request<List<String>> {
url("subjects")
if (apiKey != null && apiSecret != null) {
basicAuth(apiKey, apiSecret)
}
}
} catch (ex: RestException) {
logger.error(
Expand Down Expand Up @@ -175,6 +180,7 @@ class SchemaRegistry(
val record: SpecificRecord = AvroTopic.parseSpecificRecord(topicValueSchema)
record.javaClass to record.schema
}

defaultTopic != null -> defaultTopic.valueClass to defaultTopic.valueSchema
else -> {
logger.warn(
Expand Down

0 comments on commit d3b07b2

Please sign in to comment.