Skip to content

Commit

Permalink
cleanup (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
waltkb authored Jun 7, 2023
2 parents bfc1c44 + 9c19393 commit 2b60242
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 70 deletions.
3 changes: 0 additions & 3 deletions src/main/kotlin/id/walt/auditor/Auditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import id.walt.services.WaltIdService
import mu.KotlinLogging
import java.util.concurrent.atomic.*


private val log = KotlinLogging.logger {}


abstract class Auditor : WaltIdService() {
override val implementation: Auditor get() = serviceImplementation()

Expand All @@ -36,7 +34,6 @@ class WaltIdAuditor : Auditor() {
}

override fun verify(vc: VerifiableCredential, policies: List<VerificationPolicy>): VerificationResult {

val policyResults = policies.associateBy(keySelector = VerificationPolicy::id) { policy ->
log.debug { "Verifying vc with ${policy.id} ..." }

Expand Down
76 changes: 40 additions & 36 deletions src/main/kotlin/id/walt/auditor/AuditorRestAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,53 @@ object AuditorRestAPI {
var auditorApi: Javalin? = null

fun start(port: Int = AUDITOR_API_PORT, bindAddress: String = BIND_ADDRESS, apiTargetUrls: List<String> = listOf()) {

auditorApi = Javalin.create {

it.apply {
registerPlugin(RouteOverviewPlugin("/api-routes"))

registerPlugin(OpenApiPlugin(OpenApiOptions(InitialConfigurationCreator {
OpenAPI().apply {
info {
title = "walt.id Auditor API"
description = "The walt.id public API documentation"
contact = Contact().apply {
name = "walt.id"
url = "https://walt.id"
email = "[email protected]"
}
version = Values.version
}
servers = listOf(
Server().url("/"),
*apiTargetUrls.map { Server().url(it) }.toTypedArray()
)
externalDocs {
description = "walt.id Docs"
url = "https://docs.walt.id"
}
registerPlugin(
OpenApiPlugin(
OpenApiOptions(
InitialConfigurationCreator {
OpenAPI().apply {
info {
title = "walt.id Auditor API"
description = "The walt.id public API documentation"
contact = Contact().apply {
name = "walt.id"
url = "https://walt.id"
email = "[email protected]"
}
version = Values.version
}
servers = listOf(
Server().url("/"),
*apiTargetUrls.map { Server().url(it) }.toTypedArray()
)
externalDocs {
description = "walt.id Docs"
url = "https://docs.walt.id"
}

components {
securityScheme {
name = "bearerAuth"
type = SecurityScheme.Type.HTTP
scheme = "bearer"
`in` = SecurityScheme.In.HEADER
description = "HTTP Bearer Token authentication"
bearerFormat = "JWT"
components {
securityScheme {
name = "bearerAuth"
type = SecurityScheme.Type.HTTP
scheme = "bearer"
`in` = SecurityScheme.In.HEADER
description = "HTTP Bearer Token authentication"
bearerFormat = "JWT"
}
}
}
}
).apply {
path("/v1/api-documentation")
swagger(SwaggerOptions("/v1/swagger").title("walt.id Auditor API"))
reDoc(ReDocOptions("/v1/redoc").title("walt.id Auditor API"))
}
}
}).apply {
path("/v1/api-documentation")
swagger(SwaggerOptions("/v1/swagger").title("walt.id Auditor API"))
reDoc(ReDocOptions("/v1/redoc").title("walt.id Auditor API"))
}))
)
)
}

it.enableCorsForAllOrigins()
Expand Down
16 changes: 12 additions & 4 deletions src/main/kotlin/id/walt/auditor/PolicyRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open class PolicyFactory<P : VerificationPolicy, A : Any>(
open fun create(argument: Any? = null): P {
try {
return argType?.let {
if(optionalArgument) {
if (optionalArgument) {
argument?.let {
return policyType.primaryConstructor!!.call(it)
}
Expand All @@ -50,7 +50,10 @@ class DynamicPolicyFactory(
name: String,
description: String?
) : PolicyFactory<DynamicPolicy, JsonObject>(
DynamicPolicy::class, JsonObject::class, name, description
DynamicPolicy::class,
JsonObject::class,
name,
description
) {
override fun create(argument: Any?): DynamicPolicy {
val mergedInput = if (argument != null) {
Expand All @@ -76,7 +79,12 @@ object PolicyRegistry {

val defaultPolicyId: String = delegate.defaultPolicyId

fun <P : ParameterizedVerificationPolicy<A>, A : Any> register(policy: KClass<P>, argType: KClass<A>, description: String? = null, optionalArgument: Boolean = false) =
fun <P : ParameterizedVerificationPolicy<A>, A : Any> register(
policy: KClass<P>,
argType: KClass<A>,
description: String? = null,
optionalArgument: Boolean = false
) =
delegate.register(policy, argType, description, optionalArgument)

fun <P : SimpleVerificationPolicy> register(policy: KClass<P>, description: String? = null) =
Expand All @@ -93,7 +101,7 @@ object PolicyRegistry {
fun getPolicyWithJsonArg(id: String, argumentJson: JsonObject?): VerificationPolicy =
delegate.getPolicyWithJsonArg(id, argumentJson)

fun getPolicyWithJsonArg(id: String, argumentJson: String?): VerificationPolicy =
fun getPolicyWithJsonArg(id: String, argumentJson: String?): VerificationPolicy =
delegate.getPolicyWithJsonArg(id, argumentJson)

fun isMutable(name: String): Boolean =
Expand Down
28 changes: 17 additions & 11 deletions src/main/kotlin/id/walt/auditor/PolicyRegistryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import java.io.StringReader
import java.util.concurrent.atomic.*
import kotlin.reflect.KClass

open class PolicyRegistryService: WaltIdService() {
open class PolicyRegistryService : WaltIdService() {
override val implementation: PolicyRegistryService get() = serviceImplementation()

companion object: ServiceProvider {
companion object : ServiceProvider {
const val SAVED_POLICY_ROOT_KEY = "policies"
override fun getService() = ServiceRegistry.getService(PolicyRegistryService::class)
override fun defaultImplementation() = PolicyRegistryService()
Expand Down Expand Up @@ -53,8 +53,10 @@ open class PolicyRegistryService: WaltIdService() {
policies.put(policy.simpleName!!, PolicyFactory<P, Unit>(policy, null, policy.simpleName!!, description))

private fun registerSavedPolicy(name: String, dynamicPolicyArg: DynamicPolicyArg, immutable: Boolean = false) =
policies.put(name, DynamicPolicyFactory(dynamicPolicyArg, immutable, name = name, description = dynamicPolicyArg.description)
)
policies.put(
name,
DynamicPolicyFactory(dynamicPolicyArg, immutable, name = name, description = dynamicPolicyArg.description)
)

fun <A : Any> getPolicy(id: String, argument: A? = null) = policies[id]!!.create(argument)
fun getPolicy(id: String) = getPolicy(id, null)
Expand Down Expand Up @@ -148,12 +150,12 @@ open class PolicyRegistryService: WaltIdService() {
"Verify by an EBSI Trusted Issuers Registry compliant api.",
true
)
register(EbsiTrustedIssuerAccreditationPolicy::class,"Verify by issuer's authorized claims")
register(EbsiTrustedIssuerAccreditationPolicy::class, "Verify by issuer's authorized claims")
register(EbsiTrustedSubjectDidPolicy::class, "Verify by trusted subject did")
register(IssuedDateBeforePolicy::class, "Verify by issuance date")
register(ValidFromBeforePolicy::class, "Verify by valid from")
register(ExpirationDateAfterPolicy::class, "Verify by expiration date")
//register(GaiaxTrustedPolicy::class, "Verify Gaiax trusted fields")
// register(GaiaxTrustedPolicy::class, "Verify Gaiax trusted fields")
register(GaiaxSDPolicy::class, "Verify Gaiax SD fields")
register(ChallengePolicy::class, ChallengePolicyArg::class, "Verify challenge")
register(
Expand All @@ -167,17 +169,21 @@ open class PolicyRegistryService: WaltIdService() {
// predefined, hardcoded rego policy specializations
// VerifiableMandate policy as specialized rego policy
registerSavedPolicy(
"VerifiableMandatePolicy", DynamicPolicyArg(
"VerifiableMandatePolicy", "Predefined policy for verifiable mandates",
JsonObject(), "$.credentialSubject.policySchemaURI",
"$.credentialSubject.holder", "data.system.main"
"VerifiableMandatePolicy",
DynamicPolicyArg(
"VerifiableMandatePolicy",
"Predefined policy for verifiable mandates",
JsonObject(),
"$.credentialSubject.policySchemaURI",
"$.credentialSubject.holder",
"data.system.main"
),
immutable = true
)

// other saved (Rego) policies
initSavedPolicies()

//RegoPolicy(RegoPolicyArg(mapOf(), "")).argument.input
// RegoPolicy(RegoPolicyArg(mapOf(), "")).argument.input
}
}
5 changes: 2 additions & 3 deletions src/main/kotlin/id/walt/auditor/VerificationPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import com.beust.klaxon.Json
import com.fasterxml.jackson.annotation.JsonIgnore
import id.walt.credentials.w3c.VerifiableCredential
import id.walt.credentials.w3c.VerifiablePresentation
import io.ktor.client.plugins.*
import kotlinx.serialization.Serializable
import mu.KotlinLogging
import java.util.*

private val log = KotlinLogging.logger {}

Expand Down Expand Up @@ -71,7 +69,8 @@ class VerificationPolicyResult private constructor(
}
}

@JsonIgnore @Json(ignored = true)
@JsonIgnore
@Json(ignored = true)
val isFailure = !isSuccess

private fun getErrorString() = errors.mapIndexed { index, throwable ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package id.walt.auditor.dynamic

import id.walt.credentials.w3c.JsonConverter
import id.walt.credentials.w3c.VerifiableCredential
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject

Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/id/walt/cli/EssifCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.File
import java.util.*
import kotlin.NoSuchElementException

class EssifCommand : CliktCommand(
name = "essif",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package id.walt.credentials.w3c.templates

import id.walt.credentials.w3c.VerifiableCredential
import id.walt.credentials.w3c.toVerifiableCredential
import id.walt.services.context.ContextManager
import id.walt.services.hkvstore.HKVKey
import java.io.File

@Deprecated("Deprecated in favor of VcTemplateService", ReplaceWith("VcTemplateService"))
object VcTemplateManager {
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/id/walt/model/DecentralizedIdentifier.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package id.walt.model

import com.beust.klaxon.*
import id.walt.common.*
import com.beust.klaxon.Json
import com.beust.klaxon.TypeAdapter
import com.beust.klaxon.TypeFor
import id.walt.common.DidVerificationRelationships
import id.walt.common.KlaxonWithConverters
import id.walt.common.ListOrSingleValue
import id.walt.common.prettyPrint
import id.walt.model.did.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.web3j.rlp.RlpList
import org.web3j.utils.Numeric
import java.math.BigInteger
import java.util.*
import kotlin.NoSuchElementException

class WaltIdJsonRpcService : JsonRpcService() {

Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/id/walt/custodian/CustodianPresentTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package id.walt.custodian

import id.walt.credentials.w3c.VerifiableCredential
import id.walt.credentials.w3c.VerifiablePresentation
import id.walt.credentials.w3c.toPresentableCredential
import id.walt.credentials.w3c.toVerifiableCredential
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/id/walt/services/did/DidCheqdTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package id.walt.services.did
import id.walt.crypto.KeyId
import id.walt.model.DidMethod
import id.walt.servicematrix.ServiceMatrix
import id.walt.services.ecosystems.cheqd.CheqdService
import id.walt.services.key.KeyService
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/id/walt/services/iota/IotaTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import id.walt.crypto.KeyAlgorithm
import id.walt.model.DidMethod
import id.walt.servicematrix.ServiceMatrix
import id.walt.services.did.DidService
import id.walt.services.ecosystems.iota.IotaService
import id.walt.services.key.KeyService
import id.walt.test.RESOURCES_PATH
import io.kotest.assertions.json.shouldEqualJson
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/id/walt/services/oidc/OIDC4VCTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.core.spec.style.AnnotationSpec
import io.kotest.inspectors.shouldForAll
import io.kotest.matchers.collections.*
import io.kotest.matchers.maps.shouldContain
import io.kotest.matchers.maps.shouldContainKey
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNot
Expand Down

0 comments on commit 2b60242

Please sign in to comment.