diff --git a/kafka-2/main/no/nav/aap/kafka/streams/v2/config/SslConfig.kt b/kafka-2/main/no/nav/aap/kafka/streams/v2/config/SslConfig.kt index de0cf106..e5c0b15b 100644 --- a/kafka-2/main/no/nav/aap/kafka/streams/v2/config/SslConfig.kt +++ b/kafka-2/main/no/nav/aap/kafka/streams/v2/config/SslConfig.kt @@ -20,4 +20,14 @@ data class SslConfig( this[SslConfigs.SSL_KEY_PASSWORD_CONFIG] = credstorePsw this[SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG] = "" } + + companion object { + val DEFAULT: SslConfig by lazy { + SslConfig( + truststorePath = System.getenv("KAFKA_TRUSTSTORE_PATH"), + keystorePath = System.getenv("KAFKA_KEYSTORE_PATH"), + credstorePsw = System.getenv("KAFKA_CREDSTORE_PASSWORD") + ) + } + } } diff --git a/kafka-avroserde/main/no/nav/aap/kafka/schemaregistry/SchemaRegistryConfig.kt b/kafka-avroserde/main/no/nav/aap/kafka/schemaregistry/SchemaRegistryConfig.kt index b59caeb4..0635a15b 100644 --- a/kafka-avroserde/main/no/nav/aap/kafka/schemaregistry/SchemaRegistryConfig.kt +++ b/kafka-avroserde/main/no/nav/aap/kafka/schemaregistry/SchemaRegistryConfig.kt @@ -14,4 +14,14 @@ data class SchemaRegistryConfig( this[SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE] = "USER_INFO" this[SchemaRegistryClientConfig.USER_INFO_CONFIG] = "$user:$password" } + + companion object { + val DEFAULT: SchemaRegistryConfig by lazy { + SchemaRegistryConfig( + url = System.getenv("KAFKA_SCHEMA_REGISTRY"), + user = System.getenv("KAFKA_SCHEMA_REGISTRY_USER"), + password = System.getenv("KAFKA_SCHEMA_REGISTRY_PASSWORD"), + ) + } + } } diff --git a/kafka-avroserde/main/no/nav/aap/kafka/serde/avro/AvroSerde.kt b/kafka-avroserde/main/no/nav/aap/kafka/serde/avro/AvroSerde.kt index 800192fc..8b3fc380 100644 --- a/kafka-avroserde/main/no/nav/aap/kafka/serde/avro/AvroSerde.kt +++ b/kafka-avroserde/main/no/nav/aap/kafka/serde/avro/AvroSerde.kt @@ -5,28 +5,15 @@ import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde import no.nav.aap.kafka.schemaregistry.SchemaRegistryConfig import no.nav.aap.kafka.streams.v2.config.SslConfig import org.apache.avro.specific.SpecificRecord -import java.util.* object AvroSerde { - fun specific(): SpecificAvroSerde = SpecificAvroSerde().apply { - - // configureres før appen starter og kan ikke hentes fra KStreamsConfig eller KafkaConfig. - val schemaRegistry: Properties = SchemaRegistryConfig( - url = System.getenv("KAFKA_SCHEMA_REGISTRY"), - user = System.getenv("KAFKA_SCHEMA_REGISTRY_USER"), - password = System.getenv("KAFKA_SCHEMA_REGISTRY_PASSWORD"), - ).properties() - - // configureres før appen starter og kan ikke hentes fra KStreamsConfig eller KafkaConfig. - val ssl: Properties = SslConfig( - truststorePath = System.getenv("KAFKA_TRUSTSTORE_PATH"), - keystorePath = System.getenv("KAFKA_KEYSTORE_PATH"), - credstorePsw = System.getenv("KAFKA_CREDSTORE_PASSWORD") - ).properties() - - val avroProperties = schemaRegistry + ssl - val avroConfig = avroProperties.map { it.key.toString() to it.value.toString() } - configure(avroConfig.toMap(), false) + fun specific( + schema: SchemaRegistryConfig = SchemaRegistryConfig.DEFAULT, + ssl: SslConfig = SslConfig.DEFAULT, + ): SpecificAvroSerde = SpecificAvroSerde().apply { + val properties = schema.properties() + ssl.properties() + val serdeConfig = properties.mapKeys { it.key.toString() } + configure(serdeConfig, false) } fun generic() = GenericAvroSerde()