streamwright-console 0.3.0__py3-none-any.whl

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.
Files changed (55) hide show
  1. streamwright/console/__init__.py +29 -0
  2. streamwright/console/api/__init__.py +20 -0
  3. streamwright/console/api/acks.py +162 -0
  4. streamwright/console/api/app.py +401 -0
  5. streamwright/console/api/login.py +139 -0
  6. streamwright/console/api/logs.py +113 -0
  7. streamwright/console/api/openapi.py +205 -0
  8. streamwright/console/api/query.py +113 -0
  9. streamwright/console/auth/__init__.py +21 -0
  10. streamwright/console/auth/access.py +99 -0
  11. streamwright/console/auth/authenticator.py +45 -0
  12. streamwright/console/auth/passwords.py +83 -0
  13. streamwright/console/auth/sessions.py +65 -0
  14. streamwright/console/auth/sso.py +186 -0
  15. streamwright/console/auth/throttle.py +60 -0
  16. streamwright/console/auth/users.py +111 -0
  17. streamwright/console/cli/__init__.py +21 -0
  18. streamwright/console/cli/admin.py +267 -0
  19. streamwright/console/cli/main.py +110 -0
  20. streamwright/console/config/__init__.py +18 -0
  21. streamwright/console/config/check.py +48 -0
  22. streamwright/console/config/console.py +289 -0
  23. streamwright/console/config/login.py +141 -0
  24. streamwright/console/config/service.py +32 -0
  25. streamwright/console/db/__init__.py +18 -0
  26. streamwright/console/db/migrations/0001_console_users.py +40 -0
  27. streamwright/console/db/migrations/__init__.py +29 -0
  28. streamwright/console/db/tables/__init__.py +34 -0
  29. streamwright/console/db/tables/base.py +24 -0
  30. streamwright/console/db/tables/migrations.py +27 -0
  31. streamwright/console/db/tables/users.py +42 -0
  32. streamwright/console/db/users.py +95 -0
  33. streamwright/console/guide.md +99 -0
  34. streamwright/console/static/app.js +2014 -0
  35. streamwright/console/static/favicon.png +0 -0
  36. streamwright/console/static/favicon.svg +1 -0
  37. streamwright/console/static/index.html +66 -0
  38. streamwright/console/static/streamwright-logo-dark.svg +1 -0
  39. streamwright/console/static/style.css +410 -0
  40. streamwright/console/views/__init__.py +21 -0
  41. streamwright/console/views/attention.py +145 -0
  42. streamwright/console/views/filters.py +62 -0
  43. streamwright/console/views/job_page.py +97 -0
  44. streamwright/console/views/job_runs.py +222 -0
  45. streamwright/console/views/job_summaries.py +123 -0
  46. streamwright/console/views/overview.py +156 -0
  47. streamwright/console/views/reads.py +354 -0
  48. streamwright/console/views/run_log.py +77 -0
  49. streamwright/console/views/stores.py +190 -0
  50. streamwright_console-0.3.0.dist-info/METADATA +109 -0
  51. streamwright_console-0.3.0.dist-info/RECORD +55 -0
  52. streamwright_console-0.3.0.dist-info/WHEEL +5 -0
  53. streamwright_console-0.3.0.dist-info/entry_points.txt +5 -0
  54. streamwright_console-0.3.0.dist-info/licenses/LICENSE +201 -0
  55. streamwright_console-0.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env python
