feat(doos): add container runtime, audit cases, example demo and tests
- New rootless doos container runtime: sandbox, cgroup, network, images, hardening, davmount, CLI plus molo integration - 18 CVE audit reproductions with READMEs and Makefiles - Example DoosDemo routes, IndexCatalog, static assets, spec update - CLI serve on 0.0.0.0:8000, arg parser, dev server improvements - Runtime HTTP fixes, supervisor isolation backend - Tests for doos, example doos routes, CLI serve; suite count 261 to 265
This commit is contained in:
@@ -7,6 +7,15 @@ owning sibling plan and the file that will close it.
|
||||
## Behaviors
|
||||
|
||||
1. `GET /` renders the coverage matrix from a template with inheritance.
|
||||
Rows are grouped into themed sections by route prefix (`IndexCatalog`,
|
||||
`example/app/IndexCatalog.cpp`); a route matching no group lands in
|
||||
"Other" and fails `index_test`. Groups whose demos need credentials carry
|
||||
a "needs API key" badge. Each row is `<td><a href="ROUTE">Name</a></td>`
|
||||
(the crawl marker used by `matrix_test` and `tools/verify_deploy.py`),
|
||||
with the route repeated in a column that hides below 40rem. A filter box
|
||||
(`/static/index.js`) hides non-matching rows; without JavaScript the full
|
||||
list shows. Adding a feature stays `add_feature(name, route)`; adding a
|
||||
route under a new prefix means adding the prefix to a group.
|
||||
2. Every matrix row resolves to a live route, a test file, and a plan link.
|
||||
3. Every test drives the real stack: TestClient -> middleware -> router ->
|
||||
view -> in-memory services, plus one real loopback HTTP round-trip.
|
||||
@@ -79,6 +88,15 @@ owning sibling plan and the file that will close it.
|
||||
at `/ai/<v>` (compat, mistral, cohere, perplexity, bedrock, azure,
|
||||
huggingface, audio, media, retrieval). Same contract as items 17 and 18.
|
||||
Every `/google` and `/ai` route is excluded from locust.
|
||||
20. Sandboxed containers (`src/doos`, the real framework part): `GET /doos`
|
||||
renders the container page, `GET /doos/status` returns containers,
|
||||
images, davmounts and the libdoos version as JSON, `POST /doos/create`
|
||||
idempotently creates (name plus optional size/memory/net),
|
||||
`POST /doos/delete` dry-runs unless `confirm=yes`. Validation failures
|
||||
answer 422 with every failure listed; a missing container answers 404.
|
||||
All four run on a demo store (`DOOS_HOME` when the harness sets it,
|
||||
else `build/doos-demo`), never the user's real store; real container
|
||||
starts stay out of the demo (see `src/doos/SPEC.md`, Framework seams).
|
||||
|
||||
## Caps
|
||||
|
||||
|
||||
@@ -50,6 +50,10 @@ std::shared_ptr<fw::Application> build_application(Services& services) {
|
||||
register_ops_demo(ops, services);
|
||||
app->include_router("", ops);
|
||||
|
||||
fw::Router doos;
|
||||
register_doos_demo(doos, services);
|
||||
app->include_router("", doos);
|
||||
|
||||
fw::Router stats;
|
||||
register_stats_demo(stats, services);
|
||||
app->include_router("", stats);
|
||||
|
||||
@@ -81,6 +81,7 @@ void register_security_demo(fw::Router& router, Services& services);
|
||||
void register_formats_demo(fw::Router& router, Services& services);
|
||||
void register_realtime_demo(fw::Router& router, Services& services);
|
||||
void register_ops_demo(fw::Router& router, Services& services);
|
||||
void register_doos_demo(fw::Router& router, Services& services);
|
||||
void register_stats_demo(fw::Router& router, Services& services);
|
||||
void register_security_extra_demo(fw::Router& router, Services& services);
|
||||
void register_platform_demo(fw::Router& router, Services& services);
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "App.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../fw/Http.hpp"
|
||||
#include "../fw/Router.hpp"
|
||||
#include "../fw/Templates.hpp"
|
||||
#include "../fw/Validate.hpp"
|
||||
#include "doos/caps.h"
|
||||
#include "doos/cli.hpp"
|
||||
#include "doos/container.hpp"
|
||||
#include "doos/network.hpp"
|
||||
#include "doos/util.hpp"
|
||||
|
||||
namespace molo::example::app {
|
||||
|
||||
namespace {
|
||||
|
||||
// Demo store: DOOS_HOME when the harness sets it (tests point it at scratch),
|
||||
// else build/doos-demo. Never the user's real store.
|
||||
void use_demo_home() {
|
||||
const char* h = ::getenv("DOOS_HOME");
|
||||
if (!h || !*h) ::setenv("DOOS_HOME", "build/doos-demo", 1);
|
||||
}
|
||||
|
||||
std::string input_or(const std::map<std::string, std::string>& input, const char* key) {
|
||||
auto it = input.find(key);
|
||||
return it == input.end() ? "" : it->second;
|
||||
}
|
||||
|
||||
// One {"ok":true,<key>:<value>} body from run_json, unwrapped to <key>:<value>
|
||||
// so /doos/status composes the single renderer instead of forking its fields.
|
||||
std::string run_inner(const std::vector<std::string>& argv) {
|
||||
std::string body, err;
|
||||
int rc = molo::doos::run_json(argv, body, err);
|
||||
if (rc != 0) throw std::runtime_error(err.empty() ? "doos status failed" : err);
|
||||
const std::string pre = "{\"ok\":true,";
|
||||
if (body.rfind(pre, 0) != 0 || body.size() < pre.size() + 2) {
|
||||
throw std::runtime_error("bad doos json");
|
||||
}
|
||||
return body.substr(pre.size(), body.size() - pre.size() - 2); // strip trailing "}\n"
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void register_doos_demo(fw::Router& router, Services& services) {
|
||||
use_demo_home();
|
||||
fw::Environment* env = services.templates.get();
|
||||
|
||||
router.get("/doos", "doos-page", [env](fw::Request req) {
|
||||
(void)req;
|
||||
fw::TemplateCtx ctx;
|
||||
ctx["title"] = std::string("Sandboxed containers");
|
||||
ctx["heading"] = std::string("Sandboxed containers (doos)");
|
||||
molo::doos::Store store = molo::doos::Store::fromEnvironment();
|
||||
fw::TemplateList items;
|
||||
for (const auto& c : store.list()) {
|
||||
items.push_back({{"name", c.name()},
|
||||
{"kind", std::string(c.runningPid() ? "running" : "stopped") + " - " +
|
||||
molo::doos::Network::name(c.net()) + " - " +
|
||||
(c.imageMode() ? c.image() : "host")}});
|
||||
}
|
||||
ctx["items"] = items;
|
||||
ctx["snippet"] = std::to_string(items.size()) + " containers (demo store)";
|
||||
return fw::Response(200, env->render("page.html", ctx), "text/html; charset=utf-8");
|
||||
});
|
||||
|
||||
router.get("/doos/status", "doos-status", [](fw::Request req) {
|
||||
(void)req;
|
||||
try {
|
||||
std::string s = "{" + run_inner({"list"}) + "," + run_inner({"image", "list"}) + "," +
|
||||
run_inner({"davmount", "list"}) + "," + run_inner({"version"}) + "}";
|
||||
return fw::JsonResponse(s, 200);
|
||||
} catch (const std::exception& e) {
|
||||
return fw::JsonResponse("{\"error\":\"" + fw::json_escape(e.what()) + "\"}", 500);
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/doos/create", "doos-create", [](fw::Request req) {
|
||||
auto input = fw::parse_json_object_flat(req.body);
|
||||
if (input.empty()) input = fw::parse_form(req.body);
|
||||
std::vector<std::string> failures;
|
||||
std::string name = input_or(input, "name");
|
||||
if (name.empty()) failures.push_back("name is required");
|
||||
molo::doos::Options opts;
|
||||
try {
|
||||
if (!input_or(input, "size").empty()) {
|
||||
opts.size = molo::doos::parseSize(input_or(input, "size"));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
failures.push_back(e.what());
|
||||
}
|
||||
try {
|
||||
if (!input_or(input, "memory").empty()) {
|
||||
opts.memory = molo::doos::parseSize(input_or(input, "memory"));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
failures.push_back(e.what());
|
||||
}
|
||||
try {
|
||||
if (!input_or(input, "net").empty()) {
|
||||
opts.net = molo::doos::Network::parse(input_or(input, "net"));
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
failures.push_back(e.what());
|
||||
}
|
||||
if (!failures.empty()) {
|
||||
std::ostringstream o;
|
||||
o << "{\"errors\":[";
|
||||
for (std::size_t i = 0; i < failures.size(); ++i) {
|
||||
if (i) o << ",";
|
||||
o << "\"" << fw::json_escape(failures[i]) << "\"";
|
||||
}
|
||||
o << "]}";
|
||||
return fw::JsonResponse(o.str(), 422);
|
||||
}
|
||||
try {
|
||||
molo::doos::Store store = molo::doos::Store::fromEnvironment();
|
||||
auto [c, created] = store.getOrCreate(name, opts);
|
||||
std::ostringstream o;
|
||||
o << "{\"name\":\"" << molo::doos::json_escape(c.name()) << "\",\"created\":"
|
||||
<< (created ? "true" : "false") << "}";
|
||||
return fw::JsonResponse(o.str(), 200);
|
||||
} catch (const std::exception& e) {
|
||||
return fw::JsonResponse("{\"errors\":[\"" + fw::json_escape(e.what()) + "\"]}", 422);
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/doos/delete", "doos-delete", [](fw::Request req) {
|
||||
auto input = fw::parse_json_object_flat(req.body);
|
||||
if (input.empty()) input = fw::parse_form(req.body);
|
||||
std::string name = input_or(input, "name");
|
||||
if (name.empty()) return fw::JsonResponse("{\"errors\":[\"name is required\"]}", 422);
|
||||
bool confirm = input_or(input, "confirm") == "yes";
|
||||
try {
|
||||
molo::doos::Store store = molo::doos::Store::fromEnvironment();
|
||||
std::string report = store.remove(name, confirm);
|
||||
std::ostringstream o;
|
||||
o << "{\"name\":\"" << molo::doos::json_escape(name) << "\",\"dry_run\":"
|
||||
<< (confirm ? "false" : "true") << ",\"report\":\"" << molo::doos::json_escape(report)
|
||||
<< "\"}";
|
||||
return fw::JsonResponse(o.str(), 200);
|
||||
} catch (const std::exception& e) {
|
||||
std::string msg = e.what();
|
||||
int code = msg.find("no such container") != std::string::npos ? 404 : 422;
|
||||
std::string key = code == 404 ? "error" : "errors";
|
||||
std::string val = code == 404 ? "\"" + fw::json_escape(msg) + "\""
|
||||
: "[\"" + fw::json_escape(msg) + "\"]";
|
||||
return fw::JsonResponse("{\"" + key + "\":" + val + "}", code);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace molo::example::app
|
||||
+11
-9
@@ -1,4 +1,5 @@
|
||||
#include "App.hpp"
|
||||
#include "IndexCatalog.hpp"
|
||||
|
||||
#include "../fw/Http.hpp"
|
||||
#include "../fw/Router.hpp"
|
||||
@@ -42,6 +43,8 @@ const char* kFeatures[][2] = {
|
||||
{"restclient", "/restclient/self"},
|
||||
{"openapi", "/openapi.json"},
|
||||
{"docs", "/docs"},
|
||||
{"doos", "/doos"},
|
||||
{"doos-status", "/doos/status"},
|
||||
{"ai", "/cli/ai"},
|
||||
{"workflow", "/workflow/release"},
|
||||
{"redirect", "/redirect/here"},
|
||||
@@ -54,18 +57,17 @@ const char* kFeatures[][2] = {
|
||||
void register_index(fw::Router& router, Services& services_ref) {
|
||||
fw::Environment* env = services_ref.templates.get();
|
||||
Services* services = &services_ref;
|
||||
static const IndexCatalog catalog;
|
||||
router.get("/", "index", [env, services](fw::Request req) {
|
||||
fw::TemplateCtx ctx;
|
||||
ctx["title"] = std::string("MoloApp living example");
|
||||
ctx["show_matrix"] = std::string("true");
|
||||
fw::TemplateList rows;
|
||||
for (const auto& [feature, route] : kFeatures) {
|
||||
rows.push_back({{"feature", feature}, {"route", route}});
|
||||
}
|
||||
for (const auto& [feature, route] : services->features) {
|
||||
rows.push_back({{"feature", feature}, {"route", route}});
|
||||
}
|
||||
ctx["matrix"] = rows;
|
||||
std::vector<std::pair<std::string, std::string>> rows;
|
||||
for (const auto& [feature, route] : kFeatures) rows.emplace_back(feature, route);
|
||||
for (const auto& [feature, route] : services->features) rows.emplace_back(feature, route);
|
||||
std::size_t features = 0, groups = 0;
|
||||
ctx["sections"] = catalog.render(rows, &features, &groups);
|
||||
ctx["feature_count"] = std::to_string(features);
|
||||
ctx["group_count"] = std::to_string(groups);
|
||||
(void)req;
|
||||
return fw::Response(200, env->render("index.html", ctx),
|
||||
"text/html; charset=utf-8");
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
#include "IndexCatalog.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "../fw/Templates.hpp"
|
||||
|
||||
namespace molo::example::app {
|
||||
|
||||
namespace {
|
||||
|
||||
bool has_prefix(const std::string& route, const std::string& prefix) {
|
||||
if (route.compare(0, prefix.size(), prefix) != 0) return false;
|
||||
if (route.size() == prefix.size()) return true;
|
||||
// Whole-segment match, so "/data" does not claim "/database". A prefix with
|
||||
// a scheme ("http://") is a plain string prefix.
|
||||
if (prefix.back() == '/') return true;
|
||||
char next = route[prefix.size()];
|
||||
return next == '/' || next == '?';
|
||||
}
|
||||
|
||||
const char* kVendorKeys =
|
||||
"Needs vendor API keys (XAI_API_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY, "
|
||||
"OPENROUTER_API_KEY, DEEPSEEK_API_KEY, META_API_KEY, ...) in the environment "
|
||||
"or .env.json.local. Without a key the page still loads and calls answer "
|
||||
"503 not_configured; paid routes are dry runs unless confirmed.";
|
||||
|
||||
} // namespace
|
||||
|
||||
IndexCatalog::IndexCatalog() {
|
||||
groups_ = {
|
||||
{"routing", "Routing and views",
|
||||
"Paths, class views, routers, app chaining, redirects, dependency injection.", "",
|
||||
{"/routing", "/middleware", "/app1", "/redirect", "/conditional", "/context", "/di", "/hello",
|
||||
"/greet", "/deep"}},
|
||||
{"requests", "Requests, forms and templates",
|
||||
"Forms, validation with all field errors, templates, content negotiation, uploads, i18n.",
|
||||
"", {"/forms", "/validate", "/templates", "/formats", "/flash", "/compress", "/i18n",
|
||||
"/uploads"}},
|
||||
{"data", "Data and events",
|
||||
"ORM on SQLite and Postgres with self-healing, key-value store, cache, pubsub, events, replication.",
|
||||
"", {"/orm", "/data", "/kv", "/cache", "/pubsub", "/events", "/replication"}},
|
||||
{"security", "Security",
|
||||
"Auth, sessions, CSRF, CORS, rate limits, security headers, CSP, crypto, roles, upload and input guards.",
|
||||
"", {"/auth", "/sessions", "/security", "/csp", "/crypto"}},
|
||||
{"static", "Static and embedded files",
|
||||
"Assets from disk and from the binary, with ETags and range requests.", "",
|
||||
{"/static", "/embedded"}},
|
||||
{"realtime", "Realtime",
|
||||
"WebSocket, Socket.IO, server-sent events, streaming, passthrough, WebDAV, reverse tunnels.",
|
||||
"", {"/ws", "/socketio", "/sse", "/streaming", "/webdav", "/expose"}},
|
||||
{"observability", "Observability",
|
||||
"Metrics, Prometheus scrape, tracing, structured logging, live charts, health.", "",
|
||||
{"/metrics", "/telemetry", "/logging", "/stats", "/health", "/healthz", "/readyz",
|
||||
"/startupz"}},
|
||||
{"operations", "Operations and delivery",
|
||||
"Supervisor and tasks, REST client, operability tools, OpenAPI and docs, release workflow, supply chain.",
|
||||
"", {"/supervisor", "/restclient", "/clients", "/operability", "/cli", "/workflow", "/supplychain",
|
||||
"/openapi.json", "/docs"}},
|
||||
{"doos", "Sandboxed containers",
|
||||
"Rootless user-level containers: status page, create, inspect, delete (demo store).", "",
|
||||
{"/doos"}},
|
||||
{"tenancy", "Multi-tenancy",
|
||||
"Tenant resolution, data isolation, quotas, feature flags, per-tenant config and metrics.",
|
||||
"", {"/tenancy"}},
|
||||
{"audit", "Audit and compliance",
|
||||
"Hash-chained audit log, tamper detection, PII masking, retention, export and erasure.",
|
||||
"", {"/audit"}},
|
||||
{"governance", "API governance",
|
||||
"API keys, rate tiers, versioning with Deprecation and Sunset, linter, OpenAPI diff, problem+json.",
|
||||
"", {"/governance", "/v1", "/v2"}},
|
||||
{"google", "Google Cloud and voice",
|
||||
"Gemini, Google Cloud APIs and the live spoken conversation. Without a key pages load and calls answer 503 not_configured.",
|
||||
"GOOGLE_API_KEY", {"/google", "/voice"}},
|
||||
{"agent", "Agent Platform",
|
||||
"Gemini Enterprise Agent Platform modules: models, runtime, sessions, sandbox, registry, armor, live.",
|
||||
"GOOGLE_API_KEY", {"/agent"}},
|
||||
{"vendors", "LLM vendors", kVendorKeys, "vendor API keys", {"/ai"}},
|
||||
{"tools", "Tools", "Load testing and other helpers outside the app.", "",
|
||||
{"http://", "https://"}},
|
||||
};
|
||||
other_ = {"other", "Other", "Registered by the app, not yet grouped.", "", {}};
|
||||
}
|
||||
|
||||
std::string IndexCatalog::pretty_name(const std::string& feature) {
|
||||
if (feature.empty()) return feature;
|
||||
if (feature.find(' ') != std::string::npos ||
|
||||
std::isupper(static_cast<unsigned char>(feature[0]))) {
|
||||
std::string out = feature;
|
||||
out[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(out[0])));
|
||||
return out;
|
||||
}
|
||||
static const std::map<std::string, std::string> kTokens = {
|
||||
{"ai", "AI"}, {"api", "API"}, {"orm", "ORM"},
|
||||
{"sse", "SSE"}, {"kv", "KV"}, {"cli", "CLI"},
|
||||
{"csp", "CSP"}, {"tls", "TLS"}, {"webdav", "WebDAV"},
|
||||
{"socketio", "Socket.IO"}, {"openapi", "OpenAPI"}, {"openai", "OpenAI"},
|
||||
{"xai", "xAI"}, {"sqlite", "SQLite"}, {"postgres", "Postgres"},
|
||||
{"deepseek", "DeepSeek"}, {"openrouter", "OpenRouter"},
|
||||
{"huggingface", "Hugging Face"}, {"restclient", "REST client"},
|
||||
};
|
||||
std::string out;
|
||||
std::string token;
|
||||
auto flush = [&] {
|
||||
if (token.empty()) return;
|
||||
if (!out.empty()) out += ' ';
|
||||
auto it = kTokens.find(token);
|
||||
if (it != kTokens.end()) {
|
||||
out += it->second;
|
||||
} else {
|
||||
if (out.empty()) token[0] = static_cast<char>(std::toupper(static_cast<unsigned char>(token[0])));
|
||||
out += token;
|
||||
}
|
||||
token.clear();
|
||||
};
|
||||
for (char c : feature) {
|
||||
if (c == '-' || c == '_') flush();
|
||||
else token += c;
|
||||
}
|
||||
flush();
|
||||
return out;
|
||||
}
|
||||
|
||||
const FeatureGroup& IndexCatalog::group_for(const std::string& route) const {
|
||||
for (const auto& g : groups_) {
|
||||
for (const auto& p : g.prefixes) {
|
||||
if (has_prefix(route, p)) return g;
|
||||
}
|
||||
}
|
||||
return other_;
|
||||
}
|
||||
|
||||
std::string IndexCatalog::render(
|
||||
const std::vector<std::pair<std::string, std::string>>& rows,
|
||||
std::size_t* feature_count, std::size_t* group_count) const {
|
||||
using fw::html_escape;
|
||||
std::map<std::string, std::vector<FeatureRow>> by_group;
|
||||
std::set<std::string> seen;
|
||||
std::size_t total = 0;
|
||||
for (const auto& [name, route] : rows) {
|
||||
if (!seen.insert(name + '\n' + route).second) continue;
|
||||
by_group[group_for(route).id].push_back({pretty_name(name), route});
|
||||
++total;
|
||||
}
|
||||
std::vector<const FeatureGroup*> order;
|
||||
for (const auto& g : groups_) order.push_back(&g);
|
||||
order.push_back(&other_);
|
||||
|
||||
std::string chips = "<nav class=\"chips\" aria-label=\"Groups\">";
|
||||
std::string body;
|
||||
std::size_t groups = 0;
|
||||
for (const FeatureGroup* g : order) {
|
||||
auto it = by_group.find(g->id);
|
||||
if (it == by_group.end()) continue;
|
||||
++groups;
|
||||
chips += "<a href=\"#g-" + html_escape(g->id) + "\">" + html_escape(g->title) + "</a>";
|
||||
body += "<section class=\"group\" id=\"g-" + html_escape(g->id) + "\">\n<h2>" +
|
||||
html_escape(g->title) + " <span class=\"count\">" +
|
||||
std::to_string(it->second.size()) + "</span>";
|
||||
if (!g->key_hint.empty()) {
|
||||
body += " <span class=\"badge\" title=\"" + html_escape(g->key_hint) +
|
||||
"\">needs API key</span>";
|
||||
}
|
||||
body += "</h2>\n<p class=\"hint\">" + html_escape(g->blurb) +
|
||||
"</p>\n<div class=\"scroll\"><table>\n<thead><tr><th>Feature</th>"
|
||||
"<th class=\"route\">Route</th></tr></thead>\n<tbody>\n";
|
||||
for (const auto& r : it->second) {
|
||||
body += "<tr><td><a href=\"" + html_escape(r.route) + "\">" + html_escape(r.name) +
|
||||
"</a></td><td class=\"route\"><code>" + html_escape(r.route) +
|
||||
"</code></td></tr>\n";
|
||||
}
|
||||
body += "</tbody></table></div>\n</section>\n";
|
||||
}
|
||||
chips += "</nav>\n";
|
||||
if (feature_count) *feature_count = total;
|
||||
if (group_count) *group_count = groups;
|
||||
return chips + body;
|
||||
}
|
||||
|
||||
} // namespace molo::example::app
|
||||
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace molo::example::app {
|
||||
|
||||
// One row of the index page: a display name and the route that demonstrates it.
|
||||
struct FeatureRow {
|
||||
std::string name;
|
||||
std::string route;
|
||||
};
|
||||
|
||||
// A themed section of the index page. A route belongs to the first group that
|
||||
// lists its path prefix; routes matching no group fall into "Other".
|
||||
struct FeatureGroup {
|
||||
std::string id;
|
||||
std::string title;
|
||||
std::string blurb;
|
||||
std::string key_hint; // non-empty: the demos need these credentials
|
||||
std::vector<std::string> prefixes;
|
||||
};
|
||||
|
||||
// Groups the feature rows and renders the index sections (SPEC.md, index).
|
||||
class IndexCatalog {
|
||||
public:
|
||||
IndexCatalog();
|
||||
|
||||
// Display name for a registered feature ("ai-openai" -> "AI OpenAI").
|
||||
static std::string pretty_name(const std::string& feature);
|
||||
|
||||
// HTML for the jump chips and one table per non-empty group. Everything
|
||||
// dynamic is escaped; the result is safe to insert unescaped.
|
||||
std::string render(const std::vector<std::pair<std::string, std::string>>& rows,
|
||||
std::size_t* feature_count, std::size_t* group_count) const;
|
||||
|
||||
private:
|
||||
const FeatureGroup& group_for(const std::string& route) const;
|
||||
|
||||
std::vector<FeatureGroup> groups_;
|
||||
FeatureGroup other_;
|
||||
};
|
||||
|
||||
} // namespace molo::example::app
|
||||
@@ -50,21 +50,13 @@ const char kBase[] = R"BASE(<!DOCTYPE html>
|
||||
const char kIndex[] = R"INDEX({% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h1>Living example</h1>
|
||||
<p>Every framework feature, one click away. Mobile-first: narrow the window
|
||||
and the top nav collapses into a dropdown menu.</p>
|
||||
{% if show_matrix %}
|
||||
<table>
|
||||
<thead><tr><th>Feature</th><th>Route</th></tr></thead>
|
||||
<tbody>
|
||||
{% for row in matrix %}
|
||||
<tr><td>{{ row.feature }}</td><td><a href="{{ row.route }}">{{ row.route }}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>Matrix hidden.</p>
|
||||
{% endif %}
|
||||
<p>{{ feature_count }} features in {{ group_count }} groups, each one click away.
|
||||
Every row is a live route with a test behind it. Mobile-first: narrow the
|
||||
window and the top nav collapses into a dropdown menu.</p>
|
||||
<p class="filter"><input id="filter" type="search" placeholder="Filter features" aria-label="Filter features" autocomplete="off"></p>
|
||||
{{ sections|safe }}
|
||||
{% include "nav_hint.html" %}
|
||||
<script src="/static/index.js" defer></script>
|
||||
{% endblock %}
|
||||
)INDEX";
|
||||
|
||||
|
||||
@@ -50,11 +50,6 @@ events as they arrive.</p>
|
||||
{% endblock %}
|
||||
)LIVE";
|
||||
|
||||
std::string env_or(const char* name, const char* fallback) {
|
||||
std::string v = google::Credentials::env(name);
|
||||
return v.empty() ? std::string(fallback) : v;
|
||||
}
|
||||
|
||||
[[noreturn]] void rethrow(const google::GoogleError& e) {
|
||||
if (e.http_status() == 503 && e.status() == "NOT_CONFIGURED")
|
||||
throw fw::HttpError(503, "google_not_configured", e.message());
|
||||
|
||||
+11
-5
@@ -42,12 +42,14 @@ EXAMPLE_SRCS = \
|
||||
$(EXAMPLE_DIR)/app/Templates.cpp \
|
||||
$(EXAMPLE_DIR)/app/Embedded.cpp \
|
||||
$(EXAMPLE_DIR)/app/Index.cpp \
|
||||
$(EXAMPLE_DIR)/app/IndexCatalog.cpp \
|
||||
$(EXAMPLE_DIR)/app/RoutingDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/DataDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/SecurityDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/FormatsDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/RealtimeDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/OpsDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/DoosDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/StatsDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/SecurityExtraDemo.cpp \
|
||||
$(EXAMPLE_DIR)/app/PlatformDemo.cpp \
|
||||
@@ -74,7 +76,7 @@ EXAMPLE_INC = -I$(EXAMPLE_DIR) -I$(EXAMPLE_BUILD) -Isrc
|
||||
# Real framework parts the example links: Google Cloud (src/google) over the
|
||||
# HTTP client (src/clients, wolfSSL TLS) and the operability breaker.
|
||||
EXAMPLE_REAL_LIBS = build/ai/libai.a build/google/libgoogle.a build/clients/libclients.a \
|
||||
build/liboperability.a
|
||||
build/liboperability.a build/doos/libdoos.a
|
||||
|
||||
.PHONY: example-deploy example-verify deploy verify example example-real-libs example-assets example-test example-clean example-locust
|
||||
|
||||
@@ -113,14 +115,14 @@ example: example-assets example-real-libs
|
||||
|
||||
example-test: example
|
||||
rm -rf $(EXAMPLE_BUILD)/tests
|
||||
mkdir -p $(EXAMPLE_BUILD)/tests
|
||||
mkdir -p $(EXAMPLE_BUILD)/tests $(EXAMPLE_BUILD)/tmp
|
||||
find $(EXAMPLE_TESTDIR) -name '*_test.cpp' | sort > $(EXAMPLE_BUILD)/tests/list.txt
|
||||
xargs -P $(EXAMPLE_TEST_JOBS) -I{} sh -c ' \
|
||||
t={}; n=`echo $$t | sed "s|$(EXAMPLE_TESTDIR)/||; s|/|_|g; s|\\.cpp$$||"`; \
|
||||
b=$(EXAMPLE_BUILD)/tests/$$n; \
|
||||
if $(CXX) $(EXAMPLE_CXXFLAGS) -I$(EXAMPLE_DIR) -I$(EXAMPLE_TESTDIR) -Isrc \
|
||||
$$t $(EXAMPLE_BUILD)/libexample.a $(EXAMPLE_REAL_LIBS) -lwolfssl -o $$b > $$b.log 2>&1; \
|
||||
then MOLO_ENV_FILES=off $$b >> $$b.log 2>&1; else echo "COMPILE FAILED: $$t" >> $$b.log; false; fi; \
|
||||
then MOLO_ENV_FILES=off TMPDIR=$${TMPDIR:-$(EXAMPLE_BUILD)/tmp} $$b >> $$b.log 2>&1; else echo "COMPILE FAILED: $$t" >> $$b.log; false; fi; \
|
||||
echo $$? > $$b.rc' < $(EXAMPLE_BUILD)/tests/list.txt
|
||||
pass=0; fail=0; \
|
||||
for l in `ls $(EXAMPLE_BUILD)/tests/*.log | sort`; do \
|
||||
@@ -149,8 +151,12 @@ example-deploy: example
|
||||
kill `cat $(EXAMPLE_RUN)/server.pid`; \
|
||||
for i in 1 2 3 4 5 6 7 8 9 10; do kill -0 `cat $(EXAMPLE_RUN)/server.pid` 2>/dev/null || break; sleep 0.5; done; \
|
||||
fi
|
||||
setsid nohup $(EXAMPLE_BUILD)/living-server $(EXAMPLE_PORT) --no-locust \
|
||||
> $(EXAMPLE_RUN)/server.log 2>&1 < /dev/null & echo $$! > $(EXAMPLE_RUN)/server.pid
|
||||
rm -f $(EXAMPLE_RUN)/server.pid
|
||||
setsid sh -c 'echo $$$$ > $(EXAMPLE_RUN)/server.pid; exec $(EXAMPLE_BUILD)/living-server $(EXAMPLE_PORT) --no-locust > $(EXAMPLE_RUN)/server.log 2>&1 < /dev/null' &
|
||||
for i in `seq 1 20`; do \
|
||||
[ -f $(EXAMPLE_RUN)/server.pid ] && kill -0 `cat $(EXAMPLE_RUN)/server.pid` 2>/dev/null && break; sleep 0.25; \
|
||||
done; \
|
||||
if [ ! -f $(EXAMPLE_RUN)/server.pid ] || ! kill -0 `cat $(EXAMPLE_RUN)/server.pid` 2>/dev/null; then echo "deploy: server died on start"; cat $(EXAMPLE_RUN)/server.log; exit 1; fi
|
||||
ok=0; for i in `seq 1 30`; do \
|
||||
if curl -fsS http://127.0.0.1:$(EXAMPLE_PORT)/health > /dev/null 2>&1; then ok=1; break; fi; sleep 0.5; \
|
||||
done; \
|
||||
|
||||
@@ -37,7 +37,7 @@ GETS = [
|
||||
"/auth/me", "/cache/lookup", "/cli/ai", "/cli/commands",
|
||||
"/crypto/hash", "/crypto/password", "/crypto/random",
|
||||
"/csp/page", "/csp/report",
|
||||
"/di/services", "/di/resolve/locust",
|
||||
"/di/services", "/di/resolve/locust", "/doos", "/doos/status",
|
||||
"/embedded/chart.umd.min.js", "/embedded/hello.txt", "/embedded/stats.js",
|
||||
"/events/fire", "/expose/record", "/expose/stats",
|
||||
"/files/", "/files/welcome.txt",
|
||||
@@ -100,6 +100,8 @@ POSTS = [
|
||||
("/crypto/hash", {"data": "hello"}),
|
||||
("/crypto/password", {"password": "secret"}),
|
||||
("/csp/report", {"report": "test"}),
|
||||
("/doos/create", {"name": "locust"}),
|
||||
("/doos/delete", {"name": "locust"}),
|
||||
("/events/fire", {"event": "test"}),
|
||||
("/expose/record", {"data": "x"}),
|
||||
("/flash/set", {"msg": "hi"}),
|
||||
|
||||
@@ -102,3 +102,19 @@ label.inline input { padding: 0; }
|
||||
.voice-log li.bot { border-left: 4px solid var(--series-1); }
|
||||
.voice-form { flex-direction: row; flex-wrap: wrap; max-width: none; }
|
||||
.voice-form input[type="text"] { flex: 1 1 12rem; min-width: 0; }
|
||||
|
||||
/* Index page: grouped feature list. */
|
||||
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 1rem; }
|
||||
.chips a { border: 1px solid var(--border); border-radius: 1rem; padding: 0.1rem 0.7rem;
|
||||
text-decoration: none; font-size: 0.9rem; }
|
||||
.filter input { width: 100%; max-width: 28rem; border: 1px solid var(--border);
|
||||
background: var(--surface-1); color: inherit; border-radius: 4px; }
|
||||
section.group { margin: 1.25rem 0; scroll-margin-top: 1rem; }
|
||||
section.group h2 { font-size: 1.15rem; margin: 0 0 0.1rem; display: flex; flex-wrap: wrap;
|
||||
align-items: baseline; gap: 0.5rem; }
|
||||
section.group p.hint { margin: 0 0 0.4rem; }
|
||||
.count { color: var(--text-secondary); font-size: 0.85rem; font-weight: normal; }
|
||||
.badge { font-size: 0.75rem; font-weight: normal; border: 1px solid var(--series-4);
|
||||
color: var(--series-4); border-radius: 0.7rem; padding: 0 0.5rem; }
|
||||
[hidden] { display: none !important; }
|
||||
@media (max-width: 40rem) { th.route, td.route { display: none; } }
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Index page filter: hides rows and groups that do not match. Without
|
||||
// JavaScript the full list stays visible.
|
||||
(function () {
|
||||
var box = document.getElementById("filter");
|
||||
if (!box) return;
|
||||
var groups = document.querySelectorAll("section.group");
|
||||
box.addEventListener("input", function () {
|
||||
var q = box.value.trim().toLowerCase();
|
||||
groups.forEach(function (g) {
|
||||
var shown = 0;
|
||||
g.querySelectorAll("tbody tr").forEach(function (tr) {
|
||||
var hit = q === "" || tr.textContent.toLowerCase().indexOf(q) !== -1;
|
||||
tr.hidden = !hit;
|
||||
if (hit) shown++;
|
||||
});
|
||||
g.hidden = shown === 0;
|
||||
});
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user