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.
- streamwright/console/__init__.py +29 -0
- streamwright/console/api/__init__.py +20 -0
- streamwright/console/api/acks.py +162 -0
- streamwright/console/api/app.py +401 -0
- streamwright/console/api/login.py +139 -0
- streamwright/console/api/logs.py +113 -0
- streamwright/console/api/openapi.py +205 -0
- streamwright/console/api/query.py +113 -0
- streamwright/console/auth/__init__.py +21 -0
- streamwright/console/auth/access.py +99 -0
- streamwright/console/auth/authenticator.py +45 -0
- streamwright/console/auth/passwords.py +83 -0
- streamwright/console/auth/sessions.py +65 -0
- streamwright/console/auth/sso.py +186 -0
- streamwright/console/auth/throttle.py +60 -0
- streamwright/console/auth/users.py +111 -0
- streamwright/console/cli/__init__.py +21 -0
- streamwright/console/cli/admin.py +267 -0
- streamwright/console/cli/main.py +110 -0
- streamwright/console/config/__init__.py +18 -0
- streamwright/console/config/check.py +48 -0
- streamwright/console/config/console.py +289 -0
- streamwright/console/config/login.py +141 -0
- streamwright/console/config/service.py +32 -0
- streamwright/console/db/__init__.py +18 -0
- streamwright/console/db/migrations/0001_console_users.py +40 -0
- streamwright/console/db/migrations/__init__.py +29 -0
- streamwright/console/db/tables/__init__.py +34 -0
- streamwright/console/db/tables/base.py +24 -0
- streamwright/console/db/tables/migrations.py +27 -0
- streamwright/console/db/tables/users.py +42 -0
- streamwright/console/db/users.py +95 -0
- streamwright/console/guide.md +99 -0
- streamwright/console/static/app.js +2014 -0
- streamwright/console/static/favicon.png +0 -0
- streamwright/console/static/favicon.svg +1 -0
- streamwright/console/static/index.html +66 -0
- streamwright/console/static/streamwright-logo-dark.svg +1 -0
- streamwright/console/static/style.css +410 -0
- streamwright/console/views/__init__.py +21 -0
- streamwright/console/views/attention.py +145 -0
- streamwright/console/views/filters.py +62 -0
- streamwright/console/views/job_page.py +97 -0
- streamwright/console/views/job_runs.py +222 -0
- streamwright/console/views/job_summaries.py +123 -0
- streamwright/console/views/overview.py +156 -0
- streamwright/console/views/reads.py +354 -0
- streamwright/console/views/run_log.py +77 -0
- streamwright/console/views/stores.py +190 -0
- streamwright_console-0.3.0.dist-info/METADATA +109 -0
- streamwright_console-0.3.0.dist-info/RECORD +55 -0
- streamwright_console-0.3.0.dist-info/WHEEL +5 -0
- streamwright_console-0.3.0.dist-info/entry_points.txt +5 -0
- streamwright_console-0.3.0.dist-info/licenses/LICENSE +201 -0
- streamwright_console-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
"""The `streamwright console` command (main: serve CONSOLE_YAML, and dispatch), and `migrate` and `users` (admin)."""
|
|
18
|
+
|
|
19
|
+
from streamwright.console.cli.main import register_console
|
|
20
|
+
|
|
21
|
+
__all__ = ["register_console"]
|
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
`streamwright console migrate | users`: the console's own tables (streamwright.console.db.tables) in its database,
|
|
19
|
+
named by --url as `streamwright state` names a state database (or read from console.yaml's auth.login.users): create
|
|
20
|
+
or upgrade them, and look after the console users. A password is asked twice on a terminal, else read from the first
|
|
21
|
+
line of stdin; only its scrypt hash is stored.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import argparse
|
|
25
|
+
import getpass
|
|
26
|
+
import json
|
|
27
|
+
import os
|
|
28
|
+
import sys
|
|
29
|
+
|
|
30
|
+
from streamwright.core.cli.help_format import DescriptionFormatter
|
|
31
|
+
from streamwright.core.http_service.config_files import read_yaml
|
|
32
|
+
from streamwright.core.http_service.state import StateSpec
|
|
33
|
+
from streamwright.core.http_service.state_store import open_state
|
|
34
|
+
from streamwright.core.jobs.state.protocol import StateError
|
|
35
|
+
from streamwright.core.jobs.state.url import StateDatabaseMissingError
|
|
36
|
+
|
|
37
|
+
from streamwright.console.auth.passwords import hash_password, password_problem
|
|
38
|
+
from streamwright.console.config.console import CONSOLE_FIELD, ConsoleError
|
|
39
|
+
from streamwright.console.config.login import users_spec
|
|
40
|
+
from streamwright.console.db.users import USER_ID, ConsoleStore
|
|
41
|
+
|
|
42
|
+
__all__ = ["cmd_migrate", "cmd_users"]
|
|
43
|
+
|
|
44
|
+
SUCCESS, FAILURE, INVALID_INPUT = 0, 1, 2
|
|
45
|
+
_MAX_NAME = 100
|
|
46
|
+
_URL = ("the console's database, as a user that may change its tables: sqlite:///PATH (relative to where you run the "
|
|
47
|
+
"command), postgresql://...?schema=NAME or mysql://...")
|
|
48
|
+
_WHERE = ("instead of --url: the database console.yaml's auth.login.users names (its secrets from "
|
|
49
|
+
"STREAMWRIGHT_SECRET_<NAME>), when the console's own user may change its tables (a SQLite file, say)")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _where(parser):
|
|
53
|
+
parser.add_argument("--url", metavar="URL", help=_URL)
|
|
54
|
+
parser.add_argument("console_yaml", nargs="?", metavar="CONSOLE_YAML", help=_WHERE)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _parser(what):
|
|
58
|
+
parser = argparse.ArgumentParser(prog="streamwright console %s" % what, formatter_class=DescriptionFormatter)
|
|
59
|
+
if what == "migrate":
|
|
60
|
+
parser.description = ("Create the console's tables (sw_console_users, sw_console_migrations), or upgrade them, "
|
|
61
|
+
"in its database: idempotent, and concurrent runs wait for one another.\n\n"
|
|
62
|
+
" streamwright console migrate --url \"postgresql://admin@admin-db/admin?schema=console\"\n"
|
|
63
|
+
" streamwright console migrate --url sqlite:///console-users.db")
|
|
64
|
+
_where(parser)
|
|
65
|
+
return parser
|
|
66
|
+
parser.description = ("The console users: the people who sign in on its login page with a name and password. A "
|
|
67
|
+
"user's id is what console.yaml's principals and ack_principals list. A new password, or "
|
|
68
|
+
"removing a user, ends their sessions within a minute.\n\n"
|
|
69
|
+
" streamwright console users add alice --name \"Alice Smith\" --url sqlite:///console-users.db\n"
|
|
70
|
+
" streamwright console users list --url sqlite:///console-users.db")
|
|
71
|
+
actions = parser.add_subparsers(dest="action", required=True, metavar="ACTION")
|
|
72
|
+
listing = actions.add_parser("list", help="the users: id, name, when added and last changed")
|
|
73
|
+
_where(listing)
|
|
74
|
+
listing.add_argument("--json", action="store_true", help="one JSON object per user instead of a table")
|
|
75
|
+
adding = actions.add_parser("add", help="add a user: asks their password")
|
|
76
|
+
adding.add_argument("user", metavar="USER", help="what they sign in with: 1-64 letters, digits and . _ @ -")
|
|
77
|
+
adding.add_argument("--name", required=True, metavar="NAME", help="their name, as the console shows it")
|
|
78
|
+
_where(adding)
|
|
79
|
+
for action, text in (("password", "set a user's password: their sessions end"),
|
|
80
|
+
("remove", "remove a user: their sessions end")):
|
|
81
|
+
found = actions.add_parser(action, help=text)
|
|
82
|
+
found.add_argument("user", metavar="USER", help="the user")
|
|
83
|
+
_where(found)
|
|
84
|
+
return parser
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _say(what, text):
|
|
88
|
+
sys.stderr.write("streamwright console %s: %s\n" % (what, text))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _spec(args, what):
|
|
92
|
+
"""The StateSpec of the console's database (--url, else CONSOLE_YAML's auth.login.users), or None after saying
|
|
93
|
+
why."""
|
|
94
|
+
if args.url:
|
|
95
|
+
if args.url.startswith("duckdb:"):
|
|
96
|
+
_say(what, "--url: a DuckDB file has one writer at a time (a job's): keep the users in SQLite or a "
|
|
97
|
+
"database server")
|
|
98
|
+
return None
|
|
99
|
+
return StateSpec(url=args.url)
|
|
100
|
+
if not args.console_yaml:
|
|
101
|
+
_say(what, "give --url (the console's database), or CONSOLE_YAML (its auth.login.users names it)")
|
|
102
|
+
return None
|
|
103
|
+
try:
|
|
104
|
+
data = read_yaml(args.console_yaml, CONSOLE_FIELD, "", error=ConsoleError)
|
|
105
|
+
except ConsoleError as exc:
|
|
106
|
+
_say(what, "; ".join(exc.problems))
|
|
107
|
+
return None
|
|
108
|
+
block = ((data.get("auth") or {}).get("login") or {}).get("users")
|
|
109
|
+
if not block:
|
|
110
|
+
_say(what, "%s has no auth.login.users: name the console's database there, or give --url" % args.console_yaml)
|
|
111
|
+
return None
|
|
112
|
+
problems = []
|
|
113
|
+
spec, _ = users_spec(block, os.path.dirname(os.path.abspath(args.console_yaml)), os.environ, problems, problems)
|
|
114
|
+
if problems:
|
|
115
|
+
_say(what, "; ".join(problems))
|
|
116
|
+
return None
|
|
117
|
+
return spec
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _store(args, what, *, create=False):
|
|
121
|
+
"""The console's tables in its database (`create`: a SQLite file may be created), or None after saying why."""
|
|
122
|
+
spec = _spec(args, what)
|
|
123
|
+
if spec is None:
|
|
124
|
+
return None
|
|
125
|
+
try:
|
|
126
|
+
return open_state(spec, existing=not create).as_family(ConsoleStore)
|
|
127
|
+
except StateDatabaseMissingError:
|
|
128
|
+
_say(what, "the console's database is not there yet: `streamwright console migrate` creates it and its "
|
|
129
|
+
"tables")
|
|
130
|
+
except (ValueError, ImportError, OSError) as exc:
|
|
131
|
+
_say(what, str(exc))
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _parse(parser, argv):
|
|
136
|
+
"""
|
|
137
|
+
parser.parse_args(argv), also on Pythons whose argparse leaves a CONSOLE_YAML given after an option over
|
|
138
|
+
(3.12.0 to 3.12.6, and 3.13.0).
|
|
139
|
+
"""
|
|
140
|
+
args, extra = parser.parse_known_args(argv)
|
|
141
|
+
if len(extra) == 1 and args.console_yaml is None and not extra[0].startswith("-"):
|
|
142
|
+
args.console_yaml = extra.pop()
|
|
143
|
+
if extra:
|
|
144
|
+
parser.error("unrecognized arguments: %s" % " ".join(extra))
|
|
145
|
+
return args
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def cmd_migrate(argv) -> int:
|
|
149
|
+
"""`console migrate [CONSOLE_YAML] [--url URL]`: create or upgrade the console's tables."""
|
|
150
|
+
store = _store(_parse(_parser("migrate"), argv), "migrate", create=True)
|
|
151
|
+
if store is None:
|
|
152
|
+
return INVALID_INPUT
|
|
153
|
+
try:
|
|
154
|
+
applied = store.migrations().apply()
|
|
155
|
+
except Exception as exc: # the database's own error (permissions, connection, ...)
|
|
156
|
+
_say("migrate", str(exc).split("\n", 1)[0])
|
|
157
|
+
return FAILURE
|
|
158
|
+
if not applied:
|
|
159
|
+
sys.stdout.write("The console tables in %s are up to date: no migrations to apply.\n" % store.target)
|
|
160
|
+
for record in applied:
|
|
161
|
+
sys.stdout.write("Applied migration %s to %s (store id %s)\n" % (record["name"], store.target,
|
|
162
|
+
record["store_id"]))
|
|
163
|
+
return SUCCESS
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _password(user):
|
|
167
|
+
"""The new password (asked twice on a terminal, else stdin's first line), or None after saying why not."""
|
|
168
|
+
if sys.stdin.isatty():
|
|
169
|
+
password = getpass.getpass("Password for %s: " % user)
|
|
170
|
+
if getpass.getpass("Again: ") != password:
|
|
171
|
+
_say("users", "the passwords differ")
|
|
172
|
+
return None
|
|
173
|
+
else:
|
|
174
|
+
password = sys.stdin.readline().rstrip("\r\n")
|
|
175
|
+
problem = password_problem(password)
|
|
176
|
+
if problem:
|
|
177
|
+
_say("users", problem)
|
|
178
|
+
return None
|
|
179
|
+
return password
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _change(store, work):
|
|
183
|
+
"""(True, work()) once the console's tables are current; (False, None) after saying why not."""
|
|
184
|
+
try:
|
|
185
|
+
store.prepare(migrate=False)
|
|
186
|
+
return True, work()
|
|
187
|
+
except StateError as exc: # its migrations are pending
|
|
188
|
+
_say("users", str(exc))
|
|
189
|
+
except Exception as exc: # the driver's error: its type varies with the database
|
|
190
|
+
_say("users", "cannot use the console tables in %s: %s" % (store.target, str(exc).split("\n", 1)[0]))
|
|
191
|
+
return False, None
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _list(store, args):
|
|
195
|
+
done, users = _change(store, store.list_users)
|
|
196
|
+
if not done:
|
|
197
|
+
return FAILURE
|
|
198
|
+
if args.json:
|
|
199
|
+
sys.stdout.writelines(json.dumps(user, default=str, sort_keys=True) + "\n" for user in users)
|
|
200
|
+
elif not users:
|
|
201
|
+
sys.stdout.write("no console users in %s\n" % store.target)
|
|
202
|
+
else:
|
|
203
|
+
rows = [["USER", "NAME", "ADDED", "CHANGED"]] + [[user["user_id"], user["name"], str(user["created_at"]),
|
|
204
|
+
str(user["updated_at"])] for user in users]
|
|
205
|
+
widths = [max(len(row[column]) for row in rows) for column in range(4)]
|
|
206
|
+
sys.stdout.writelines(" ".join(cell.ljust(width) for cell, width in zip(row, widths, strict=True)).rstrip()
|
|
207
|
+
+ "\n" for row in rows)
|
|
208
|
+
return SUCCESS
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _add(store, args):
|
|
212
|
+
name = " ".join(args.name.split())
|
|
213
|
+
if not name or len(name) > _MAX_NAME:
|
|
214
|
+
_say("users", "--name: 1-%d characters" % _MAX_NAME)
|
|
215
|
+
return INVALID_INPUT
|
|
216
|
+
done, found = _change(store, lambda: store.get_user(args.user))
|
|
217
|
+
if not done or found is not None:
|
|
218
|
+
if done:
|
|
219
|
+
_say("users", "%s is a user already (`console users password` sets their password)" % args.user)
|
|
220
|
+
return FAILURE
|
|
221
|
+
password = _password(args.user)
|
|
222
|
+
if password is None:
|
|
223
|
+
return INVALID_INPUT
|
|
224
|
+
done, added = _change(store, lambda: store.add_user(args.user, name, hash_password(password)))
|
|
225
|
+
if not done or not added:
|
|
226
|
+
return FAILURE
|
|
227
|
+
sys.stdout.write("added %s (%s): they sign in on the console's login page\n" % (args.user, name))
|
|
228
|
+
return SUCCESS
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def _set_password(store, args):
|
|
232
|
+
done, found = _change(store, lambda: store.get_user(args.user))
|
|
233
|
+
if not done or found is None:
|
|
234
|
+
if done:
|
|
235
|
+
_say("users", "no user %s in %s" % (args.user, store.target))
|
|
236
|
+
return FAILURE
|
|
237
|
+
password = _password(args.user)
|
|
238
|
+
if password is None:
|
|
239
|
+
return INVALID_INPUT
|
|
240
|
+
done, changed = _change(store, lambda: store.set_password(args.user, hash_password(password)))
|
|
241
|
+
if not done or not changed:
|
|
242
|
+
return FAILURE
|
|
243
|
+
sys.stdout.write("password of %s changed: their sessions end within a minute\n" % args.user)
|
|
244
|
+
return SUCCESS
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _remove(store, args):
|
|
248
|
+
done, removed = _change(store, lambda: store.remove_user(args.user))
|
|
249
|
+
if not done:
|
|
250
|
+
return FAILURE
|
|
251
|
+
if not removed:
|
|
252
|
+
_say("users", "no user %s in %s" % (args.user, store.target))
|
|
253
|
+
return FAILURE
|
|
254
|
+
sys.stdout.write("removed %s: their sessions end within a minute\n" % args.user)
|
|
255
|
+
return SUCCESS
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def cmd_users(argv) -> int:
|
|
259
|
+
"""`console users list | add | password | remove`."""
|
|
260
|
+
args = _parse(_parser("users"), argv)
|
|
261
|
+
if args.action != "list" and not USER_ID.match(args.user):
|
|
262
|
+
_say("users", "user %r: 1-64 letters, digits and . _ @ -, starting with a letter or digit" % args.user)
|
|
263
|
+
return INVALID_INPUT
|
|
264
|
+
store = _store(args, "users")
|
|
265
|
+
if store is None:
|
|
266
|
+
return INVALID_INPUT
|
|
267
|
+
return {"list": _list, "add": _add, "password": _set_password, "remove": _remove}[args.action](store, args)
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
`streamwright console`, plugged into the streamwright CLI (the `streamwright.commands` entry point):
|
|
19
|
+
|
|
20
|
+
streamwright console CONSOLE_YAML [logging options] serve the console (its page and API) for the clients
|
|
21
|
+
console.yaml lists: a long-running process, like serve
|
|
22
|
+
streamwright console migrate --url URL create or upgrade the console's tables in its database
|
|
23
|
+
(or CONSOLE_YAML for its auth.login.users)
|
|
24
|
+
streamwright console users ACTION ... its users: list, add, password, remove (admin.py)
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import argparse
|
|
28
|
+
import importlib
|
|
29
|
+
import logging
|
|
30
|
+
|
|
31
|
+
from streamwright.core.cli.help_format import DescriptionFormatter
|
|
32
|
+
from streamwright.core.cli.log_options import add_log_options, log_setup
|
|
33
|
+
from streamwright.core.runtime.logs.sql import sql_values
|
|
34
|
+
|
|
35
|
+
from streamwright.console.cli import admin
|
|
36
|
+
from streamwright.console.config.console import ConsoleError, load_console
|
|
37
|
+
|
|
38
|
+
__all__ = ["register_console"]
|
|
39
|
+
|
|
40
|
+
LOG = logging.getLogger("streamwright.console")
|
|
41
|
+
SUCCESS, INVALID_INPUT = 0, 2
|
|
42
|
+
_EXTRA = "the console's web server is not installed: pip install streamwright-console"
|
|
43
|
+
_USAGE = """streamwright console CONSOLE_YAML [logging options]
|
|
44
|
+
streamwright console migrate [--url URL] [CONSOLE_YAML]
|
|
45
|
+
streamwright console users {list,add,password,remove} ... (streamwright console users -h)"""
|
|
46
|
+
_HELP = """\
|
|
47
|
+
Serve a console over the state databases of the clients CONSOLE_YAML lists: pick a client, see each job's health and
|
|
48
|
+
latest batch, a batch's story (no row values), what needs a person, the leases and the serve runs. It changes no batch:
|
|
49
|
+
the people a client's ack_principals list may acknowledge its problems from the page. A client's credentials are
|
|
50
|
+
looked up (its lookups: Secrets Manager, a command, ...) when it is picked, and kept for cache.ttl. People sign in on
|
|
51
|
+
the login page (console users, single sign-on: auth.login), scripts with an API key or a JWT; each client lists who
|
|
52
|
+
may pick it. A non-loopback `bind` needs an `auth` section. Console users live in the console's own database
|
|
53
|
+
(auth.login.users): `migrate` creates its tables there, `users` looks after them; both take --url, as `state` does.
|
|
54
|
+
|
|
55
|
+
streamwright validate console.yaml
|
|
56
|
+
streamwright console migrate --url sqlite:///console-users.db
|
|
57
|
+
streamwright console users add alice --name "Alice Smith" --url sqlite:///console-users.db
|
|
58
|
+
streamwright console console.yaml # http://127.0.0.1:8090"""
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def register_console(subparsers):
|
|
62
|
+
parser = subparsers.add_parser("console", help="a console over many clients' job state (it changes no batch)",
|
|
63
|
+
description=_HELP, usage=_USAGE, formatter_class=DescriptionFormatter)
|
|
64
|
+
parser.add_argument("what", metavar="CONSOLE_YAML", help="the clients, their stores and who may see them (or "
|
|
65
|
+
"migrate, users)")
|
|
66
|
+
parser.add_argument("rest", nargs=argparse.REMAINDER, help=argparse.SUPPRESS)
|
|
67
|
+
parser.set_defaults(command_handler=cmd_console)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _serve_parser():
|
|
71
|
+
parser = argparse.ArgumentParser(prog="streamwright console", usage="streamwright console CONSOLE_YAML [logging "
|
|
72
|
+
"options]", description=_HELP,
|
|
73
|
+
formatter_class=DescriptionFormatter)
|
|
74
|
+
parser.add_argument("console_yaml", metavar="CONSOLE_YAML", help="the clients, their stores and who may see them")
|
|
75
|
+
add_log_options(parser.add_argument_group("logging options"))
|
|
76
|
+
return parser
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _console(args):
|
|
80
|
+
try:
|
|
81
|
+
console = load_console(args.console_yaml)
|
|
82
|
+
except ConsoleError as exc:
|
|
83
|
+
for problem in exc.problems:
|
|
84
|
+
LOG.error("%s", problem, extra={"event": "console_invalid"})
|
|
85
|
+
return INVALID_INPUT
|
|
86
|
+
try:
|
|
87
|
+
uvicorn = importlib.import_module("uvicorn")
|
|
88
|
+
app = importlib.import_module("streamwright.console.api.app").create_app(console)
|
|
89
|
+
except ImportError:
|
|
90
|
+
LOG.error("%s", _EXTRA)
|
|
91
|
+
return INVALID_INPUT
|
|
92
|
+
LOG.info("console for %d client(s) on http://%s:%d", len(console.clients), console.host, console.port)
|
|
93
|
+
with sql_values(False): # no row value in a log line: SQL lines keep their placeholders
|
|
94
|
+
uvicorn.run(app, host=console.host, port=console.port, log_config=None, access_log=False,
|
|
95
|
+
server_header=False, date_header=False)
|
|
96
|
+
return SUCCESS
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def cmd_console(args):
|
|
100
|
+
"""Serves CONSOLE_YAML, or runs `migrate` or `users` with the arguments after it."""
|
|
101
|
+
if args.what in ("migrate", "users"):
|
|
102
|
+
return (admin.cmd_migrate if args.what == "migrate" else admin.cmd_users)(args.rest)
|
|
103
|
+
served = _serve_parser().parse_args([args.what, *args.rest])
|
|
104
|
+
setup = log_setup(served)
|
|
105
|
+
if setup is None:
|
|
106
|
+
return INVALID_INPUT
|
|
107
|
+
try:
|
|
108
|
+
return _console(served)
|
|
109
|
+
finally:
|
|
110
|
+
setup.close()
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
"""console.yaml: its clients and stores (console), its login page (login), its checks for `streamwright validate`
|
|
18
|
+
(check) and its ServiceConfig for core's validate and the MCP tools (service)."""
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
`streamwright validate` of a console.yaml: its structure, its clients (stores, lookups, secrets, principals) and its
|
|
19
|
+
included files, without the environment: no lookup runs and no store opens.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import yaml
|
|
23
|
+
from streamwright.core.http_service.config_files import unread_includes
|
|
24
|
+
|
|
25
|
+
from streamwright.console.config.console import ConsoleError, load_console
|
|
26
|
+
|
|
27
|
+
__all__ = ["validate_console", "validate_console_text"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def validate_console(path, text=None):
|
|
31
|
+
"""The problems of console.yaml at `path` (`text`: its content, when read): [message]."""
|
|
32
|
+
try:
|
|
33
|
+
load_console(path, environ={}, static=True, text=text)
|
|
34
|
+
except ConsoleError as exc:
|
|
35
|
+
return list(exc.problems)
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def validate_console_text(text):
|
|
40
|
+
"""
|
|
41
|
+
The problems of console.yaml's `text`, and what it names but no text can read (it has no folder: the files it
|
|
42
|
+
includes): ([message], [message]).
|
|
43
|
+
"""
|
|
44
|
+
try:
|
|
45
|
+
load_console(None, environ={}, static=True, text=text)
|
|
46
|
+
except ConsoleError as exc:
|
|
47
|
+
return list(exc.problems), []
|
|
48
|
+
return [], unread_includes(yaml.safe_load(text))
|