Skip to content

Commit

Permalink
ignore monitoring event
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrebruninmaif committed Dec 21, 2023
1 parent ec4fbee commit 833767f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
67 changes: 34 additions & 33 deletions src/main/java/fr/maif/automate/commons/Configuration.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
)
}
}
Expand All @@ -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 =
Expand All @@ -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")
)
}
}

Expand All @@ -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")
)
}
}

Expand Down Expand Up @@ -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(
Expand All @@ -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")
)
}
}
5 changes: 2 additions & 3 deletions src/main/java/fr/maif/automate/commons/otoroshi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoutingContext> {

companion object {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ otoroshi {
sharedKey = ${?CLAIM_SHAREDKEY}
issuer = "Otoroshi"
issuer = ${?OTOROSHI_ISSUER}
providerMonitoringHeader = "X-CleverCloud-Monitoring"
providerMonitoringHeader = ${?OTOROSHI_PROVIDER_MONITORING_HEADER}
}

teams {
Expand Down

0 comments on commit 833767f

Please sign in to comment.