vlambda 0.2.2__tar.gz → 0.2.3__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.3}/PKG-INFO +3 -1
- {vlambda-0.2.2 → vlambda-0.2.3}/README.md +2 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/pyproject.toml +1 -1
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/__main__.py +24 -7
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/auth.py +7 -1
- {vlambda-0.2.2 → vlambda-0.2.3}/src/vlambda_native.v +4 -2
- {vlambda-0.2.2 → vlambda-0.2.3}/tests/test_unit.py +2 -1
- {vlambda-0.2.2 → vlambda-0.2.3}/tests/test_vlambda.py +11 -1
- {vlambda-0.2.2 → vlambda-0.2.3}/vcraft.toml +1 -1
- {vlambda-0.2.2 → vlambda-0.2.3}/LICENSE +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/__init__.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/assets.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/cache.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/dbpool.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/metrics.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/packages.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/pool.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/project.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/py.typed +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/request.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/reset.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/runner.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/sandbox.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/sandbox_os.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/shared_cache.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/tasks.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/python/vlambda/transfer.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/tests/conftest.py +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/v.mod +0 -0
- {vlambda-0.2.2 → vlambda-0.2.3}/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.3
|
|
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
|
|
@@ -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
|
|
@@ -168,19 +168,32 @@ def main() -> None:
|
|
|
168
168
|
if data is None:
|
|
169
169
|
return -1
|
|
170
170
|
try:
|
|
171
|
-
|
|
171
|
+
uid = int(data.get("sub", -1))
|
|
172
172
|
except (ValueError, TypeError):
|
|
173
173
|
return -1
|
|
174
|
+
epoch = str(data.get("epoch", ""))
|
|
175
|
+
if uid < 0 or not epoch:
|
|
176
|
+
return -1
|
|
177
|
+
from vlambda.dbpool import get as db_get
|
|
178
|
+
try:
|
|
179
|
+
with db_get(args.sqlite_path) as conn:
|
|
180
|
+
row = conn.execute("SELECT auth_epoch FROM users WHERE id = ?", (uid,)).fetchone()
|
|
181
|
+
except Exception:
|
|
182
|
+
return -1
|
|
183
|
+
if row is None or row[0] != epoch:
|
|
184
|
+
return -1
|
|
185
|
+
return uid
|
|
174
186
|
|
|
175
187
|
register_auth_verifier(_auth_verify)
|
|
176
188
|
|
|
177
189
|
# Auth: register user
|
|
178
190
|
def _auth_register(username, password):
|
|
179
191
|
from vlambda.dbpool import get as db_get
|
|
192
|
+
epoch = new_auth_epoch()
|
|
180
193
|
try:
|
|
181
194
|
with db_get(args.sqlite_path) as conn:
|
|
182
|
-
conn.execute("INSERT INTO users (username, password_hash) VALUES (?, ?)",
|
|
183
|
-
(username, hash_password(password)))
|
|
195
|
+
conn.execute("INSERT INTO users (username, password_hash, auth_epoch) VALUES (?, ?, ?)",
|
|
196
|
+
(username, hash_password(password), epoch))
|
|
184
197
|
conn.commit()
|
|
185
198
|
uid = conn.execute("SELECT id FROM users WHERE username = ?", (username,)).fetchone()[0]
|
|
186
199
|
return uid
|
|
@@ -193,13 +206,17 @@ def main() -> None:
|
|
|
193
206
|
def _auth_login(username, password):
|
|
194
207
|
from vlambda.dbpool import get as db_get
|
|
195
208
|
with db_get(args.sqlite_path) as conn:
|
|
196
|
-
row = conn.execute("SELECT id, password_hash FROM users WHERE username = ?", (username,)).fetchone()
|
|
209
|
+
row = conn.execute("SELECT id, password_hash, auth_epoch FROM users WHERE username = ?", (username,)).fetchone()
|
|
197
210
|
if row is None:
|
|
198
211
|
return ""
|
|
199
|
-
uid, stored = row
|
|
212
|
+
uid, stored, epoch = row
|
|
200
213
|
if not check_password(password, stored):
|
|
201
214
|
return ""
|
|
202
|
-
|
|
215
|
+
if not epoch:
|
|
216
|
+
epoch = new_auth_epoch()
|
|
217
|
+
conn.execute("UPDATE users SET auth_epoch = ? WHERE id = ?", (epoch, uid))
|
|
218
|
+
conn.commit()
|
|
219
|
+
return create_token(uid, username, epoch)
|
|
203
220
|
|
|
204
221
|
# Register V bridges
|
|
205
222
|
from vlambda_native import register_auth_register, register_auth_login
|
|
@@ -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()
|
|
@@ -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,
|
|
@@ -2345,7 +2347,7 @@ pub fn db_verify_api_token(raw string) string {
|
|
|
2345
2347
|
hash := sha256.sum256(raw.bytes()).hex()
|
|
2346
2348
|
mut db := init_db(vlambda_db_path) or { return '' }
|
|
2347
2349
|
defer { db.close() or {} }
|
|
2348
|
-
rows := db.exec_param('SELECT user_id, scopes FROM api_tokens WHERE token_hash = ? AND revoked = 0;',
|
|
2350
|
+
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
2351
|
hash) or { return '' }
|
|
2350
2352
|
if rows.len == 0 {
|
|
2351
2353
|
return ''
|
|
@@ -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():
|
|
@@ -592,7 +592,17 @@ def test_admin_reset():
|
|
|
592
592
|
assert status == 200
|
|
593
593
|
assert "rows" in body
|
|
594
594
|
status, body = req("GET", "/vlambda", token=token)
|
|
595
|
-
assert
|
|
595
|
+
assert status == 401
|
|
596
|
+
# A newly created user gets a new ID/epoch; the old token must stay invalid.
|
|
597
|
+
u = _unique_user()
|
|
598
|
+
status, body = req("POST", "/register", f"{u}:testpass")
|
|
599
|
+
assert status == 201, body
|
|
600
|
+
status, new_token = req("POST", "/login", f"{u}:testpass")
|
|
601
|
+
assert status == 200 and "token" in new_token
|
|
602
|
+
status, body = req("GET", "/vlambda", token=token)
|
|
603
|
+
assert status == 401
|
|
604
|
+
status, body = req("GET", "/vlambda", token=new_token["token"])
|
|
605
|
+
assert status == 200 and body.get("count") == 0
|
|
596
606
|
# Wrong token must not reset.
|
|
597
607
|
status, body = req("POST", "/admin/reset", extra_headers={"X-Admin-Token": "wrong"})
|
|
598
608
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|