Skip to content

Commit

Permalink
Fjern trenger-endepunkt (har blitt erstattet) (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjerga authored Sep 27, 2024
1 parent ca2f46a commit 6057f0a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ object Routes {
const val PREFIX = "/api/v1"

const val HENT_FORESPOERSEL = "/hent-forespoersel"
const val TRENGER = "/trenger"
const val INNTEKT = "/inntekt"
const val INNTEKT_SELVBESTEMT = "/inntekt-selvbestemt"
const val INNSENDING = "/inntektsmelding"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,61 +45,59 @@ fun Route.hentForespoerselRoute(
.help("hent forespoersel endpoint latency in seconds")
.register()

setOf(Routes.TRENGER, Routes.HENT_FORESPOERSEL).forEach { routeUrl ->
post(routeUrl) {
val transaksjonId = UUID.randomUUID()
post(Routes.HENT_FORESPOERSEL) {
val transaksjonId = UUID.randomUUID()

val requestTimer = requestLatency.startTimer()
runCatching {
receive(HentForespoerselRequest.serializer())
}.onSuccess { request ->
logger.info("Henter data for uuid: ${request.uuid}")
try {
tilgangskontroll.validerTilgangTilForespoersel(call.request, request.uuid)
val requestTimer = requestLatency.startTimer()
runCatching {
receive(HentForespoerselRequest.serializer())
}.onSuccess { request ->
logger.info("Henter data for uuid: ${request.uuid}")
try {
tilgangskontroll.validerTilgangTilForespoersel(call.request, request.uuid)

val arbeidsgiverFnr = call.request.lesFnrFraAuthToken()
val arbeidsgiverFnr = call.request.lesFnrFraAuthToken()

hentForespoerselProducer.publish(transaksjonId, request, arbeidsgiverFnr)
hentForespoerselProducer.publish(transaksjonId, request, arbeidsgiverFnr)

val resultatJson = redisPoller.hent(transaksjonId).fromJson(ResultJson.serializer())
val resultatJson = redisPoller.hent(transaksjonId).fromJson(ResultJson.serializer())

sikkerLogger.info("Hentet forespørsel: $resultatJson")
sikkerLogger.info("Hentet forespørsel: $resultatJson")

val resultat = resultatJson.success?.fromJson(HentForespoerselResultat.serializer())
if (resultat != null) {
respond(HttpStatusCode.Created, resultat.toResponse(), HentForespoerselResponse.serializer())
} else {
val feilmelding = resultatJson.failure?.fromJson(String.serializer()) ?: "Teknisk feil, prøv igjen senere."
val response =
ResultJson(
failure = feilmelding.toJson(),
)
respond(HttpStatusCode.ServiceUnavailable, response, ResultJson.serializer())
}
} catch (e: ManglerAltinnRettigheterException) {
val response =
ResultJson(
failure = "Du har ikke rettigheter for organisasjon.".toJson(),
)
respondForbidden(response, ResultJson.serializer())
} catch (_: RedisPollerTimeoutException) {
logger.info("Fikk timeout for ${request.uuid}")
val resultat = resultatJson.success?.fromJson(HentForespoerselResultat.serializer())
if (resultat != null) {
respond(HttpStatusCode.Created, resultat.toResponse(), HentForespoerselResponse.serializer())
} else {
val feilmelding = resultatJson.failure?.fromJson(String.serializer()) ?: "Teknisk feil, prøv igjen senere."
val response =
ResultJson(
failure = RedisTimeoutResponse(request.uuid).toJson(RedisTimeoutResponse.serializer()),
failure = feilmelding.toJson(),
)
respondInternalServerError(response, ResultJson.serializer())
respond(HttpStatusCode.ServiceUnavailable, response, ResultJson.serializer())
}
}.also {
requestTimer.observeDuration()
}.onFailure {
logger.error("Klarte ikke lese request.", it)
} catch (e: ManglerAltinnRettigheterException) {
val response =
ResultJson(
failure = "Du har ikke rettigheter for organisasjon.".toJson(),
)
respondForbidden(response, ResultJson.serializer())
} catch (_: RedisPollerTimeoutException) {
logger.info("Fikk timeout for ${request.uuid}")
val response =
ResultJson(
failure = "Mangler forespørsel-ID for å hente forespørsel.".toJson(),
failure = RedisTimeoutResponse(request.uuid).toJson(RedisTimeoutResponse.serializer()),
)
respondBadRequest(response, ResultJson.serializer())
respondInternalServerError(response, ResultJson.serializer())
}
}.also {
requestTimer.observeDuration()
}.onFailure {
logger.error("Klarte ikke lese request.", it)
val response =
ResultJson(
failure = "Mangler forespørsel-ID for å hente forespørsel.".toJson(),
)
respondBadRequest(response, ResultJson.serializer())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class AuthorizationTest : ApiTest() {
testApi {
listOf(
Routes.HENT_FORESPOERSEL to ::postUtenAuth,
Routes.TRENGER to ::postUtenAuth,
Routes.INNTEKT to ::postUtenAuth,
Routes.INNTEKT_SELVBESTEMT to ::postUtenAuth,
Routes.INNSENDING + "/0" to ::postUtenAuth,
Routes.SELVBESTEMT_INNTEKTSMELDING to ::postUtenAuth,
Routes.SELVBESTEMT_INNTEKTSMELDING + "/0" to ::getUtenAuth,
Routes.KVITTERING to ::getUtenAuth,
Routes.AKTIVEORGNR to ::postUtenAuth,
Routes.TILGANG_ORGNR to ::getUtenAuth,
).forEach { (path, callFn) ->
val response = callFn(Routes.PREFIX + path)

Expand Down
Loading

0 comments on commit 6057f0a

Please sign in to comment.