vlambda 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vlambda-0.2.2 → vlambda-0.2.4}/PKG-INFO +3 -1
- {vlambda-0.2.2 → vlambda-0.2.4}/README.md +2 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/pyproject.toml +1 -1
- vlambda-0.2.4/python/vlambda/__init__.py +8 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/__main__.py +29 -10
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/auth.py +7 -1
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/pool.py +26 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/request.py +16 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/runner.py +18 -3
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/sandbox.py +2 -14
- {vlambda-0.2.2 → vlambda-0.2.4}/src/vlambda_native.v +13 -7
- {vlambda-0.2.2 → vlambda-0.2.4}/tests/test_unit.py +2 -1
- {vlambda-0.2.2 → vlambda-0.2.4}/tests/test_vlambda.py +21 -1
- {vlambda-0.2.2 → vlambda-0.2.4}/vcraft.toml +1 -1
- vlambda-0.2.2/python/vlambda/__init__.py +0 -3
- {vlambda-0.2.2 → vlambda-0.2.4}/LICENSE +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/assets.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/cache.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/dbpool.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/metrics.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/packages.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/project.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/py.typed +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/reset.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/sandbox_os.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/shared_cache.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/tasks.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/python/vlambda/transfer.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/tests/conftest.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/v.mod +0 -0
- {vlambda-0.2.2 → vlambda-0.2.4}/vcraft_build.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vlambda
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: An ASGI-like server for Python lambdas, written in V.
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.14
|
|
@@ -288,6 +288,8 @@ The demo can be wiped with:
|
|
|
288
288
|
python -m vlambda reset --yes --url http://127.0.0.1:8080 --token "$VLAMBDA_ADMIN_TOKEN"
|
|
289
289
|
```
|
|
290
290
|
|
|
291
|
+
A reset also invalidates existing JWT sessions and API tokens.
|
|
292
|
+
|
|
291
293
|
For a disposable demo, run it from cron every day:
|
|
292
294
|
|
|
293
295
|
```cron
|
|
@@ -277,6 +277,8 @@ The demo can be wiped with:
|
|
|
277
277
|
python -m vlambda reset --yes --url http://127.0.0.1:8080 --token "$VLAMBDA_ADMIN_TOKEN"
|
|
278
278
|
```
|
|
279
279
|
|
|
280
|
+
A reset also invalidates existing JWT sessions and API tokens.
|
|
281
|
+
|
|
280
282
|
For a disposable demo, run it from cron every day:
|
|
281
283
|
|
|
282
284
|
```cron
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""vlambda: an ASGI-like server for Python lambdas, written in V."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
# Sandboxed runners only need the pure-Python modules; importing the native
|
|
6
|
+
# extension there adds startup latency without being used.
|
|
7
|
+
if os.environ.get("VLRUN_NO_NATIVE") != "1":
|
|
8
|
+
from vlambda_native import * # noqa: F401,F403
|
|
@@ -51,7 +51,7 @@ def main() -> None:
|
|
|
51
51
|
if not has_handler:
|
|
52
52
|
return "missing handler function"
|
|
53
53
|
return "" # valid
|
|
54
|
-
from vlambda.auth import verify_token, create_token, hash_password, check_password
|
|
54
|
+
from vlambda.auth import verify_token, create_token, hash_password, check_password, new_auth_epoch
|
|
55
55
|
import sqlite3
|
|
56
56
|
from vlambda.request import Request
|
|
57
57
|
from vlambda_native import start_server, db_init, register_pool, register_auth_verifier, register_auth_register, register_auth_login, configure, register_validate_code, register_ui_html, register_get_asset, register_get_project_json, register_save_project_json, register_list_versions, register_list_aliases, register_admin_reset, register_admin_create_user, register_list_packages, register_install_packages, register_create_task, register_get_task, register_record_metric, register_query_metrics, register_query_stats, register_query_summary, register_query_aggregate, register_query_logs, register_delete_metrics, register_delete_logs, register_export_metrics, register_pool_stats, register_run_project, register_create_project, register_delete_project, register_schedule_delete, register_get_dlq, register_export_lambda, register_import_lambda, register_duplicate_lambda, set_overloaded
|
|
@@ -113,7 +113,9 @@ def main() -> None:
|
|
|
113
113
|
body = body or b""
|
|
114
114
|
# Response cache for GET requests, storing the final serialized payload.
|
|
115
115
|
cache_key = None
|
|
116
|
-
|
|
116
|
+
# A lambda that writes logs has side effects; never serve it from the
|
|
117
|
+
# GET response cache or its log lines would silently disappear.
|
|
118
|
+
if method == "GET" and "request.log" not in code:
|
|
117
119
|
cache_key = f"{code}:{path}:{query}"
|
|
118
120
|
from vlambda.cache import get_response
|
|
119
121
|
cached = get_response(cache_key)
|
|
@@ -168,19 +170,32 @@ def main() -> None:
|
|
|
168
170
|
if data is None:
|
|
169
171
|
return -1
|
|
170
172
|
try:
|
|
171
|
-
|
|
173
|
+
uid = int(data.get("sub", -1))
|
|
172
174
|
except (ValueError, TypeError):
|
|
173
175
|
return -1
|
|
176
|
+
epoch = str(data.get("epoch", ""))
|
|
177
|
+
if uid < 0 or not epoch:
|
|
178
|
+
return -1
|
|
179
|
+
from vlambda.dbpool import get as db_get
|
|
180
|
+
try:
|
|
181
|
+
with db_get(args.sqlite_path) as conn:
|
|
182
|
+
row = conn.execute("SELECT auth_epoch FROM users WHERE id = ?", (uid,)).fetchone()
|
|
183
|
+
except Exception:
|
|
184
|
+
return -1
|
|
185
|
+
if row is None or row[0] != epoch:
|
|
186
|
+
return -1
|
|
187
|
+
return uid
|
|
174
188
|
|
|
175
189
|
register_auth_verifier(_auth_verify)
|
|
176
190
|
|
|
177
191
|
# Auth: register user
|
|
178
192
|
def _auth_register(username, password):
|
|
179
193
|
from vlambda.dbpool import get as db_get
|
|
194
|
+
epoch = new_auth_epoch()
|
|
180
195
|
try:
|
|
181
196
|
with db_get(args.sqlite_path) as conn:
|
|
182
|
-
conn.execute("INSERT INTO users (username, password_hash) VALUES (?, ?)",
|
|
183
|
-
(username, hash_password(password)))
|
|
197
|
+
conn.execute("INSERT INTO users (username, password_hash, auth_epoch) VALUES (?, ?, ?)",
|
|
198
|
+
(username, hash_password(password), epoch))
|
|
184
199
|
conn.commit()
|
|
185
200
|
uid = conn.execute("SELECT id FROM users WHERE username = ?", (username,)).fetchone()[0]
|
|
186
201
|
return uid
|
|
@@ -193,13 +208,17 @@ def main() -> None:
|
|
|
193
208
|
def _auth_login(username, password):
|
|
194
209
|
from vlambda.dbpool import get as db_get
|
|
195
210
|
with db_get(args.sqlite_path) as conn:
|
|
196
|
-
row = conn.execute("SELECT id, password_hash FROM users WHERE username = ?", (username,)).fetchone()
|
|
211
|
+
row = conn.execute("SELECT id, password_hash, auth_epoch FROM users WHERE username = ?", (username,)).fetchone()
|
|
197
212
|
if row is None:
|
|
198
213
|
return ""
|
|
199
|
-
uid, stored = row
|
|
214
|
+
uid, stored, epoch = row
|
|
200
215
|
if not check_password(password, stored):
|
|
201
216
|
return ""
|
|
202
|
-
|
|
217
|
+
if not epoch:
|
|
218
|
+
epoch = new_auth_epoch()
|
|
219
|
+
conn.execute("UPDATE users SET auth_epoch = ? WHERE id = ?", (epoch, uid))
|
|
220
|
+
conn.commit()
|
|
221
|
+
return create_token(uid, username, epoch)
|
|
203
222
|
|
|
204
223
|
# Register V bridges
|
|
205
224
|
from vlambda_native import register_auth_register, register_auth_login
|
|
@@ -382,11 +401,11 @@ def main() -> None:
|
|
|
382
401
|
|
|
383
402
|
from vlambda.project import create_project as _create_project, execute_project as _execute_project, delete_project as _delete_project_impl, schedule_delete as _schedule_delete_impl
|
|
384
403
|
|
|
385
|
-
def _run_project(project_dir, entrypoint, method, path, query, body):
|
|
404
|
+
def _run_project(project_dir, entrypoint, method, path, query, body, request_id, slug):
|
|
386
405
|
import json
|
|
387
406
|
timeout = args.invoke_timeout
|
|
388
407
|
try:
|
|
389
|
-
result = pool.execute_project(project_dir, entrypoint, method, path, query, body, timeout=timeout)
|
|
408
|
+
result = pool.execute_project(project_dir, entrypoint, method, path, query, body, timeout=timeout, request_id=request_id, slug=slug)
|
|
390
409
|
if isinstance(result, str):
|
|
391
410
|
return result
|
|
392
411
|
if isinstance(result, (dict, list)):
|
|
@@ -23,11 +23,17 @@ def _b64decode(s: str) -> bytes:
|
|
|
23
23
|
return base64.urlsafe_b64decode(s)
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
def
|
|
26
|
+
def new_auth_epoch() -> str:
|
|
27
|
+
"""Random per-user value that invalidates old tokens after a DB reset."""
|
|
28
|
+
return os.urandom(16).hex()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def create_token(user_id: int, username: str, auth_epoch: str = "", expires_in: int = 3600) -> str:
|
|
27
32
|
header = _b64encode(json.dumps({"alg": "HS256", "typ": "JWT"}).encode())
|
|
28
33
|
payload = _b64encode(json.dumps({
|
|
29
34
|
"sub": str(user_id),
|
|
30
35
|
"username": username,
|
|
36
|
+
"epoch": auth_epoch,
|
|
31
37
|
"exp": int(time.time()) + expires_in,
|
|
32
38
|
}).encode())
|
|
33
39
|
sig_input = f"{header}.{payload}".encode()
|
|
@@ -280,9 +280,32 @@ def _runner_env() -> dict[str, str]:
|
|
|
280
280
|
env["HOME"] = "/tmp"
|
|
281
281
|
env["TMPDIR"] = "/tmp"
|
|
282
282
|
env["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
283
|
+
env["VLRUN_NO_NATIVE"] = "1"
|
|
283
284
|
return env
|
|
284
285
|
|
|
285
286
|
|
|
287
|
+
def _record_runner_logs(logs) -> None:
|
|
288
|
+
"""Persist logs produced in a short-lived runner process."""
|
|
289
|
+
if not isinstance(logs, list) or not logs:
|
|
290
|
+
return
|
|
291
|
+
try:
|
|
292
|
+
from vlambda.metrics import record_log
|
|
293
|
+
except Exception:
|
|
294
|
+
return
|
|
295
|
+
for item in logs:
|
|
296
|
+
if not isinstance(item, dict):
|
|
297
|
+
continue
|
|
298
|
+
try:
|
|
299
|
+
record_log(
|
|
300
|
+
str(item.get("request_id", "")),
|
|
301
|
+
str(item.get("slug", "")),
|
|
302
|
+
str(item.get("level", "info")),
|
|
303
|
+
str(item.get("message", "")),
|
|
304
|
+
)
|
|
305
|
+
except Exception:
|
|
306
|
+
pass
|
|
307
|
+
|
|
308
|
+
|
|
286
309
|
class ProcessWorker:
|
|
287
310
|
def __init__(self):
|
|
288
311
|
self._lock = threading.Lock()
|
|
@@ -360,6 +383,7 @@ class ProcessWorker:
|
|
|
360
383
|
except json.JSONDecodeError:
|
|
361
384
|
self._proc = None
|
|
362
385
|
return {"error": "invalid runner response"}
|
|
386
|
+
_record_runner_logs(envelope.get("logs"))
|
|
363
387
|
if envelope.get("ok"):
|
|
364
388
|
return envelope.get("payload")
|
|
365
389
|
return {"error": envelope.get("error", "execution failed")}
|
|
@@ -505,6 +529,7 @@ class LandlockWorker:
|
|
|
505
529
|
envelope = json.loads(lines[-1])
|
|
506
530
|
except json.JSONDecodeError:
|
|
507
531
|
return {"error": "invalid runner response"}
|
|
532
|
+
_record_runner_logs(envelope.get("logs"))
|
|
508
533
|
if envelope.get("ok"):
|
|
509
534
|
return envelope.get("payload")
|
|
510
535
|
return {"error": envelope.get("error", "execution failed")}
|
|
@@ -608,6 +633,7 @@ class NsjailWorker:
|
|
|
608
633
|
envelope = json.loads(lines[-1])
|
|
609
634
|
except json.JSONDecodeError:
|
|
610
635
|
return {"error": "invalid runner response"}
|
|
636
|
+
_record_runner_logs(envelope.get("logs"))
|
|
611
637
|
if envelope.get("ok"):
|
|
612
638
|
return envelope.get("payload")
|
|
613
639
|
return {"error": envelope.get("error", "execution failed")}
|
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
_log_sink = None
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def set_log_sink(sink):
|
|
9
|
+
"""Route Request.log() to an alternate sink (used by sandboxed runners)."""
|
|
10
|
+
global _log_sink
|
|
11
|
+
_log_sink = sink
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def clear_log_sink():
|
|
15
|
+
global _log_sink
|
|
16
|
+
_log_sink = None
|
|
17
|
+
|
|
5
18
|
|
|
6
19
|
class Request:
|
|
7
20
|
__slots__ = ("method", "path", "query_string", "headers", "body", "request_id", "slug")
|
|
@@ -18,6 +31,9 @@ class Request:
|
|
|
18
31
|
|
|
19
32
|
def log(self, message, level="info"):
|
|
20
33
|
"""Persist a log line for this invocation."""
|
|
34
|
+
if _log_sink is not None:
|
|
35
|
+
_log_sink(self.request_id, self.slug, level, message)
|
|
36
|
+
return None
|
|
21
37
|
from vlambda.metrics import record_log
|
|
22
38
|
record_log(self.request_id, self.slug, level, message)
|
|
23
39
|
return None
|
|
@@ -17,9 +17,23 @@ if ROOT not in sys.path:
|
|
|
17
17
|
sys.path.insert(0, ROOT)
|
|
18
18
|
|
|
19
19
|
from vlambda.cache import get as get_compiled
|
|
20
|
-
from vlambda.request import Request
|
|
20
|
+
from vlambda.request import Request, set_log_sink
|
|
21
21
|
from vlambda.sandbox import make_sandbox
|
|
22
22
|
|
|
23
|
+
_current_logs: list[dict] = []
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _log_sink(request_id: str, slug: str, level: str, message: str):
|
|
27
|
+
_current_logs.append({
|
|
28
|
+
"request_id": request_id,
|
|
29
|
+
"slug": slug,
|
|
30
|
+
"level": level,
|
|
31
|
+
"message": str(message),
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
set_log_sink(_log_sink)
|
|
36
|
+
|
|
23
37
|
|
|
24
38
|
def _execute(code: str, method: str, path: str, query: str, body: bytes, request_id: str = "", slug: str = ""):
|
|
25
39
|
compiled, ns_template, handler = get_compiled(code)
|
|
@@ -79,6 +93,7 @@ def main() -> None:
|
|
|
79
93
|
line = line.strip()
|
|
80
94
|
if not line:
|
|
81
95
|
continue
|
|
96
|
+
_current_logs.clear()
|
|
82
97
|
try:
|
|
83
98
|
req = json.loads(line)
|
|
84
99
|
code = req.get("code", "")
|
|
@@ -113,9 +128,9 @@ def main() -> None:
|
|
|
113
128
|
payload = _json.dumps(result, default=_default)
|
|
114
129
|
else:
|
|
115
130
|
payload = str(result)
|
|
116
|
-
print(json.dumps({"ok": True, "payload": payload}), flush=True)
|
|
131
|
+
print(json.dumps({"ok": True, "payload": payload, "logs": _current_logs}), flush=True)
|
|
117
132
|
except Exception as e:
|
|
118
|
-
print(json.dumps({"ok": False, "error": f"{type(e).__name__}: {e}"}), flush=True)
|
|
133
|
+
print(json.dumps({"ok": False, "error": f"{type(e).__name__}: {e}", "logs": _current_logs}), flush=True)
|
|
119
134
|
|
|
120
135
|
|
|
121
136
|
if __name__ == "__main__":
|
|
@@ -32,21 +32,9 @@ def blocked_import(name, *args, **kwargs):
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
# Pre-imported modules (loaded once, shared across sandboxes)
|
|
35
|
+
# Modules are imported on demand by blocked_import. Preloading them at module
|
|
36
|
+
# import makes every fresh sandbox process pay for modules the lambda may not use.
|
|
35
37
|
_PREIMPORTED = {}
|
|
36
|
-
def _preload():
|
|
37
|
-
import json, math, re, datetime, collections, itertools, functools
|
|
38
|
-
import hashlib, base64, string, textwrap, operator
|
|
39
|
-
import decimal, fractions, random, statistics
|
|
40
|
-
_PREIMPORTED.update({
|
|
41
|
-
"json": json, "math": math, "re": re,
|
|
42
|
-
"datetime": datetime, "collections": collections,
|
|
43
|
-
"itertools": itertools, "functools": functools,
|
|
44
|
-
"hashlib": hashlib, "base64": base64, "string": string,
|
|
45
|
-
"textwrap": textwrap, "operator": operator,
|
|
46
|
-
"decimal": decimal, "fractions": fractions,
|
|
47
|
-
"random": random, "statistics": statistics,
|
|
48
|
-
})
|
|
49
|
-
_preload()
|
|
50
38
|
|
|
51
39
|
|
|
52
40
|
|
|
@@ -98,8 +98,10 @@ fn init_db(db_path string) !sqlite.DB {
|
|
|
98
98
|
db.exec('CREATE TABLE IF NOT EXISTS users (
|
|
99
99
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
100
100
|
username TEXT UNIQUE NOT NULL,
|
|
101
|
-
password_hash TEXT NOT NULL
|
|
101
|
+
password_hash TEXT NOT NULL,
|
|
102
|
+
auth_epoch TEXT NOT NULL DEFAULT ""
|
|
102
103
|
);')!
|
|
104
|
+
db.exec('ALTER TABLE users ADD COLUMN auth_epoch TEXT NOT NULL DEFAULT "";') or {}
|
|
103
105
|
db.exec('CREATE TABLE IF NOT EXISTS lambdas (
|
|
104
106
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
105
107
|
slug TEXT UNIQUE NOT NULL,
|
|
@@ -1564,7 +1566,9 @@ pub fn (mut h VlambdaHandler) handle(req http.Request) http.Response {
|
|
|
1564
1566
|
if qi2 := req.url.index('?') {
|
|
1565
1567
|
q = req.url[qi2+1..]
|
|
1566
1568
|
}
|
|
1567
|
-
|
|
1569
|
+
vlambda_request_counter++
|
|
1570
|
+
request_id := 'req-${vlambda_request_counter}'
|
|
1571
|
+
result := run_project(project_dir, entrypoint, method, req.url, q, req.data, request_id, slug)
|
|
1568
1572
|
elapsed := time.since(start_time).microseconds()
|
|
1569
1573
|
vlambda_latency_sum += f64(elapsed) / 1000.0
|
|
1570
1574
|
vlambda_latency_count++
|
|
@@ -1573,7 +1577,9 @@ pub fn (mut h VlambdaHandler) handle(req http.Request) http.Response {
|
|
|
1573
1577
|
if result.contains('error') {
|
|
1574
1578
|
vlambda_lambda_errors[slug] = (vlambda_lambda_errors[slug] or { u64(0) }) + 1
|
|
1575
1579
|
}
|
|
1576
|
-
|
|
1580
|
+
mut resp := cors_response(200, result, lambda_content_type(result))
|
|
1581
|
+
resp.header.add_custom('X-Request-Id', request_id) or {}
|
|
1582
|
+
return resp
|
|
1577
1583
|
}
|
|
1578
1584
|
// Split code and method
|
|
1579
1585
|
parts := code_method.split('|')
|
|
@@ -2345,7 +2351,7 @@ pub fn db_verify_api_token(raw string) string {
|
|
|
2345
2351
|
hash := sha256.sum256(raw.bytes()).hex()
|
|
2346
2352
|
mut db := init_db(vlambda_db_path) or { return '' }
|
|
2347
2353
|
defer { db.close() or {} }
|
|
2348
|
-
rows := db.exec_param('SELECT user_id, scopes FROM api_tokens WHERE token_hash = ? AND revoked = 0;',
|
|
2354
|
+
rows := db.exec_param('SELECT t.user_id, t.scopes FROM api_tokens t JOIN users u ON u.id = t.user_id WHERE t.token_hash = ? AND t.revoked = 0;',
|
|
2349
2355
|
hash) or { return '' }
|
|
2350
2356
|
if rows.len == 0 {
|
|
2351
2357
|
return ''
|
|
@@ -2446,14 +2452,14 @@ pub fn run_lambda(request_id string, slug string, code string, method string, pa
|
|
|
2446
2452
|
}
|
|
2447
2453
|
|
|
2448
2454
|
@[vc_fn]
|
|
2449
|
-
pub fn run_project(project_dir string, entrypoint string, method string, path string, query string, body string) string {
|
|
2455
|
+
pub fn run_project(project_dir string, entrypoint string, method string, path string, query string, body string, request_id string, slug string) string {
|
|
2450
2456
|
vlambda_result_str = '{"error": "not started"}'
|
|
2451
|
-
vcraft.with_gil(fn [project_dir, entrypoint, method, path, query, body] () {
|
|
2457
|
+
vcraft.with_gil(fn [project_dir, entrypoint, method, path, query, body, request_id, slug] () {
|
|
2452
2458
|
if vlambda_run_project == unsafe { nil } {
|
|
2453
2459
|
vlambda_result_str = '{"error": "no project runner registered"}'
|
|
2454
2460
|
return
|
|
2455
2461
|
}
|
|
2456
|
-
args := [vcraft.to_py_string(project_dir).ptr, vcraft.to_py_string(entrypoint).ptr, vcraft.to_py_string(method).ptr, vcraft.to_py_string(path).ptr, vcraft.to_py_string(query).ptr, body_to_py_bytes(body).ptr]
|
|
2462
|
+
args := [vcraft.to_py_string(project_dir).ptr, vcraft.to_py_string(entrypoint).ptr, vcraft.to_py_string(method).ptr, vcraft.to_py_string(path).ptr, vcraft.to_py_string(query).ptr, body_to_py_bytes(body).ptr, vcraft.to_py_string(request_id).ptr, vcraft.to_py_string(slug).ptr]
|
|
2457
2463
|
result := vcraft.call(vlambda_run_project, args)
|
|
2458
2464
|
for a in args { vcraft.borrow(a).decref() }
|
|
2459
2465
|
if result.is_null() {
|
|
@@ -192,11 +192,12 @@ def test_gc_orphans_respects_grace(tmp_path, monkeypatch):
|
|
|
192
192
|
|
|
193
193
|
def test_auth_token_roundtrip():
|
|
194
194
|
from vlambda.auth import create_token, verify_token
|
|
195
|
-
token = create_token(42, "alice")
|
|
195
|
+
token = create_token(42, "alice", "epoch-1")
|
|
196
196
|
data = verify_token(token)
|
|
197
197
|
assert data is not None
|
|
198
198
|
assert data["sub"] == "42"
|
|
199
199
|
assert data["username"] == "alice"
|
|
200
|
+
assert data["epoch"] == "epoch-1"
|
|
200
201
|
|
|
201
202
|
|
|
202
203
|
def test_auth_bad_token():
|
|
@@ -385,6 +385,7 @@ def test_landlock_sandbox():
|
|
|
385
385
|
" check('fork', lambda: os.fork())\n"
|
|
386
386
|
" check('subprocess', lambda: __import__('subprocess').run(['/bin/true']))\n"
|
|
387
387
|
" check('tmp_other', lambda: open('/tmp/not-mine', 'w'))\n"
|
|
388
|
+
" request.log('landlock log line')\n"
|
|
388
389
|
" values = []\n"
|
|
389
390
|
" thread = threading.Thread(target=lambda: values.append(1))\n"
|
|
390
391
|
" thread.start(); thread.join()\n"
|
|
@@ -405,6 +406,15 @@ def test_landlock_sandbox():
|
|
|
405
406
|
assert body.get("tmp_other") == "PermissionError", body
|
|
406
407
|
assert body.get("thread") == [1], body
|
|
407
408
|
assert body.get("env") == [], body
|
|
409
|
+
deadline = time.time() + 4
|
|
410
|
+
logs = {}
|
|
411
|
+
while time.time() < deadline:
|
|
412
|
+
status, logs = req("GET", f"/logs/history?days=1&slug={slug}", token=token)
|
|
413
|
+
assert status == 200
|
|
414
|
+
if any(item.get("message") == "landlock log line" for item in logs.get("items", [])):
|
|
415
|
+
break
|
|
416
|
+
time.sleep(0.3)
|
|
417
|
+
assert any(item.get("message") == "landlock log line" for item in logs.get("items", [])), logs
|
|
408
418
|
finally:
|
|
409
419
|
stop_server()
|
|
410
420
|
|
|
@@ -592,7 +602,17 @@ def test_admin_reset():
|
|
|
592
602
|
assert status == 200
|
|
593
603
|
assert "rows" in body
|
|
594
604
|
status, body = req("GET", "/vlambda", token=token)
|
|
595
|
-
assert
|
|
605
|
+
assert status == 401
|
|
606
|
+
# A newly created user gets a new ID/epoch; the old token must stay invalid.
|
|
607
|
+
u = _unique_user()
|
|
608
|
+
status, body = req("POST", "/register", f"{u}:testpass")
|
|
609
|
+
assert status == 201, body
|
|
610
|
+
status, new_token = req("POST", "/login", f"{u}:testpass")
|
|
611
|
+
assert status == 200 and "token" in new_token
|
|
612
|
+
status, body = req("GET", "/vlambda", token=token)
|
|
613
|
+
assert status == 401
|
|
614
|
+
status, body = req("GET", "/vlambda", token=new_token["token"])
|
|
615
|
+
assert status == 200 and body.get("count") == 0
|
|
596
616
|
# Wrong token must not reset.
|
|
597
617
|
status, body = req("POST", "/admin/reset", extra_headers={"X-Admin-Token": "wrong"})
|
|
598
618
|
assert body.get("error") == "forbidden"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|