Bring the wilm branch into main: endpoints plugin, agent, policies, CSV import
Ports the corporate-GitHub wilm branch onto main, keeping the two branches
separate. Thirteen upstream commits arrive with their authorship intact; the
review fixes and the portability work below are on top.
What arrives:
endpoints plugin - a ShopDB agent reporting endpoint state, telemetry,
services and interfaces, with a command channel the agent
long-polls. Ingest stays on the generic collector route
(ADR-006); the agent key is a UI-managed single-scope
token whose revocation is an instant kill switch.
computers policies - Configuration and Business Policies (RMM-style), scope
trees validated at write time, actions checked against
the endpoints command allowlist. Feature-gated: every
route 404s while the setting is off, so enabling it can
never half-expose the surface.
asset CSV import - templates, a collector script carrying the site path, and
a validate-then-commit import. A plugin can own a virtual
column plus a post-write row hook, which is how a PC's
machine number becomes a controls link without a
hand-built relationships sheet.
agent/ - the Windows agent and its installer.
Contract 0.21.0 -> 0.24.0, additive throughout: register_import_hook (0.22),
mint/list/revoke_service_token (0.23), collector_authorized (0.24). The stability
table had no rows for any of them and now does.
MySQL 5.6 portability. The branch stored three policy columns as sa.JSON, the
only JSON columns in the product, and 5.6 has no JSON type: the migration failed
with a bare syntax error near the word JSON. They are TEXT now, through a
JSONText type decorator, so all seventeen call sites still read and write dicts.
The convention elsewhere is already TEXT (guides.blocksjson,
geenforce.manifestjson).
Review fixes carried on top:
- six policy GETs were jwt_required(optional=True), which authenticates a
caller without checking anything; they require computers.view now, and six
redundant jwt_required decorators are gone
- the agent installer took a default BaseUrl and CollectorKey, so a mistyped
run silently pointed an endpoint at the wrong instance; both are mandatory
and a non-https BaseUrl throws unless -AllowInsecureHttp is passed
- a committing CSV import wrote no audit row
Documentation: the 34 new routes are described in docs/api-inventory.json, which
is hand-maintained on purpose, and the generated spec now covers 331 paths and
477 operations across 22 surfaces. DEVELOPMENT-SETUP's 1071 troubleshooting row
said "use MySQL 8 for dev" and now gives the actual fix, including the trap that
5.6 downgrades ROW_FORMAT=DYNAMIC to Compact with a warning instead of an error.
Full suite 2123 passed, vitest 260 passed, all seventeen plugin chains migrate
clean on MySQL 5.6 and the naming, docs, parity and read-surface gates are green.
This commit is contained in:
@@ -75,8 +75,28 @@ from shopdb.utils.authz import require_permission, require_any_permission, requi
|
||||
# internals.
|
||||
from shopdb.utils.apitoken_auth import (
|
||||
service_token_authorized, authorized_service_token,
|
||||
mint_service_token, list_service_tokens, revoke_service_tokens,
|
||||
)
|
||||
|
||||
# Collector-token authorization for agent-facing plugin routes that live outside
|
||||
# the generic collector blueprint (e.g. the endpoints command claim/result
|
||||
# callbacks). Reuses the same per-plugin collector key + managed-token check the
|
||||
# ingest route uses, so a plugin never imports core collector internals.
|
||||
def collector_authorized(pluginname: str):
|
||||
"""Authorize an agent-facing route on a plugin's collector token.
|
||||
|
||||
Returns None when the caller presented a valid collector credential for
|
||||
this plugin (the per-plugin env key or a collector.ingest[.<plugin>]-scoped
|
||||
managed token), else the error_response to return. Lets a plugin gate an
|
||||
agent callback on the same key and kill switch as its ingest route without
|
||||
reaching into core collector internals.
|
||||
|
||||
Imported lazily: shopdb.core.api imports back into shopdb.api (send_upload),
|
||||
so a module-level import here would be a circular import at load time.
|
||||
"""
|
||||
from shopdb.core.api.collector import _check_collector_auth, _plugin_api_key
|
||||
return _check_collector_auth(_plugin_api_key(pluginname), pluginname)
|
||||
|
||||
# Serving an uploaded file safely. A plugin that serves user-supplied bytes must
|
||||
# not have to remember the headers that keep an SVG or an HTML file from running
|
||||
# as script in this origin - see shopdb/utils/uploads.py.
|
||||
@@ -95,6 +115,15 @@ from shopdb.core.services.dualpath import (
|
||||
dualpath_single_machine_enabled,
|
||||
)
|
||||
|
||||
# Bulk-import extension point: a plugin registers a virtual column on an
|
||||
# importable CSV table plus a post-write row hook, so a relationship a site
|
||||
# would otherwise hand-build (a PC's machine number -> a controls link) can be
|
||||
# written in the row itself. Core never learns what the column means.
|
||||
from shopdb.core.services.csvimport import (
|
||||
register_import_hook,
|
||||
RowWarning,
|
||||
)
|
||||
|
||||
# Legacy employee directory lookup (read-only) used by notifications
|
||||
from shopdb.utils.employee_db import employee_connection
|
||||
from shopdb.utils.mailer import send_email, send_alert, send_webhook
|
||||
@@ -261,6 +290,9 @@ __all__ = [
|
||||
'resolve_asset_position',
|
||||
'resolve_dualpath_pairs',
|
||||
'dualpath_single_machine_enabled',
|
||||
# Bulk-import extension point
|
||||
'register_import_hook',
|
||||
'RowWarning',
|
||||
# Infrastructure
|
||||
'db',
|
||||
'cache',
|
||||
@@ -302,6 +334,10 @@ __all__ = [
|
||||
'require_role',
|
||||
'service_token_authorized',
|
||||
'authorized_service_token',
|
||||
'mint_service_token',
|
||||
'list_service_tokens',
|
||||
'revoke_service_tokens',
|
||||
'collector_authorized',
|
||||
'SupportTeam',
|
||||
# Serving uploads
|
||||
'send_upload',
|
||||
|
||||
Reference in New Issue
Block a user