diff --git a/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt b/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt index 54748950..35230e1a 100644 --- a/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt +++ b/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt @@ -15,10 +15,10 @@ sealed interface Entity { val id: String } data class KongConsumer( val entityId: String, val username: String?, - val customId: String, + val customId: String?, ) : Entity { override val id: String - get() = entityId + get() = customId ?: username ?: entityId } data class MemberUUID(val value: UUID) : Entity { diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt index 3d2d52da..20f8ac8b 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt @@ -9,9 +9,9 @@ import java.util.UUID sealed interface GetSignerRequest { companion object { - operator fun invoke(id: Entity, account: AccountInfo): GetSignerRequest = when (id) { - is KongConsumer -> GetSignerByAddressRequest(id.customId, account) - is MemberUUID -> GetSignerByUUIDRequest(id.value, account) + operator fun invoke(entity: Entity, account: AccountInfo): GetSignerRequest = when (entity) { + is KongConsumer -> GetSignerByAddressRequest(entity.id, account) + is MemberUUID -> GetSignerByUUIDRequest(entity.value, account) } } diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt index f8983a00..43ceb322 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt @@ -141,11 +141,11 @@ class ProvenanceHandler( ) }.foldToServerResponse() - suspend fun checkCustody(req: ServerRequest): ServerResponse = kotlin.runCatching { + suspend fun checkCustody(req: ServerRequest): ServerResponse = runCatching { getSigner.execute( GetSignerRequest( - id = req.getEntity(), - account = req.awaitBodyOrNull() ?: AccountInfo() + entity = req.getEntity(), + account = req.awaitBodyOrNull() ?: AccountInfo(), ) ) }.fold( diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt b/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt index 77f33eab..275a5082 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt @@ -8,7 +8,7 @@ import org.springframework.web.reactive.function.server.ServerRequest import org.springframework.web.reactive.function.server.awaitBodyOrNull import java.util.UUID -private val log = KotlinLogging.logger {} +private val log = KotlinLogging.logger("ServerRequest") val ServerRequest.ipAddress: String get() = headers().firstHeader("x-real-ip") ?: remoteAddress().get().address.toString() @@ -22,6 +22,7 @@ suspend inline fun ServerRequest.requireBody(): T = fun ServerRequest.getEntity(): Entity { try { + log.info { "headers: ${headers().asHttpHeaders()}" } return requireNotNull(getMemberUUIDOrNull() ?: getConsumerOrNull()) } catch (exception: IllegalArgumentException) { log.error(exception) { "error parsing headers for entity (x-uuid and x-consumer-id)" } @@ -37,9 +38,7 @@ private fun ServerRequest.getConsumerOrNull(): KongConsumer? { KongConsumer( entityId = id, username = headers().firstHeader("x-consumer-username"), - customId = requireNotNull(headers().firstHeader("x-consumer-custom-id")) { - "Custom ID for consumer (x-consumer-custom-id) missing" - }, + customId = headers().firstHeader("x-consumer-custom-id"), ) } }