diff --git a/build.gradle.kts b/build.gradle.kts index 29a9551..9b98a4b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,10 @@ repositories { mavenCentral() } +extra["springCloudVersion"] = "2023.0.2" + dependencies { + implementation("org.springframework.cloud:spring-cloud-starter-config") implementation("org.springframework.boot:spring-boot-starter-oauth2-authorization-server") implementation("org.springframework.boot:spring-boot-starter-oauth2-client") implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server") @@ -53,6 +56,12 @@ dependencies { implementation("io.opentelemetry:opentelemetry-exporter-zipkin") } +dependencyManagement { + imports { + mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}") + } +} + tasks.withType { kotlinOptions { freeCompilerArgs += "-Xjsr305=strict" diff --git a/src/main/kotlin/com/api/auth/config/SecurityConfig.kt b/src/main/kotlin/com/api/auth/config/SecurityConfig.kt index e9de21d..aadeed7 100644 --- a/src/main/kotlin/com/api/auth/config/SecurityConfig.kt +++ b/src/main/kotlin/com/api/auth/config/SecurityConfig.kt @@ -6,9 +6,7 @@ import org.springframework.context.annotation.Configuration import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity import org.springframework.security.config.annotation.web.builders.HttpSecurity import org.springframework.security.config.annotation.web.builders.WebSecurity -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer -import org.springframework.security.config.http.SessionCreationPolicy import org.springframework.security.web.SecurityFilterChain import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 0000000..6d18e0d --- /dev/null +++ b/src/main/resources/application-local.yml @@ -0,0 +1,29 @@ + +#spring: +# cloud: +# config: +# enabled: false +# datasource: +# url: jdbc:postgresql://localhost:5433/auth +# username: auth +# password: auth +# flyway: +# locations: classpath:db/migration +# r2dbc: +# url: r2dbc:postgresql://localhost:5433/auth +# username: auth +# password: auth +# +#jwt: +# rsa-key-path: "rsaKey.json" + + +spring: + application: + name: auth + config: + import: "optional:configserver:http://localhost:9000" + cloud: + config: + fail-fast: true + diff --git a/src/main/resources/application-stag.yml b/src/main/resources/application-stag.yml index af1b2eb..82ff3b2 100644 --- a/src/main/resources/application-stag.yml +++ b/src/main/resources/application-stag.yml @@ -1,45 +1,9 @@ spring: application: name: auth + config: + import: "optional:configserver:http://localhost:9000" + cloud: + config: + fail-fast: true - datasource: - url: jdbc:postgresql://cnpg-cluster-rw.database.svc.cluster.local:5432/auth - username: auth - password: auth - flyway: - locations: classpath:db/migration - r2dbc: - url: r2dbc:postgresql://cnpg-cluster-rw.database.svc.cluster.local:5432/auth - username: auth - password: auth - -jwt: - rsa-key-path: "rsaKey.json" - -######################## -# DevOps -######################## -# Actuator, Prometheus, OpenTelemetry -management: - endpoints: - info: - enabled: true - web: - exposure: - include: health, info, prometheus, metrics - metrics: - enabled: true - export: - prometheus: - enabled: true - prometheus: - enabled: true - tracing: - sampling: - probability: 1.0 - zipkin: - tracing: - endpoint: http://otel-collector-opentelemetry-collector.tracing:9411/api/v2/spans -logging: - pattern: - level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]" \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index 5e39d21..0000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1,21 +0,0 @@ -server: - port: 8081 - -spring: - application: - name: auth - - datasource: - url: jdbc:postgresql://localhost:5433/auth - username: auth - password: auth - flyway: - locations: classpath:db/migration - r2dbc: - url: r2dbc:postgresql://localhost:5433/auth - username: auth - password: auth - -jwt: - rsa-key-path: "rsaKey.json" - diff --git a/src/main/resources/bootstrap.yaml b/src/main/resources/bootstrap.yaml new file mode 100644 index 0000000..4702afa --- /dev/null +++ b/src/main/resources/bootstrap.yaml @@ -0,0 +1,9 @@ +spring: + application: + name: auth + cloud: + config: + uri: https://localhost:9000 + fail-fast: true + profiles: + active: local diff --git a/src/test/kotlin/com/api/auth/JwtTest.kt b/src/test/kotlin/com/api/auth/JwtTest.kt index 30f0b9a..cda8a80 100644 --- a/src/test/kotlin/com/api/auth/JwtTest.kt +++ b/src/test/kotlin/com/api/auth/JwtTest.kt @@ -8,10 +8,13 @@ import com.api.auth.service.AuthService import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest +import org.springframework.data.annotation.AccessType +import org.springframework.test.context.ActiveProfiles import java.time.Instant import java.time.temporal.ChronoUnit @SpringBootTest +@ActiveProfiles("local") class JwtTest( @Autowired private val rsaKeyBuilder: RsaKeyBuilder, @Autowired private val jwtBuilder: JwtBuilder, @@ -35,7 +38,7 @@ class JwtTest( @Test fun createToken1() { val request = JwtRequest( - address = "qweqwascfsadadfasd" + address = "test12345123" ) authService.createToken(request).block() }