2
+ # /*************************************************************************
3
+ # * Copyright 2026 Karthick Jaganathan
4
+ # *
5
+ # * Licensed under the Apache License, Version 2.0 (the "License");
6
+ # * you may not use this file except in compliance with the License.
7
+ # * You may obtain a copy of the License at
8
+ # *
9
+ # * https://www.apache.org/licenses/LICENSE-2.0
10
+ # *
11
+ # * Unless required by applicable law or agreed to in writing, software
12
+ # * distributed under the License is distributed on an "AS IS" BASIS,
13
+ # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # * See the License for the specific language governing permissions and
15
+ # * limitations under the License.
16
+ # **************************************************************************/
17
+ """Table sw_console_users: the people who sign in to the console with a name and password (`streamwright console
18
+ users`)."""
19
+
20
+ from sqlalchemy import Column, PrimaryKeyConstraint, String, Table
21
+ from streamwright.core.jobs.state.tables.base import KEY_LEN, TIMESTAMP_TYPE
22
+
23
+ from streamwright.console.db.tables.base import metadata
24
+
25
+ __all__ = ["sw_console_users"]
26
+
27
+ sw_console_users = Table(
28
+ "sw_console_users",
29
+ metadata,
30
+ Column("user_id", String(KEY_LEN), nullable=False,
31
+ comment="What the person signs in with, and what console.yaml's principals and ack_principals name."),
32
+ Column("name", String(KEY_LEN), nullable=False, comment="The person's name: the console shows it, and records it "
33
+ "with what the person acknowledges."),
34
+ Column("password_hash", String(KEY_LEN), nullable=False,
35
+ comment="The password's scrypt hash, with its salt and cost (never the password)."),
36
+ Column("created_at", TIMESTAMP_TYPE, nullable=False, comment="When the user was added (the database's clock)."),
37
+ Column("updated_at", TIMESTAMP_TYPE, nullable=False,
38
+ comment="When the password last changed: a session signed in before a password change ends."),
39
+ PrimaryKeyConstraint("user_id", name="pk_sw_console_users"),
40
+ comment="Console users: the people who sign in to `streamwright console` with a name and password "
41
+ "(`streamwright console users`).",
42
+ )
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env python
2
+ # /*************************************************************************
3
+ # * Copyright 2026 Karthick Jaganathan
4
+ # *
5
+ # * Licensed under the Apache License, Version 2.0 (the "License");
6
+ # * you may not use this file except in compliance with the License.
7
+ # * You may obtain a copy of the License at
8
+ # *
9
+ # * https://www.apache.org/licenses/LICENSE-2.0
10
+ # *
11
+ # * Unless required by applicable law or agreed to in writing, software
12
+ # * distributed under the License is distributed on an "AS IS" BASIS,
13
+ # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # * See the License for the specific language governing permissions and
15
+ # * limitations under the License.
16
+ # **************************************************************************/
17
+ """
18
+ The console's store: its own tables (streamwright.console.db.tables) in the database console.yaml's auth.login.users
19
+ names (SQLite, PostgreSQL or MySQL; an admin database of their own, say), and the console users kept there. A user is
20
+ an id (what principals and ack_principals name), a name (shown, and recorded with what they acknowledge) and a
21
+ password's scrypt hash (streamwright.console.auth.passwords). The tables are a family of their own (CONSOLE_TABLES):
22
+ a client's state database holds none of them, and the console's database no job table.
23
+ """
24
+
25
+ import re
26
+ from collections.abc import Sequence
27
+ from typing import Any
28
+
29
+ from streamwright.core.jobs.state.sql import SqlBase
30
+
31
+ from streamwright.console.db.migrations import CONSOLE_TABLES
32
+
33
+ __all__ = ["USER_ID", "ConsoleStore"]
34
+
35
+ USER_ID = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._@-]{0,63}$") # what a console user signs in with
36
+ _COLUMNS = ("user_id", "name", "password_hash", "created_at", "updated_at")
37
+
38
+
39
+ class ConsoleStore(SqlBase):
40
+ """The console's tables in a database (open a state store, then `as_family(ConsoleStore)`): its users."""
41
+
42
+ FAMILY = CONSOLE_TABLES
43
+
44
+ def _user_row(self, row: Sequence[Any]) -> dict[str, Any]:
45
+ found = dict(zip(_COLUMNS, row, strict=True))
46
+ for column in ("created_at", "updated_at"):
47
+ found[column] = self._dialect.read_timestamp(found[column])
48
+ return found
49
+
50
+ def get_user(self, user_id: str) -> dict[str, Any] | None:
51
+ """The user (id, name, password hash, when added and last changed), or None."""
52
+ row = self._run(lambda conn: self._x(conn, "SELECT %s FROM {sw_console_users} WHERE user_id = ?" % ", ".join(
53
+ _COLUMNS), (user_id,)).fetchone())
54
+ return None if row is None else self._user_row(row)
55
+
56
+ def list_users(self) -> list[dict[str, Any]]:
57
+ """Every user by id: id, name, when added and last changed (no password hash)."""
58
+ rows = self._run(lambda conn: self._x(conn, "SELECT %s FROM {sw_console_users} ORDER BY user_id" % ", ".join(
59
+ _COLUMNS)).fetchall())
60
+ return [{key: value for key, value in self._user_row(row).items() if key != "password_hash"} for row in rows]
61
+
62
+ def _exists(self, conn: Any, user_id: str) -> bool:
63
+ return self._x(conn, "SELECT 1 FROM {sw_console_users} WHERE user_id = ?", (user_id,)).fetchone() is not None
64
+
65
+ def add_user(self, user_id: str, name: str, password_hash: str) -> bool:
66
+ """Adds a user; False when the id is taken (nothing changes)."""
67
+ def work(conn):
68
+ if self._exists(conn, user_id):
69
+ return False
70
+ self._x(conn, "INSERT INTO {sw_console_users} (user_id, name, password_hash, created_at, updated_at) "
71
+ "VALUES (?, ?, ?, {now}, {now})", (user_id, name, password_hash))
72
+ return True
73
+
74
+ return self._run(work)
75
+
76
+ def set_password(self, user_id: str, password_hash: str) -> bool:
77
+ """Sets a user's password hash; False when there is no such user."""
78
+ def work(conn):
79
+ if not self._exists(conn, user_id):
80
+ return False
81
+ self._x(conn, "UPDATE {sw_console_users} SET password_hash = ?, updated_at = {now} WHERE user_id = ?",
82
+ (password_hash, user_id))
83
+ return True
84
+
85
+ return self._run(work)
86
+
87
+ def remove_user(self, user_id: str) -> bool:
88
+ """Removes a user; False when there is no such user."""
89
+ def work(conn):
90
+ if not self._exists(conn, user_id):
91
+ return False
92
+ self._x(conn, "DELETE FROM {sw_console_users} WHERE user_id = ?", (user_id,))
93
+ return True
94
+
95
+ return self._run(work)
@@ -0,0 +1,99 @@
1
+ # console guide
2
+
3
+ ## console.yaml
4
+ `streamwright console CONSOLE_YAML` (`pip install streamwright-console`) serves a page and API over the state
5
+ databases of many clients, read-only but for acknowledgements: pick a client, see each job and scope's health (`ok`, `running`, `failed`, `held`,
6
+ `rejected`: rows the vendor rejected in a completed batch), its latest batch and last 24 hours, a batch's timeline and
7
+ rows not applied (never row values; a vendor's error message may quote the value it rejected), what needs a person (with
8
+ the `streamwright state` command that fixes it), leases and serve runs. A long-running process like serve, without
9
+ workers. Each client lists its stores (serve.yaml's `state` block) and who may pick it; its credentials come from
10
+ lookups when it is picked (`defaults` apply to every client; `{{ client.id }}` is filled in).
11
+
12
+ ```yaml
13
+ # console.yaml
14
+ kind: console # what the file is (required)
15
+ bind: 127.0.0.1:8090 # a non-loopback address needs `auth` (serve's api_keys / jwt)
16
+ auth: # as serve.yaml's: API keys (digests only) and/or a JWT issuer
17
+ api_keys: [{id: ops, sha256_env: SW_CONSOLE_OPS_SHA256}]
18
+ jwt: {issuer: https://idp.example.com, audience: sw-console, jwks_url: https://idp.example.com/jwks}
19
+ login: # the login page: console users and/or single sign-on
20
+ users: {url: "sqlite:///console-users.db"} # the console's own database (`streamwright console migrate`)
21
+ sso: {label: Okta, issuer: https://example.okta.com/oauth2/default, client_id: 0oa1b2c3d4,
22
+ client_secret_env: SW_CONSOLE_SSO_SECRET}
23
+ session_secret_env: SW_CONSOLE_SESSION_SECRET # signs sessions (32+ characters); session_ttl: 8h
24
+ links: {logs: "https://logs.example.com/search?q={request_id}"} # a batch's logs ({request_id}, {job_id})
25
+ cache: {clients: 20, ttl: 10m} # clients kept open; their looked-up secrets live as long
26
+ defaults:
27
+ lookups: {db: {type: aws_secretsmanager, secret_id: "sw/clients/{{ client.id }}/state", region: us-east-1}}
28
+ secrets: {password: {lookup: {from: db, field: password}}}
29
+ include: [clients/*.yaml] # files holding only `clients:`
30
+ clients:
31
+ acme: # its URL segment: /v1/clients/acme
32
+ name: Acme Corp
33
+ principals: [ops, acme-team, alice] # an api_keys id grants that key only; others: a console user, an SSO
34
+ # email, a JWT sub, or a group (SSO's or a JWT's `groups`)
35
+ ack_principals: [alice] # who of them may acknowledge from the page (default: nobody)
36
+ log_principals: [ops, alice] # who of them may read its runs' log files (default: all of them)
37
+ stores:
38
+ main: {state: {url: "postgresql://console_ro:{{ secrets.password }}@acme-db/sw?schema=sw"},
39
+ logs: {dir: /mnt/sw-logs/acme}} # its runs' --log-dir, as this host sees it (a shared mount, say)
40
+ ```
41
+
42
+ `kind: console` says what the file is; an included file holds only `clients:`, and `kind: console` if you like
43
+ (then it validates on its own too). `streamwright validate console.yaml` checks it and its included files (no lookup
44
+ runs, no store opens).
45
+
46
+ ## Users, clients and stores
47
+ - Without `auth` (only on a loopback `bind`, the default) there is no login and no `principals`: the local user sees
48
+ every client, and may acknowledge (recorded as the console's OS user and host). With `auth`, every client needs
49
+ `principals`.
50
+ - `auth.login` adds a login page: console users (`users`: the console's own database, an admin database say, holding
51
+ only its tables sw_console_users and sw_console_migrations: `streamwright console migrate --url URL` creates them,
52
+ `streamwright console users add|list|password|remove --url URL` looks after the users, URL being a user that may
53
+ change them; CONSOLE_YAML in place of --url uses `users`' database; scrypt hashes) and/or single sign-on (`sso`:
54
+ OpenID Connect, code flow with PKCE; register `https://CONSOLE/login/callback` at the provider). A session is a token
55
+ the console signs (`session_secret_env`), kept in the browser tab for `session_ttl` (8h); a new password or a removed
56
+ user ends it within a minute. After 5 failed sign-ins a name waits a minute.
57
+ - A store's `logs.dir` is the folder its runs write their own log files to (`--log-dir`), as this host sees it
58
+ (relative to the file declaring the client): a run's page gets a Log tab, Runs a Log column (each run's `log` in
59
+ `job-runs`), a batch page its lines; `GET .../job-runs/RUN_ID/log` reads a page of one, `/log/download` the file.
60
+ `log_principals` (a subset of `principals`) narrows who may read them: logs may hold row values.
61
+ - `ack_principals` (a subset of `principals`) may acknowledge from the page: the console writes sw_job_acks alone,
62
+ recording who (`Alice Smith (user:alice)`, `Alice Smith (alice@corp.com)`, `key:ops`). Not for DuckDB stores.
63
+ - A store's `state` is serve.yaml's block, not a job's `runtime.state`: `url` (`sqlite:///PATH`, a relative PATH
64
+ starting at the file that declares the client; `postgresql://...`), or `connection` with `schema`.
65
+ - The page and its API come from one origin, so console.yaml takes no `cors` (serve.yaml's `cors` is for pages on
66
+ other origins calling serve).
67
+
68
+ ## Credentials and unreachable stores
69
+ - A secret without a `lookup` comes from `STREAMWRIGHT_SECRET_<NAME>`; `command` and `function` lookups need
70
+ `allow_lookup_exec: true`; `database` lookups are refused. Nothing is looked up by `streamwright validate`.
71
+ - A store that cannot be read is tried again once with its secrets looked up again (at most every 30 s), then shown
72
+ by code only (`unreachable`, `secrets-missing`, `secrets-failed`; a store that failed to open is retried after
73
+ 30 s). PostgreSQL URLs get `connect_timeout=5` unless they set one. Reads take no write lock (SQLite); DuckDB files
74
+ open read-only.
75
+
76
+ ## Routes
77
+ - Signing in: `POST /v1/login` `{user, password}`, `GET /login/sso` (to the provider, back at `/login/callback`),
78
+ `POST /v1/login/exchange` `{code}`; `GET /v1/me` (who, what is recorded, the clients they may acknowledge in).
79
+ Acknowledging: `POST /v1/clients/C/acks` `{store, job, target, note}` or `{store, job, all: true, note}`, `DELETE
80
+ /v1/clients/C/acks/TARGET?store=&job=`, `DELETE /v1/clients/C/acks?store=&job=&all=1` (403 not in ack_principals,
81
+ 409 nothing to acknowledge, 501 DuckDB).
82
+ - A client the caller may not pick is 404. Routes: `GET /v1/clients`, `/v1/clients/C/overview|leases`,
83
+ `/v1/clients/C/attention?kind=&acked=&filter=&since=&until=&limit=&offset=` (what needs a person, or `acked=yes`
84
+ what a person acknowledged with `state ack`, a page with each kind's `counts`),
85
+ `/v1/clients/C/job-summaries?job=&health=&filter=&since=&until=&sort=&order=&limit=&offset=` (each job once),
86
+ `/v1/clients/C/jobs?job=&health=&q=&filter=&store=&since=&until=&sort=&order=&limit=&offset=` (its scopes: a page,
87
+ newest batch first, with `total` and each health's `counts`),
88
+ `/v1/clients/C/runs?job=&filter=&status=&since=&until=&sort=&order=&limit=&offset=`,
89
+ `/v1/clients/C/jobs/JOB/batches?store=&scope=&status=&limit=`, `/v1/clients/C/batches/JOB_ID?store=&job=`,
90
+ `/openapi.json`, `/healthz`, `/readyz`. `since`/`until`: an ISO date (`until` takes in that day) or time, UTC. A
91
+ read-only database user is enough; to acknowledge from the page, also INSERT, UPDATE, DELETE on sw_job_acks.
92
+ - Lists take `filter=FIELD:OP:VALUE`, repeatable (at most 10, all must hold, case aside): FIELD job, scope or store
93
+ (jobs); job or store (job-summaries); job, scope, store or error (attention); job, run, store or error (job-runs);
94
+ job, run, caller, store or error (runs); job, token, holder or store (leases); OP contains, not_contains, equals,
95
+ not_equals or starts_with. The UI's Filter panel sends them on Apply.
96
+ - Pages: Overview (cards; Needs attention and Acknowledged tabs), Jobs (each job once), a job (Summary, Scopes, Runs
97
+ tabs), a batch, Runs (every job's runs), a run, Serve requests, Leases. An acknowledgement (`streamwright state ack`
98
+ or the page's Acknowledge…, sw_job_acks) changes no health: it moves an item to Acknowledged while its problem is the
99
+ same.