From 30ce43c29bd416856d6d39a0f884bdc85a1fbf4c Mon Sep 17 00:00:00 2001 From: Bastiaan Date: Thu, 23 May 2024 21:33:22 +0200 Subject: [PATCH 1/4] Fix authentication issue --- java-sdk/build.gradle.kts | 12 +++++++++--- java-sdk/buildSrc/src/main/kotlin/Versions.kt | 2 +- java-sdk/radar-schemas-registration/build.gradle.kts | 4 ---- .../radarbase/schema/registration/SchemaRegistry.kt | 9 ++++++--- java-sdk/radar-schemas-tools/build.gradle.kts | 4 ---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/java-sdk/build.gradle.kts b/java-sdk/build.gradle.kts index bb1c88b9..ac68d0ff 100644 --- a/java-sdk/build.gradle.kts +++ b/java-sdk/build.gradle.kts @@ -23,6 +23,12 @@ val githubIssueUrl = "https://github.com/$githubRepoName/issues" subprojects { apply(plugin = "org.radarbase.radar-kotlin") + repositories{ + mavenCentral() + gradlePluginPortal() + maven(url = "https://jitpack.io") + } + radarKotlin { javaVersion.set(Versions.java) kotlinVersion.set(Versions.kotlin) @@ -64,9 +70,9 @@ configure(listOf( githubUrl.set("https://github.com/$githubRepoName") developers { developer { - id.set("blootsvoets") - name.set("Joris Borgdorff") - email.set("joris@thehyve.nl") + id.set("bdegraaf1234") + name.set("Bastiaan de Graaf") + email.set("bastiaan@thehyve.nl") organization.set("The Hyve") } developer { diff --git a/java-sdk/buildSrc/src/main/kotlin/Versions.kt b/java-sdk/buildSrc/src/main/kotlin/Versions.kt index 500a6baa..3da93e40 100644 --- a/java-sdk/buildSrc/src/main/kotlin/Versions.kt +++ b/java-sdk/buildSrc/src/main/kotlin/Versions.kt @@ -5,7 +5,7 @@ object Versions { const val java = 17 const val avroGenerator = "1.9.1" - const val radarCommons = "1.1.2" + const val radarCommons = "1.1.3-SNAPSHOT" const val avro = "1.11.3" const val jackson = "2.16.1" const val argparse = "0.9.0" diff --git a/java-sdk/radar-schemas-registration/build.gradle.kts b/java-sdk/radar-schemas-registration/build.gradle.kts index e70db27b..8d398e6a 100644 --- a/java-sdk/radar-schemas-registration/build.gradle.kts +++ b/java-sdk/radar-schemas-registration/build.gradle.kts @@ -1,9 +1,5 @@ description = "RADAR Schemas specification and validation tools" -repositories { - maven(url = "https://jitpack.io") -} - dependencies { api(project(":radar-schemas-commons")) api(project(":radar-schemas-core")) diff --git a/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt b/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt index 3728f5e5..ede1c83a 100644 --- a/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt +++ b/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt @@ -15,6 +15,8 @@ */ package org.radarbase.schema.registration +import io.ktor.client.HttpClient +import io.ktor.client.engine.cio.CIO import io.ktor.client.plugins.auth.Auth import io.ktor.client.plugins.auth.providers.BasicAuthCredentials import io.ktor.client.plugins.auth.providers.basic @@ -44,6 +46,7 @@ import org.radarcns.kafka.ObservationKey import org.slf4j.LoggerFactory import java.io.IOException import java.net.MalformedURLException +import java.net.URI import java.time.Duration import kotlin.streams.asSequence import kotlin.time.Duration.Companion.seconds @@ -62,7 +65,7 @@ class SchemaRegistry( private val topicConfiguration: Map = emptyMap(), ) { private val schemaClient: SchemaRetriever = schemaRetriever(baseUrl) { - httpClient { + httpClient = HttpClient(CIO) { timeout(10.seconds) if (apiKey != null && apiSecret != null) { install(Auth) { @@ -94,7 +97,7 @@ class SchemaRegistry( .mapNotNull { try { httpClient.request> { - url("subjects") + url(URI(baseUrl).resolve("subjects").toString()) if (apiKey != null && apiSecret != null) { basicAuth(apiKey, apiSecret) } @@ -224,7 +227,7 @@ class SchemaRegistry( logger.info("Setting compatibility to {}", compatibility) return try { httpClient.requestEmpty { - url("config") + url(URI(baseUrl).resolve("config").toString()) method = HttpMethod.Put contentType(ContentType("application", "vnd.schemaregistry.v1+json")) setBody("{\"compatibility\": \"${compatibility.name}\"}") diff --git a/java-sdk/radar-schemas-tools/build.gradle.kts b/java-sdk/radar-schemas-tools/build.gradle.kts index e48fd8e1..03904060 100644 --- a/java-sdk/radar-schemas-tools/build.gradle.kts +++ b/java-sdk/radar-schemas-tools/build.gradle.kts @@ -1,9 +1,5 @@ description = "RADAR Schemas specification and validation tools." -repositories { - maven(url = "https://jitpack.io") -} - dependencies { implementation(project(":radar-schemas-registration")) implementation(platform("com.fasterxml.jackson:jackson-bom:${Versions.jackson}")) From 267bd197ee5cc4f4f2482853af26d873efa0977f Mon Sep 17 00:00:00 2001 From: Bastiaan Date: Mon, 10 Jun 2024 14:04:19 +0200 Subject: [PATCH 2/4] Bump to 0.8.10-SNAPSHOT --- java-sdk/buildSrc/src/main/kotlin/Versions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-sdk/buildSrc/src/main/kotlin/Versions.kt b/java-sdk/buildSrc/src/main/kotlin/Versions.kt index 9702c2b0..fcbb114c 100644 --- a/java-sdk/buildSrc/src/main/kotlin/Versions.kt +++ b/java-sdk/buildSrc/src/main/kotlin/Versions.kt @@ -1,5 +1,5 @@ object Versions { - const val project = "0.8.9" + const val project = "0.8.10-SNAPSHOT" const val kotlin = "1.9.10" const val java = 17 From dea9da5880a3b52be3de2244abd826d3c60dd75d Mon Sep 17 00:00:00 2001 From: Bastiaan Date: Wed, 12 Jun 2024 14:11:12 +0200 Subject: [PATCH 3/4] Add a test to see if basic-authentication is really passed to the schemaregistry and it's webrequests --- .editorconfig | 20 ++--- java-sdk/buildSrc/src/main/kotlin/Versions.kt | 2 +- .../build.gradle.kts | 1 + .../schema/registration/SchemaRegistry.kt | 5 +- .../schema/registration/SchemaRegistryTest.kt | 87 +++++++++++++++++++ 5 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 java-sdk/radar-schemas-registration/src/test/java/org/radarbase/schema/registration/SchemaRegistryTest.kt diff --git a/.editorconfig b/.editorconfig index 40e3f9b5..30c675e0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,20 +5,20 @@ root = true # Unix-style newlines with a newline ending every file [*] +end_of_line = lf insert_final_newline = true +charset = utf-8 indent_style = space -indent_size = 2 -trim_trailing_whitespace = true +indent_size = 4 -# Markdown -[*.md] -trim_trailing_whitespace = false +[{*.yml, *.yaml}] +indent_size = 2 -# Gradle [*.gradle] indent_size = 4 -# Java -[*.{java,kt,kts}] -indent_size = 4 -continuation_indent_size = 8 +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma_on_call_site = true +ij_kotlin_allow_trailing_comma = true +# To satisfy ktlint rules, see: https://stackoverflow.com/questions/59849619/intellij-does-not-sort-kotlin-imports-according-to-ktlints-expectations +ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^ \ No newline at end of file diff --git a/java-sdk/buildSrc/src/main/kotlin/Versions.kt b/java-sdk/buildSrc/src/main/kotlin/Versions.kt index fcbb114c..a46e36c5 100644 --- a/java-sdk/buildSrc/src/main/kotlin/Versions.kt +++ b/java-sdk/buildSrc/src/main/kotlin/Versions.kt @@ -5,7 +5,7 @@ object Versions { const val java = 17 const val avroGenerator = "1.9.1" - const val radarCommons = "1.1.3-SNAPSHOT" + const val radarCommons = "1.1.2" const val avro = "1.11.3" const val jackson = "2.16.1" const val argparse = "0.9.0" diff --git a/java-sdk/radar-schemas-registration/build.gradle.kts b/java-sdk/radar-schemas-registration/build.gradle.kts index 8d398e6a..146785eb 100644 --- a/java-sdk/radar-schemas-registration/build.gradle.kts +++ b/java-sdk/radar-schemas-registration/build.gradle.kts @@ -13,4 +13,5 @@ dependencies { implementation("org.apache.kafka:connect-json:${Versions.kafka}") implementation("io.ktor:ktor-client-auth:${Versions.ktor}") + testImplementation("com.squareup.okhttp3:mockwebserver:${Versions.okHttp}") } diff --git a/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt b/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt index ede1c83a..bdc1f549 100644 --- a/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt +++ b/java-sdk/radar-schemas-registration/src/main/java/org/radarbase/schema/registration/SchemaRegistry.kt @@ -46,7 +46,6 @@ import org.radarcns.kafka.ObservationKey import org.slf4j.LoggerFactory import java.io.IOException import java.net.MalformedURLException -import java.net.URI import java.time.Duration import kotlin.streams.asSequence import kotlin.time.Duration.Companion.seconds @@ -97,7 +96,7 @@ class SchemaRegistry( .mapNotNull { try { httpClient.request> { - url(URI(baseUrl).resolve("subjects").toString()) + url("subjects") if (apiKey != null && apiSecret != null) { basicAuth(apiKey, apiSecret) } @@ -227,7 +226,7 @@ class SchemaRegistry( logger.info("Setting compatibility to {}", compatibility) return try { httpClient.requestEmpty { - url(URI(baseUrl).resolve("config").toString()) + url("config") method = HttpMethod.Put contentType(ContentType("application", "vnd.schemaregistry.v1+json")) setBody("{\"compatibility\": \"${compatibility.name}\"}") diff --git a/java-sdk/radar-schemas-registration/src/test/java/org/radarbase/schema/registration/SchemaRegistryTest.kt b/java-sdk/radar-schemas-registration/src/test/java/org/radarbase/schema/registration/SchemaRegistryTest.kt new file mode 100644 index 00000000..7c4d55a4 --- /dev/null +++ b/java-sdk/radar-schemas-registration/src/test/java/org/radarbase/schema/registration/SchemaRegistryTest.kt @@ -0,0 +1,87 @@ +package org.radarbase.schema.registration + +import io.ktor.http.HttpHeaders +import kotlinx.coroutines.runBlocking +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.MockWebServer +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.radarbase.schema.registration.SchemaRegistry.Compatibility.FORWARD +import org.radarbase.topic.AvroTopic +import org.radarcns.kafka.ObservationKey +import org.radarcns.passive.phone.PhoneAcceleration + +class SchemaRegistryTest { + private var server = MockWebServer() + private val expectedAuthHeader = "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" + lateinit var schemaRegistry: SchemaRegistry + + @BeforeEach + fun setUpClass() { + schemaRegistry = SchemaRegistry( + server.url("/").toString(), + "username", + "password", + ) + + val mockresponse = + MockResponse() + .setHeader(HttpHeaders.ContentType, "application/json") + .setBody( + """ + { + "id": 1 + } + """.trimIndent(), + ) + + server.enqueue(mockresponse) + server.enqueue(mockresponse) + } + + @AfterEach + fun tearDown() { + server.shutdown() + } + + @Test + fun registerSchema() { + // Create an instance of AvroTopic + val avroTopic = AvroTopic( + "test", + ObservationKey.getClassSchema(), + PhoneAcceleration.getClassSchema(), + ObservationKey::class.java, + PhoneAcceleration::class.java, + ) + + runBlocking { + // Register the schema + schemaRegistry.registerSchema(avroTopic) + + // Get the request that was received by the MockWebServer + val request = server.takeRequest() + + // Verify the Basic Auth credentials + val authHeader = request.getHeader("Authorization") + assertEquals(expectedAuthHeader, authHeader) + } + } + + @Test + fun putCompatibility() { + runBlocking { + // Register the schema + schemaRegistry.putCompatibility(compatibility = FORWARD) + + // Get the request that was received by the MockWebServer + val request = server.takeRequest() + + // Verify the Basic Auth credentials + val authHeader = request.getHeader("Authorization") + assertEquals(expectedAuthHeader, authHeader) + } + } +} From 10414045196766757602354ec1bc319be136589e Mon Sep 17 00:00:00 2001 From: Bastiaan Date: Mon, 10 Jun 2024 14:20:33 +0200 Subject: [PATCH 4/4] Remove snapshot versions --- java-sdk/buildSrc/src/main/kotlin/Versions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-sdk/buildSrc/src/main/kotlin/Versions.kt b/java-sdk/buildSrc/src/main/kotlin/Versions.kt index a46e36c5..3ec38247 100644 --- a/java-sdk/buildSrc/src/main/kotlin/Versions.kt +++ b/java-sdk/buildSrc/src/main/kotlin/Versions.kt @@ -1,5 +1,5 @@ object Versions { - const val project = "0.8.10-SNAPSHOT" + const val project = "0.8.10" const val kotlin = "1.9.10" const val java = 17