Make main the lean product a site receives
main was 16 days and 259 commits behind the line the product is actually built on, at contract 0.30.0 against 0.35.0, with no per-PC credential code at all. It was neither current nor curated - just stale. This brings it forward and, at the same time, makes it mean something: main is what a receiving site installs, and nothing else. WHAT IT CARRIES. Twelve plugins - backups, computers, endpoints, guides, knowledgebase, machines, network, notifications, printers, slides, tools, warranty - plus applications, which is manifest-less core and always ships. The only manifest dependency inside that set is endpoints on computers, and both are in it, so the closure is self-contained. WHAT IT DOES NOT. employees, geenforce, measuringtools, printedparts and usb stay on the site line. So do the Windows installer tree, the VM rehearsal helpers, the agent tooling config, one site's data loader, the internal audit and findings records, and the planner spreadsheet. 1,135 tracked files against 1,438. A REMOVAL THAT BREAKS THE APP IS NOT A REMOVAL, and two nearly shipped: deploy/site-profile-universal.json still named all seventeen plugins. It is the file docs/DEPLOY.md tells a site to provision from, so a fresh install would have failed at `flask plugin apply-profile` with PluginError - the first thing a receiving site does, broken by the branch meant to serve them. It now names the twelve that exist, and its comment says the two must agree. agent/ was never refreshed. Whoever populated this branch copied shopdb/, plugins/, frontend/ and tests/ from the site line and left the agent tree at its September state: 22 C# and PowerShell sources missing, including AgentCredentials, EnrollmentService, AgentHttpFactory and the fleet-alert client, plus one file the site line had deleted still present. The old tree is internally consistent, so it compiles, and nothing in CI builds it - every gate was green over a server that speaks enrollment and per-PC credentials to a bundled agent source that cannot. Resynced whole. DECISIONS THIS ENCODES, rather than defers: - The plugin-authoring lab builds printedparts, whose manifest depends on employees, so it could not stay. The lab remains on the site line and main ships no build-along tutorial. That is a real loss for an adopting developer and is recorded here rather than discovered later. - Recognition, Training and Recertification notifications are no longer seeded. Each splits one notification into a card per employee and renders a photo, which needs a plugin this branch does not bundle. Seeding them would offer an author a type that cannot resolve anybody. A site that installs employees gets them from that plugin's own seed. - Windows/IIS is documented as the legacy path throughout, and the README leads with Docker, because that is what a receiving site gets. The API description is regenerated for THIS branch - 347 paths and 483 operations, down from 415 and 573 - so the published contract describes what is here rather than what the site line serves. docs/CONFIG.md lost the two measuring-tool label keys the code no longer declares, which two lanes had decided opposite ways. Suite: 3124 passed, 6 skipped. Naming and style gates pass. The docs gates run rather than skip, and every index line count is derived from the file it names.
This commit is contained in:
@@ -32,6 +32,7 @@ from shopdb.core.models import (
|
||||
Asset,
|
||||
AssetType,
|
||||
AssetStatus,
|
||||
BusinessUnit,
|
||||
Vendor,
|
||||
Model,
|
||||
Communication,
|
||||
@@ -70,11 +71,11 @@ from shopdb.utils.pagination import get_pagination_params, paginate_query
|
||||
|
||||
# Authorization decorators for gating plugin write routes
|
||||
from shopdb.utils.authz import (require_permission, require_any_permission,
|
||||
require_role, caller_holds)
|
||||
require_role, caller_holds, caller_is_role)
|
||||
|
||||
# Service-token authorization for unattended plugin endpoints (collector,
|
||||
# GE-Enforce fetch, ...): checks a scoped managed token without exposing token
|
||||
# internals.
|
||||
# Service-token authorization for unattended plugin endpoints (the collector
|
||||
# ingest API, a plugin's own machine-to-machine fetch route, ...): checks a
|
||||
# scoped managed token without exposing token internals.
|
||||
from shopdb.utils.apitoken_auth import (
|
||||
service_token_authorized, authorized_service_token,
|
||||
mint_service_token, list_service_tokens, revoke_service_tokens,
|
||||
@@ -99,6 +100,82 @@ def collector_authorized(pluginname: str):
|
||||
from shopdb.core.api.collector import _check_collector_auth, _plugin_api_key
|
||||
return _check_collector_auth(_plugin_api_key(pluginname), pluginname)
|
||||
|
||||
|
||||
def _enabled_plugins():
|
||||
from flask import current_app
|
||||
|
||||
manager = current_app.extensions.get('plugin_manager')
|
||||
if not manager:
|
||||
return []
|
||||
return [plugin for name, plugin in manager.get_all_plugins().items()
|
||||
if manager.registry.is_enabled(name)]
|
||||
|
||||
|
||||
def resolve_agent_credential(secret: str) -> Optional[int]:
|
||||
"""Asset id for an active per-PC agent credential, or None.
|
||||
|
||||
Asks every enabled plugin's resolve_agent_credential hook and returns the
|
||||
first non-None answer.
|
||||
"""
|
||||
if not secret:
|
||||
return None
|
||||
for plugin in _enabled_plugins():
|
||||
assetid = plugin.resolve_agent_credential(secret)
|
||||
if assetid is not None:
|
||||
return assetid
|
||||
return None
|
||||
|
||||
|
||||
def agent_shared_key_refused(hostname: str) -> bool:
|
||||
"""True when any enabled plugin refuses the shared collector key for hostname."""
|
||||
return any(plugin.agent_shared_key_refused(hostname)
|
||||
for plugin in _enabled_plugins())
|
||||
|
||||
|
||||
def collector_ingest(pluginname: str):
|
||||
"""Run the generic collector ingest for a plugin on the current request.
|
||||
|
||||
Lets a plugin serve the same ingest under its own prefix (the endpoints
|
||||
agent posts to /api/endpoints/collect) without importing core collector
|
||||
internals. Auth, validation, audit and response are exactly those of
|
||||
POST /api/collector/<pluginname>.
|
||||
"""
|
||||
from shopdb.core.api.collector import generic_collect
|
||||
return generic_collect(pluginname)
|
||||
|
||||
|
||||
def application_package_location():
|
||||
"""Where application installers live, and the URL prefix that serves them.
|
||||
|
||||
Returns (directory, urlprefix). A plugin that registers an installable
|
||||
payload (the endpoint agent bundle, for example) must put the file exactly
|
||||
where the applications API expects it and build installpath the same way,
|
||||
or update_app cannot resolve the download. Reconstructing either by hand
|
||||
lets the two drift silently, so both come from one place.
|
||||
|
||||
Imported lazily for the same reason as collector_authorized above:
|
||||
shopdb.core.api imports back into shopdb.api, so a module-level import
|
||||
would be circular at load time.
|
||||
"""
|
||||
from shopdb.core.api.applications import (
|
||||
_apppackage_dir, APP_PACKAGE_URL_PREFIX)
|
||||
return _apppackage_dir(), APP_PACKAGE_URL_PREFIX
|
||||
|
||||
|
||||
def script_body_location():
|
||||
"""Where script bodies live, and the URL prefix that serves them.
|
||||
|
||||
Returns (directory, urlprefix). Same reasoning as
|
||||
application_package_location: a plugin that seeds a script into the
|
||||
library must write the body where the download route reads it from, and
|
||||
reconstructing that path by hand lets the two drift apart silently.
|
||||
|
||||
Imported lazily to avoid the shopdb.core.api -> shopdb.api cycle.
|
||||
"""
|
||||
from shopdb.core.api.scripts import _script_dir, SCRIPT_URL_PREFIX
|
||||
return _script_dir(), SCRIPT_URL_PREFIX
|
||||
|
||||
|
||||
# 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.
|
||||
@@ -110,6 +187,11 @@ from shopdb.utils.uploads import send_upload, harden_upload_response
|
||||
# nothing. See shopdb/utils/clientip.py.
|
||||
from shopdb.utils.clientip import client_ip, strip_port
|
||||
|
||||
# Network-position allowlists for the unauthenticated kiosk routes. On the
|
||||
# contract surface because two plugins need the identical gate and a
|
||||
# copy-pasted CIDR parser is exactly where a fail-open creeps in.
|
||||
from shopdb.utils.ipallowlist import ip_in_cidrs, request_ip_allowlisted
|
||||
|
||||
# Strict date parsing. On the contract surface because every plugin that stores
|
||||
# a date needs it and the two that rolled their own both swallowed the error.
|
||||
from shopdb.utils.queryargs import QueryArgError, intarg, intargs
|
||||
@@ -145,13 +227,17 @@ from shopdb.core.services.csvimport import (
|
||||
RowWarning,
|
||||
)
|
||||
|
||||
# Legacy employee directory lookup (read-only) used by notifications
|
||||
# External HR employee directory lookup (read-only) used by core global search
|
||||
# and core audit-log name resolution.
|
||||
from shopdb.utils.employee_db import employee_connection
|
||||
# The two resolvers built on top of it. On the contract surface because a plugin
|
||||
# that shows a person - a notification aimed at somebody, a card on a wall
|
||||
# screen - must render the same name and the same photo core does, and a plugin
|
||||
# may not reach into shopdb.core.
|
||||
from shopdb.core.api.employees import (
|
||||
resolve_employee_display_name, resolve_employee_photo_url)
|
||||
from shopdb.utils.mailer import send_email, send_alert, send_webhook
|
||||
|
||||
# CMMC USB check-in/out database (read-write) used by the usb plugin
|
||||
from shopdb.utils.cmmc_usb_db import cmmc_usb_connection
|
||||
|
||||
|
||||
# Reversible bulk-import journal. A plugin that drives a bulk import (a site
|
||||
# asset adoption, an integration sync) records the primitive changes it makes so
|
||||
@@ -341,6 +427,7 @@ __all__ = [
|
||||
'Asset',
|
||||
'AssetType',
|
||||
'AssetStatus',
|
||||
'BusinessUnit',
|
||||
'Vendor',
|
||||
'Model',
|
||||
'Communication',
|
||||
@@ -380,6 +467,7 @@ __all__ = [
|
||||
'require_permission',
|
||||
'require_any_permission',
|
||||
'caller_holds',
|
||||
'caller_is_role',
|
||||
'require_role',
|
||||
'service_token_authorized',
|
||||
'authorized_service_token',
|
||||
@@ -387,23 +475,31 @@ __all__ = [
|
||||
'list_service_tokens',
|
||||
'revoke_service_tokens',
|
||||
'collector_authorized',
|
||||
'resolve_agent_credential',
|
||||
'agent_shared_key_refused',
|
||||
'collector_ingest',
|
||||
'application_package_location',
|
||||
'script_body_location',
|
||||
'SupportTeam',
|
||||
# Serving uploads
|
||||
'send_upload',
|
||||
'harden_upload_response',
|
||||
'client_ip',
|
||||
'strip_port',
|
||||
'ip_in_cidrs',
|
||||
'request_ip_allowlisted',
|
||||
# Import-mode helpers
|
||||
'apply_import_timestamps',
|
||||
'import_mode_active',
|
||||
'parse_import_datetime',
|
||||
# Legacy employee directory
|
||||
# External HR employee directory (read-only) and the two resolvers a
|
||||
# plugin uses to show a person the same way core does.
|
||||
'employee_connection',
|
||||
'resolve_employee_display_name',
|
||||
'resolve_employee_photo_url',
|
||||
'send_email',
|
||||
'send_alert',
|
||||
'send_webhook',
|
||||
'User',
|
||||
'Role',
|
||||
# CMMC USB check-in/out database
|
||||
'cmmc_usb_connection',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user