Skip to content

Commit 3018e10

Browse files
committed
Ktlint versjon 1.x
1 parent c861a9c commit 3018e10

File tree

76 files changed

+3734
-3290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3734
-3290
lines changed

build.gradle.kts

Lines changed: 79 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,79 @@
1-
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2-
import org.gradle.api.tasks.testing.logging.TestLogEvent
3-
4-
plugins {
5-
kotlin("jvm") version Kotlin.version
6-
id(Spotless.spotless) version Spotless.version
7-
`java-library`
8-
`maven-publish`
9-
}
10-
11-
allprojects {
12-
group = "no.nav.dagpenger"
13-
14-
apply(plugin = "org.jetbrains.kotlin.jvm")
15-
apply(plugin = Spotless.spotless)
16-
17-
dependencies {
18-
implementation(kotlin("stdlib-jdk8"))
19-
20-
// ulid
21-
implementation(Ulid.ulid)
22-
23-
testImplementation(kotlin("test"))
24-
testImplementation(Junit5.api)
25-
testRuntimeOnly(Junit5.engine)
26-
testImplementation(KoTest.assertions)
27-
testImplementation(KoTest.runner)
28-
}
29-
30-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
31-
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
32-
}
33-
34-
java {
35-
sourceCompatibility = JavaVersion.VERSION_17
36-
targetCompatibility = JavaVersion.VERSION_17
37-
}
38-
39-
tasks.withType<Wrapper> {
40-
gradleVersion = "7.5.1"
41-
}
42-
43-
spotless {
44-
kotlin {
45-
ktlint(Ktlint.version)
46-
}
47-
kotlinGradle {
48-
target("*.gradle.kts", "buildSrc/**/*.kt*")
49-
ktlint(Ktlint.version)
50-
}
51-
}
52-
53-
tasks.withType<Test> {
54-
useJUnitPlatform()
55-
testLogging {
56-
showExceptions = true
57-
showStackTraces = true
58-
exceptionFormat = TestExceptionFormat.FULL
59-
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
60-
showStandardStreams = true
61-
}
62-
}
63-
64-
tasks.named("compileKotlin") {
65-
dependsOn("spotlessApply", "spotlessKotlinCheck")
66-
}
67-
68-
repositories {
69-
mavenCentral()
70-
maven("https://jitpack.io")
71-
}
72-
}
73-
74-
subprojects {
75-
apply(plugin = "org.jetbrains.kotlin.jvm")
76-
apply(plugin = "maven-publish")
77-
78-
dependencies {
79-
implementation(kotlin("stdlib-jdk8"))
80-
81-
testImplementation(kotlin("test"))
82-
testImplementation(Junit5.api)
83-
testRuntimeOnly(Junit5.engine)
84-
testImplementation(Mockk.mockk)
85-
}
86-
87-
val repoUrl = "https://github.com/navikt/dp-inntekt.git"
88-
val scmUrl = "scm:git:https://github.com/navikt/dp-inntekt.git"
89-
90-
val sourcesJar by tasks.registering(Jar::class) {
91-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
92-
archiveClassifier.set("sources")
93-
from(sourceSets["main"].allSource)
94-
}
95-
96-
artifacts {
97-
add("archives", sourcesJar)
98-
}
99-
100-
publishing {
101-
publications {
102-
create<MavenPublication>("maven") {
103-
from(components["java"])
104-
artifact(sourcesJar.get())
105-
106-
pom {
107-
name.set(project.name)
108-
url.set(repoUrl)
109-
withXml {
110-
asNode().appendNode("packaging", "jar")
111-
}
112-
licenses {
113-
license {
114-
name.set("MIT License")
115-
name.set("https://opensource.org/licenses/MIT")
116-
}
117-
}
118-
developers {
119-
developer {
120-
organization.set("NAV (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration")
121-
organizationUrl.set("https://www.nav.no")
122-
}
123-
}
124-
125-
scm {
126-
connection.set(scmUrl)
127-
developerConnection.set(scmUrl)
128-
url.set(repoUrl)
129-
}
130-
}
131-
}
132-
}
133-
}
134-
}
1+
buildscript { repositories { mavenCentral() } }
2+
3+
//
4+
//allprojects {
5+
// group = "no.nav.dagpenger"
6+
//
7+
// apply(plugin = "org.jetbrains.kotlin.jvm")
8+
// apply(plugin = Spotless.spotless)
9+
//
10+
// dependencies {
11+
// implementation(kotlin("stdlib-jdk8"))
12+
//
13+
// // ulid
14+
// implementation(Ulid.ulid)
15+
//
16+
// testImplementation(kotlin("test"))
17+
// testImplementation(Junit5.api)
18+
// testRuntimeOnly(Junit5.engine)
19+
// testImplementation(KoTest.assertions)
20+
// testImplementation(KoTest.runner)
21+
// }
22+
//
23+
// tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
24+
// kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
25+
// }
26+
//
27+
// java {
28+
// sourceCompatibility = JavaVersion.VERSION_17
29+
// targetCompatibility = JavaVersion.VERSION_17
30+
// }
31+
//
32+
// tasks.withType<Wrapper> {
33+
// gradleVersion = "7.5.1"
34+
// }
35+
//
36+
// spotless {
37+
// kotlin {
38+
// ktlint(Ktlint.version)
39+
// }
40+
// kotlinGradle {
41+
// target("*.gradle.kts", "buildSrc/**/*.kt*")
42+
// ktlint(Ktlint.version)
43+
// }
44+
// }
45+
//
46+
// tasks.withType<Test> {
47+
// useJUnitPlatform()
48+
// testLogging {
49+
// showExceptions = true
50+
// showStackTraces = true
51+
// exceptionFormat = TestExceptionFormat.FULL
52+
// events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
53+
// showStandardStreams = true
54+
// }
55+
// }
56+
//
57+
// tasks.named("compileKotlin") {
58+
// dependsOn("spotlessApply", "spotlessKotlinCheck")
59+
// }
60+
//
61+
// repositories {
62+
// mavenCentral()
63+
// maven("https://jitpack.io")
64+
// }
65+
//}
66+
//
67+
//subprojects {
68+
// apply(plugin = "org.jetbrains.kotlin.jvm")
69+
// apply(plugin = "maven-publish")
70+
//
71+
// dependencies {
72+
// implementation(kotlin("stdlib-jdk8"))
73+
//
74+
// testImplementation(kotlin("test"))
75+
// testImplementation(Junit5.api)
76+
// testRuntimeOnly(Junit5.engine)
77+
// testImplementation(Mockk.mockk)
78+
// }
79+
//}

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
plugins {
22
`kotlin-dsl`
3+
id("com.diffplug.spotless") version "6.23.3"
34
}
45

