Skip to content

Commit

Permalink
Gå over til unleash next (#57)
Browse files Browse the repository at this point in the history
* gå over til unleash next

* Mangler Permissions for deploy

* Feil navn secret + manglende prod-config

* workflow concurrency

---------

Co-authored-by: Hans Petter Simonsen <[email protected]>
  • Loading branch information
marcjas and holymaloney authored Sep 14, 2023
1 parent edda861 commit 8d0280e
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
branches:
- main

concurrency:
group: deploy_main
cancel-in-progress: true

permissions:
packages: write
contents: write
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/feature-branch-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: Deploy feature branch
on:
workflow_dispatch:

concurrency:
group: deploy_feture_branch
cancel-in-progress: true

permissions:
packages: write
contents: write

env:
IMAGE_TAG: ${{ github.sha }}
IMAGE: ghcr.io/${{ github.repository }}/aktivitet-arena-acl
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/unleash-apitoken.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Unleash api-tokens

on:
push:
branches:
- main
paths:
- '.github/workflows/unleash-apitoken.yaml'
- '.nais/unleash-apitoken-dev.yaml'
- '.nais/unleash-apitoken.yaml'

jobs:
apply-apitoken-unleash:
name: Apply ApiToken for Unleash to cluster
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: deploy to dev
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-gcp
RESOURCE: .nais/unleash-apitoken-dev.yaml
- name: deploy to prod
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: prod-gcp
RESOURCE: .nais/unleash-apitoken.yaml
5 changes: 5 additions & 0 deletions .nais/nais-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ spec:
external:
- host: amt-arena-ords-proxy.dev-fss-pub.nais.io
- host: veilarboppfolging.dev-fss-pub.nais.io
- host: dab-unleash-api.nav.cloud.nais.io
envFrom:
- secret: aktivitet-arena-acl-unleash-api-token
env:
# q2: api://dev-fss.amt.amt-arena-ords-proxy/.default q1: api://dev-fss.amt.amt-arena-ords-proxy-q1/.default
- name: AMT_ARENA_ORDS_PROXY_SCOPE
Expand All @@ -75,6 +78,8 @@ spec:
value: api://dev-fss.pto.veilarboppfolging/.default
- name: VEILARBOPPFOLGING_URL
value: https://veilarboppfolging.dev-fss-pub.nais.io
- name: UNLEASH_ENVIRONMENT
value: development
gcp:
sqlInstances:
- name: aktivitet-arena-acl-v1
Expand Down
5 changes: 5 additions & 0 deletions .nais/nais-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ spec:
external:
- host: amt-arena-ords-proxy.prod-fss-pub.nais.io
- host: veilarboppfolging.prod-fss-pub.nais.io
- host: dab-unleash-api.nav.cloud.nais.io
envFrom:
- secret: aktivitet-arena-acl-unleash-api-token
env:
- name: AMT_ARENA_ORDS_PROXY_SCOPE
value: api://prod-fss.amt.amt-arena-ords-proxy/.default
Expand All @@ -71,6 +74,8 @@ spec:
value: api://prod-fss.pto.veilarboppfolging/.default
- name: VEILARBOPPFOLGING_URL
value: https://veilarboppfolging.prod-fss-pub.nais.io
- name: UNLEASH_ENVIRONMENT
value: production
gcp:
sqlInstances:
- name: aktivitet-arena-acl-v1
Expand Down
14 changes: 14 additions & 0 deletions .nais/unleash-apitoken-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: unleash.nais.io/v1
kind: ApiToken
metadata:
name: aktivitet-arena-acl
namespace: dab
labels:
team: dab
spec:
unleashInstance:
apiVersion: unleash.nais.io/v1
kind: RemoteUnleash
name: dab
secretName: aktivitet-arena-acl-unleash-api-token
environment: development
14 changes: 14 additions & 0 deletions .nais/unleash-apitoken.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: unleash.nais.io/v1
kind: ApiToken
metadata:
name: aktivitet-arena-acl
namespace: dab
labels:
team: dab
spec:
unleashInstance:
apiVersion: unleash.nais.io/v1
kind: RemoteUnleash
name: dab
secretName: aktivitet-arena-acl-unleash-api-token
environment: production
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.getunleash</groupId>
<artifactId>unleash-client-java</artifactId>
<version>8.2.1</version>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package no.nav.arena_tiltak_aktivitet_acl.configuration

import io.getunleash.DefaultUnleash
import io.getunleash.Unleash
import no.nav.common.rest.filter.LogRequestFilter
import no.nav.common.token_client.builder.AzureAdTokenClientBuilder
import no.nav.common.token_client.client.MachineToMachineTokenClient
import no.nav.common.utils.EnvironmentUtils
import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile

@EnableJwtTokenValidation(ignore = ["org.springdoc", "org.springframework"])
@Configuration
@EnableConfigurationProperties(UnleashConfig::class)
open class ApplicationConfig {

companion object {
Expand All @@ -37,6 +41,12 @@ open class ApplicationConfig {
return registration
}

@Bean
@Profile("default")
open fun unleash(config: UnleashConfig): Unleash {
return DefaultUnleash(config.toUnleashConfig())
}

}

fun getEnvOrProperty(key: String): String {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package no.nav.arena_tiltak_aktivitet_acl.configuration

import io.getunleash.util.UnleashConfig
import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "unleash")
data class UnleashConfig(
val appName: String,
val url: String,
val token: String,
val instanceId: String,
val environment: String,
) {
fun toUnleashConfig(): UnleashConfig {
return UnleashConfig.builder()
.appName(appName)
.instanceId(instanceId)
.unleashAPI("$url/api")
.apiKey(token)
.environment(environment)
.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.nav.arena_tiltak_aktivitet_acl.kafka

import io.getunleash.Unleash
import io.micrometer.core.instrument.MeterRegistry
import no.nav.arena_tiltak_aktivitet_acl.services.ArenaMessageProcessorService
import no.nav.common.featuretoggle.UnleashClient
import no.nav.common.kafka.consumer.KafkaConsumerClient
import no.nav.common.kafka.consumer.util.KafkaConsumerClientBuilder
import no.nav.common.kafka.consumer.util.deserializer.Deserializers.stringDeserializer
Expand All @@ -16,7 +16,7 @@ open class KafkaConsumer(
kafkaTopicProperties: KafkaTopicProperties,
kafkaProperties: KafkaProperties,
private val arenaMessageProcessorService: ArenaMessageProcessorService,
unleashClient: UnleashClient,
unleash: Unleash,
private val meterRegistry: MeterRegistry
) {

Expand Down Expand Up @@ -45,7 +45,7 @@ open class KafkaConsumer(

client = KafkaConsumerClientBuilder.builder()
.withProperties(kafkaProperties.consumer())
.withToggle { unleashClient.isEnabled("aktivitet-arena-acl.kafka.consumer.disabled") }
.withToggle { unleash.isEnabled("aktivitet-arena-acl.kafka.consumer.disabled") }
.withTopicConfigs(topicConfigs)
.build()
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ app.env.arenaTiltakDeltakerTopic=${ARENA_TILTAK_DELTAKER_TOPIC:null}
app.env.aktivitetskortTopic=${AKTIVITETSKORT_TOPIC:null}
app.unleashUrl=https://unleash.nais.io/api/

unleash.appName=${NAIS_APP_NAME}
unleash.url=${UNLEASH_SERVER_API_URL}
unleash.token=${UNLEASH_SERVER_API_TOKEN}
unleash.instanceId=${NAIS_CLIENT_ID}
unleash.environment=${UNLEASH_ENVIRONMENT}

# swagger-ui custom path
springdoc.swagger-ui.path=/internal/swagger-ui.html
springdoc.api-docs.enabled=true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package no.nav.arena_tiltak_aktivitet_acl

import io.getunleash.Unleash
import io.mockk.every
import io.mockk.mockk
import no.nav.arena_tiltak_aktivitet_acl.utils.token_provider.ScopedTokenProvider
import no.nav.common.featuretoggle.UnleashClient
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
open class LocalApplicationConfig {

@Bean
open fun unlead(): UnleashClient {
val mock = mockk<UnleashClient>()
open fun unlead(): Unleash {
val mock = mockk<Unleash>()
every { mock.isEnabled(any()) } returns false
return mock
}
Expand Down

0 comments on commit 8d0280e

Please sign in to comment.