From c303a904eebc0123ae3bf5822b44a4391de50b1d Mon Sep 17 00:00:00 2001 From: John Melati Date: Wed, 13 Nov 2024 18:15:44 +0100 Subject: [PATCH] Feature/oidf 65 2 (#45) --- .docker/prod-deployment/build.sh | 7 ++++-- .docker/prod-deployment/version-config.sh | 23 +++++++++++++------ gradle/libs.versions.toml | 4 ++-- modules/logger/build.gradle.kts | 6 +++++ .../oid/fed/client/mapper/JsonMapper.kt | 4 ++-- .../oid/fed/client/trustchain/TrustChain.kt | 6 +++-- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/.docker/prod-deployment/build.sh b/.docker/prod-deployment/build.sh index 96c2a23e..6c322441 100644 --- a/.docker/prod-deployment/build.sh +++ b/.docker/prod-deployment/build.sh @@ -1,6 +1,9 @@ #!/bin/bash -source ./version-config.sh +if ! source ./version-config.sh; then + echo "Error: Failed to source version-config.sh" + exit 1 +fi docker build -t ${FED_IMAGE}:${FED_VERSION} -f ../federation-server/Dockerfile ../../ -docker build -t ${ADMIN_IMAGE}:${ADMIN_VERSION} -f ../admin-server/Dockerfile ../../ +docker build -t ${ADMIN_IMAGE}:${FED_VERSION} -f ../admin-server/Dockerfile ../../ diff --git a/.docker/prod-deployment/version-config.sh b/.docker/prod-deployment/version-config.sh index 541e6c5c..595ce4c0 100644 --- a/.docker/prod-deployment/version-config.sh +++ b/.docker/prod-deployment/version-config.sh @@ -3,22 +3,31 @@ # Function to extract version from gradle file get_version() { local gradle_file=$1 + if [ ! -f "$gradle_file" ]; then + echo "Error: Gradle file not found: $gradle_file" >&2 + exit 1 + fi + local version=$(grep -m 1 "version = " "$gradle_file" | cut -d'"' -f2) if [ -z "$version" ]; then - echo "Could not find version in $gradle_file" + echo "Error: Could not find version in $gradle_file" >&2 exit 1 fi echo "$version" } # Base paths -MODULES_PATH="../../modules" +MODULES_PATH="../../" REGISTRY="sphereonregistry.azurecr.io" -# Get versions -FED_VERSION=$(get_version "${MODULES_PATH}/federation-server/build.gradle.kts") -ADMIN_VERSION=$(get_version "${MODULES_PATH}/admin-server/build.gradle.kts") +# Get versions with error handling +FED_VERSION=$(get_version "${MODULES_PATH}/build.gradle.kts") || exit 1 # Image names -FED_IMAGE="federation-server" -ADMIN_IMAGE="federation-admin-server" +FED_IMAGE="${REGISTRY}/federation-server" +ADMIN_IMAGE="${REGISTRY}/federation-admin-server" + +# Export variables +export FED_VERSION +export FED_IMAGE +export ADMIN_IMAGE diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5ceb00ef..7fa3e99e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ androidx-test-junit = "1.1.5" compose-plugin = "1.6.10" junit = "4.13.2" kotlin = "2.0.0" -ktor = "2.3.11" +ktor = "2.3.12" kotlinxSerialization = "1.7.1" kotlinxCoroutines = "1.8.0" springboot = "3.3.1" @@ -84,4 +84,4 @@ kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } springboot = { id = "org.springframework.boot", version.ref = "springboot" } springDependencyManagement = { id = "io.spring.dependency-management", version.ref = "springDependencyManagement" } -kotlinPluginSpring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" } \ No newline at end of file +kotlinPluginSpring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" } diff --git a/modules/logger/build.gradle.kts b/modules/logger/build.gradle.kts index 138444fb..a0c1bfcf 100644 --- a/modules/logger/build.gradle.kts +++ b/modules/logger/build.gradle.kts @@ -20,5 +20,11 @@ kotlin { implementation(libs.kermit.logging) } } + + val jsMain by getting { + dependencies { + implementation(libs.kermit.logging) + } + } } } diff --git a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/mapper/JsonMapper.kt b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/mapper/JsonMapper.kt index d3d43505..0165fc9c 100644 --- a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/mapper/JsonMapper.kt +++ b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/mapper/JsonMapper.kt @@ -34,8 +34,8 @@ fun decodeJWTComponents(jwtToken: String): JWT { throw InvalidJwtException("Invalid JWT format: Expected 3 parts, found ${parts.size}") } - val headerJson = Base64.decode(parts[0]).decodeToString() - val payloadJson = Base64.decode(parts[1]).decodeToString() + val headerJson = Base64.UrlSafe.decode(parts[0]).decodeToString() + val payloadJson = Base64.UrlSafe.decode(parts[1]).decodeToString() return try { JWT( diff --git a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt index f17d95c6..c78c273c 100644 --- a/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt +++ b/modules/openid-federation-client/src/commonMain/kotlin/com/sphereon/oid/fed/client/trustchain/TrustChain.kt @@ -31,7 +31,8 @@ class TrustChain val chain: MutableList = arrayListOf() return try { buildTrustChainRecursive(entityIdentifier, trustAnchors, chain, cache, 0, maxDepth) - } catch (_: Exception) { + } catch (e: Exception) { + TrustChainConst.LOG.error("buildTrustChainRecursive failed", e) // Log error null } @@ -198,7 +199,8 @@ class TrustChain if (result != null) return result chain.removeLast() } - } catch (_: Exception) { + } catch (e: Exception) { // TODO distinguish between remote HTTP errors and internal errors + TrustChainConst.LOG.error("no trust", e) return null }