Skip to content

Commit

Permalink
change entity toString
Browse files Browse the repository at this point in the history
  • Loading branch information
rromanowski-figure committed Aug 15, 2023
1 parent 61ae5b4 commit 34fcab5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -22,6 +22,7 @@ suspend inline fun <reified T> 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)" }
Expand All @@ -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"),
)
}
}

0 comments on commit 34fcab5

Please sign in to comment.