diff --git a/src/main/json/service.config.schema.json b/src/main/json/service.config.schema.json index f390d65..f0001da 100644 --- a/src/main/json/service.config.schema.json +++ b/src/main/json/service.config.schema.json @@ -4,6 +4,7 @@ "properties": { "artifactsRepo": { "type": "string" }, "authSecret": { "type": "string" }, + "debug": { "type": "bool" }, "pwdCost": { "type": "integer" }, "projects": { "title": "ProjectsList", diff --git a/src/main/nim/strawbosspkg/configuration.nim b/src/main/nim/strawbosspkg/configuration.nim index 48f8e46..a01cfc2 100644 --- a/src/main/nim/strawbosspkg/configuration.nim +++ b/src/main/nim/strawbosspkg/configuration.nim @@ -34,6 +34,7 @@ type StrawBossConfig* = object artifactsRepo*: string authSecret*: string + debug*: bool projects*: seq[ProjectDef] pwdCost*: int8 users*: seq[UserRef] @@ -98,6 +99,7 @@ proc loadStrawBossConfig*(cfgFile: string): StrawBossConfig = result = StrawBossConfig( artifactsRepo: jsonCfg.getIfExists("artifactsRepo").getStr("artifacts"), authSecret: jsonCfg.getOrFail("authSecret", "strawboss config").getStr, + debug: jsonCfg.getIfExists("debug").getBVal(false), pwdCost: int8(jsonCfg.getOrFail("pwdCost", "strawboss config").getNum), projects: projectDefs, users: users) diff --git a/src/main/nim/strawbosspkg/server.nim b/src/main/nim/strawbosspkg/server.nim index 4be72fe..b8d12c7 100644 --- a/src/main/nim/strawbosspkg/server.nim +++ b/src/main/nim/strawbosspkg/server.nim @@ -1,4 +1,4 @@ -import asyncdispatch, bcrypt, jester, json, jwt, osproc, sequtils, tempfile, +import asyncdispatch, bcrypt, jester, json, jwt, os, osproc, sequtils, tempfile, times, unittest import ./configuration, ./core, private/util @@ -111,6 +111,7 @@ template requireAuth() = proc start*(givenCfg: StrawBossConfig): void = + let stopFuture = newFuture[void]() var workers: seq[Worker] = @[] routes: @@ -136,4 +137,10 @@ proc start*(givenCfg: StrawBossConfig): void = buildRef: if @"buildRef" != "": @"buildRef" else: nil, forceRebuild: false))) # TODO support this with optional query params - runForever() + post "/service/debug/stop": + if not givenCfg.debug: resp(Http404, makeJsonResp(Http404), "application/json") + else: + callSoon(proc(): void = complete(stopFuture)) + resp($(%*"shutting down"), "application/json") + + waitFor(stopFuture) diff --git a/src/test/json/strawboss.config.json b/src/test/json/strawboss.config.json index 0b9c044..e608d60 100644 --- a/src/test/json/strawboss.config.json +++ b/src/test/json/strawboss.config.json @@ -1,6 +1,7 @@ { "artifactsRepo": "artifacts", "authSecret": "change me", + "debug": true, "users": [ { "name": "bob@builder.com", "hashedPwd": "testvalue" }, { "name": "sam@sousa.com", "hashedPwd": "testvalue" } diff --git a/strawboss.config.json b/strawboss.config.json index c674130..3f25516 100644 --- a/strawboss.config.json +++ b/strawboss.config.json @@ -1,5 +1,6 @@ { "artifactsRepo": "artifacts", + "debug": true, "users": [], "authSecret": "change me", "pwdCost": 11,