Skip to content

Commit

Permalink
Merge pull request #231 from walt-id/deps-update_ktor
Browse files Browse the repository at this point in the history
deps-update_ktor
  • Loading branch information
waltkb authored Mar 1, 2023
2 parents 6ab7206 + 44b0e92 commit ee5f372
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 205 deletions.
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ dependencies {
implementation("org.json:json:20220924")
implementation("com.beust:klaxon:5.6")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.0")
implementation("io.ktor:ktor-client-jackson:2.1.3")
implementation("io.ktor:ktor-client-content-negotiation:2.1.3")
implementation("com.jayway.jsonpath:json-path:2.7.0")
implementation("com.networknt:json-schema-validator:1.0.73")
implementation("net.pwall.json:json-kotlin-schema:0.39")
Expand All @@ -72,11 +70,13 @@ dependencies {
implementation("io.minio:minio:8.4.6")

// HTTP
implementation("io.ktor:ktor-client-core:2.1.3")
implementation("io.ktor:ktor-client-cio:2.1.3")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.1.3")
implementation("io.ktor:ktor-client-logging:2.1.3")
implementation("io.github.rybalkinsd:kohttp:0.12.0")
implementation("io.ktor:ktor-client-jackson-jvm:2.2.4")
implementation("io.ktor:ktor-client-content-negotiation:2.2.4")
implementation("io.ktor:ktor-client-core-jvm:2.2.4")
//implementation("io.ktor:ktor-client-cio-jvm:2.2.4")
implementation("io.ktor:ktor-client-okhttp:2.2.4")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.2.4")
implementation("io.ktor:ktor-client-logging-jvm:2.2.4")

// REST
implementation("io.javalin:javalin:4.6.7")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions src/main/kotlin/id/walt/cli/AuthCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import com.github.ajalt.clikt.core.requireObject
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.prompt
import com.nimbusds.jwt.SignedJWT
import io.ktor.client.*
import id.walt.services.WaltIdServices.http
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.JsonObject
Expand Down Expand Up @@ -40,7 +39,8 @@ class AuthCommand : CliktCommand(
*/

runBlocking {
val client = HttpClient(CIO)
//val client = HttpClient(CIO)
val client = http
val token = client.post("https://api.walt.id/users/auth/login") {
setBody(mapOf("email" to email, "password" to password))
}.body<JsonObject>()["token"].toString()
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/id/walt/cli/GaiaxCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import id.walt.model.Did
import id.walt.model.DidMethod
import id.walt.model.gaiax.GaiaxCredentialGroup
import id.walt.model.gaiax.ParticipantVerificationResult
import id.walt.services.WaltIdServices.http
import id.walt.services.did.DidService
import id.walt.services.ecosystems.gaiax.GaiaxService
import id.walt.services.key.KeyService
Expand All @@ -19,9 +20,7 @@ import id.walt.signatory.ProofConfig
import id.walt.signatory.ProofType
import id.walt.signatory.Signatory
import id.walt.signatory.dataproviders.CLIDataProvider
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import kotlinx.coroutines.runBlocking
import java.nio.file.Path
Expand Down Expand Up @@ -197,7 +196,7 @@ class GaiaxVerifyCredentialGroupCommand : CliktCommand(
)

val verificationResult = runBlocking {
HttpClient(CIO).post("https://compliance.lab.gaia-x.eu/api/v2206/participant/verify/raw") {
http.post("https://compliance.lab.gaia-x.eu/api/v2206/participant/verify/raw") {
setBody(credentialGroup)
}.body<ParticipantVerificationResult>()
}
Expand Down
14 changes: 2 additions & 12 deletions src/main/kotlin/id/walt/common/CommonUtils.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
package id.walt.common

import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.contentnegotiation.*
import id.walt.services.WaltIdServices.http
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.runBlocking
import java.io.File


val client = HttpClient(CIO) {
install(ContentNegotiation) {
json()
}
}

fun resolveContent(fileUrlContent: String): String {
val file = File(fileUrlContent)
if (file.exists()) {
return file.readText()
}
if (Regex("^https?:\\/\\/.*$").matches(fileUrlContent)) {
return runBlocking { client.get(fileUrlContent).bodyAsText() }
return runBlocking { http.get(fileUrlContent).bodyAsText() }
}
return fileUrlContent
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/id/walt/model/oidc/IDToken.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package id.walt.model.oidc

import com.beust.klaxon.Json
import com.beust.klaxon.Klaxon
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.nimbusds.jwt.SignedJWT
import id.walt.common.KlaxonWithConverters
import id.walt.model.dif.PresentationSubmission
import id.walt.services.did.DidService
import id.walt.services.jwt.JwtService
import id.walt.services.keystore.KeyStoreService
import java.time.Instant

data class IDToken(
@Json("iss") val issuer: String = "https://self-issued.me/v2",
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/id/walt/services/WaltIdServices.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import com.sksamuel.hoplite.yaml.YamlParser
import com.zaxxer.hikari.HikariDataSource
import id.walt.Values
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.engine.okhttp.*
//import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.serialization.kotlinx.json.*
Expand All @@ -35,7 +36,8 @@ object WaltIdServices {
val httpLogging = false
private val log = KotlinLogging.logger {}

val http = HttpClient(CIO) {
//val http = HttpClient(CIO) {
val http = HttpClient(OkHttp) {
install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true })
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/id/walt/services/did/DidService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ object DidService {
vm.type
)
) {
log.error { "Key import does currently not support verification-key algorithm: ${vm.type}" }
log.warn { "Key import does currently not support verification-key algorithm: ${vm.type}" }
// TODO: support RSA and Secp256k1
return null
}
Expand All @@ -691,7 +691,7 @@ object DidService {
vm.type
)
) {
log.error { "Key import does currently not support verification-key algorithm: ${vm.type}" }
log.warn { "Key import does currently not support verification-key algorithm: ${vm.type}" }
// TODO: support RSA and Secp256k1
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package id.walt.services.ecosystems.cheqd
import id.walt.common.KlaxonWithConverters
import id.walt.model.did.DidCheqd
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import kotlinx.coroutines.runBlocking
Expand All @@ -20,7 +19,7 @@ object CheqdService {
fun resolveDid(did: String): DidCheqd {
log.debug { "Resolving did:cheqd, DID: $did" }
val resultText = runBlocking {
HttpClient(CIO).get("https://resolver.cheqd.net/1.0/identifiers/$did").bodyAsText()
HttpClient().get("https://resolver.cheqd.net/1.0/identifiers/$did").bodyAsText()
}

log.debug { "Received body from CHEQD resolver: $resultText" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package id.walt.services.ecosystems.gaiax

import id.walt.servicematrix.ServiceProvider
import id.walt.services.WaltIdService
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import id.walt.services.WaltIdServices.http
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
Expand Down Expand Up @@ -54,7 +53,7 @@ class WaltIdGaiaxService : GaiaxService() {
val complianceCredential = runCatching {

val complianceCredential = runBlocking {
val req = HttpClient(CIO).post("https://compliance.lab.gaia-x.eu/v2206/api/sign") {
val req = http.post("https://compliance.lab.gaia-x.eu/v2206/api/sign") {
contentType(ContentType.Application.Json)
setBody(selfDescription)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/id/walt/services/oidc/OIDC4VPService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ object OIDC4VPService {
}
// 2
?: OIDCUtils.getVCClaims(authReq).vp_token?.presentation_definition?.also {
customParameters.put(LEGACY_OIDC4VP_FLAG, listOf("true"))
customParameters[LEGACY_OIDC4VP_FLAG] = listOf("true")
}
// 3
?: (authReq.requestObject?.jwtClaimsSet?.getJSONObjectClaim("claims")
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/id/walt/signatory/RevocationClientService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import id.walt.services.WaltIdServices
import id.walt.signatory.RevocationService.RevocationResult
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
Expand Down Expand Up @@ -38,7 +37,7 @@ class WaltIdRevocationClientService : RevocationClientService() {

private val logger = KotlinLogging.logger("WaltIdRevocationClientService")

private val http = HttpClient(CIO) {
private val http = HttpClient {
install(ContentNegotiation) {
json()
}
Expand Down
24 changes: 9 additions & 15 deletions src/test/kotlin/id/walt/auditor/AuditorApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@ import id.walt.common.KlaxonWithConverters
import id.walt.credentials.w3c.toVerifiableCredential
import id.walt.model.DidMethod
import id.walt.servicematrix.ServiceMatrix
import id.walt.services.WaltIdServices
import id.walt.services.did.DidService
import id.walt.signatory.ProofConfig
import id.walt.signatory.Signatory
import id.walt.test.RESOURCES_PATH
import id.walt.test.readVerifiableCredential
import id.walt.test.readVerifiablePresentation
import io.github.rybalkinsd.kohttp.dsl.httpPost
import io.github.rybalkinsd.kohttp.ext.asString
import io.kotest.core.annotation.Ignored
import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.matchers.collections.shouldContainAll
import io.kotest.matchers.shouldBe
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import java.net.URL
import java.time.LocalDateTime
import java.time.ZoneOffset

Expand All @@ -44,7 +43,7 @@ class AuditorApiTest : AnnotationSpec() {

val DEFAULT_POLICIES = "SignaturePolicy, JsonSchemaPolicy"

val client = HttpClient(CIO) {
val client = HttpClient() {
install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true })
}
Expand Down Expand Up @@ -77,12 +76,9 @@ class AuditorApiTest : AnnotationSpec() {
}

private fun postAndVerify(vcToVerify: String, policyList: String = DEFAULT_POLICIES) {
val verificationResponseJson = httpPost {
host = Auditor_HOST
port = Auditor_API_PORT
path = "/v1/verify"
body {
json(
val verificationResponseJson = runBlocking {
WaltIdServices.http.post(URL("http", Auditor_HOST, Auditor_API_PORT, "/v1/verify")) {
setBody(
KlaxonWithConverters().toJsonString(
VerificationRequest(
policies = policyList.split(",").map { p -> PolicyRequest(policy = p.trim()) }.toList(),
Expand All @@ -92,8 +88,8 @@ class AuditorApiTest : AnnotationSpec() {
)
)
)
}
}.asString()!!
}.bodyAsText()
}

println(verificationResponseJson)

Expand All @@ -108,9 +104,7 @@ class AuditorApiTest : AnnotationSpec() {

val vcToVerify = signatory.issue(
"VerifiableId", ProofConfig(
subjectDid = did,
issuerDid = did,
issueDate = LocalDateTime.of(2020, 11, 3, 0, 0).toInstant(ZoneOffset.UTC)
subjectDid = did, issuerDid = did, issueDate = LocalDateTime.of(2020, 11, 3, 0, 0).toInstant(ZoneOffset.UTC)
)
)

Expand Down
4 changes: 1 addition & 3 deletions src/test/kotlin/id/walt/rest/CoreApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import id.walt.signatory.ProofConfig
import id.walt.test.RESOURCES_PATH
import id.walt.test.getTemplate
import id.walt.test.readCredOffer
import io.kotest.assertions.json.shouldEqualJson
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.data.blocking.forAll
Expand All @@ -32,7 +31,6 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
Expand All @@ -54,7 +52,7 @@ class CoreApiTest : AnnotationSpec() {
val CORE_API_URL = "http://localhost:7013"
val keyService = KeyService.getService()

val client = HttpClient(CIO) {
val client = HttpClient() {
install(ContentNegotiation) {
json()
}
Expand Down
15 changes: 9 additions & 6 deletions src/test/kotlin/id/walt/rest/CustodianApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import id.walt.rest.custodian.CustodianAPI
import id.walt.rest.custodian.ExportKeyRequest
import id.walt.rest.custodian.PresentCredentialsRequest
import id.walt.servicematrix.ServiceMatrix
import id.walt.services.WaltIdServices.http
import id.walt.services.did.DidService
import id.walt.services.key.KeyFormat
import id.walt.services.key.KeyService
Expand All @@ -28,7 +29,13 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.instanceOf
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.engine.cio.*
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.call.body
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
Expand All @@ -40,11 +47,7 @@ class CustodianApiTest : StringSpec({

ServiceMatrix("service-matrix.properties")

val client = HttpClient(CIO) {
install(ContentNegotiation) {
json()
}
}
val client = http

println("${CustodianAPI.DEFAULT_BIND_ADDRESS}/${CustodianAPI.DEFAULT_Custodian_API_PORT}")

Expand Down
11 changes: 2 additions & 9 deletions src/test/kotlin/id/walt/rest/EssifApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@ package id.walt.rest
import id.walt.rest.essif.EbsiTimestampRequest
import id.walt.rest.essif.EssifAPI
import id.walt.servicematrix.ServiceMatrix
import id.walt.services.WaltIdServices.http
import io.kotest.core.annotation.Ignored
import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldStartWith
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.runBlocking

@Ignored
class EssifApiTest : AnnotationSpec() {

val ESSIF_API_URL = "http://localhost:7012"

val client = HttpClient(CIO) {
install(ContentNegotiation) {
json()
}
}
val client = http

init {
ServiceMatrix("service-matrix.properties")
Expand Down
Loading

0 comments on commit ee5f372

Please sign in to comment.