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()