From b271bc3b8816b03c524bd646422cbdc747a475f1 Mon Sep 17 00:00:00 2001 From: Josha von Gizycki Date: Sat, 18 Jan 2020 18:02:32 +0100 Subject: [PATCH] add revision to query params --- src/main/kotlin/de/joshavg/BuildsEndpoint.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/de/joshavg/BuildsEndpoint.kt b/src/main/kotlin/de/joshavg/BuildsEndpoint.kt index bee047a..a35e310 100644 --- a/src/main/kotlin/de/joshavg/BuildsEndpoint.kt +++ b/src/main/kotlin/de/joshavg/BuildsEndpoint.kt @@ -7,6 +7,7 @@ import javax.inject.Inject import javax.ws.rs.* import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response +import javax.ws.rs.core.Response.Status.PRECONDITION_REQUIRED @Path("/builds") class BuildsEndpoint( @@ -35,19 +36,24 @@ class BuildsEndpoint( fun trigger(@PathParam("build") build: String, @QueryParam("key") - key: String?) = + key: String?, + @QueryParam("rev") + rev: String?) = security.requireKey(build, key) { val logFile = builds.createLogFile(build) - startBuildThread(build, logFile, it) + if (rev == null) { + return@requireKey Response.status(PRECONDITION_REQUIRED).build() + } + + startBuildThread(build, rev, logFile, it) Response.ok(mapOf( "log" to logFile.absolutePath - )) - .build() + )).build() } - fun startBuildThread(build: String, logFile: File, config: BuildConfig) = + fun startBuildThread(build: String, rev: String, logFile: File, config: BuildConfig) = Thread { logger.info("preparing process for build $build with config ${config.asPublic()}") logger.info("log file: $logFile") @@ -59,6 +65,7 @@ class BuildsEndpoint( .apply { environment().putAll(config.env) environment()["ALFRED_LOG_FILE"] = logFile.absolutePath + environment()["ALFRED_GIT_REV"] = rev } .start() .toHandle()