56
repositories {
7+
gradlePluginPortal()
68
mavenCentral()
79
}
10+
11+
dependencies {
12+
implementation(kotlin("gradle-plugin"))
13+
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.23.3")
14+
}

buildSrc/settings.gradle.kts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import com.diffplug.spotless.LineEnding
2+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
3+
import org.gradle.api.tasks.testing.logging.TestLogEvent
4+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
5+
6+
plugins {
7+
kotlin("jvm")
8+
id("com.diffplug.spotless")
9+
}
10+
11+
repositories {
12+
mavenCentral()
13+
maven("https://www.jitpack.io")
14+
}
15+
16+
dependencies {
17+
testImplementation(kotlin("test"))
18+
}
19+
20+
kotlin {
21+
jvmToolchain(17)
22+
}
23+
24+
tasks.test {
25+
useJUnitPlatform()
26+
testLogging {
27+
showExceptions = true
28+
showStackTraces = true
29+
exceptionFormat = TestExceptionFormat.FULL
30+
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
31+
}
32+
}
33+
34+
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
35+
kotlin {
36+
ktlint()
37+
targetExclude("build/generated/**")
38+
}
39+
40+
kotlinGradle {
41+
ktlint()
42+
}
43+
}
44+
45+
tasks.withType<KotlinCompile>().configureEach {
46+
dependsOn("spotlessApply")
47+
}

dp-inntekt-api/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCach
33

44

55
plugins {
6+
id("common")
67
application
78
id(Shadow.shadow) version Shadow.version
89
id("com.expediagroup.graphql") version "6.4.0"
910
id("de.undercouch.download") version "5.5.0"
1011
}
1112

