|
|
@ -46,25 +46,6 @@ template checkAuth(cfg: PitApiCfg) =
|
|
|
|
response.data[2]["Content-Type"] = TXT
|
|
|
|
response.data[2]["Content-Type"] = TXT
|
|
|
|
response.data[3] = getCurrentExceptionMsg()
|
|
|
|
response.data[3] = getCurrentExceptionMsg()
|
|
|
|
|
|
|
|
|
|
|
|
proc paramsToArgs(params: StringTableRef): tuple[stripAnsi: bool, args: seq[string]] =
|
|
|
|
|
|
|
|
result = (false, @[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if params.hasKey("color"):
|
|
|
|
|
|
|
|
if params["color"] != "true":
|
|
|
|
|
|
|
|
result[0] = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for k,v in params:
|
|
|
|
|
|
|
|
if k == "color": continue
|
|
|
|
|
|
|
|
elif k.startsWith("arg"): result[1].add(v) # support ?arg1=val1&arg2=val2 -> cmd val1 val2
|
|
|
|
|
|
|
|
else :
|
|
|
|
|
|
|
|
result[1].add("--" & k)
|
|
|
|
|
|
|
|
if v != "true": result[1].add(v) # support things like ?verbose=true -> cmd --verbose
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let STRIP_ANSI_REGEX = re"\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc stripAnsi(str: string): string =
|
|
|
|
|
|
|
|
return str.replace(STRIP_ANSI_REGEX, "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc start*(cfg: PitApiCfg) =
|
|
|
|
proc start*(cfg: PitApiCfg) =
|
|
|
|
|
|
|
|
|
|
|
|
var stopFuture = newFuture[void]()
|
|
|
|
var stopFuture = newFuture[void]()
|
|
|
@ -81,19 +62,28 @@ proc start*(cfg: PitApiCfg) =
|
|
|
|
get "/issues":
|
|
|
|
get "/issues":
|
|
|
|
checkAuth(cfg); if not authed: return true
|
|
|
|
checkAuth(cfg); if not authed: return true
|
|
|
|
|
|
|
|
|
|
|
|
var (stripAnsi, args) = paramsToArgs(request.params)
|
|
|
|
var args = queryParamsToCliArgs(request.params)
|
|
|
|
args = @["list"] & args
|
|
|
|
args = @["list"] & args
|
|
|
|
|
|
|
|
|
|
|
|
info "args: \n" & args.join(" ")
|
|
|
|
info "args: \n" & args.join(" ")
|
|
|
|
let execResult = execWithOutput("pit", ".", args)
|
|
|
|
let execResult = execWithOutput("pit", ".", args)
|
|
|
|
if execResult[2] != 0: resp(Http500, stripAnsi($execResult[0] & "\n" & $execResult[1]), TXT)
|
|
|
|
if execResult[2] != 0: resp(Http500, stripAnsi($execResult[0] & "\n" & $execResult[1]), TXT)
|
|
|
|
else:
|
|
|
|
else: resp(stripAnsi(execResult[0]), TXT)
|
|
|
|
if stripAnsi: resp(stripAnsi(execResult[0]), TXT)
|
|
|
|
|
|
|
|
else: resp(execResult[0], TXT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
post "/issues":
|
|
|
|
post "/issues":
|
|
|
|
checkAuth(cfg); if not authed: return true
|
|
|
|
checkAuth(cfg); if not authed: return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/issue/@issueId":
|
|
|
|
|
|
|
|
checkAuth(cfg); if not authed: return true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var args = queryParamsToCliArgs(request.params)
|
|
|
|
|
|
|
|
args = @["list", @"issueId"] & args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info "args: \n" & args.join(" ")
|
|
|
|
|
|
|
|
let execResult = execWithOutput("pit", ".", args)
|
|
|
|
|
|
|
|
if execResult[2] != 0: resp(Http500, stripAnsi($execResult[0] & "\n" & $execResult[1]), TXT)
|
|
|
|
|
|
|
|
else: resp(stripAnsi(execResult[0]), TXT)
|
|
|
|
|
|
|
|
|
|
|
|
waitFor(stopFuture)
|
|
|
|
waitFor(stopFuture)
|
|
|
|
|
|
|
|
|
|
|
|
proc loadApiConfig(args: Table[string, Value]): PitApiCfg =
|
|
|
|
proc loadApiConfig(args: Table[string, Value]): PitApiCfg =
|
|
|
|