mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 13:10:55 +00:00
DevServer: Parse pipeline payload for filtering.
This commit is contained in:
parent
f7e19b1509
commit
e3402505fd
@ -5,6 +5,7 @@ import cloud.kubelet.foundation.core.devupdate.DevUpdateServer
|
||||
import cloud.kubelet.foundation.core.persist.PersistentStore
|
||||
import cloud.kubelet.foundation.core.persist.setAllProperties
|
||||
import io.papermc.paper.event.player.AsyncChatEvent
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.TextComponent
|
||||
import org.bukkit.GameMode
|
||||
@ -17,6 +18,7 @@ import java.nio.file.Path
|
||||
import java.time.Instant
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@ExperimentalSerializationApi
|
||||
class FoundationCorePlugin : JavaPlugin(), Listener {
|
||||
internal val persistentStores = ConcurrentHashMap<String, PersistentStore>()
|
||||
private lateinit var _pluginDataPath: Path
|
||||
|
@ -0,0 +1,13 @@
|
||||
package cloud.kubelet.foundation.core.devupdate
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable
|
||||
class DevUpdatePayload(
|
||||
@SerialName("object_kind")
|
||||
val objectKind: String,
|
||||
@SerialName("object_attributes")
|
||||
val objectAttributes: Map<String, JsonElement>
|
||||
)
|
@ -5,13 +5,24 @@ import cloud.kubelet.foundation.core.Util
|
||||
import com.charleskorn.kaml.Yaml
|
||||
import com.sun.net.httpserver.HttpExchange
|
||||
import com.sun.net.httpserver.HttpServer
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import java.net.InetSocketAddress
|
||||
import kotlin.io.path.inputStream
|
||||
|
||||
@ExperimentalSerializationApi
|
||||
class DevUpdateServer(val plugin: FoundationCorePlugin) {
|
||||
private lateinit var config: DevUpdateConfig
|
||||
private var server: HttpServer? = null
|
||||
|
||||
private val json = Json {
|
||||
prettyPrint = true
|
||||
prettyPrintIndent = " "
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
|
||||
fun enable() {
|
||||
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
||||
plugin.slF4JLogger,
|
||||
@ -58,6 +69,23 @@ class DevUpdateServer(val plugin: FoundationCorePlugin) {
|
||||
return@setHandler
|
||||
}
|
||||
|
||||
val payload: DevUpdatePayload
|
||||
try {
|
||||
payload = json.decodeFromStream(exchange.requestBody)
|
||||
} catch (e: Exception) {
|
||||
plugin.slF4JLogger.error("Failed to decode request body.", e)
|
||||
exchange.respond(400, "Bad Request")
|
||||
return@setHandler
|
||||
}
|
||||
|
||||
if (payload.objectKind != "pipeline" ||
|
||||
payload.objectAttributes["ref"]?.jsonPrimitive?.content != "main" ||
|
||||
payload.objectAttributes["status"]?.jsonPrimitive?.content != "success"
|
||||
) {
|
||||
exchange.respond(200, "Event was not relevant for update.")
|
||||
return@setHandler
|
||||
}
|
||||
|
||||
exchange.respond(200, "Success.")
|
||||
plugin.server.scheduler.runTask(plugin) { ->
|
||||
plugin.slF4JLogger.info("DevUpdate Server Restart")
|
||||
|
Loading…
Reference in New Issue
Block a user