12-
buildscript {
13-
repositories {
14-
mavenCentral()
15-
}
16-
}
17-
1813
repositories {
1914
mavenCentral()
2015
maven("https://packages.confluent.io/maven/")

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/ApiKeyAuthentication.kt

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@ import javax.crypto.spec.SecretKeySpec
1919

2020
enum class ApiKeyLocation(val location: String) {
2121
QUERY("query"),
22-
HEADER("header")
22+
HEADER("header"),
2323
}
2424

2525
fun ApplicationRequest.apiKeyAuthenticationCredentials(
2626
apiKeyName: String,
27-
apiKeyLocation: ApiKeyLocation
27+
apiKeyLocation: ApiKeyLocation,
2828
): ApiKeyCredential? {
2929
return when (
30-
val value: String? = when (apiKeyLocation) {
31-
ApiKeyLocation.QUERY -> this.queryParameters[apiKeyName]
32-
ApiKeyLocation.HEADER -> this.headers[apiKeyName]
33-
}
30+
val value: String? =
31+
when (apiKeyLocation) {
32+
ApiKeyLocation.QUERY -> this.queryParameters[apiKeyName]
33+
ApiKeyLocation.HEADER -> this.headers[apiKeyName]
34+
}
3435
) {
3536
null -> null
3637
else -> ApiKeyCredential(value)
3738
}
3839
}
3940

4041
data class ApiKeyCredential(val value: String) : Credential
42+
4143
data class ApiPrincipal(val apiKeyCredential: ApiKeyCredential?) : Principal
4244

4345
class ApiKeyAuthenticationProvider internal constructor(config: Configuration) : AuthenticationProvider(config) {
44-
4546
private var apiKeyName: String = config.apiKeyName
4647
private var apiKeyLocation: ApiKeyLocation = config.apiKeyLocation
4748
private val authenticationFunction = config.authenticationFunction
@@ -65,11 +66,12 @@ class ApiKeyAuthenticationProvider internal constructor(config: Configuration) :
6566
val credential = call.request.apiKeyAuthenticationCredentials(apiKeyName, apiKeyLocation)
6667
val principal = credential?.let { authenticationFunction(call, it) }
6768

68-
val cause = when {
69-
credential == null -> AuthenticationFailedCause.NoCredentials
70-
principal == null -> AuthenticationFailedCause.InvalidCredentials
71-
else -> null
72-
}
69+
val cause =
70+
when {
71+
credential == null -> AuthenticationFailedCause.NoCredentials
72+
principal == null -> AuthenticationFailedCause.InvalidCredentials
73+
else -> null
74+
}
7375

7476
if (cause != null) {
7577
context.challenge(apiKeyName, cause) { challenge, call ->
@@ -78,9 +80,9 @@ class ApiKeyAuthenticationProvider internal constructor(config: Configuration) :
7880
HttpAuthHeader.Parameterized(
7981
"API_KEY",
8082
mapOf("key" to apiKeyName),
81-
HeaderValueEncoding.QUOTED_ALWAYS
82-
)
83-
)
83+
HeaderValueEncoding.QUOTED_ALWAYS,
84+
),
85+
),
8486
)
8587
challenge.complete()
8688
}
@@ -94,17 +96,19 @@ class ApiKeyAuthenticationProvider internal constructor(config: Configuration) :
9496

9597
fun AuthenticationConfig.apiKeyAuth(
9698
name: String? = null,
97-
configure: ApiKeyAuthenticationProvider.Configuration.() -> Unit
99+
configure: ApiKeyAuthenticationProvider.Configuration.() -> Unit,
98100
) {
99101
val provider = ApiKeyAuthenticationProvider.Configuration(name).apply(configure).build()
100102
register(provider)
101103
}
102104

103105
internal class ApiKeyVerifier(private val secret: String) {
104-
105106
private val algorithm = "HmacSHA256"
106107

107-
fun verify(apiKey: String, expectedApiKey: String): Boolean {
108+
fun verify(
109+
apiKey: String,
110+
expectedApiKey: String,
111+
): Boolean {
108112
return apiKey == generate(expectedApiKey)
109113
}
110114

0 commit comments

Comments
 (0)