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

Oppdater github workflow og fiks swagger annotering #239

Merged
merged 4 commits into from
Sep 21, 2023
Merged
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
File renamed without changes.
5 changes: 3 additions & 2 deletions .github/workflows/deploy_feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- '**'
- '!main'

env:
GITHUB_USERNAME: x-access-token
Expand All @@ -27,7 +28,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -Dmaven.test.skip=true -B -e --settings .github/.m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand All @@ -54,7 +55,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -B -e --settings .github/.m2/maven-settings.xml clean install

deploy-feature:
runs-on: ubuntu-latest
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Deploy to dev
on:
pull_request:
types: [ ready_for_review, opened, synchronize ]
push:
branches:
- 'main'

env:
GITHUB_USERNAME: x-access-token
Expand All @@ -29,7 +26,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -Dmaven.test.skip=true -B -e --settings .github/.m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand All @@ -56,7 +53,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -B -e --settings .github/.m2/maven-settings.xml clean install

deploy-main:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -Dmaven.test.skip=true -B -e --settings .m2/maven-settings.xml clean install
- run: mvn -Dmaven.test.skip=true -B -e --settings .github/.m2/maven-settings.xml clean install
- uses: nais/docker-build-push@v0
id: docker-push
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
.settings/
.vscode/
.DS_Store
*nais-secrets*
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,29 @@ Kan vurdere å sette opp wiremocks for de eksterne tjenestene for å kunne kjør
Applikasjonen testes enklest i Swagger (for generering av gyldig token, se over):
```
https://bidrag-grunnlag.dev.intern.nav.no/bidrag-grunnlag/swagger-ui/index.html?configUrl=/bidrag-grunnlag/v3/api-docs/swagger-config#/grunnlagspakke-controller
```
```

### Kjøre lokalt mot nais med lokal database
##### Start opp database
Start opp lokal postgres database med følgende kommando på rotmappen.
```
docker-compose up -d
```
Dette vil starte en tom postgres database.
Ved oppstart av appen vil flyway skriptene initialiseree alle tabeller som er nødvendig for lokal kjøring.

Databasen er persistent. Det vil si at all data vil bli lagret lokalt og være tilgjengelig selv ved restart av PC eller docker.

##### Initialiser miljøvariabler
Kjør ```initLocalEnv.sh``` skriptet for å sette opp miljøvariabler for lokal kjøring.
<br/>
Dette vil hente Azure hemmeligheter og diverse miljøvariabler fra POD kjørende i dev

Hvis du ikke får `permission denied` når du prøver å kjøre skriptet så må du gi deg selv tilgang til å kjøre shell skript med følgende kommand:
```bash
Kjør chmod +x ./initLocalEnv.sh
```

Du kan da starte opp applikasjonen ved å kjøre [BidragGrunnlagLokalNais.kt](src/test/kotlin/no/nav/bidrag/grunnlag/BidragGrunnlagLokalNais.kt)

Gå til http://localhost:8086 for å åpne swagger-ui
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.9"
services:
database:
image: postgres:latest
ports:
- "5455:5432"
environment:
POSTGRES_USER: cloudsqliamuser
POSTGRES_PASSWORD: admin
POSTGRES_DB: bidrag-grunnlag
volumes:
- db:/var/lib/postgresql/data
volumes:
db:
driver: local
storage:
driver: local
2 changes: 2 additions & 0 deletions initEnv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kubectl config use dev-gcp
kubectl exec -n=bidrag --tty deployment/bidrag-grunnlag printenv | grep -E 'AZURE_|_URL|SCOPE' > src/test/resources/application-lokal-nais-secrets.properties
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<version>3.1.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -43,7 +43,12 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
<version>2.2</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.15</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/no/nav/bidrag/grunnlag/BidragGrunnlag.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.boot.SpringApplication
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration

@EnableJwtTokenValidation(ignore = ["org.springdoc", "org.springframework"])
@SpringBootApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.http.SessionCreationPolicy
import org.springframework.security.web.SecurityFilterChain
import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint

@Configuration
class SecurityConfiguration {

@Bean
fun filterChain(http: HttpSecurity): SecurityFilterChain {
http.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.csrf()
.disable()
.authorizeHttpRequests()
.requestMatchers("/**")
.permitAll()
.anyRequest()
.fullyAuthenticated()

http
.authorizeHttpRequests { auth ->
auth.anyRequest().permitAll()
}
.csrf { it.disable() }
return http.build()
}
}
35 changes: 19 additions & 16 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,7 @@ management:
####################################################################

spring:
config.activate.on-profile: live
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_DATABASE}?user=${DB_USERNAME}&password=${DB_PASSWORD}
hikari:
idle-timeout: 10001
max-lifetime: 30001
connectionTimeout: 1000
maximum-pool-size: 10
minimum-idle: 1
flyway:
enabled: true
locations: classpath:/db/migration
jpa:
hibernate.connection.provider_class: org.hibernate.hikaricp.internal.HikariCPConnectionProvider
database: postgresql
config.activate.on-profile: live,lokal-nais
security:
oauth2:
resourceserver:
Expand Down Expand Up @@ -114,3 +99,21 @@ no.nav.security.jwt:
discoveryurl: ${AZURE_APP_WELL_KNOWN_URL}
accepted_audience: ${AZURE_APP_CLIENT_ID}, api://${AZURE_APP_CLIENT_ID}

---
spring:
config.activate.on-profile: live
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_DATABASE}?user=${DB_USERNAME}&password=${DB_PASSWORD}
hikari:
idle-timeout: 10001
max-lifetime: 30001
connectionTimeout: 1000
maximum-pool-size: 10
minimum-idle: 1
flyway:
enabled: true
locations: classpath:/db/migration
jpa:
hibernate.connection.provider_class: org.hibernate.hikaricp.internal.HikariCPConnectionProvider
database: postgresql
23 changes: 23 additions & 0 deletions src/test/kotlin/no/nav/bidrag/grunnlag/BidragGrunnlagLokalNais.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package no.nav.bidrag.grunnlag

import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
import no.nav.security.token.support.spring.test.EnableMockOAuth2Server
import org.springframework.boot.SpringApplication
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.FilterType
import org.springframework.context.annotation.Profile

@SpringBootApplication
@EnableJwtTokenValidation(ignore = ["org.springdoc", "org.springframework"])
@ComponentScan(excludeFilters = [ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = [BidragGrunnlag::class])])
@Profile("lokal-nais")
class BidragGrunnlagLokalNais

fun main(args: Array<String>) {
val app = SpringApplication(BidragGrunnlagLokalNais::class.java)
app.setAdditionalProfiles("lokal-nais", "lokal-nais-secrets")
app.run(*args)
}
16 changes: 16 additions & 0 deletions src/test/resources/application-lokal-nais.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server.port: 8086
spring:
flyway:
enabled: true
locations: classpath:/db/migration
datasource:
url: jdbc:postgresql://localhost:${DB_PORT:5455}/${DB_DATABASE:bidrag-grunnlag}?user=${DB_USERNAME:cloudsqliamuser}&password=${DB_PASSWORD:admin}
type: com.zaxxer.hikari.HikariDataSource
kafka:
bootstrap-servers: ${KAFKA_BROKERS}
properties:
security.protocol: PLAINTEXT
consumer:
enableAutoCommit: false
listener:
ackMode: RECORD