Build GE-Enforce manifest-store plugin (P0/P1): model, importer, parity gate
All checks were successful
CI / backend (push) Successful in 1m36s
CI / naming (push) Successful in 2s
CI / frontend (push) Successful in 8s

First execution phases of docs/proposals/ge-enforce-plugin.md. The GE-Enforce
manifest becomes shopdb data.

P0 scaffold: new geenforce plugin (api_prefix /api/geenforce, default_enabled
false, core_version >=0.7.0). Registered in PLUGIN_TABLE_OWNERS (ADR-008); its
0001 baseline really creates the tables.

P1a model: one wide manifestentries table + entrytype discriminator (not STI,
not JSON blob), manifestscopes (UNIQUE scopename+phase), the three multi-value
filter child tables, inusechecks + processes, immutable manifestpublishedversions
(frozen rendered JSON), manifestpayloads (inline, capped), pctypealiases
(mirror of the engine lib's alias graph). regvalue stored as its raw JSON
literal so DWord typing survives.

P1c importer + exporter: parse common + gea-shopfloor-* + preinstall.json into
draft rows and rebuild the JSON verbatim from rows in sortorder.

P1d parity harness (GATE A): filters.py mirrors the engine's four filter
functions + alias graph; parity.py proves import+export is behaviorally lossless
(field-identical + same-entries-fire across 18 machine-profile fixtures) WITHOUT
byte-diffing. Verified PASS against all 11 real reference manifests (64 entries)
and a synthetic site-neutral fixture covering every type/filter (the CI gate).

First slice (gea-shopfloor-cmm shape): service layer (import/publish/rollback/
export-to-share), CLI (parity, import-share, publish, export-share), and the
client endpoint GET /api/geenforce/manifest serving the current published
snapshot (never the draft) with ETag/304. Split permissions
geenforce.manage/publish/fetch. Tests prove import->publish->serve, draft edits
never change served bytes, publish+rollback, and auth (401 unauth/wrong-scope).

Contract 0.11.0: added service_token_authorized(scope) to shopdb.api so plugin
service endpoints authorize a scoped managed token without importing core token
internals. Documented in PLUGIN-HOOKS.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-07-12 16:53:18 -04:00
parent cf2f9c308e
commit d85b33bd68
24 changed files with 1830 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
"""Alembic environment for the GE-Enforce plugin migration chain.
Delegates to the shared runner in shopdb.plugins.alembic_template, which filters
the metadata to this plugin's tables and drives Alembic against the per-plugin
version table alembic_version_geenforce (ADR-008). This plugin is NEW: its 0001
baseline really CREATES its tables, because the core chain never built them.
"""
import os
os.environ['PLUGIN_NAME'] = 'geenforce'
from shopdb.plugins.alembic_template import run_migrations # noqa: E402
run_migrations()

View File

@@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,198 @@
"""geenforce plugin baseline (real create).
This plugin was built after the ADR-008 ownership cutover, so this baseline
actually CREATES the plugin's tables (the core chain never knew about them). It
runs from `flask plugin install geenforce` / `flask plugin upgrade-all` after
`flask db upgrade` builds the core schema. All foreign keys are intra-plugin, so
tables are created parent-first. computertypeid / measuringtooltypeid /
publishedby are SOFT references (plain columns, no FK) to optional plugins/core.
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'geenforce0001baseline'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
'manifestscopes',
sa.Column('scopeid', sa.Integer(), nullable=False),
sa.Column('scopename', sa.String(length=64), nullable=False),
sa.Column('phase', sa.String(length=16), nullable=False),
sa.Column('computertypeid', sa.Integer(), nullable=True),
sa.Column('measuringtooltypeid', sa.Integer(), nullable=True),
sa.Column('manifestversion', sa.String(length=16), nullable=False),
sa.Column('description', sa.String(length=255), nullable=True),
sa.Column('topcomment', sa.Text(), nullable=True),
sa.Column('site', sa.String(length=100), nullable=True),
sa.Column('iscommon', sa.Boolean(), nullable=False),
sa.Column('createddate', sa.DateTime(), nullable=False),
sa.Column('modifieddate', sa.DateTime(), nullable=False),
sa.Column('isactive', sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint('scopeid'),
sa.UniqueConstraint('scopename', 'phase', name='uq_scope_name_phase'),
)
op.create_table(
'manifestentries',
sa.Column('entryid', sa.Integer(), nullable=False),
sa.Column('scopeid', sa.Integer(), nullable=False),
sa.Column('sortorder', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('entrytype', sa.String(length=16), nullable=False),
sa.Column('comment', sa.Text(), nullable=True),
sa.Column('installer', sa.String(length=255), nullable=True),
sa.Column('installargs', sa.Text(), nullable=True),
sa.Column('scriptpath', sa.String(length=255), nullable=True),
sa.Column('scriptargs', sa.String(length=255), nullable=True),
sa.Column('sourcepath', sa.String(length=255), nullable=True),
sa.Column('destination', sa.String(length=255), nullable=True),
sa.Column('regpath', sa.String(length=255), nullable=True),
sa.Column('regname', sa.String(length=128), nullable=True),
sa.Column('regvalue', sa.Text(), nullable=True),
sa.Column('regtype', sa.String(length=16), nullable=True),
sa.Column('payloadsource', sa.String(length=8), nullable=False),
sa.Column('payloadref', sa.String(length=512), nullable=True),
sa.Column('payloadsha256', sa.String(length=64), nullable=True),
sa.Column('detectionmethod', sa.String(length=16), nullable=True),
sa.Column('detectionpath', sa.String(length=255), nullable=True),
sa.Column('detectionname', sa.String(length=128), nullable=True),
sa.Column('detectionvalue', sa.String(length=255), nullable=True),
sa.Column('detectionpattern', sa.String(length=255), nullable=True),
sa.Column('cmmversion', sa.String(length=16), nullable=True),
sa.Column('logfile', sa.String(length=255), nullable=True),
sa.Column('waittimeoutsec', sa.Integer(), nullable=True),
sa.Column('applymode', sa.String(length=16), nullable=True),
sa.Column('updatewindow', sa.String(length=11), nullable=True),
sa.Column('preenrollment', sa.Boolean(), nullable=False),
sa.Column('killafterdetection', sa.Boolean(), nullable=False),
sa.Column('pctypesstrict', sa.Boolean(), nullable=False),
sa.Column('createddate', sa.DateTime(), nullable=False),
sa.Column('modifieddate', sa.DateTime(), nullable=False),
sa.Column('isactive', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['scopeid'], ['manifestscopes.scopeid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('entryid'),
sa.UniqueConstraint('scopeid', 'name', name='uq_entry_scope_name'),
)
op.create_index('idx_entry_scope', 'manifestentries', ['scopeid'])
op.create_index('idx_entry_scope_order', 'manifestentries',
['scopeid', 'sortorder'])
op.create_table(
'manifestentrypctypes',
sa.Column('entrypctypeid', sa.Integer(), nullable=False),
sa.Column('entryid', sa.Integer(), nullable=False),
sa.Column('sortorder', sa.Integer(), nullable=False),
sa.Column('pctypevalue', sa.String(length=64), nullable=False),
sa.ForeignKeyConstraint(['entryid'], ['manifestentries.entryid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('entrypctypeid'),
)
op.create_index('idx_pctype_entry', 'manifestentrypctypes', ['entryid'])
op.create_table(
'manifestentryhostnames',
sa.Column('entryhostnameid', sa.Integer(), nullable=False),
sa.Column('entryid', sa.Integer(), nullable=False),
sa.Column('sortorder', sa.Integer(), nullable=False),
sa.Column('hostnamepattern', sa.String(length=64), nullable=False),
sa.ForeignKeyConstraint(['entryid'], ['manifestentries.entryid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('entryhostnameid'),
)
op.create_index('idx_hostname_entry', 'manifestentryhostnames', ['entryid'])
op.create_table(
'manifestentrymachinenumbers',
sa.Column('entrymachinenumberid', sa.Integer(), nullable=False),
sa.Column('entryid', sa.Integer(), nullable=False),
sa.Column('sortorder', sa.Integer(), nullable=False),
sa.Column('machinenumber', sa.String(length=16), nullable=False),
sa.ForeignKeyConstraint(['entryid'], ['manifestentries.entryid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('entrymachinenumberid'),
)
op.create_index('idx_machinenumber_entry', 'manifestentrymachinenumbers',
['entryid'])
op.create_table(
'manifestinusechecks',
sa.Column('inusecheckid', sa.Integer(), nullable=False),
sa.Column('entryid', sa.Integer(), nullable=False),
sa.Column('behavior', sa.String(length=20), nullable=False),
sa.ForeignKeyConstraint(['entryid'], ['manifestentries.entryid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('inusecheckid'),
sa.UniqueConstraint('entryid'),
)
op.create_table(
'manifestinusecheckprocesses',
sa.Column('inusecheckprocessid', sa.Integer(), nullable=False),
sa.Column('inusecheckid', sa.Integer(), nullable=False),
sa.Column('sortorder', sa.Integer(), nullable=False),
sa.Column('processname', sa.String(length=64), nullable=False),
sa.Column('exepath', sa.String(length=255), nullable=True),
sa.Column('gracefulclosetimeoutsec', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['inusecheckid'],
['manifestinusechecks.inusecheckid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('inusecheckprocessid'),
)
op.create_index('idx_process_check', 'manifestinusecheckprocesses',
['inusecheckid'])
op.create_table(
'manifestpublishedversions',
sa.Column('publishedversionid', sa.Integer(), nullable=False),
sa.Column('scopeid', sa.Integer(), nullable=False),
sa.Column('versionnumber', sa.Integer(), nullable=False),
sa.Column('manifestjson', sa.Text(length=16777215), nullable=False),
sa.Column('publishedat', sa.DateTime(), nullable=False),
sa.Column('publishedby', sa.Integer(), nullable=True),
sa.Column('iscurrent', sa.Boolean(), nullable=False),
sa.Column('notes', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['scopeid'], ['manifestscopes.scopeid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('publishedversionid'),
sa.UniqueConstraint('scopeid', 'versionnumber',
name='uq_published_scope_version'),
)
op.create_index('idx_published_scope', 'manifestpublishedversions',
['scopeid'])
op.create_table(
'manifestpayloads',
sa.Column('payloadid', sa.Integer(), nullable=False),
sa.Column('entryid', sa.Integer(), nullable=False),
sa.Column('filename', sa.String(length=255), nullable=False),
sa.Column('contenttype', sa.String(length=128), nullable=True),
sa.Column('payloadbytes', sa.LargeBinary(length=16777215), nullable=False),
sa.Column('payloadsha256', sa.String(length=64), nullable=False),
sa.Column('uploadedat', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['entryid'], ['manifestentries.entryid'],
ondelete='CASCADE'),
sa.PrimaryKeyConstraint('payloadid'),
)
op.create_index('idx_payload_entry', 'manifestpayloads', ['entryid'])
op.create_table(
'pctypealiases',
sa.Column('aliasid', sa.Integer(), nullable=False),
sa.Column('aliasgroup', sa.Integer(), nullable=False),
sa.Column('aliasname', sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('aliasid'),
sa.UniqueConstraint('aliasgroup', 'aliasname',
name='uq_alias_group_name'),
)
op.create_index('idx_alias_group', 'pctypealiases', ['aliasgroup'])
def downgrade():
op.drop_table('pctypealiases')
op.drop_table('manifestpayloads')
op.drop_table('manifestpublishedversions')
op.drop_table('manifestinusecheckprocesses')
op.drop_table('manifestinusechecks')
op.drop_table('manifestentrymachinenumbers')
op.drop_table('manifestentryhostnames')
op.drop_table('manifestentrypctypes')
op.drop_table('manifestentries')
op.drop_table('manifestscopes')