From 4c80b523e1ccbc9a2bc84d1de8e3c91ff8d21fb6 Mon Sep 17 00:00:00 2001 From: sanderPostma Date: Wed, 3 Jul 2024 14:03:00 +0200 Subject: [PATCH 1/9] chore: extract ktor version --- modules/openid-federation-common/build.gradle.kts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/openid-federation-common/build.gradle.kts b/modules/openid-federation-common/build.gradle.kts index 2bc918dd..62762b20 100644 --- a/modules/openid-federation-common/build.gradle.kts +++ b/modules/openid-federation-common/build.gradle.kts @@ -9,6 +9,8 @@ plugins { kotlin("plugin.serialization") version "2.0.0" } +val ktorVersion = "2.3.11" + kotlin { @OptIn(ExperimentalWasmDsl::class) @@ -47,7 +49,7 @@ kotlin { sourceSets { val commonMain by getting { dependencies { - implementation("io.ktor:ktor-client-core:2.3.11") + implementation("io.ktor:ktor-client-core:$ktorVersion") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.0") } @@ -60,7 +62,7 @@ kotlin { } val jvmMain by getting { dependencies { - implementation("io.ktor:ktor-client-cio:2.3.11") + implementation("io.ktor:ktor-client-core-jvm:$ktorVersion") } } val jvmTest by getting { @@ -71,7 +73,7 @@ kotlin { val androidMain by getting { dependencies { - implementation("io.ktor:ktor-client-okhttp:2.3.11") + implementation("io.ktor:ktor-client-core-jvm:$ktorVersion") } } val androidUnitTest by getting { @@ -83,7 +85,7 @@ kotlin { val iosMain by creating { dependsOn(commonMain) dependencies { - implementation("io.ktor:ktor-client-ios:2.3.11") + implementation("io.ktor:ktor-client-ios:$ktorVersion") } } val iosX64Main by getting { @@ -105,7 +107,7 @@ kotlin { val jsMain by getting { dependencies { - implementation("io.ktor:ktor-client-js:2.3.11") + implementation("io.ktor:ktor-client-js:$ktorVersion") } } From 1639346fb5ba13e3e42fc57f4bf7a214d3ae85ad Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Tue, 9 Jul 2024 23:49:43 +0530 Subject: [PATCH 2/9] Feature/oidf 32 postgres docker (#7) * Added Spring boot with status API * chores: PR feedback * Updated the server name in gradle module * Added test for status endpoint and added README * Enabled test run on gradle build * Added Postgres and docker * Added environment file * Updated env variable * Fixed merge conflicts * Updated CI for GitHub secrets * Added docker in GitHub action * Added env variable for docker in GitHub action * Removed Windows in GitHub action * Added comment for removing Windows in CI * Removed hardcoded path from run script * fix: make admin server load env variables from root .env file (#10) * chore: fix project name * chore: extract ktor version * fix: temporarily hardcode db credentials * fix: import .env variables from file * fix: adjust ci file to new docker compose dir --------- Co-authored-by: sanderPostma --------- Co-authored-by: John Melati Co-authored-by: sanderPostma --- .env | 4 ++++ .fleet/run.json | 2 +- .github/workflows/ci.yml | 15 +++++++++++- .gitignore | 2 ++ docker-compose.yaml | 23 +++++++++++++++++++ gradle/libs.versions.toml | 2 ++ modules/admin-server/README.md | 7 ++++++ modules/admin-server/build.gradle.kts | 2 ++ .../src/main/resources/application.properties | 9 +++++++- 9 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .env create mode 100644 docker-compose.yaml diff --git a/.env b/.env new file mode 100644 index 00000000..34ab61a8 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +DATASOURCE_URL=jdbc:postgresql://localhost:5432/openid-federation-db +DATASOURCE_USER=openid-federation-db-user +DATASOURCE_PASSWORD=openid-federation-db-password +DATASOURCE_DB=openid-federation-db \ No newline at end of file diff --git a/.fleet/run.json b/.fleet/run.json index f360fcd9..a523f1a3 100644 --- a/.fleet/run.json +++ b/.fleet/run.json @@ -1,7 +1,7 @@ { "configurations": [ { - "name": "OpenID-Federation [:server:build]", + "name": "OpenID-Federation [:admin-server:build]", "type": "gradle", "workingDir": "$PROJECT_DIR$", "tasks": [ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9acc12e1..73b95060 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,9 @@ jobs: gradle: strategy: matrix: - os: [ ubuntu-latest, windows-latest ] + # Removed windows, because build failing with docker network. "bridge" network driver is not supported for Windows containers + # os: [ ubuntu-latest, windows-latest ] + os: [ ubuntu-latest ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -16,6 +18,13 @@ jobs: distribution: adopt-hotspot java-version: 17 + - name: Build the stack + run: docker-compose -f docker-compose.yaml up -d + env: + DATASOURCE_USER: ${{ secrets.DATASOURCE_USER }} + DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} + - name: Setup Gradle uses: gradle/gradle-build-action@v3 @@ -25,3 +34,7 @@ jobs: - name: Execute Gradle build run: ./gradlew build + env: + DATASOURCE_USER: ${{ secrets.DATASOURCE_USER }} + DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} diff --git a/.gitignore b/.gitignore index f0e9e76a..161fec79 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ captures /platforms/ /platform-tools/ /.temp/ +/docker/.env +/.run/* diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..af8db708 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,23 @@ +version: '3.9' + +services: + db: + image: postgres:latest + container_name: openid-federation-datastore + environment: + POSTGRES_USER: ${DATASOURCE_USER} + POSTGRES_PASSWORD: ${DATASOURCE_PASSWORD} + POSTGRES_DB: openid-federation-db + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + networks: + - openid_network + +networks: + openid_network: + driver: bridge + +volumes: + postgres_data: \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8f2751ea..7a25a76a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -33,8 +33,10 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" } springboot-actuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator" } springboot-web = { group = "org.springframework.boot", name = "spring-boot-starter-web" } +springboot-data-jdbc = { group = "org.springframework.boot", name = "spring-boot-starter-data-jdbc" } springboot-devtools = { group = "org.springframework.boot", name = "spring-boot-devtools" } springboot-test = { group = "org.springframework.boot", name = "spring-boot-starter-test" } +postgres = { module = "org.postgresql:postgresql" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } diff --git a/modules/admin-server/README.md b/modules/admin-server/README.md index 5081c690..aecd1dbb 100644 --- a/modules/admin-server/README.md +++ b/modules/admin-server/README.md @@ -6,6 +6,13 @@ API
+Add environment file (.env) with following properties +``` +DATASOURCE_USER= +DATASOURCE_PASSWORD= +DATASOURCE_URL= +``` + To build
```./gradlew :modules:admin-server:build``` diff --git a/modules/admin-server/build.gradle.kts b/modules/admin-server/build.gradle.kts index d7e90794..b1def3cc 100644 --- a/modules/admin-server/build.gradle.kts +++ b/modules/admin-server/build.gradle.kts @@ -18,8 +18,10 @@ java { dependencies { implementation(libs.springboot.actuator) implementation(libs.springboot.web) + implementation(libs.springboot.data.jdbc) implementation(libs.kotlin.reflect) testImplementation(libs.springboot.test) + runtimeOnly(libs.postgres) runtimeOnly(libs.springboot.devtools) } diff --git a/modules/admin-server/src/main/resources/application.properties b/modules/admin-server/src/main/resources/application.properties index 79c568ef..683495f2 100644 --- a/modules/admin-server/src/main/resources/application.properties +++ b/modules/admin-server/src/main/resources/application.properties @@ -1,5 +1,12 @@ +spring.config.import=optional:file:../../.env[.properties] + spring.application.name=OpenID Federation +spring.datasource.url=${DATASOURCE_URL} +spring.datasource.username=${DATASOURCE_USER} +spring.datasource.password=${DATASOURCE_PASSWORD} +spring.datasource.driver-class-name=org.postgresql.Driver + # Mapping /actuator/health to /status management.endpoints.web.base-path=/ -management.endpoints.web.path-mapping.health=status +management.endpoints.web.path-mapping.health=status \ No newline at end of file From 90d7466e7ef7732edf7c4f62047b81d218d315f6 Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Wed, 10 Jul 2024 09:44:05 +0200 Subject: [PATCH 3/9] chore: Fixed versioning --- modules/openapi/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi/build.gradle.kts b/modules/openapi/build.gradle.kts index 37f06fa7..832d0d63 100644 --- a/modules/openapi/build.gradle.kts +++ b/modules/openapi/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "com.sphereon.oid.fed" -version = "1.0-SNAPSHOT" +version = "0.1.0-SNAPSHOT" project.extra.set("openApiPackage", "com.sphereon.oid.fed.openapi") From 353a7d66717993c0339d41569e889034023b8012 Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Wed, 10 Jul 2024 10:03:37 +0200 Subject: [PATCH 4/9] bugfix: Fixed Open Api specs file path --- modules/openapi/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi/build.gradle.kts b/modules/openapi/build.gradle.kts index 832d0d63..13adedba 100644 --- a/modules/openapi/build.gradle.kts +++ b/modules/openapi/build.gradle.kts @@ -25,7 +25,7 @@ openApiGenerate { packageName.set("com.sphereon.oid.fed.openapi") apiPackage.set("$openApiPackage.api") modelPackage.set("$openApiPackage.models") - inputSpec.set("$rootDir/src/main/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml") + inputSpec.set("$projectDir/src/main/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml") library.set("jvm-okhttp4") configOptions.set( mapOf( From 593a8a4fb780dc57142239d51d892625cec1c9dc Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Tue, 16 Jul 2024 11:15:10 +0200 Subject: [PATCH 5/9] refactor: Fixed the profiles section of the documentation --- modules/openapi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi/README.md b/modules/openapi/README.md index 339b4ea6..efe2a4eb 100644 --- a/modules/openapi/README.md +++ b/modules/openapi/README.md @@ -12,7 +12,7 @@ Immediate Subordinate Entities called Subordinate Statements. ### Profiles -The Open API generator will generate only models, infrastructures and apis by default. To make it generate apis. To make +The Open API generator will generate models, infrastructures and apis by default. To make it generate models only uncomment `profiles=models-only` from gradle.properties or pass the profile in the comment line. ### Run Open API generator From 057e7dc6aced5462481b9457849831f3c6a16223 Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Tue, 16 Jul 2024 23:27:49 +0200 Subject: [PATCH 6/9] refactor: Added fat jat and maven publication to local repository --- modules/openapi/build.gradle.kts | 46 ++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/modules/openapi/build.gradle.kts b/modules/openapi/build.gradle.kts index 13adedba..583ab1d6 100644 --- a/modules/openapi/build.gradle.kts +++ b/modules/openapi/build.gradle.kts @@ -1,6 +1,7 @@ plugins { kotlin("jvm") version "2.0.0" - id("org.openapi.generator") version "6.2.1" + id("org.openapi.generator") version "6.6.0" + id("maven-publish") } group = "com.sphereon.oid.fed" @@ -10,13 +11,18 @@ project.extra.set("openApiPackage", "com.sphereon.oid.fed.openapi") val profiles = project.properties["profiles"]?.toString()?.split(",") ?: emptyList() val isModelsOnlyProfile = profiles.contains("models-only") +val ktorVersion = "2.3.11" repositories { mavenCentral() } dependencies { - testImplementation(kotlin("test")) + implementation("io.ktor:ktor-client-core:$ktorVersion") + implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion") + implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.0") } openApiGenerate { @@ -26,8 +32,9 @@ openApiGenerate { apiPackage.set("$openApiPackage.api") modelPackage.set("$openApiPackage.models") inputSpec.set("$projectDir/src/main/kotlin/com/sphereon/oid/fed/openapi/openapi.yaml") - library.set("jvm-okhttp4") - configOptions.set( + library.set("multiplatform") + outputDir.set("$projectDir/build/generated") +configOptions.set( mapOf( "dateLibrary" to "java8", "serializationLibrary" to "jackson" @@ -45,21 +52,32 @@ openApiGenerate { } } -tasks.jar { - dependsOn(tasks.openApiGenerate) - archiveBaseName.set(project.name) - from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) -} -sourceSets { - main { - java.srcDirs("build/generated/sources/openapi/src/main/kotlin") +publishing { + publications { + create("mavenKotlin") { + from(components["kotlin"]) + } } } -tasks.test { - useJUnitPlatform() +tasks.compileKotlin { + dependsOn(tasks.openApiGenerate) +} + +tasks.jar { + dependsOn(tasks.compileKotlin) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + archiveBaseName.set(project.name) + from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) + from("$projectDir/build/classes/kotlin/main") } + kotlin { + sourceSets.main { + kotlin.srcDirs( + "$projectDir/build/generated/src/commonMain/kotlin" + ) + } jvmToolchain(21) } From 7258a024d03cb9e45c5b291c1510d2be8b4cf432 Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Thu, 18 Jul 2024 17:31:18 +0200 Subject: [PATCH 7/9] refactor: changed to string the value of the dateTimeLibrary property --- modules/openapi/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi/build.gradle.kts b/modules/openapi/build.gradle.kts index 583ab1d6..053ee59d 100644 --- a/modules/openapi/build.gradle.kts +++ b/modules/openapi/build.gradle.kts @@ -36,7 +36,7 @@ openApiGenerate { outputDir.set("$projectDir/build/generated") configOptions.set( mapOf( - "dateLibrary" to "java8", + "dateLibrary" to "string", "serializationLibrary" to "jackson" ) ) From 88db3a12c14f961e492ee4d520d7d4b5abc0c693 Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Fri, 19 Jul 2024 13:25:39 +0200 Subject: [PATCH 8/9] refactor: Upgraded OpenAPI generator and removed unneeded serialization configuration --- modules/openapi/build.gradle.kts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/openapi/build.gradle.kts b/modules/openapi/build.gradle.kts index 053ee59d..d8e95628 100644 --- a/modules/openapi/build.gradle.kts +++ b/modules/openapi/build.gradle.kts @@ -1,6 +1,6 @@ plugins { kotlin("jvm") version "2.0.0" - id("org.openapi.generator") version "6.6.0" + id("org.openapi.generator") version "7.7.0" id("maven-publish") } @@ -36,8 +36,7 @@ openApiGenerate { outputDir.set("$projectDir/build/generated") configOptions.set( mapOf( - "dateLibrary" to "string", - "serializationLibrary" to "jackson" + "dateLibrary" to "string" ) ) From fc14070e69dd4ae5ebe6a1541b46878fe9524a4f Mon Sep 17 00:00:00 2001 From: Robert Mathew Date: Mon, 22 Jul 2024 11:56:59 +0530 Subject: [PATCH 9/9] OIDF -31: Added Kermit logging library (#12) * Added Kermit logging * Added logger class and added dependency in admin-server * fix: adding env parameter for logging * chores: removed logger env --- gradle/libs.versions.toml | 2 ++ modules/admin-server/build.gradle.kts | 3 ++- modules/openid-federation-common/README.md | 12 +++++++++ .../openid-federation-common/build.gradle.kts | 1 + .../sphereon/oid/fed/common/logging/Logger.kt | 26 +++++++++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 modules/openid-federation-common/README.md create mode 100644 modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/logging/Logger.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7a25a76a..19b09680 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,6 +16,7 @@ kotlin = "2.0.0" kotlinxSerializationJson = "1.7.0-RC" springboot = "3.3.1" springDependencyManagement = "1.1.5" +kermitLogging = "2.0.4" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -29,6 +30,7 @@ androidx-material = { group = "com.google.android.material", name = "material", androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" } +kermit-logging = { module = "co.touchlab:kermit", version.ref = "kermitLogging"} kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" } springboot-actuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator" } diff --git a/modules/admin-server/build.gradle.kts b/modules/admin-server/build.gradle.kts index b1def3cc..8abb8cef 100644 --- a/modules/admin-server/build.gradle.kts +++ b/modules/admin-server/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "com.sphereon.oid.fed.server.admin" -version = "1.0.0" +version = "0.0.1" java { toolchain { @@ -16,6 +16,7 @@ java { } dependencies { + api(projects.modules.openidFederationCommon) implementation(libs.springboot.actuator) implementation(libs.springboot.web) implementation(libs.springboot.data.jdbc) diff --git a/modules/openid-federation-common/README.md b/modules/openid-federation-common/README.md new file mode 100644 index 00000000..cd400ec4 --- /dev/null +++ b/modules/openid-federation-common/README.md @@ -0,0 +1,12 @@ +# Open Federation common + +
+ +Usage of Logger +``` +Logger.verbose("TAG", "Verbose log") +Logger.debug("TAG", "Debug log") +Logger.info("TAG", "Info log") +Logger.warn("TAG", "Warn log") +Logger.error("TAG", "Error log", exception) +``` \ No newline at end of file diff --git a/modules/openid-federation-common/build.gradle.kts b/modules/openid-federation-common/build.gradle.kts index 62762b20..678dcc90 100644 --- a/modules/openid-federation-common/build.gradle.kts +++ b/modules/openid-federation-common/build.gradle.kts @@ -52,6 +52,7 @@ kotlin { implementation("io.ktor:ktor-client-core:$ktorVersion") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.0") + implementation(libs.kermit.logging) } } val commonTest by getting { diff --git a/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/logging/Logger.kt b/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/logging/Logger.kt new file mode 100644 index 00000000..a9669633 --- /dev/null +++ b/modules/openid-federation-common/src/commonMain/kotlin/com/sphereon/oid/fed/common/logging/Logger.kt @@ -0,0 +1,26 @@ +package com.sphereon.oid.fed.common.logging + +import co.touchlab.kermit.Logger + +object Logger { + + fun verbose(tag: String, message: String) { + Logger.v(tag = tag, messageString = message) + } + + fun debug(tag: String, message: String) { + Logger.d(tag = tag, messageString = message) + } + + fun info(tag: String, message: String) { + Logger.i(tag = tag, messageString = message) + } + + fun warn(tag: String, message: String) { + Logger.w(tag = tag, messageString = message) + } + + fun error(tag: String, message: String, throwable: Throwable? = null) { + Logger.e(tag = tag, messageString = message, throwable = throwable) + } +} \ No newline at end of file