[ADD] Implement /tokens/[tokenname]

This commit is contained in:
lda 2023-11-01 17:58:41 +01:00
parent ed298aaa90
commit 688c1d3b9e
Signed by: lda
GPG key ID: 6898757653ABE3E6
2 changed files with 11 additions and 3 deletions

View file

@ -87,6 +87,7 @@ RouterBuild(void)
R("/_telodendria/admin/v1/privileges", RoutePrivileges); R("/_telodendria/admin/v1/privileges", RoutePrivileges);
R("/_telodendria/admin/v1/privileges/(.*)", RoutePrivileges); R("/_telodendria/admin/v1/privileges/(.*)", RoutePrivileges);
R("/_telodendria/admin/v1/deactivate/(.*)", RouteAdminDeactivate); R("/_telodendria/admin/v1/deactivate/(.*)", RouteAdminDeactivate);
R("/_telodendria/admin/v1/tokens/(.*)", RouteAdminTokens);
R("/_telodendria/admin/v1/tokens", RouteAdminTokens); R("/_telodendria/admin/v1/tokens", RouteAdminTokens);
#undef R #undef R

View file

@ -43,8 +43,6 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
HttpRequestMethod method = HttpRequestMethodGet(args->context); HttpRequestMethod method = HttpRequestMethodGet(args->context);
(void) path;
if ((method != HTTP_GET)) if ((method != HTTP_GET))
{ {
char *msg = "Route only supports GET for now."; char *msg = "Route only supports GET for now.";
@ -75,7 +73,7 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
goto finish; goto finish;
} }
if (method == HTTP_GET) if (method == HTTP_GET && ArraySize(path) == 0)
{ {
Array *tokensarray = ArrayCreate(); Array *tokensarray = ArrayCreate();
@ -104,6 +102,15 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
DbListFree(tokens); DbListFree(tokens);
} }
else if (method == HTTP_GET && ArraySize(path) == 1)
{
RegTokenInfo *info = RegTokenGetInfo(db, ArrayGet(path, 0));
response = RegTokenJSON(info);
RegTokenClose(info);
RegTokenFree(info);
}
finish: finish:
UserUnlock(user); UserUnlock(user);
return response; return response;