Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/ktor3 #4546

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@ package no.nav.mulighetsrommet.ktor
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import org.slf4j.LoggerFactory

fun startKtorApplication(config: ServerConfig, configure: Application.() -> Unit) {
val loggerName = configure.javaClass.name.split('$').first()

val server = embeddedServer(
Netty,
environment = applicationEngineEnvironment {
log = LoggerFactory.getLogger(loggerName)

module(configure)

connector {
port = config.port
host = config.host
}
},
port = config.port,
host = config.host,
module = configure,
)

server.start(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.ktor.server.auth.*
import io.ktor.server.auth.jwt.*
import io.ktor.server.metrics.micrometer.*
import io.ktor.server.plugins.callid.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.calllogging.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ koin = "4.0.0"
kotest = "5.9.1"
kotest-testcontainers = "2.0.2"
kotlin = "2.0.21"
ktor = "2.3.12"
ktor = "3.0.0"
logback = "1.5.12"
metrics = "4.2.28"
arrow = "1.2.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package no.nav.mulighetsrommet.api.okonomi.refusjon

import arrow.core.getOrElse
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.plugins.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
import io.ktor.util.pipeline.*
import kotlinx.serialization.Serializable
import no.nav.mulighetsrommet.api.okonomi.models.DeltakelsePeriode
import no.nav.mulighetsrommet.api.okonomi.models.RefusjonKravBeregningAft
Expand Down Expand Up @@ -44,7 +42,7 @@ fun Route.arrangorflateRoutes() {
val refusjonskrav: RefusjonskravRepository by inject()
val deltakerRepository: DeltakerRepository by inject()

suspend fun <T : Any> PipelineContext<T, ApplicationCall>.arrangorerMedTilgang(): List<UUID> {
suspend fun RoutingContext.arrangorerMedTilgang(): List<UUID> {
return call.principal<ArrangorflatePrincipal>()
?.organisasjonsnummer
?.map {
Expand All @@ -57,7 +55,7 @@ fun Route.arrangorflateRoutes() {
?: throw StatusException(HttpStatusCode.Unauthorized)
}

fun <T : Any> PipelineContext<T, ApplicationCall>.requireTilgangHosArrangor(organisasjonsnummer: Organisasjonsnummer) {
fun RoutingContext.requireTilgangHosArrangor(organisasjonsnummer: Organisasjonsnummer) {
call.principal<ArrangorflatePrincipal>()
?.organisasjonsnummer
?.find { it == organisasjonsnummer }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package no.nav.mulighetsrommet.api.parameters

import io.ktor.server.application.*
import io.ktor.util.pipeline.*
import io.ktor.server.routing.*
import no.nav.mulighetsrommet.database.utils.Pagination

const val FIRST_PAGE = 1

const val DEFAULT_PAGE_SIZE = 50

fun <T : Any> PipelineContext<T, ApplicationCall>.getPaginationParams(): Pagination {
fun RoutingContext.getPaginationParams(): Pagination {
return Pagination.of(
page = call.parameters["page"]?.toIntOrNull() ?: FIRST_PAGE,
size = call.parameters["size"]?.toIntOrNull() ?: DEFAULT_PAGE_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun Route.authenticate(
* Gets a NAVident from the underlying [JWTPrincipal], or throws a [StatusException]
* if the claim is not available.
*/
fun <T : Any> PipelineContext<T, ApplicationCall>.getNavIdent(): NavIdent {
fun RoutingContext.getNavIdent(): NavIdent {
return call.principal<JWTPrincipal>()?.get("NAVident")?.let { NavIdent(it) } ?: throw StatusException(
HttpStatusCode.Forbidden,
"NAVident mangler i JWTPrincipal",
Expand All @@ -66,7 +66,7 @@ fun <T : Any> PipelineContext<T, ApplicationCall>.getNavIdent(): NavIdent {
* Gets a NavAnsattAzureId from the underlying [JWTPrincipal], or throws a [StatusException]
* if the claim is not available.
*/
fun <T : Any> PipelineContext<T, ApplicationCall>.getNavAnsattAzureId(): UUID {
fun RoutingContext.getNavAnsattAzureId(): UUID {
return call.principal<JWTPrincipal>()?.get("oid")?.let { UUID.fromString(it) } ?: throw StatusException(
HttpStatusCode.Forbidden,
"NavAnsattAzureId mangler i JWTPrincipal",
Expand All @@ -77,7 +77,7 @@ fun <T : Any> PipelineContext<T, ApplicationCall>.getNavAnsattAzureId(): UUID {
* Gets a pid from the underlying [JWTPrincipal], or throws a [StatusException]
* if the claim is not available.
*/
fun <T : Any> PipelineContext<T, ApplicationCall>.getPid(): NorskIdent {
fun RoutingContext.getPid(): NorskIdent {
return call.principal<JWTPrincipal>()?.get("pid")?.let { NorskIdent(it) } ?: throw StatusException(
HttpStatusCode.Forbidden,
"pid mangler i JWTPrincipal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ enum class ApentForInnsok {
APENT_ELLER_STENGT,
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getArbeidsmarkedstiltakFilter(): ArbeidsmarkedstiltakFilter {
fun RoutingContext.getArbeidsmarkedstiltakFilter(): ArbeidsmarkedstiltakFilter {
val queryParameters = call.request.queryParameters

val enheter = queryParameters.getAll("enheter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ data class ArrangorFilter(
val sortering: String? = null,
)

fun <T : Any> PipelineContext<T, ApplicationCall>.getArrangorFilter(): ArrangorFilter {
fun RoutingContext.getArrangorFilter(): ArrangorFilter {
val til = call.request.queryParameters["til"]
val sok = call.request.queryParameters["sok"]
val sortering = call.request.queryParameters["sortering"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
Expand Down Expand Up @@ -241,7 +240,7 @@ fun Route.avtaleRoutes() {
}
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getAvtaleFilter(): AvtaleFilter {
fun RoutingContext.getAvtaleFilter(): AvtaleFilter {
val tiltakstypeIder = call.parameters.getAll("tiltakstyper")?.map { it.toUUID() } ?: emptyList()
val search = call.request.queryParameters["search"]
val statuser = call.parameters.getAll("statuser")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
import io.ktor.util.pipeline.*
import no.nav.mulighetsrommet.api.domain.dbo.NavAnsattRolle
import no.nav.mulighetsrommet.api.plugins.getNavAnsattAzureId
import no.nav.mulighetsrommet.api.services.NavAnsattService
Expand Down Expand Up @@ -38,7 +37,7 @@ fun Route.navAnsattRoutes() {
}
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getNavAnsattFilter(): NavAnsattFilter {
fun RoutingContext.getNavAnsattFilter(): NavAnsattFilter {
val azureIder = call.parameters.getAll("roller")
?.map { NavAnsattRolle.valueOf(it) }
?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.util.*
import io.ktor.util.pipeline.*
import no.nav.mulighetsrommet.api.clients.norg2.Norg2Type
import no.nav.mulighetsrommet.api.domain.dbo.NavEnhetStatus
import no.nav.mulighetsrommet.api.services.EnhetFilter
Expand Down Expand Up @@ -38,7 +36,7 @@ fun Route.navEnhetRoutes() {
}
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getEnhetFilter(): EnhetFilter {
fun RoutingContext.getEnhetFilter(): EnhetFilter {
val statuser = call.parameters.getAll("statuser")
?.map { NavEnhetStatus.valueOf(it) }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.mulighetsrommet.api.routes.v1

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
Expand Down Expand Up @@ -61,7 +60,7 @@ data class SetNotificationStatusRequest(
)
}

fun <T : Any> PipelineContext<T, ApplicationCall>.getNotificationFilter(): NotificationFilter {
fun RoutingContext.getNotificationFilter(): NotificationFilter {
val status = call.request.queryParameters["status"]
return NotificationFilter(
status = status?.let { NotificationStatus.valueOf(it) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ data class AdminTiltaksgjennomforingFilter(
val publisert: Boolean? = null,
)

fun <T : Any> PipelineContext<T, ApplicationCall>.getAdminTiltaksgjennomforingsFilter(): AdminTiltaksgjennomforingFilter {
fun RoutingContext.getAdminTiltaksgjennomforingsFilter(): AdminTiltaksgjennomforingFilter {
val search = call.request.queryParameters["search"]
val navEnheter = call.parameters.getAll("navEnheter") ?: emptyList()
val tiltakstypeIder = call.parameters.getAll("tiltakstyper")?.map { UUID.fromString(it) } ?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data class TiltakstypeFilter(
val sortering: String? = null,
)

fun <T : Any> PipelineContext<T, ApplicationCall>.getTiltakstypeFilter(): TiltakstypeFilter {
fun RoutingContext.getTiltakstypeFilter(): TiltakstypeFilter {
val sortering = call.request.queryParameters["sort"]
return TiltakstypeFilter(
sortering = sortering,
Expand Down
Loading