Skip to content

Commit

Permalink
added API endpoint to provider for testing secure auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanskodje committed Apr 15, 2024
1 parent 56bc16d commit e79b705
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
7 changes: 7 additions & 0 deletions ebms-provider/src/main/kotlin/no/nav/emottak/ebms/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ fun Application.ebmsProviderModule() {
get("/") {
call.respondText("Hello, world!")
}

get("/test/send-in-token") {
log.info("Tester send-in-token auth")
val result = sendInClient.testSecureApi()
log.info("Received result from send-in-token auth: $result")
call.respondText(result)
}
registerHealthEndpoints(appMicrometerRegistry)
postEbmsAsync(validator, processing)
postEbmsSync(validator, processing, sendInService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.cio.CIO
import io.ktor.client.plugins.auth.providers.BearerTokens
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.headers
import io.ktor.client.request.post
Expand Down Expand Up @@ -57,6 +58,14 @@ class SendInClient(clientProvider: () -> HttpClient) {
contentType(ContentType.Application.Json)
}.body()
}

// TEMP: Ivan will delete me!
suspend fun testSecureApi(): String {
return httpClient.get("http://ebms-send-in/") {
contentType(ContentType.Application.Json)

}.bodyAsText()
}
}

val LENIENT_JSON_PARSER = Json {
Expand Down
42 changes: 21 additions & 21 deletions ebms-send-in/src/main/kotlin/no/nav/emottak/ebms/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,31 @@ fun Application.ebmsSendInModule() {
call.respondText(marshal(response))
}

post("/fagmelding/synkron") {
val request = this.call.receive(SendInRequest::class)
runCatching {
log.info(request.marker(), "Payload ${request.payloadId} videresendes")
frikortsporring(wrapMessageInEIFellesFormat(request))
}.onSuccess {
log.info(request.marker(), "Payload ${request.payloadId} videresendt til fagsystem")
call.respond(
SendInResponse(
request.messageId,
request.conversationId,
it.eiFellesformat.addressing(request.addressing.from),
marshal(it.eiFellesformat.msgHead).toByteArray()
)
)
}.onFailure {
log.error(request.marker(), "Payload ${request.payloadId} videresending feilet", it)
call.respond(HttpStatusCode.BadRequest, it.localizedMessage)
}
}

authenticate(AZURE_AD_AUTH) {
get("/") {
call.respondText("Hello world, but securely")
}

post("/fagmelding/synkron") {
val request = this.call.receive(SendInRequest::class)
runCatching {
log.info(request.marker(), "Payload ${request.payloadId} videresendes")
frikortsporring(wrapMessageInEIFellesFormat(request))
}.onSuccess {
log.info(request.marker(), "Payload ${request.payloadId} videresendt til fagsystem")
call.respond(
SendInResponse(
request.messageId,
request.conversationId,
it.eiFellesformat.addressing(request.addressing.from),
marshal(it.eiFellesformat.msgHead).toByteArray()
)
)
}.onFailure {
log.error(request.marker(), "Payload ${request.payloadId} videresending feilet", it)
call.respond(HttpStatusCode.BadRequest, it.localizedMessage)
}
}
}
}
}

0 comments on commit e79b705

Please sign in to comment.