diff --git a/build.gradle.kts b/build.gradle.kts index 9afd316ed..dfc6bfa6c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -60,6 +60,7 @@ scmVersion { commit { version -> "Release $version" } } + localOnly = true scmVersion { checks.isSnapshotDependencies = false } diff --git a/reposilite-backend/src/generated/kotlin/com/reposilite/ReposiliteProperties.kt b/reposilite-backend/src/generated/kotlin/com/reposilite/ReposiliteProperties.kt index 654223d1e..243037058 100644 --- a/reposilite-backend/src/generated/kotlin/com/reposilite/ReposiliteProperties.kt +++ b/reposilite-backend/src/generated/kotlin/com/reposilite/ReposiliteProperties.kt @@ -1,3 +1,3 @@ package com.reposilite -const val VERSION = "3.0.0-SNAPSHOT" \ No newline at end of file +const val VERSION = "3.0.1-SNAPSHOT" \ No newline at end of file diff --git a/reposilite-backend/src/integration/kotlin/com/reposilite/configuration/SettingsIntegrationTest.kt b/reposilite-backend/src/integration/kotlin/com/reposilite/configuration/SettingsIntegrationTest.kt index 4e192f1f7..7f774f1f0 100644 --- a/reposilite-backend/src/integration/kotlin/com/reposilite/configuration/SettingsIntegrationTest.kt +++ b/reposilite-backend/src/integration/kotlin/com/reposilite/configuration/SettingsIntegrationTest.kt @@ -1,20 +1,20 @@ package com.reposilite.configuration -import com.reposilite.specification.LocalSpecificationJunitExtension -import com.reposilite.specification.RemoteSpecificationJunitExtension import com.reposilite.ReposiliteObjectMapper import com.reposilite.auth.application.AuthenticationSettings import com.reposilite.auth.application.LdapSettings -import com.reposilite.frontend.application.FrontendSettings -import com.reposilite.maven.application.MavenSettings import com.reposilite.configuration.shared.SharedConfigurationFacade import com.reposilite.configuration.specification.SettingsIntegrationSpecification +import com.reposilite.frontend.application.FrontendSettings +import com.reposilite.maven.application.MavenSettings +import com.reposilite.specification.LocalSpecificationJunitExtension +import com.reposilite.specification.RemoteSpecificationJunitExtension import com.reposilite.statistics.api.ResolvedRequestsInterval.YEARLY import com.reposilite.statistics.application.StatisticsSettings import com.reposilite.web.application.WebSettings import com.reposilite.web.http.ErrorResponse -import io.javalin.http.HttpCode.OK -import io.javalin.http.HttpCode.UNAUTHORIZED +import io.javalin.http.HttpStatus.OK +import io.javalin.http.HttpStatus.UNAUTHORIZED import kong.unirest.Unirest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue diff --git a/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenApiIntegrationTest.kt b/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenApiIntegrationTest.kt index 4023714ec..06dea92e3 100644 --- a/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenApiIntegrationTest.kt +++ b/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenApiIntegrationTest.kt @@ -18,11 +18,11 @@ package com.reposilite.maven +import com.reposilite.maven.specification.MavenIntegrationSpecification import com.reposilite.specification.LocalSpecificationJunitExtension import com.reposilite.specification.RemoteSpecificationJunitExtension -import com.reposilite.maven.specification.MavenIntegrationSpecification import com.reposilite.token.RoutePermission.READ -import io.javalin.http.HttpCode.UNAUTHORIZED +import io.javalin.http.HttpStatus.UNAUTHORIZED import kong.unirest.Unirest.get import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue @@ -60,7 +60,7 @@ internal abstract class MavenApiIntegrationTest : MavenIntegrationSpecification( .asString() // then: service rejects request - assertEquals(UNAUTHORIZED.status, unauthorizedResponse.status) + assertEquals(UNAUTHORIZED.code, unauthorizedResponse.status) // given: valid credentials val (name, secret) = useAuth("name", "secret", routes = mapOf("/$artifactPath" to READ)) @@ -90,7 +90,7 @@ internal abstract class MavenApiIntegrationTest : MavenIntegrationSpecification( .asString() // then: service rejects request - assertEquals(UNAUTHORIZED.status, unauthorizedResponse.status) + assertEquals(UNAUTHORIZED.code, unauthorizedResponse.status) // given: valid credentials val (name, secret) = useAuth("name", "secret", routes = mapOf(endpoint.replace("/api/maven/details", "") to READ)) @@ -130,7 +130,7 @@ internal abstract class MavenApiIntegrationTest : MavenIntegrationSpecification( .asString() // then: service rejects request - assertEquals(UNAUTHORIZED.status, unauthorizedResponse.status) + assertEquals(UNAUTHORIZED.code, unauthorizedResponse.status) // given: valid credentials val (name, secret) = useAuth("name", "secret", routes = mapOf("/private" to READ)) diff --git a/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenIntegrationTest.kt b/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenIntegrationTest.kt index 987922a38..da7d94f5d 100644 --- a/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenIntegrationTest.kt +++ b/reposilite-backend/src/integration/kotlin/com/reposilite/maven/MavenIntegrationTest.kt @@ -18,14 +18,14 @@ package com.reposilite.maven +import com.reposilite.configuration.local.LocalConfiguration +import com.reposilite.maven.specification.MavenIntegrationSpecification import com.reposilite.specification.LocalSpecificationJunitExtension import com.reposilite.specification.RemoteSpecificationJunitExtension -import com.reposilite.maven.specification.MavenIntegrationSpecification -import com.reposilite.configuration.local.LocalConfiguration import com.reposilite.storage.api.DocumentInfo import com.reposilite.web.http.ErrorResponse -import io.javalin.http.HttpCode.NOT_FOUND -import io.javalin.http.HttpCode.UNAUTHORIZED +import io.javalin.http.HttpStatus.NOT_FOUND +import io.javalin.http.HttpStatus.UNAUTHORIZED import kong.unirest.HeaderNames.CONTENT_LENGTH import kong.unirest.Unirest.delete import kong.unirest.Unirest.get @@ -86,7 +86,7 @@ internal abstract class MavenIntegrationTest : MavenIntegrationSpecification() { .asObject(ErrorResponse::class.java) // then: service should reject the request - assertEquals(UNAUTHORIZED.status, response.status) + assertEquals(UNAUTHORIZED.code, response.status) } @Test @@ -164,7 +164,7 @@ internal abstract class MavenIntegrationTest : MavenIntegrationSpecification() { val response = get(address).asString() // then: service responds with custom 404 page - assertEquals(NOT_FOUND.status, response.status) + assertEquals(NOT_FOUND.code, response.status) assertTrue(response.body.contains("Reposilite - 404 Not Found")) } diff --git a/reposilite-backend/src/integration/kotlin/com/reposilite/specification/ReposiliteSpecification.kt b/reposilite-backend/src/integration/kotlin/com/reposilite/specification/ReposiliteSpecification.kt index e606fea0f..58c427a50 100644 --- a/reposilite-backend/src/integration/kotlin/com/reposilite/specification/ReposiliteSpecification.kt +++ b/reposilite-backend/src/integration/kotlin/com/reposilite/specification/ReposiliteSpecification.kt @@ -25,8 +25,8 @@ import com.reposilite.token.Route import com.reposilite.token.RoutePermission import com.reposilite.token.api.CreateAccessTokenRequest import com.reposilite.web.http.ErrorResponse -import io.javalin.http.HttpCode -import io.javalin.http.HttpCode.UNAUTHORIZED +import io.javalin.http.HttpStatus +import io.javalin.http.HttpStatus.UNAUTHORIZED import kong.unirest.HttpRequest import kong.unirest.HttpResponse import kong.unirest.Unirest @@ -64,16 +64,16 @@ internal abstract class ReposiliteSpecification : ReposiliteRunner() { fun HttpRequest<*>.asJacksonObject(type: KClass): HttpResponse = this.asObject { ReposiliteObjectMapper.DEFAULT_OBJECT_MAPPER.readValue(it.contentAsString, type.java) } - fun assertStatus(expectedCode: HttpCode, value: Int) { - assertEquals(expectedCode.status, value) + fun assertStatus(expectedCode: HttpStatus, value: Int) { + assertEquals(expectedCode.code, value) } - fun assertErrorResponse(expectedCode: HttpCode, response: HttpResponse<*>) { + fun assertErrorResponse(expectedCode: HttpStatus, response: HttpResponse<*>) { assertStatus(expectedCode, response.status) assertFalse(response.isSuccess) } - fun assertSuccessResponse(expectedCode: HttpCode, response: HttpResponse, block: (T) -> Unit = {}): T { + fun assertSuccessResponse(expectedCode: HttpStatus, response: HttpResponse, block: (T) -> Unit = {}): T { assertStatus(expectedCode, response.status) assertTrue(response.isSuccess) return response.body.also { block(it) } diff --git a/reposilite-backend/src/integration/kotlin/com/reposilite/statistics/StatisticsIntegrationTest.kt b/reposilite-backend/src/integration/kotlin/com/reposilite/statistics/StatisticsIntegrationTest.kt index 5da208fd7..d88cbbfb4 100644 --- a/reposilite-backend/src/integration/kotlin/com/reposilite/statistics/StatisticsIntegrationTest.kt +++ b/reposilite-backend/src/integration/kotlin/com/reposilite/statistics/StatisticsIntegrationTest.kt @@ -26,7 +26,7 @@ import com.reposilite.statistics.api.ResolvedCountResponse import com.reposilite.statistics.specification.StatisticsIntegrationSpecification import com.reposilite.token.AccessTokenPermission.MANAGER import com.reposilite.token.RoutePermission.READ -import io.javalin.http.HttpCode.UNAUTHORIZED +import io.javalin.http.HttpStatus.UNAUTHORIZED import kong.unirest.Unirest.get import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -57,7 +57,7 @@ internal abstract class StatisticsIntegrationTest : StatisticsIntegrationSpecifi val unauthorizedResponse = get(endpoint).asString() // then: service rejects request - assertEquals(UNAUTHORIZED.status, unauthorizedResponse.status) + assertEquals(UNAUTHORIZED.code, unauthorizedResponse.status) // given: a valid credentials val (name, secret) = useAuth("name", "secret", listOf(MANAGER)) @@ -82,7 +82,7 @@ internal abstract class StatisticsIntegrationTest : StatisticsIntegrationSpecifi val unauthorizedResponse = get(endpoint).asString() // then: service rejects request - assertEquals(UNAUTHORIZED.status, unauthorizedResponse.status) + assertEquals(UNAUTHORIZED.code, unauthorizedResponse.status) // given: a valid credentials val (name, secret) = useAuth("name", "secret", emptyList(), mapOf(identifier.toString() to READ)) diff --git a/reposilite-backend/src/integration/kotlin/com/reposilite/token/AccessTokenIntegrationTest.kt b/reposilite-backend/src/integration/kotlin/com/reposilite/token/AccessTokenIntegrationTest.kt index 00a39322a..438a0cd47 100644 --- a/reposilite-backend/src/integration/kotlin/com/reposilite/token/AccessTokenIntegrationTest.kt +++ b/reposilite-backend/src/integration/kotlin/com/reposilite/token/AccessTokenIntegrationTest.kt @@ -27,9 +27,9 @@ import com.reposilite.token.api.CreateAccessTokenResponse import com.reposilite.token.api.CreateAccessTokenWithNoNameRequest import com.reposilite.token.specification.AccessTokenIntegrationSpecification import com.reposilite.web.http.ErrorResponse -import io.javalin.http.HttpCode.OK -import io.javalin.http.HttpCode.UNAUTHORIZED -import io.javalin.http.HttpCode.FORBIDDEN +import io.javalin.http.HttpStatus.FORBIDDEN +import io.javalin.http.HttpStatus.OK +import io.javalin.http.HttpStatus.UNAUTHORIZED import kong.unirest.Unirest.delete import kong.unirest.Unirest.get import kong.unirest.Unirest.put diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/auth/BasicAuthenticator.kt b/reposilite-backend/src/main/kotlin/com/reposilite/auth/BasicAuthenticator.kt index 6df418615..484fbe6f3 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/auth/BasicAuthenticator.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/auth/BasicAuthenticator.kt @@ -21,7 +21,7 @@ import com.reposilite.token.AccessTokenFacade import com.reposilite.token.api.AccessTokenDto import com.reposilite.web.http.ErrorResponse import com.reposilite.web.http.errorResponse -import io.javalin.http.HttpCode.UNAUTHORIZED +import io.javalin.http.HttpStatus.UNAUTHORIZED import panda.std.Result import panda.std.asSuccess diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/auth/LdapAuthenticator.kt b/reposilite-backend/src/main/kotlin/com/reposilite/auth/LdapAuthenticator.kt index 1c9e3776b..90af52095 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/auth/LdapAuthenticator.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/auth/LdapAuthenticator.kt @@ -24,12 +24,11 @@ import com.reposilite.token.AccessTokenFacade import com.reposilite.token.api.AccessTokenDto import com.reposilite.token.api.CreateAccessTokenRequest import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse +import com.reposilite.web.http.badRequest +import com.reposilite.web.http.badRequestError +import com.reposilite.web.http.internalServerError import com.reposilite.web.http.notFoundError import com.reposilite.web.http.unauthorized -import io.javalin.http.HttpCode.BAD_REQUEST -import io.javalin.http.HttpCode.INTERNAL_SERVER_ERROR -import io.javalin.http.HttpCode.UNAUTHORIZED import panda.std.Result import panda.std.asSuccess import panda.std.reactive.Reference @@ -65,7 +64,7 @@ internal class LdapAuthenticator( userAttribute ) } - .filter({ it.size == 1 }, { ErrorResponse(BAD_REQUEST, "Could not identify one specific result") }) // only one search result allowed + .filter({ it.size == 1 }, { badRequest("Could not identify one specific result") }) // only one search result allowed .map { it.first() } .flatMap { createContext(user = it.first, password = credentials.secret) } // try to authenticate user with matched domain namespace .flatMap { @@ -74,10 +73,10 @@ internal class LdapAuthenticator( userAttribute ) } - .filter({ it.size == 1 }, { ErrorResponse(BAD_REQUEST, "Could not identify one specific result as user") }) // only one search result allowed + .filter({ it.size == 1 }, { badRequest("Could not identify one specific result as user") }) // only one search result allowed .map { it.first() } .map { (_, attributes) -> attributes[userAttribute]!! } // search returns only lists with values - .filter({ it.size == 1 }, { ErrorResponse(BAD_REQUEST, "Could not identify one specific attribute") }) // only one attribute value is allowed + .filter({ it.size == 1 }, { badRequest("Could not identify one specific attribute") }) // only one attribute value is allowed .map { it.first() } .filter( { credentials.name == it }, // make sure requested name matches required attribute @@ -109,7 +108,7 @@ internal class LdapAuthenticator( .let { Result.attempt { InitialDirContext(it) } } .mapErr { accessTokenFacade.logger.exception(DEBUG, it) - ErrorResponse(UNAUTHORIZED, "Unauthorized LDAP access") + unauthorized("Unauthorized LDAP access") } fun search(ldapFilterQuery: String, vararg requestedAttributes: String): Result, ErrorResponse> = @@ -134,10 +133,10 @@ internal class LdapAuthenticator( notFoundError(nameNotFoundException.toString()) } catch (invalidSearchFilterException: InvalidSearchFilterException) { failureFacade.throwException("Bad search request in LDAP", invalidSearchFilterException) - errorResponse(BAD_REQUEST, invalidSearchFilterException.toString()) + badRequestError(invalidSearchFilterException.toString()) } catch (exception: Exception) { failureFacade.throwException("Unknown LDAP search exception", exception) - errorResponse(INTERNAL_SERVER_ERROR, exception.toString()) + internalServerError(exception.toString()) } private fun SearchResult.attributesMap(vararg requestedAttributes: String): AttributesMap = diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/auth/infrastructure/PostAuthHandler.kt b/reposilite-backend/src/main/kotlin/com/reposilite/auth/infrastructure/PostAuthHandler.kt index 495d29c5b..84425d668 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/auth/infrastructure/PostAuthHandler.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/auth/infrastructure/PostAuthHandler.kt @@ -18,7 +18,7 @@ package com.reposilite.auth.infrastructure import com.reposilite.web.api.ReposiliteRoute import com.reposilite.web.api.ReposiliteRoutes import com.reposilite.web.routing.RouteMethod.AFTER -import io.javalin.http.HttpCode.UNAUTHORIZED +import io.javalin.http.HttpStatus.UNAUTHORIZED private const val WWW_AUTHENTICATE = "www-authenticate" private const val WWW_BASIC_REALM = """Basic realm="Reposilite", charset="UTF-8"""" @@ -26,7 +26,7 @@ private const val WWW_BASIC_REALM = """Basic realm="Reposilite", charset="UTF-8" internal class PostAuthHandler : ReposiliteRoutes() { private val realmDescription = ReposiliteRoute("/{repository}/<*>", AFTER) { - if (ctx.status() == UNAUTHORIZED.status && !uri.startsWith("/api")) { + if (ctx.status() == UNAUTHORIZED && !uri.startsWith("/api")) { ctx.header(WWW_AUTHENTICATE, WWW_BASIC_REALM) } } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/configuration/shared/infrastructure/SettingsEndpoints.kt b/reposilite-backend/src/main/kotlin/com/reposilite/configuration/shared/infrastructure/SettingsEndpoints.kt index 692c2e6b3..526a1a300 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/configuration/shared/infrastructure/SettingsEndpoints.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/configuration/shared/infrastructure/SettingsEndpoints.kt @@ -20,11 +20,10 @@ import com.reposilite.configuration.shared.SharedConfigurationFacade import com.reposilite.configuration.shared.api.SharedSettings import com.reposilite.web.api.ReposiliteRoute import com.reposilite.web.api.ReposiliteRoutes -import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse +import com.reposilite.web.http.badRequest +import com.reposilite.web.http.badRequestError import com.reposilite.web.routing.RouteMethod.GET import com.reposilite.web.routing.RouteMethod.PUT -import io.javalin.http.HttpCode.BAD_REQUEST import io.javalin.openapi.HttpMethod import io.javalin.openapi.OpenApi import io.javalin.openapi.OpenApiContent @@ -120,8 +119,8 @@ internal class SettingsEndpoints(private val sharedConfigurationFacade: SharedCo .takeIf { it.isNotEmpty() } ?.let { sharedConfigurationFacade.getSettingsReference(this)?.type } ?.let { sharedConfigurationFacade.updateSharedSettings(this, ctx.bodyAsClass(it.java)) } - ?.mapErr { ErrorResponse(BAD_REQUEST, it.toString()) } - ?: errorResponse(BAD_REQUEST, "Body is empty") + ?.mapErr { badRequest(it.toString()) } + ?: badRequestError("Body is empty") } } } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/console/ConsoleFacade.kt b/reposilite-backend/src/main/kotlin/com/reposilite/console/ConsoleFacade.kt index 75d8bc21d..6c0d569bf 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/console/ConsoleFacade.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/console/ConsoleFacade.kt @@ -22,8 +22,7 @@ import com.reposilite.journalist.Journalist import com.reposilite.journalist.Logger import com.reposilite.plugin.api.Facade import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse -import io.javalin.http.HttpCode.BAD_REQUEST +import com.reposilite.web.http.badRequestError import panda.std.Result import panda.std.asSuccess import panda.utilities.StringUtils @@ -38,11 +37,11 @@ class ConsoleFacade internal constructor( fun executeCommand(command: String): Result { if (StringUtils.isEmpty(command)) { - return errorResponse(BAD_REQUEST, "Missing command") + return badRequestError("Missing command") } if (command.length > MAX_COMMAND_LENGTH) { - return errorResponse(BAD_REQUEST, "The given command exceeds allowed length (${command.length} > $MAX_COMMAND_LENGTH)") + return badRequestError("The given command exceeds allowed length (${command.length} > $MAX_COMMAND_LENGTH)") } return commandExecutor.execute(command).asSuccess() diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/frontend/infrastructure/NotFoundHandler.kt b/reposilite-backend/src/main/kotlin/com/reposilite/frontend/infrastructure/NotFoundHandler.kt index 1e3865246..897443756 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/frontend/infrastructure/NotFoundHandler.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/frontend/infrastructure/NotFoundHandler.kt @@ -20,7 +20,7 @@ import com.reposilite.frontend.FrontendFacade import io.javalin.http.Context import io.javalin.http.ExceptionHandler import io.javalin.http.Handler -import io.javalin.http.HttpCode.NOT_FOUND +import io.javalin.http.HttpStatus.NOT_FOUND import io.javalin.http.NotFoundResponse internal class NotFoundHandler(private val frontendFacade: FrontendFacade) : Handler, ExceptionHandler { diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/maven/MavenService.kt b/reposilite-backend/src/main/kotlin/com/reposilite/maven/MavenService.kt index 6f762eb2f..1cc5418c3 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/maven/MavenService.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/maven/MavenService.kt @@ -19,12 +19,10 @@ import com.reposilite.storage.api.FileType.DIRECTORY import com.reposilite.storage.api.Location import com.reposilite.token.AccessTokenIdentifier import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse +import com.reposilite.web.http.badRequestError import com.reposilite.web.http.notFound import com.reposilite.web.http.notFoundError import com.reposilite.web.http.unauthorizedError -import io.javalin.http.HttpCode.BAD_REQUEST -import io.javalin.http.HttpCode.NOT_FOUND import panda.std.Result import panda.std.asSuccess import java.io.InputStream @@ -67,7 +65,7 @@ internal class MavenService( val (repository, path) = deployRequest if (repository.redeployment.not() && !path.getSimpleName().contains(METADATA_FILE) && repository.exists(path)) { - return errorResponse(BAD_REQUEST, "Redeployment is not allowed") + return badRequestError("Redeployment is not allowed") } return repository.putFile(path, deployRequest.content).peek { @@ -90,7 +88,7 @@ internal class MavenService( private fun findFile(accessToken: AccessTokenIdentifier?, repository: Repository, gav: Location): Result, ErrorResponse> = findDetails(accessToken, repository, gav) - .`is`(DocumentInfo::class.java) { ErrorResponse(NOT_FOUND, "Requested file is a directory") } + .`is`(DocumentInfo::class.java) { notFound("Requested file is a directory") } .flatMap { details -> findInputStream(repository, gav).map { details to it } } .let { extensions.emitEvent(ResolvedFileEvent(accessToken, repository, gav, it)).result } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/maven/MetadataService.kt b/reposilite-backend/src/main/kotlin/com/reposilite/maven/MetadataService.kt index c7e47ae5e..6cead99e5 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/maven/MetadataService.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/maven/MetadataService.kt @@ -34,9 +34,9 @@ import com.reposilite.maven.api.VersionsResponse import com.reposilite.storage.VersionComparator import com.reposilite.storage.api.Location import com.reposilite.web.http.ErrorResponse +import com.reposilite.web.http.internalServer import com.reposilite.web.http.notFound import com.reposilite.web.http.unauthorizedError -import io.javalin.http.HttpCode.INTERNAL_SERVER_ERROR import panda.std.Result import panda.std.letIf import panda.std.mapToUnit @@ -59,7 +59,7 @@ internal class MetadataService(private val repositorySecurityProvider: Repositor fun saveMetadata(saveMetadataRequest: SaveMetadataRequest): Result = with (saveMetadataRequest) { Result.attempt { xml.writeValueAsBytes(metadata) } - .mapErr { ErrorResponse(INTERNAL_SERVER_ERROR, "Cannot parse metadata file") } + .mapErr { internalServer("Cannot parse metadata file") } .flatMap { repository.putFile(gav.resolveMetadataFile(), it.inputStream()).map { _ -> it } } .flatMap { repository.writeFileChecksums(gav.resolveMetadataFile(), it) } .map { metadata } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositorySecurityProvider.kt b/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositorySecurityProvider.kt index 9f9b66b55..e3fdf6dff 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositorySecurityProvider.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositorySecurityProvider.kt @@ -26,8 +26,9 @@ import com.reposilite.token.RoutePermission import com.reposilite.token.RoutePermission.READ import com.reposilite.token.RoutePermission.WRITE import com.reposilite.web.http.ErrorResponse +import com.reposilite.web.http.toErrorResponse import com.reposilite.web.http.unauthorizedError -import io.javalin.http.HttpCode +import io.javalin.http.HttpStatus.FORBIDDEN import panda.std.Result internal class RepositorySecurityProvider(private val accessTokenFacade: AccessTokenFacade) { @@ -60,7 +61,7 @@ internal class RepositorySecurityProvider(private val accessTokenFacade: AccessT ?.let { Result.`when`(accessTokenFacade.hasPermissionTo(accessToken, "/${repository.name}/$gav", permission), { }, - { ErrorResponse(HttpCode.FORBIDDEN, "You must be the token owner or a manager to access this.") } + { FORBIDDEN.toErrorResponse("You must be the token owner or a manager to access this.") } ) } ?: unauthorizedError("You need to provide credentials.") diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositoryService.kt b/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositoryService.kt index 7768d4731..ad162346c 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositoryService.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/maven/RepositoryService.kt @@ -21,8 +21,7 @@ import com.reposilite.storage.api.DirectoryInfo import com.reposilite.storage.api.SimpleDirectoryInfo import com.reposilite.token.AccessTokenIdentifier import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse -import io.javalin.http.HttpCode.NOT_FOUND +import com.reposilite.web.http.notFoundError import panda.std.Result import panda.std.asSuccess @@ -35,7 +34,7 @@ internal class RepositoryService( fun findRepository(name: String): Result = getRepository(name) ?.asSuccess() - ?: errorResponse(NOT_FOUND, "Repository $name not found") + ?: notFoundError("Repository $name not found") fun getRepository(name: String): Repository? = repositoryProvider.getRepositories()[name] diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenApiEndpoints.kt b/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenApiEndpoints.kt index cf6e11ab9..a216036b8 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenApiEndpoints.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenApiEndpoints.kt @@ -28,7 +28,7 @@ import com.reposilite.web.api.ReposiliteRoute import com.reposilite.web.http.ErrorResponse import com.reposilite.web.routing.RouteMethod.GET import com.reposilite.web.routing.RouteMethod.POST -import io.javalin.http.HttpCode.CREATED +import io.javalin.http.HttpStatus.CREATED import io.javalin.openapi.HttpMethod import io.javalin.openapi.OpenApi import io.javalin.openapi.OpenApiContent diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenLatestApiEndpoints.kt b/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenLatestApiEndpoints.kt index 9b54ec96c..af32849eb 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenLatestApiEndpoints.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/maven/infrastructure/MavenLatestApiEndpoints.kt @@ -31,17 +31,16 @@ import com.reposilite.storage.api.toLocation import com.reposilite.token.api.AccessTokenDto import com.reposilite.web.api.ReposiliteRoute import com.reposilite.web.http.ErrorResponse +import com.reposilite.web.http.badRequestError import com.reposilite.web.http.contentDisposition import com.reposilite.web.routing.RouteMethod.GET import io.javalin.http.ContentType -import io.javalin.http.HttpCode.BAD_REQUEST import io.javalin.openapi.HttpMethod import io.javalin.openapi.OpenApi import io.javalin.openapi.OpenApiContent import io.javalin.openapi.OpenApiParam import io.javalin.openapi.OpenApiResponse import panda.std.Result -import panda.std.asError import panda.std.asSuccess internal class MavenLatestApiEndpoints( @@ -78,7 +77,7 @@ internal class MavenLatestApiEndpoints( when (val type = ctx.queryParam("type")) { "raw" -> it.version.asSuccess() // -> String "json", null -> it.asSuccess() // -> LatestVersionResponse - else -> ErrorResponse(BAD_REQUEST, "Unsupported response type: $type").asError() // -> ErrorResponse + else -> badRequestError("Unsupported response type: $type") // -> ErrorResponse } } } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/shared/BadgeGenerator.kt b/reposilite-backend/src/main/kotlin/com/reposilite/shared/BadgeGenerator.kt index 86244f7cf..07c600ad0 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/shared/BadgeGenerator.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/shared/BadgeGenerator.kt @@ -17,8 +17,7 @@ package com.reposilite.shared import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse -import io.javalin.http.HttpCode.BAD_REQUEST +import com.reposilite.web.http.badRequestError import org.intellij.lang.annotations.Language import panda.std.Result import panda.std.asSuccess @@ -49,7 +48,7 @@ object BadgeGenerator { val color = optionalColor ?: colorBlue if (!(name + value + color).matches(supportedCharacters)) { - return errorResponse(BAD_REQUEST, "Request contains invalid characters") + return badRequestError("Request contains invalid characters") } val padding = 11 diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/shared/extensions/CdnExtensions.kt b/reposilite-backend/src/main/kotlin/com/reposilite/shared/extensions/CdnExtensions.kt index 94712afe4..62994614f 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/shared/extensions/CdnExtensions.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/shared/extensions/CdnExtensions.kt @@ -17,7 +17,7 @@ package com.reposilite.shared.extensions import com.reposilite.web.http.ErrorResponse -import io.javalin.http.HttpCode.BAD_REQUEST +import com.reposilite.web.http.badRequest import net.dzikoysk.cdn.Cdn import net.dzikoysk.cdn.KCdnFactory import net.dzikoysk.cdn.source.Source @@ -36,4 +36,4 @@ fun String.createCdnByExtension(): Result = fun Cdn.validateAndLoad(source: String, testConfiguration: T, configuration: T): Result = load(Source.of(source), testConfiguration) // validate .flatMap { load(Source.of(source), configuration) } - .mapErr { ErrorResponse(BAD_REQUEST, "Cannot load configuration: ${it.message}") } + .mapErr { badRequest("Cannot load configuration: ${it.message}") } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/shared/http/HttpRemoteClient.kt b/reposilite-backend/src/main/kotlin/com/reposilite/shared/http/HttpRemoteClient.kt index 0ac7774b7..43f8df39c 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/shared/http/HttpRemoteClient.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/shared/http/HttpRemoteClient.kt @@ -31,10 +31,10 @@ import com.reposilite.storage.api.UNKNOWN_LENGTH import com.reposilite.storage.api.toLocation import com.reposilite.storage.getExtension import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse +import com.reposilite.web.http.badRequestError +import com.reposilite.web.http.toErrorResult import io.javalin.http.ContentType -import io.javalin.http.HttpCode.BAD_REQUEST -import io.javalin.http.HttpCode.NOT_ACCEPTABLE +import io.javalin.http.HttpStatus.NOT_ACCEPTABLE import panda.std.Result import panda.std.asSuccess import java.io.InputStream @@ -103,11 +103,12 @@ class HttpRemoteClient(private val journalist: Journalist, proxy: Proxy?) : Remo logger.debug("HttpRemoteClient | $url responded with ${response.statusCode} (Content-Type: ${response.contentType})") when { - response.contentType == ContentType.HTML -> errorResponse(NOT_ACCEPTABLE, "Illegal file type (${response.contentType})") - response.isSuccessStatusCode.not() -> errorResponse(NOT_ACCEPTABLE, "Unsuccessful request (${response.statusCode})") + response.contentType == ContentType.HTML -> NOT_ACCEPTABLE.toErrorResult("Illegal file type (${response.contentType})") + response.isSuccessStatusCode.not() -> NOT_ACCEPTABLE.toErrorResult("Unsuccessful request (${response.statusCode})") else -> consumer(response) + }.onError { + response.disconnect() } - .onError { response.disconnect() } } catch (exception: Exception) { createExceptionResponse(this.url.toString(), exception) } @@ -121,7 +122,7 @@ class HttpRemoteClient(private val journalist: Journalist, proxy: Proxy?) : Remo private fun createExceptionResponse(uri: String, exception: Exception): Result { logger.debug("HttpRemoteClient | Cannot get $uri") logger.exception(Channel.DEBUG, exception) - return errorResponse(BAD_REQUEST, "An error of type ${exception.javaClass} happened: ${exception.message}") + return badRequestError("An error of type ${exception.javaClass} happened: ${exception.message}") } override fun getLogger(): Logger = diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/statistics/StatisticsFacade.kt b/reposilite-backend/src/main/kotlin/com/reposilite/statistics/StatisticsFacade.kt index 56546ee4c..022b4a656 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/statistics/StatisticsFacade.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/statistics/StatisticsFacade.kt @@ -22,8 +22,7 @@ import com.reposilite.plugin.api.Facade import com.reposilite.statistics.api.IncrementResolvedRequest import com.reposilite.statistics.api.ResolvedCountResponse import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse -import io.javalin.http.HttpCode.BAD_REQUEST +import com.reposilite.web.http.badRequestError import panda.std.Result import panda.std.asSuccess import panda.std.reactive.Reference @@ -59,7 +58,7 @@ class StatisticsFacade internal constructor( ).asSuccess() } } - ?: errorResponse(BAD_REQUEST, "Requested too many records ($limit > $MAX_PAGE_SIZE)") + ?: badRequestError("Requested too many records ($limit > $MAX_PAGE_SIZE)") fun countUniqueRecords(): Long = statisticsRepository.countUniqueResolvedRequests() diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/storage/Paths.kt b/reposilite-backend/src/main/kotlin/com/reposilite/storage/Paths.kt index e034fd97d..30c87f342 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/storage/Paths.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/storage/Paths.kt @@ -21,7 +21,8 @@ import com.reposilite.storage.api.FileType.DIRECTORY import com.reposilite.storage.api.FileType.FILE import com.reposilite.web.http.ErrorResponse import com.reposilite.web.http.notFound -import io.javalin.http.HttpCode.NO_CONTENT +import com.reposilite.web.http.toErrorResponse +import io.javalin.http.HttpStatus.NO_CONTENT import panda.std.Result import java.io.InputStream import java.nio.file.Files @@ -33,7 +34,7 @@ fun Path.type(): FileType = fun Path.inputStream(): Result = Result.`when`(Files.exists(this), this, notFound("")) - .filter({ it.isDirectory().not() }, { ErrorResponse(NO_CONTENT, "Requested file is a directory") }) + .filter({ it.isDirectory().not() }, { NO_CONTENT.toErrorResponse("Requested file is a directory") }) .map { Files.newInputStream(it) } internal fun Path.getExtension(): String = diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemQuotaProviders.kt b/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemQuotaProviders.kt index eb9587d43..acc932a9e 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemQuotaProviders.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemQuotaProviders.kt @@ -17,7 +17,8 @@ package com.reposilite.storage.filesystem import com.reposilite.web.http.ErrorResponse -import io.javalin.http.HttpCode.INSUFFICIENT_STORAGE +import com.reposilite.web.http.toErrorResponse +import io.javalin.http.HttpStatus.INSUFFICIENT_STORAGE import panda.std.Result import java.nio.file.Files import java.nio.file.Path @@ -37,7 +38,7 @@ internal class FixedQuota(rootDirectory: Path, private val maxSize: Long) : File override fun canHold(contentLength: Long): Result = usage() .map { usage -> maxSize - usage } - .filter({ available -> contentLength <= available }, { ErrorResponse(INSUFFICIENT_STORAGE, "Repository cannot hold the given file (${maxSize - it} + $contentLength > $maxSize)") }) + .filter({ available -> contentLength <= available }, { INSUFFICIENT_STORAGE.toErrorResponse("Repository cannot hold the given file (${maxSize - it} + $contentLength > $maxSize)") }) } @@ -63,6 +64,6 @@ internal class PercentageQuota( val max = capacity * maxPercentage max.toLong() - usage } - .filter({ available -> contentLength <= available }, { ErrorResponse(INSUFFICIENT_STORAGE, "Repository cannot hold the given file ($contentLength too much for $maxPercentage%)") }) + .filter({ available -> contentLength <= available }, { INSUFFICIENT_STORAGE.toErrorResponse("Repository cannot hold the given file ($contentLength too much for $maxPercentage%)") }) } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemStorageProvider.kt b/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemStorageProvider.kt index b16b52dc4..c6352adae 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemStorageProvider.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/storage/filesystem/FileSystemStorageProvider.kt @@ -31,11 +31,12 @@ import com.reposilite.storage.getSimpleName import com.reposilite.storage.inputStream import com.reposilite.storage.type import com.reposilite.web.http.ErrorResponse +import com.reposilite.web.http.badRequest import com.reposilite.web.http.notFound +import com.reposilite.web.http.toErrorResponse import io.javalin.http.ContentType import io.javalin.http.ContentType.APPLICATION_OCTET_STREAM -import io.javalin.http.HttpCode.BAD_REQUEST -import io.javalin.http.HttpCode.INSUFFICIENT_STORAGE +import io.javalin.http.HttpStatus.INSUFFICIENT_STORAGE import panda.std.Result import panda.std.asSuccess import java.io.File @@ -59,7 +60,7 @@ abstract class FileSystemStorageProvider protected constructor( override fun putFile(location: Location, inputStream: InputStream): Result = inputStream.use { data -> canHold(data.available().toLong()) - .mapErr { ErrorResponse(INSUFFICIENT_STORAGE, "Not enough storage space available: ${it.message}") } + .mapErr { INSUFFICIENT_STORAGE.toErrorResponse("Not enough storage space available: ${it.message}") } .flatMap { location.resolveWithRootDirectory() } .map { file -> if (file.parent != null && !Files.exists(file.parent)) { @@ -180,6 +181,6 @@ abstract class FileSystemStorageProvider protected constructor( private fun Location.resolveWithRootDirectory(): Result = toPath() .map { rootDirectory.resolve(it) } - .mapErr { ErrorResponse(BAD_REQUEST, it) } + .mapErr { badRequest(it) } } diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/storage/s3/S3StorageProvider.kt b/reposilite-backend/src/main/kotlin/com/reposilite/storage/s3/S3StorageProvider.kt index c40d9f5bc..89a73306c 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/storage/s3/S3StorageProvider.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/storage/s3/S3StorageProvider.kt @@ -27,12 +27,11 @@ import com.reposilite.storage.api.Location import com.reposilite.storage.api.SimpleDirectoryInfo import com.reposilite.storage.api.toLocation import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse +import com.reposilite.web.http.internalServerError +import com.reposilite.web.http.notFoundError import io.javalin.http.ContentType import io.javalin.http.ContentType.APPLICATION_OCTET_STREAM import io.javalin.http.ContentType.Companion.OCTET_STREAM -import io.javalin.http.HttpCode.INTERNAL_SERVER_ERROR -import io.javalin.http.HttpCode.NOT_FOUND import panda.std.Result import panda.std.Result.ok import panda.std.asSuccess @@ -101,7 +100,7 @@ class S3StorageProvider( ok(Unit) } catch (ioException: IOException) { failureFacade.throwException("S3 Storage Provider failed with IO Exception", ioException) - errorResponse(INTERNAL_SERVER_ERROR, "Failed to write $location") + internalServerError("Failed to write $location") } finally { temporary.delete() } @@ -116,9 +115,9 @@ class S3StorageProvider( // val bytes = ByteArray(Math.toIntExact(response.response().contentLength())) // response.read(bytes) } catch (noSuchKeyException: NoSuchKeyException) { - errorResponse(NOT_FOUND, "File not found: $location") + notFoundError("File not found: $location") } catch (ioException: IOException) { - errorResponse(NOT_FOUND, "File not found: $location") + notFoundError("File not found: $location") } override fun getFileDetails(location: Location): Result = @@ -161,7 +160,7 @@ class S3StorageProvider( ok(Unit) } catch (exception: Exception) { - errorResponse(INTERNAL_SERVER_ERROR, exception.message ?: exception::class.toString()) + internalServerError(exception.message ?: exception::class.toString()) } private fun createDeleteRequest(location: Location): DeleteObjectRequest = @@ -196,11 +195,11 @@ class S3StorageProvider( val paths = directories + files if (paths.isEmpty()) - errorResponse(NOT_FOUND, "Directory not found or is empty") + notFoundError("Directory not found or is empty") else paths.asSuccess() } catch (exception: Exception) { - errorResponse(INTERNAL_SERVER_ERROR, exception.localizedMessage) + internalServerError(exception.localizedMessage) } override fun getLastModifiedTime(location: Location): Result = @@ -218,9 +217,9 @@ class S3StorageProvider( request.key(location.toString().replace('\\', '/')) s3.headObject(request.build()).asSuccess() } catch (ignored: NoSuchKeyException) { - errorResponse(NOT_FOUND, ignored.message ?: "File not found") + notFoundError(ignored.message ?: "File not found") } catch (exception: Exception) { - errorResponse(INTERNAL_SERVER_ERROR, exception.message ?: "Generic exception") + internalServerError(exception.message ?: "Generic exception") } override fun exists(location: Location): Boolean = diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/token/infrastructure/AccessTokenApiEndpoints.kt b/reposilite-backend/src/main/kotlin/com/reposilite/token/infrastructure/AccessTokenApiEndpoints.kt index f3f0e4afb..dd11ab966 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/token/infrastructure/AccessTokenApiEndpoints.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/token/infrastructure/AccessTokenApiEndpoints.kt @@ -24,13 +24,13 @@ import com.reposilite.token.api.CreateAccessTokenResponse import com.reposilite.token.api.CreateAccessTokenWithNoNameRequest import com.reposilite.web.api.ReposiliteRoute import com.reposilite.web.api.ReposiliteRoutes -import com.reposilite.web.http.ErrorResponse -import com.reposilite.web.http.errorResponse +import com.reposilite.web.http.badRequest import com.reposilite.web.http.notFoundError +import com.reposilite.web.http.toErrorResult import com.reposilite.web.routing.RouteMethod.DELETE import com.reposilite.web.routing.RouteMethod.GET import com.reposilite.web.routing.RouteMethod.PUT -import io.javalin.http.HttpCode +import io.javalin.http.HttpStatus.FORBIDDEN import io.javalin.http.bodyAsClass import io.javalin.openapi.HttpMethod import io.javalin.openapi.OpenApi @@ -66,7 +66,7 @@ internal class AccessTokenApiEndpoints(private val accessTokenFacade: AccessToke response = accessTokenFacade.getAccessToken(requireParameter("name")) ?.takeIf { isManager() || name == it.name } ?.asSuccess() - ?: errorResponse(HttpCode.FORBIDDEN, "You must be the token owner or a manager to access this.") + ?: FORBIDDEN.toErrorResult("You must be the token owner or a manager to access this.") } } @@ -85,7 +85,7 @@ internal class AccessTokenApiEndpoints(private val accessTokenFacade: AccessToke val createOrUpdateToken = ReposiliteRoute("/api/tokens/{name}", PUT) { managerOnly { response = panda.std.Result.attempt { ctx.bodyAsClass() } - .mapErr { ErrorResponse(HttpCode.BAD_REQUEST, "Failed to read body") } + .mapErr { badRequest("Failed to read body") } .map { request -> Pair( accessTokenFacade.createAccessToken(CreateAccessTokenRequest(request.type, requireParameter("name"), secret = request.secret)), diff --git a/reposilite-backend/src/main/kotlin/com/reposilite/web/application/JavalinConfiguration.kt b/reposilite-backend/src/main/kotlin/com/reposilite/web/application/JavalinConfiguration.kt index 147de22ac..7ce879f92 100644 --- a/reposilite-backend/src/main/kotlin/com/reposilite/web/application/JavalinConfiguration.kt +++ b/reposilite-backend/src/main/kotlin/com/reposilite/web/application/JavalinConfiguration.kt @@ -38,6 +38,7 @@ import com.reposilite.web.infrastructure.CacheBypassHandler import com.reposilite.web.routing.RoutingPlugin import io.javalin.config.JavalinConfig import io.javalin.openapi.plugin.OpenApiConfiguration +import io.javalin.openapi.plugin.OpenApiInfo import io.javalin.openapi.plugin.OpenApiPlugin import io.javalin.plugin.json.JavalinJackson import org.eclipse.jetty.server.Server @@ -145,7 +146,7 @@ internal object JavalinConfiguration { val sslContextFactory = SslContextFactory.Server() sslContextFactory.keyStorePath = localConfiguration.keyStorePath.get().replace("\${WORKING_DIRECTORY}", reposilite.parameters.workingDirectory.toAbsolutePath().toString()) - sslContextFactory.setKeyStorePassword(localConfiguration.keyStorePassword.get()) + sslContextFactory.keyStorePassword = localConfiguration.keyStorePassword.get() val sslConnector = ServerConnector(server, sslContextFactory) sslConnector.port = localConfiguration.sslPort.get() @@ -165,14 +166,20 @@ internal object JavalinConfiguration { } private fun configureCors(config: JavalinConfig) { - config.plugins.enableCorsForAllOrigins() + config.plugins.enableCors { + it.allowedOrigins = listOf("*") + } } private fun configureOpenApi(config: JavalinConfig, frontendSettings: FrontendSettings) { val openApiConfiguration = OpenApiConfiguration() - openApiConfiguration.title = frontendSettings.title - openApiConfiguration.description = frontendSettings.description - openApiConfiguration.version = VERSION + + openApiConfiguration.info = OpenApiInfo().also { + it.title = frontendSettings.title + it.description = frontendSettings.description + it.version = VERSION + } + config.plugins.register(OpenApiPlugin(openApiConfiguration)) } diff --git a/reposilite-backend/src/test/kotlin/com/reposilite/auth/AuthenticationFacadeTest.kt b/reposilite-backend/src/test/kotlin/com/reposilite/auth/AuthenticationFacadeTest.kt index 24d2dd418..1507ada1e 100644 --- a/reposilite-backend/src/test/kotlin/com/reposilite/auth/AuthenticationFacadeTest.kt +++ b/reposilite-backend/src/test/kotlin/com/reposilite/auth/AuthenticationFacadeTest.kt @@ -18,8 +18,7 @@ package com.reposilite.auth import com.reposilite.auth.api.Credentials import com.reposilite.auth.specification.AuthenticationSpecification -import com.reposilite.web.http.ErrorResponse -import io.javalin.http.HttpCode.UNAUTHORIZED +import com.reposilite.web.http.unauthorized import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Test import panda.std.ResultAssertions.assertError @@ -37,7 +36,7 @@ internal class AuthenticationFacadeTest : AuthenticationSpecification() { val response = authenticationFacade.authenticateByCredentials(Credentials(name, "invalid-secret")) // then: the request has been rejected - assertError(ErrorResponse(UNAUTHORIZED, "Invalid authorization credentials"), response) + assertError(unauthorized("Invalid authorization credentials"), response) } @Test