all repos — litestore @ f717f3c7312636704e1d540e4af3755c65916bce

A minimalist nosql document store.

Updates.
h3rald h3rald@h3rald.com
Sat, 22 Feb 2020 09:59:06 +0100
commit

f717f3c7312636704e1d540e4af3755c65916bce

parent

2114e9d3e3fe70c059fdf2889229d2fb36c078ad

3 files changed, 39 insertions(+), 19 deletions(-)

jump to
M src/litestorepkg/lib/api_v6.nimsrc/litestorepkg/lib/api_v6.nim

@@ -1074,6 +1074,8 @@ result.add m.getStr

proc execute*(req: var LSRequest, LS: LiteStore, resource, id: string): LSResponse = let middleware = getMiddlewareSeq(resource, id, $req.reqMethod) + if middleware.len == 0: + return route(req, LS, resource, id) var jReq = $(%* req) echo jReq var jRes = """{
M src/litestorepkg/lib/cli.nimsrc/litestorepkg/lib/cli.nim

@@ -69,6 +69,21 @@ -v, --version Display the program version.

-w, --middleware Specify a path to a folder containing middleware definitions. """ +proc setLogLevel(val: string) = + case val: + of "info": + LOG.level = lvInfo + of "warn": + LOG.level = lvWarn + of "debug": + LOG.level = lvDebug + of "error": + LOG.level = lvError + of "none": + LOG.level = lvNone + else: + fail(103, "Invalid log level '$1'" % val) + for kind, key, val in getOpt(): case kind: of cmdArgument:

@@ -107,20 +122,8 @@ cliSettings["store"] = %file

of "log", "l": if val == "": fail(102, "Log level not specified.") - case val: - of "info": - LOG.level = lvInfo - of "warn": - LOG.level = lvWarn - of "debug": - LOG.level = lvDebug - of "error": - LOG.level = lvError - of "none": - LOG.level = lvNone - else: - fail(103, "Invalid log level '$1'" % val) - loglevel = val + setLogLevel(val) + logLevel = val cliSettings["log"] = %logLevel of "directory", "d": if val == "":

@@ -166,7 +169,7 @@ configuration = val.parseFile

configFile = val of "mount", "m": mount = true - cliSettings["mounnt"] = %mount + cliSettings["mount"] = %mount of "version", "v": echo pkgVersion quit(0)

@@ -188,8 +191,10 @@ auth = newJObject();

auth["access"] = newJObject(); auth["signature"] = configuration["signature"] for k, v in configuration["resources"].pairs: - if v.hasKey("auth"): - auth["access"][k] = v["auth"] + auth["access"][k] = newJObject() + for meth, content in v.pairs: + if content.hasKey("auth"): + auth["access"][k][meth] = content["auth"] # Process config settings if present and if no cli settings are set

@@ -203,6 +208,9 @@ if not cliSettings.hasKey("store") and settings.hasKey("store"):

file = settings["store"].getStr if not cliSettings.hasKey("directory") and settings.hasKey("directory"): directory = settings["directory"].getStr + if not cliSettings.hasKey("log") and settings.hasKey("log"): + logLevel = settings["log"].getStr + setLogLevel(logLevel) if not cliSettings.hasKey("mount") and settings.hasKey("mount"): mount = settings["mount"].getBool if not cliSettings.hasKey("readonly") and settings.hasKey("readonly"):

@@ -231,7 +239,7 @@ LS.file = file

LS.directory = directory LS.readonly = readonly LS.favicon = favicon -LS.loglevel = loglevel +LS.logLevel = logLevel LS.auth = auth LS.manageSystemData = system LS.middleware = middleware
M src/litestorepkg/lib/types.nimsrc/litestorepkg/lib/types.nim

@@ -6,6 +6,8 @@ uri,

pegs, json, strtabs, + strutils, + sequtils, jwt, tables import

@@ -147,7 +149,15 @@

proc `%`*(req: LSRequest): JsonNode = result = newJObject() result["method"] = %($req.reqMethod) - result["headers"] = %req.headers + result["jwt"] = newJObject(); + if req.jwt.signature.len > 0: + result["jwt"]["header"] = %req.jwt.header + result["jwt"]["claims"] = %req.jwt.claims + result["headers"] = newJObject() + let headers = %req.headers + result["headers"] = newJObject() + for k, v in headers["table"].pairs: + result["headers"][k] = %join(v.mapIt(it.getStr), ", ") result["protocol"] = %req.protocol result["url"] = %req.url result["hostname"] = %req.hostname