From 833767fa2eb824f3af93fff4376dd1461a29ff4a Mon Sep 17 00:00:00 2001 From: pierrebruninmaif Date: Thu, 21 Dec 2023 13:11:48 +0100 Subject: [PATCH] ignore monitoring event --- .../fr/maif/automate/commons/Configuration.kt | 67 ++++++++++--------- .../java/fr/maif/automate/commons/otoroshi.kt | 5 +- src/main/resources/application.conf | 2 + 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/main/java/fr/maif/automate/commons/Configuration.kt b/src/main/java/fr/maif/automate/commons/Configuration.kt index 1f99fe5..e582e9c 100644 --- a/src/main/java/fr/maif/automate/commons/Configuration.kt +++ b/src/main/java/fr/maif/automate/commons/Configuration.kt @@ -1,8 +1,6 @@ package fr.maif.automate.commons -import arrow.core.None import arrow.core.Option -import arrow.core.toOption import com.typesafe.config.Config import com.typesafe.config.ConfigObject import java.util.concurrent.TimeUnit @@ -22,16 +20,16 @@ data class LetsAutomateConfig( companion object { fun load(config: Config): LetsAutomateConfig { return LetsAutomateConfig( - http = HttpConfig.load(config), - env = Env.load(config), - ovh = Ovh.load(config), - logout = config.getString("logout"), - certificates = CertificatesConfig.load(config), - letSEncrypt = LetSEncryptConfig.load(config), - postgresConfig = PostgresConfig.load(config), - clevercloud = CleverConfig.load(config), - teams = TeamsConfig.load(config), - otoroshi = OtoroshiConfig.load(config) + http = HttpConfig.load(config), + env = Env.load(config), + ovh = Ovh.load(config), + logout = config.getString("logout"), + certificates = CertificatesConfig.load(config), + letSEncrypt = LetSEncryptConfig.load(config), + postgresConfig = PostgresConfig.load(config), + clevercloud = CleverConfig.load(config), + teams = TeamsConfig.load(config), + otoroshi = OtoroshiConfig.load(config) ) } } @@ -57,7 +55,7 @@ data class CertificatesConfig(val pollingInterval: Interval) { } data class TeamsConfig( - val url: String + val url: String ) { companion object { fun load(config: Config): TeamsConfig = @@ -75,12 +73,12 @@ data class Ovh( ) { companion object { fun load(config: Config): Ovh = - Ovh( - applicationKey = config.getString("ovh.applicationKey"), - applicationSecret = config.getString("ovh.applicationSecret"), - consumerKey = config.getString("ovh.consumerKey"), - host = config.getString("ovh.host") - ) + Ovh( + applicationKey = config.getString("ovh.applicationKey"), + applicationSecret = config.getString("ovh.applicationSecret"), + consumerKey = config.getString("ovh.consumerKey"), + host = config.getString("ovh.host") + ) } } @@ -99,10 +97,10 @@ data class Interval(val period: Long, val unit: TimeUnit) { data class LetSEncryptConfig(val server: String, val accountId: String) { companion object { fun load(config: Config): LetSEncryptConfig = - LetSEncryptConfig( - server = config.getString("letsencrypt.server"), - accountId = config.getString("letsencrypt.accountId") - ) + LetSEncryptConfig( + server = config.getString("letsencrypt.server"), + accountId = config.getString("letsencrypt.accountId") + ) } } @@ -136,15 +134,16 @@ data class CleverConfig(val host: String, val consumerKey: String, val consumerS sealed class Env { companion object { fun load(config: Config): Env = - when(config.getString("env")) { + when (config.getString("env")) { "dev" -> Dev "prod" -> Prod else -> throw IllegalArgumentException("Env type unknown ${config.getString("env")}") } } } -object Dev: Env() -object Prod: Env() + +object Dev : Env() +object Prod : Env() data class OtoroshiConfig( @@ -153,16 +152,18 @@ data class OtoroshiConfig( val headerGatewayState: String, val headerClaim: String, val sharedKey: String, - val issuer: String) { + val issuer: String, + val providerMonitoringHeader: String) { companion object { fun load(config: Config): OtoroshiConfig = OtoroshiConfig( - config.getString("otoroshi.headerRequestId"), - config.getString("otoroshi.headerGatewayStateResp"), - config.getString("otoroshi.headerGatewayState"), - config.getString("otoroshi.headerClaim"), - config.getString("otoroshi.sharedKey"), - config.getString("otoroshi.issuer") + config.getString("otoroshi.headerRequestId"), + config.getString("otoroshi.headerGatewayStateResp"), + config.getString("otoroshi.headerGatewayState"), + config.getString("otoroshi.headerClaim"), + config.getString("otoroshi.sharedKey"), + config.getString("otoroshi.issuer"), + config.getString("otoroshi.providerMonitoringHeader") ) } } \ No newline at end of file diff --git a/src/main/java/fr/maif/automate/commons/otoroshi.kt b/src/main/java/fr/maif/automate/commons/otoroshi.kt index 81cd15b..4d0195b 100644 --- a/src/main/java/fr/maif/automate/commons/otoroshi.kt +++ b/src/main/java/fr/maif/automate/commons/otoroshi.kt @@ -14,7 +14,6 @@ import io.vertx.reactivex.ext.web.RoutingContext import org.slf4j.Logger import org.slf4j.LoggerFactory - class OtoroshiHandler(private val config: OtoroshiConfig, private val env: Env): Handler { companion object { @@ -40,7 +39,7 @@ class OtoroshiHandler(private val config: OtoroshiConfig, private val env: Env): val maybeReqId = req.getHeader(config.headerRequestId).toOption() val maybeState = req.getHeader(config.headerGatewayState).toOption() val maybeClaim = req.getHeader(config.headerClaim).toOption() - LOGGER.info("New request ${req.method()} ${req.absoluteURI()} id = $maybeReqId, state = $maybeState, claim = $maybeClaim") + LOGGER.debug("New request ${req.method()} ${req.absoluteURI()} id = $maybeReqId, state = $maybeState, claim = $maybeClaim") maybeReqId.forall { id -> val method = routingContext.request().method() @@ -87,7 +86,7 @@ class OtoroshiHandler(private val config: OtoroshiConfig, private val env: Env): Unit }.fix().getOrElse { - LOGGER.error("Error during otoroshi filter") + if(req.headers().contains(config.providerMonitoringHeader)) LOGGER.error("Error during otoroshi filter") routingContext.response().headers().add(config.headerGatewayStateResp, maybeState.getOrElse { "--" }) routingContext.response() .setStatusCode(401) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 506230a..dc1aed8 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -80,6 +80,8 @@ otoroshi { sharedKey = ${?CLAIM_SHAREDKEY} issuer = "Otoroshi" issuer = ${?OTOROSHI_ISSUER} + providerMonitoringHeader = "X-CleverCloud-Monitoring" + providerMonitoringHeader = ${?OTOROSHI_PROVIDER_MONITORING_HEADER} } teams {