Compare commits
No commits in common. "76daadaebe8e6528bdef7ae30e963e7b9caa2b51" and "596aa06809fc94937d72caf87aede090798cc3f2" have entirely different histories.
76daadaebe
...
596aa06809
|
@ -14,7 +14,7 @@ group = "dev.frogmc"
|
|||
version = "0.0.1"
|
||||
|
||||
application {
|
||||
mainClass.set("dev.frogmc.meta.ApplicationKt")
|
||||
mainClass.set("dev.frogmc.ApplicationKt")
|
||||
|
||||
val isDevelopment: Boolean = project.ext.has("development")
|
||||
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
|
||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package dev.frogmc.meta
|
||||
package dev.frogmc
|
||||
|
||||
import dev.frogmc.meta.plugins.configureHTTP
|
||||
import dev.frogmc.meta.plugins.configureRouting
|
||||
import dev.frogmc.meta.plugins.configureSerialization
|
||||
import dev.frogmc.plugins.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
|
@ -1,4 +1,4 @@
|
|||
package dev.frogmc.meta
|
||||
package dev.frogmc
|
||||
|
||||
object Config {
|
||||
val POSTGRES_DATABASE = getEnv("DATABASE", "frogmc")
|
|
@ -1,8 +1,6 @@
|
|||
package dev.frogmc.meta
|
||||
package dev.frogmc
|
||||
|
||||
import dev.frogmc.meta.types.LibraryVersion
|
||||
import dev.frogmc.meta.types.LibraryVersions
|
||||
import dev.frogmc.meta.types.LoaderVersions
|
||||
import dev.frogmc.types.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
|
@ -23,7 +21,8 @@ object DB {
|
|||
transaction(db) {
|
||||
SchemaUtils.create(
|
||||
LoaderVersions,
|
||||
LibraryVersions
|
||||
LibraryVersions,
|
||||
File
|
||||
)
|
||||
}
|
||||
if (db == null) {
|
|
@ -1,18 +0,0 @@
|
|||
package dev.frogmc.meta.plugins
|
||||
|
||||
import dev.frogmc.meta.Config
|
||||
import dev.frogmc.meta.logger
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import java.security.MessageDigest
|
||||
|
||||
val authPlugin = createRouteScopedPlugin("auth") {
|
||||
onCall {
|
||||
val authorization = it.request.headers["Authorization"]
|
||||
if (authorization.isNullOrEmpty() || !MessageDigest.isEqual(authorization.toByteArray(), Config.UPLOAD_SECRET)) {
|
||||
logger.info("Authentication Failed: provided: ${authorization?.toByteArray()}; expected: ${Config.UPLOAD_SECRET}")
|
||||
it.respond(HttpStatusCode.Unauthorized)
|
||||
}
|
||||
}
|
||||
}
|
16
src/main/kotlin/dev/frogmc/plugins/Auth.kt
Normal file
16
src/main/kotlin/dev/frogmc/plugins/Auth.kt
Normal file
|
@ -0,0 +1,16 @@
|
|||
package dev.frogmc.plugins
|
||||
|
||||
import dev.frogmc.Config
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.MessageDigest
|
||||
|
||||
val authPlugin = createRouteScopedPlugin("auth") {
|
||||
onCall {
|
||||
val authorization = it.request.headers["Authorization"]
|
||||
if (authorization.isNullOrEmpty() || !MessageDigest.isEqual(authorization.toByteArray(), Config.UPLOAD_SECRET))
|
||||
it.respond(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package dev.frogmc.meta.plugins
|
||||
package dev.frogmc.plugins
|
||||
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.plugins.cors.routing.*
|
||||
import io.ktor.server.response.*
|
||||
|
||||
fun Application.configureHTTP() {
|
||||
install(CORS) {
|
||||
|
@ -11,5 +12,7 @@ fun Application.configureHTTP() {
|
|||
allowMethod(HttpMethod.Delete)
|
||||
allowMethod(HttpMethod.Patch)
|
||||
allowHeader(HttpHeaders.Authorization)
|
||||
allowHeader("MyCustomHeader")
|
||||
anyHost() // @TODO: Don't do this in production if possible. Try to limit it.
|
||||
}
|
||||
}
|
|
@ -1,19 +1,21 @@
|
|||
package dev.frogmc.meta.plugins
|
||||
package dev.frogmc.plugins
|
||||
|
||||
import dev.frogmc.meta.DB
|
||||
import dev.frogmc.meta.types.LoaderVersion
|
||||
import dev.frogmc.meta.types.PartialLoaderVersion
|
||||
import dev.frogmc.meta.types.LoaderVersions
|
||||
import dev.frogmc.meta.types.ModrinthVersion
|
||||
import dev.frogmc.DB
|
||||
import dev.frogmc.types.LoaderVersion
|
||||
import dev.frogmc.types.PartialLoaderVersion
|
||||
import dev.frogmc.types.LoaderVersions
|
||||
import dev.frogmc.types.ModrinthVersion
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.html.*
|
||||
import io.ktor.server.http.content.*
|
||||
import io.ktor.server.request.*
|
||||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
import kotlinx.html.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
||||
import org.jetbrains.exposed.sql.*
|
|
@ -1,4 +1,4 @@
|
|||
package dev.frogmc.meta.plugins
|
||||
package dev.frogmc.plugins
|
||||
|
||||
import io.ktor.serialization.kotlinx.json.*
|
||||
import io.ktor.server.application.*
|
|
@ -1,4 +1,4 @@
|
|||
package dev.frogmc.meta.types
|
||||
package dev.frogmc.types
|
||||
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.serialization.Serializable
|
|
@ -1,4 +1,4 @@
|
|||
package dev.frogmc.meta.types
|
||||
package dev.frogmc.types
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.exposed.sql.Table
|
Loading…
Reference in a new issue