Implemented GET on /projects/<proj-id> and started unit tests.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import asyncdispatch, bcrypt, jester, json, jwt, os, osproc, sequtils,
|
||||
strutils, tempfile, times, unittest
|
||||
import algorithm, asyncdispatch, bcrypt, jester, json, jwt, os, osproc,
|
||||
sequtils, strutils, tempfile, times, unittest
|
||||
|
||||
import logging
|
||||
import ./configuration, ./core, private/util
|
||||
@ -143,7 +143,60 @@ proc start*(cfg: StrawBossConfig): void =
|
||||
resp(Http200, $(%*{ "username": session.user.name }), JSON)
|
||||
|
||||
get "/projects": withSession:
|
||||
resp($(%(givenCfg.projects)), "application/json")
|
||||
# List project summaries (ProjectDefs only)
|
||||
resp($(%(cfg.projects)), JSON)
|
||||
|
||||
post "/projects": withSession:
|
||||
# Create a new project definition
|
||||
resp(Http501, makeJsonResp(Http501), JSON)
|
||||
|
||||
get "/project/@projectName/@version?": withSession:
|
||||
## Get a detailed project record including step definitions (ProjectConfig).
|
||||
|
||||
# Make sure we know about that project
|
||||
var project: ProjectDef
|
||||
try: project = cfg.findProject(@"projectName")
|
||||
except: resp(Http404, makeJsonResp(Http404, getCurrentExceptionMsg()), JSON)
|
||||
|
||||
# Given version
|
||||
|
||||
var cachedFilePath: string
|
||||
if @"version" != "":
|
||||
cachedFilePath = cfg.artifactsRepo & "/" & project.name &
|
||||
"/configuration." & @"version" & ".json"
|
||||
|
||||
if not existsFile(cachedFilePath):
|
||||
resp(Http404,
|
||||
makeJsonResp(Http404, "I have never built version " & @"version"),
|
||||
JSON)
|
||||
|
||||
# No version requested, use "latest"
|
||||
else:
|
||||
let confFilePaths = toSeq(walkFiles("configuration.*.json"))
|
||||
if confFilePaths.len == 0:
|
||||
resp(Http404, makeJsonResp(Http404, "I have not built any versions of " & project.name), JSON)
|
||||
let modTimes = confFilePaths.mapIt(it.getLastModificationTime)
|
||||
cachedFilePath = sorted(zip(confFilePaths, modTimes),
|
||||
proc (a, b: tuple): int = cmp(a.b, b.b))[0].a
|
||||
|
||||
try: resp(readFile(cachedFilePath), JSON)
|
||||
except:
|
||||
debug "Could not serve cached project configuration at: " &
|
||||
cachedFilePath & "\n\t Reason: " & getCurrentExceptionMsg()
|
||||
resp(Http500, makeJsonResp(Http500, "could not read cached project configuration"), JSON)
|
||||
|
||||
get "/api/project/@projectName/active": withSession:
|
||||
# List all currently active runs
|
||||
resp(Http501, makeJsonResp(Http501), JSON)
|
||||
|
||||
get "/api/project/@projectName/@stepName": withSession:
|
||||
|
||||
# Get step details including runs.
|
||||
resp(Http501, makeJsonResp(Http501), JSON)
|
||||
|
||||
get "/api/project/@projectName/@stepName/run/@buildRef": withSession:
|
||||
# Get detailed information about a run
|
||||
resp(Http501, makeJsonResp(Http501), JSON)
|
||||
|
||||
post "/project/@projectName/@stepName/run/@buildRef?":
|
||||
# Kick off a run
|
||||
@ -159,4 +212,12 @@ proc start*(cfg: StrawBossConfig): void =
|
||||
callSoon(proc(): void = complete(stopFuture))
|
||||
resp($(%*"shutting down"), JSON)
|
||||
|
||||
#[
|
||||
get re".*":
|
||||
resp(Http404, makeJsonResp(Http404), JSON)
|
||||
|
||||
post re".*":
|
||||
resp(Http404, makeJsonResp(Http404), JSON)
|
||||
]#
|
||||
|
||||
waitFor(stopFuture)
|
||||
|
Reference in New Issue
Block a user