Skip to content

Commit

Permalink
Dala 1189 ktlint latest version (#175)
Browse files Browse the repository at this point in the history
update ktlint to latest version
  • Loading branch information
emanueldfine authored Feb 8, 2023
1 parent ab8911f commit 0770ba1
Show file tree
Hide file tree
Showing 139 changed files with 786 additions and 693 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*.{kt,kts}]
ktlint_standard_argument-list-wrapping = disabled
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE/manual_maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Note: To create a PR using this template add the query parameter `template=manua
## Dataland
### Skipped updates
The following known issues need to be reviewed in case a compatible version is available. Add new known issues as they appear.
- [ ] ktlint 0.45.2 (higher version is not compatible with jlleitschuh plugin)
- [ ] io.gitlab.arturbosch.detekt:detekt-cli 1.21.0 (Failed to compile)
- [ ] sonarqube 3.4.0.2513 not update to 3.5.X, due to issues in file resolving mechanism
- [ ] Cypress 11.2.0 not updated to 12.X.X, due to introduction of spurious errors in the CI
Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ plugins {
id("io.gitlab.arturbosch.detekt") version "1.20.0"
id("com.github.node-gradle.node") version "3.5.1" apply false
id("org.springframework.boot") version "3.0.1" apply false
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
id("org.jlleitschuh.gradle.ktlint") version "11.1.0"
kotlin("jvm") version "1.8.0"
kotlin("plugin.spring") version "1.8.0" apply false
id("org.sonarqube") version "3.4.0.2513"
Expand All @@ -82,11 +82,11 @@ sonarqube {
"**/test/**," +
"**/tests/**," +
"**/LocalCorsConfig.kt," +
"./dataland-frontend/src/main.ts"
"./dataland-frontend/src/main.ts",
)
property(
"sonar.sources",
subprojects.flatMap { project -> project.properties["sonarSources"] as Iterable<*> }
subprojects.flatMap { project -> project.properties["sonarSources"] as Iterable<*> },
)
}
}
Expand All @@ -99,10 +99,10 @@ tasks.jacocoTestReport {
dependsOn(tasks.build)
dependsOn(subprojects.flatMap { it.tasks.filter { it.name == "compileKotlin" } })
sourceDirectories.setFrom(
subprojects.flatMap { project -> project.properties["jacocoSources"] as Iterable<*> }
subprojects.flatMap { project -> project.properties["jacocoSources"] as Iterable<*> },
)
classDirectories.setFrom(
subprojects.flatMap { project -> project.properties["jacocoClasses"] as Iterable<*> }
subprojects.flatMap { project -> project.properties["jacocoClasses"] as Iterable<*> },
)
reports {
xml.required.set(true)
Expand Down
2 changes: 1 addition & 1 deletion dataland-api-key-manager/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ val jacocoClasses by extra(
exclude("**/openApiClient/**")
}.files
}
}
},
)
val jacocoVersion: String by project
val openApiGeneratorTimeOutThresholdInSeconds: String by project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import org.springframework.context.annotation.Import
KnownErrorControllerAdvice::class,
UnknownErrorControllerAdvice::class,
DefaultResponseSchemaCustomizer::class,
RequestRejectedExceptionHandler::class
]
RequestRejectedExceptionHandler::class,
],
)
@ComponentScan(basePackages = ["org.dataland"])
class DatalandApiKeyManager : OpenAPIConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,96 +18,96 @@ import org.springframework.web.bind.annotation.RequestParam
*/
interface ApiKeyAPI {

/**
* A method to generate a new API key
* @param daysValid defines how many days the generated API key can be used, a null value results in an
* infinite validity
* @return new API key for the user together with meta info associated with that API key
*/
@Operation(
summary = "Generate a new API key.",
description = "Generates and persists a new API key for the requesting user with an expiry date based on " +
"the number of valid days in the request param."
"the number of valid days in the request param.",
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "Successfully retrieved new api key.")
]
ApiResponse(responseCode = "200", description = "Successfully retrieved new api key."),
],
)
@GetMapping(
value = ["/generateApiKey"],
produces = ["application/json"]
produces = ["application/json"],
)
@PreAuthorize("hasRole('ROLE_USER')")
@SecurityRequirement(name = "default-bearer-auth")
@SecurityRequirement(name = "default-oauth")
/**
* A method to generate a new API key
* @param daysValid defines how many days the generated API key can be used, a null value results in an
* infinite validity
* @return new API key for the user together with meta info associated with that API key
*/
fun generateApiKey(
@RequestParam(required = false) daysValid: Int?
@RequestParam(required = false) daysValid: Int?,
): ResponseEntity<ApiKeyAndMetaInfo>

/** A method to get meta information about the API key status of a specific user, like if that user
* even has an API key registered, and what the expiry date of that (potential) API key is.
* Information about the user is derived from the Bearer token of the request.
* This method is needed by the Frontend to display the API key status to a logged in user.
* @return API key meta info which includes all the required info for the API key status
*/
@Operation(
summary = "Get API key meta info of a specific user.",
description = "Gets meta info about the API key status of a user based on the Keycloak user ID."
description = "Gets meta info about the API key status of a user based on the Keycloak user ID.",
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "Successfully retrieved API key status for the user ID.")
]
ApiResponse(responseCode = "200", description = "Successfully retrieved API key status for the user ID."),
],
)
@GetMapping(
value = ["/getApiKeyMetaInfoForUser"],
produces = ["application/json"]
produces = ["application/json"],
)
@PreAuthorize("hasRole('ROLE_USER')")
@SecurityRequirement(name = "default-bearer-auth")
@SecurityRequirement(name = "default-oauth")
/** A method to get meta information about the API key status of a specific user, like if that user
* even has an API key registered, and what the expiry date of that (potential) API key is.
* Information about the user is derived from the Bearer token of the request.
* This method is needed by the Frontend to display the API key status to a logged in user.
* @return API key meta info which includes all the required info for the API key status
*/
fun getApiKeyMetaInfoForUser(): ResponseEntity<ApiKeyMetaInfo>

/**
* A method to validate an API key
* @param apiKey holds the API key which needs to be validated as string
* @return API key meta info which also includes the result of the validation process
*/

@Operation(
summary = "Validate an API key.",
description = "Checks if an API key is valid and returns the validation results together with its meta info."
description = "Checks if an API key is valid and returns the validation results together with its meta info.",
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "API key validation process finished.")
]
ApiResponse(responseCode = "200", description = "API key validation process finished."),
],
)
@GetMapping(
value = ["/validateApiKey"],
produces = ["application/json"]
produces = ["application/json"],
)
fun validateApiKey(@RequestParam apiKey: String): ResponseEntity<ApiKeyMetaInfo>

/**
* A method to validate an API key
* @param apiKey holds the API key which needs to be validated as string
* @return API key meta info which also includes the result of the validation process
* A method to revoke the API key of the requesting user.
* @return a response model which informs about the success of the revokement process together with a message.
*/

fun validateApiKey(@RequestParam apiKey: String,): ResponseEntity<ApiKeyMetaInfo>

@Operation(
summary = "Revoke an existing API key.",
description = "Checks if API key exists in storage for the requesting user and revokes it. If there is no " +
"API key registered for the user, this is reported in the response."
"API key registered for the user, this is reported in the response.",
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "API key revokement process finished.")
]
ApiResponse(responseCode = "200", description = "API key revokement process finished."),
],
)
@PostMapping(
value = ["/revokeApiKey"],
produces = ["application/json"]
produces = ["application/json"],
)
/**
* A method to revoke the API key of the requesting user.
* @return a response model which informs about the success of the revokement process together with a message.
*/
@PreAuthorize("hasRole('ROLE_USER')")
@SecurityRequirement(name = "default-bearer-auth")
@SecurityRequirement(name = "default-oauth")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ import io.swagger.v3.oas.annotations.servers.Server
@OpenAPIDefinition(
info = Info(
title = "Dataland API key manager API documentation",
version = "1.0.0"
version = "1.0.0",
),
servers = [Server(url = "/api-keys")]
servers = [Server(url = "/api-keys")],
)
@SecurityScheme(
name = "default-bearer-auth",
scheme = "bearer",
type = SecuritySchemeType.HTTP,
`in` = SecuritySchemeIn.HEADER
`in` = SecuritySchemeIn.HEADER,
)
@SecurityScheme(
name = "default-oauth",
type = SecuritySchemeType.OAUTH2,
flows = OAuthFlows(
authorizationCode = OAuthFlow(
authorizationUrl = "/keycloak/realms/datalandsecurity/protocol/openid-connect/auth",
tokenUrl = "/keycloak/realms/datalandsecurity/protocol/openid-connect/token"
)
)
tokenUrl = "/keycloak/realms/datalandsecurity/protocol/openid-connect/token",
),
),
)
interface OpenAPIConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SwaggerUiSecurityConfig {
.headers().contentSecurityPolicy(
"default-src 'self'; script-src 'self' 'sha256-4IiDsMH+GkJlxivIDNfi6qk0O5HPtzyvNwVT3Wt8TIw=';" +
" style-src 'self'; frame-ancestors 'self'; form-action 'self'; font-src 'self' data:;" +
" img-src 'self' data:"
" img-src 'self' data:",
)
return http.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ data class ApiKeyMetaInfo(
val active: Boolean? = null,

@field:JsonProperty(required = false)
val validationMessage: String? = null
val validationMessage: String? = null,
) {
constructor(apiKeyEntity: ApiKeyEntity, active: Boolean?, validationMessage: String?) :
this(
apiKeyEntity.keycloakUserId,
apiKeyEntity.keycloakRoles,
apiKeyEntity.expiryDate,
active,
validationMessage
validationMessage,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ data class RevokeApiKeyResponse(
val revokementProcessSuccessful: Boolean,

@field:JsonProperty(required = true)
val revokementProcessMessage: String
val revokementProcessMessage: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ApiKeyManager(
if (daysValid != null && daysValid <= 0) {
throw InvalidInputApiException(
"If set, the value of daysValid must be a positive integer.",
"If set, the value of daysValid must be a positive integer but it was $daysValid"
"If set, the value of daysValid must be a positive integer but it was $daysValid",
)
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ class ApiKeyManager(
val apiKeyEntity = ApiKeyEntity(encodedSecret, apiKeyMetaInfo)
apiKeyRepository.save(apiKeyEntity)
logger.info(
"Generated Api Key with encoded secret value $encodedSecret and meta info $apiKeyMetaInfo."
"Generated Api Key with encoded secret value $encodedSecret and meta info $apiKeyMetaInfo.",
)
return ApiKeyAndMetaInfo(apiKeyUtility.convertToApiKey(parsedApiKey), apiKeyMetaInfo)
}
Expand All @@ -118,7 +118,7 @@ class ApiKeyManager(
active = true,
keycloakUserId = keycloakUserId,
expiryDate = apiKeyEntityOfKeycloakUser.expiryDate,
keycloakRoles = apiKeyEntityOfKeycloakUser.keycloakRoles
keycloakRoles = apiKeyEntityOfKeycloakUser.keycloakRoles,
)
} else { ApiKeyMetaInfo(active = false, validationMessage = validationMessageExpiredApiKey) }
}
Expand All @@ -133,13 +133,13 @@ class ApiKeyManager(
val receivedAndParsedApiKey = apiKeyUtility.parseApiKey(receivedApiKey)

val apiKeyEntityOptional = apiKeyRepository.findById(
receivedAndParsedApiKey.keycloakUserId
receivedAndParsedApiKey.keycloakUserId,
)

if (apiKeyEntityOptional.isEmpty) {
logger.info(
"Dataland user with the encoded Keycloak user Id" +
"${receivedAndParsedApiKey.keycloakUserId} has no API key registered."
"${receivedAndParsedApiKey.keycloakUserId} has no API key registered.",
)
return ApiKeyMetaInfo(active = false, validationMessage = validationMessageNoApiKeyRegistered)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ApiKeyManagerTest(
Assertions.assertEquals(
"The API key you provided for your Dataland account is expired.",
responseMessage,
"The expired api key was unexpectedly validated."
"The expired api key was unexpectedly validated.",
)
}
}
2 changes: 1 addition & 1 deletion dataland-backend-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ val jacocoClasses by extra(
exclude("**/openApiClient/**")
}.files
}
}
},
)
val jacocoVersion: String by project

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ApiKeyUtility {
if (receivedApiKey.count { it.toString() == "_" } != numberOfUnderscoreDelimitersExpectedInApiKey) {
throw InvalidInputApiException(
apiKeyInvalidFormatSummary,
validateApiKeyDelimitersExceptionMessage
validateApiKeyDelimitersExceptionMessage,
)
}
}
Expand All @@ -51,7 +51,7 @@ class ApiKeyUtility {
if (!regexFor80HexCharacters.matches(potentialApiKeySecret)) {
throw InvalidInputApiException(
apiKeyInvalidFormatSummary,
validateApiKeySecretExceptionMessage
validateApiKeySecretExceptionMessage,
)
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ class ApiKeyUtility {
val apiKeyWithoutCrc32Value = keycloakUserIdBase64Encoded + "_" + apiKeySecret

return calculateCrc32Value(
apiKeyWithoutCrc32Value.toByteArray(charset)
apiKeyWithoutCrc32Value.toByteArray(charset),
).toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class DefaultResponseSchemaCustomizer : OpenApiCustomizer {
.content(
Content().addMediaType(
org.springframework.http.MediaType.APPLICATION_JSON_VALUE,
MediaType().schema(errorResponseSchema)
)
MediaType().schema(errorResponseSchema),
),
)
.description("An error occurred")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import org.springframework.http.HttpStatus
*/
class HttpStatusIntegerSerializer : JsonSerializer<HttpStatus>() {
override fun serialize(value: HttpStatus?, gen: JsonGenerator, serializers: SerializerProvider) {
if (value == null) gen.writeNull()
else gen.writeNumber(value.value())
if (value == null) {
gen.writeNull()
} else {
gen.writeNumber(value.value())
}
}
}
Loading

0 comments on commit 0770ba1

Please sign in to comment.