Skip to content

Commit

Permalink
Merge pull request #77 from navikt/debug_unleash
Browse files Browse the repository at this point in the history
Debug unleash
  • Loading branch information
flexable777 authored Dec 15, 2020
2 parents b2cdbf0 + 030672c commit 2c7f629
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package no.nav.klage.oppgave.config
import no.finn.unleash.DefaultUnleash
import no.finn.unleash.FakeUnleash
import no.finn.unleash.Unleash
import no.finn.unleash.strategy.UserWithIdStrategy
import no.finn.unleash.util.UnleashConfig
import no.nav.klage.oppgave.service.unleash.ByClusterStrategy
import no.nav.klage.oppgave.service.unleash.ByEnhetStrategy
import no.nav.klage.oppgave.service.unleash.ByUserStrategy
import no.nav.klage.oppgave.util.getLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
Expand All @@ -33,14 +33,14 @@ class FeatureToggleConfig {

@Bean
@Profile("dev-gcp", "prod-gcp")
fun unleash(byClusterStrategy: ByClusterStrategy, byEnhetStrategy: ByEnhetStrategy): Unleash? {
fun unleash(byClusterStrategy: ByClusterStrategy, byEnhetStrategy: ByEnhetStrategy, byUserStrategy: ByUserStrategy): Unleash? {
val unleashConfig = UnleashConfig.builder()
.appName(appName)
.instanceId(instance)
.unleashAPI(unleashUrl)
.build()
logger.info("Unleash settes opp med appName {}, instanceId {} og url {}", appName, instance, unleashUrl)
return DefaultUnleash(unleashConfig, byClusterStrategy, byEnhetStrategy, UserWithIdStrategy())
return DefaultUnleash(unleashConfig, byClusterStrategy, byEnhetStrategy, byUserStrategy)
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package no.nav.klage.oppgave.config

import no.finn.unleash.Unleash
import no.finn.unleash.UnleashContext
import no.nav.klage.oppgave.config.FeatureToggleConfig.Companion.KLAGE_GENERELL_TILGANG
import no.nav.klage.oppgave.exceptions.FeatureNotEnabledException
import no.nav.klage.oppgave.repositories.InnloggetSaksbehandlerRepository
Expand Down Expand Up @@ -40,15 +39,7 @@ class FeatureToggleInterceptor(

private fun isEnabled(feature: String): Boolean {
logger.debug("Unleash: feature: {}", feature)
val contextMedInnloggetBruker = contextMedInnloggetBruker()
logger.debug("contextMedInnloggetBruker: {}", contextMedInnloggetBruker)
return unleash.isEnabled(feature, contextMedInnloggetBruker)
}

private fun contextMedInnloggetBruker(): UnleashContext? {
val ident = getIdent()
logger.debug("Unleash: getIdent(): {}", ident)
return UnleashContext.builder().userId(ident).build()
return unleash.isEnabled(feature)
}

private fun getIdent() = innloggetSaksbehandlerRepository.getInnloggetIdent()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package no.nav.klage.oppgave.service.unleash

import no.finn.unleash.strategy.Strategy
import no.nav.klage.oppgave.repositories.InnloggetSaksbehandlerRepository
import no.nav.klage.oppgave.util.getLogger
import org.springframework.stereotype.Component

@Component
class ByUserStrategy(private val innloggetSaksbehandlerRepository: InnloggetSaksbehandlerRepository) : Strategy {

companion object {
@Suppress("JAVA_CLASS_ON_COMPANION")
private val logger = getLogger(javaClass.enclosingClass)
const val PARAM = "user"
}

override fun getName(): String = "byUserId"

override fun isEnabled(parameters: Map<String, String>?): Boolean =
getEnabledUsers(parameters)?.any { isCurrentUserEnabled(it) } ?: false

private fun getEnabledUsers(parameters: Map<String, String>?) =
parameters?.get(PARAM)?.split(',')

private fun isCurrentUserEnabled(ident: String): Boolean {
val currentIdent = getIdent()
logger.debug("isCurrentUserEnabled? ident: {}, currentIdent: {}", ident, currentIdent)
return ident == currentIdent
}

private fun getIdent() = innloggetSaksbehandlerRepository.getInnloggetIdent()
}

0 comments on commit 2c7f629

Please sign in to comment.