mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 21:20: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.PersistentStore
|
||||||
import cloud.kubelet.foundation.core.persist.setAllProperties
|
import cloud.kubelet.foundation.core.persist.setAllProperties
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent
|
import io.papermc.paper.event.player.AsyncChatEvent
|
||||||
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
import net.kyori.adventure.text.Component
|
import net.kyori.adventure.text.Component
|
||||||
import net.kyori.adventure.text.TextComponent
|
import net.kyori.adventure.text.TextComponent
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
@ -17,6 +18,7 @@ import java.nio.file.Path
|
|||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
|
@ExperimentalSerializationApi
|
||||||
class FoundationCorePlugin : JavaPlugin(), Listener {
|
class FoundationCorePlugin : JavaPlugin(), Listener {
|
||||||
internal val persistentStores = ConcurrentHashMap<String, PersistentStore>()
|
internal val persistentStores = ConcurrentHashMap<String, PersistentStore>()
|
||||||
private lateinit var _pluginDataPath: Path
|
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.charleskorn.kaml.Yaml
|
||||||
import com.sun.net.httpserver.HttpExchange
|
import com.sun.net.httpserver.HttpExchange
|
||||||
import com.sun.net.httpserver.HttpServer
|
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 java.net.InetSocketAddress
|
||||||
import kotlin.io.path.inputStream
|
import kotlin.io.path.inputStream
|
||||||
|
|
||||||
|
@ExperimentalSerializationApi
|
||||||
class DevUpdateServer(val plugin: FoundationCorePlugin) {
|
class DevUpdateServer(val plugin: FoundationCorePlugin) {
|
||||||
private lateinit var config: DevUpdateConfig
|
private lateinit var config: DevUpdateConfig
|
||||||
private var server: HttpServer? = null
|
private var server: HttpServer? = null
|
||||||
|
|
||||||
|
private val json = Json {
|
||||||
|
prettyPrint = true
|
||||||
|
prettyPrintIndent = " "
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
}
|
||||||
|
|
||||||
fun enable() {
|
fun enable() {
|
||||||
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
val configPath = Util.copyDefaultConfig<FoundationCorePlugin>(
|
||||||
plugin.slF4JLogger,
|
plugin.slF4JLogger,
|
||||||
@ -58,6 +69,23 @@ class DevUpdateServer(val plugin: FoundationCorePlugin) {
|
|||||||
return@setHandler
|
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.")
|
exchange.respond(200, "Success.")
|
||||||
plugin.server.scheduler.runTask(plugin) { ->
|
plugin.server.scheduler.runTask(plugin) { ->
|
||||||
plugin.slF4JLogger.info("DevUpdate Server Restart")
|
plugin.slF4JLogger.info("DevUpdate Server Restart")
|
||||||
|
Loading…
Reference in New Issue
Block a user