compose-plugins 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/PKG-INFO +16 -7
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/README.md +15 -6
- compose_plugins-0.2.0/compose_plugins/__init__.py +26 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/conformance.py +10 -2
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/consent.py +87 -9
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/errors.py +64 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/fixtures/__init__.py +11 -4
- compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula/EULA.txt +14 -0
- compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula/manifest.json +52 -0
- compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v1/hello_world/plugin.py +54 -0
- compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v2/__init__.py +0 -0
- compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v2/hello_world/__init__.py +1 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/lifecycle.py +373 -92
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/manifest.py +225 -19
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/package.py +160 -1
- compose_plugins-0.2.0/compose_plugins/schema/__init__.py +8 -0
- compose_plugins-0.2.0/compose_plugins/schema/manifest-0.2.schema.json +226 -0
- compose_plugins-0.2.0/compose_plugins/store.py +307 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/version.py +1 -1
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/web.py +103 -13
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/PKG-INFO +16 -7
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/SOURCES.txt +11 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/pyproject.toml +3 -1
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_qa_wave1_rulings.py +6 -4
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_schema_file.py +24 -4
- compose_plugins-0.2.0/tests/test_v02_install_log.py +782 -0
- compose_plugins-0.2.0/tests/test_v02_license_eula.py +616 -0
- compose_plugins-0.2.0/tests/test_v02_record_decline.py +338 -0
- compose_plugins-0.2.0/tests/test_v02_schema_by_contract.py +98 -0
- compose_plugins-0.2.0/tests/test_v02_uninstall_confirm.py +218 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_version.py +6 -5
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_wave2_web.py +13 -1
- compose_plugins-0.1.0/compose_plugins/__init__.py +0 -15
- compose_plugins-0.1.0/compose_plugins/schema/__init__.py +0 -6
- compose_plugins-0.1.0/compose_plugins/store.py +0 -66
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/LICENSE +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/_child.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/_probe.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/config.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/derive.py +0 -0
- {compose_plugins-0.1.0/compose_plugins/fixtures/hello_world_v1 → compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula}/__init__.py +0 -0
- {compose_plugins-0.1.0/compose_plugins/fixtures/hello_world_v1 → compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula}/hello_world/__init__.py +0 -0
- {compose_plugins-0.1.0/compose_plugins/fixtures/hello_world_v1 → compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_eula}/hello_world/plugin.py +0 -0
- {compose_plugins-0.1.0/compose_plugins/fixtures/hello_world_v2 → compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v1}/__init__.py +0 -0
- {compose_plugins-0.1.0/compose_plugins/fixtures/hello_world_v2 → compose_plugins-0.2.0/compose_plugins/fixtures/hello_world_v1}/hello_world/__init__.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/fixtures/hello_world_v1/manifest.json +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/fixtures/hello_world_v2/hello_world/plugin.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/fixtures/hello_world_v2/manifest.json +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/host.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/probe_client.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/runner.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins/schema/manifest-0.1.schema.json +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/dependency_links.txt +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/entry_points.txt +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/requires.txt +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/compose_plugins.egg-info/top_level.txt +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/setup.cfg +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_consent.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_consent_record_r9.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_host_name_r10.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_manifest.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_package.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_r21_permissions.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_r24_conformance_hooks.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_validator_readings.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_wave2_build.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_wave2_conformance.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_wave2_lifecycle.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_wave2_r18.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_wave2_r19.py +0 -0
- {compose_plugins-0.1.0 → compose_plugins-0.2.0}/tests/test_wave2_runner.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: compose-plugins
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: The shared plug-in contract library (manifest, consent, version rule) for ComposeIO and Gnomon hosts
|
|
5
5
|
License: MIT
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -12,9 +12,18 @@ Dynamic: license-file
|
|
|
12
12
|
# compose-plugins
|
|
13
13
|
|
|
14
14
|
The shared plug-in contract library for ComposeIO's ComposeServer and for
|
|
15
|
-
Gnomon, implementing the Shared Plug-in Contract v0.
|
|
16
|
-
`[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24). It is the layer
|
|
17
|
-
INSTALLED and CONSENTED to, plus the shared manager that drives it.
|
|
15
|
+
Gnomon, implementing the Shared Plug-in Contract v0.2 (ComposeIO spec 95,
|
|
16
|
+
`[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24 plus its v0.2 delta). It is the layer
|
|
17
|
+
a plug-in is INSTALLED and CONSENTED to, plus the shared manager that drives it.
|
|
18
|
+
|
|
19
|
+
Contract 0.2 is an additive MINOR over 0.1: optional manifest fields `license`
|
|
20
|
+
(an SPDX expression, informational) and `eula` (a package-relative UTF-8 text
|
|
21
|
+
file, shown verbatim at consent, its sha256 stored in the consent record);
|
|
22
|
+
`PluginManager.record_decline(prompt, *, decided_by)`; the append-only install
|
|
23
|
+
event log `installs.jsonl` and `PluginManager.install_log_findings()`; and a
|
|
24
|
+
confirm step in front of uninstall in the web manager. The one non-additive
|
|
25
|
+
change: the web manager's `POST .../uninstall` no longer uninstalls, it shows
|
|
26
|
+
the confirm screen.
|
|
18
27
|
|
|
19
28
|
One runtime dependency: `composebus==0.1.2` (the runtime `ComposePlugin` and
|
|
20
29
|
its `MessageType` names). No ComposeIO distribution is required, so a host
|
|
@@ -24,7 +33,7 @@ that is not ComposeIO can use the library on its own.
|
|
|
24
33
|
|
|
25
34
|
| module | what |
|
|
26
35
|
|---|---|
|
|
27
|
-
| `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON
|
|
36
|
+
| `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON Schemas, one per contract (`schema/manifest-0.1.schema.json`, unchanged from 0.1.0, and `schema/manifest-0.2.schema.json`; `schema_for(manifest)` picks by the manifest's `contract`), generated from the validator's own patterns |
|
|
28
37
|
| `compose_plugins.package` | reading `manifest.json` from a directory or a wheel WITHOUT executing anything, and the `manifest_sha256` rule (exact bytes, no canonicalization) |
|
|
29
38
|
| `compose_plugins.version` | the contract version rule: a host accepts the same MAJOR and a MINOR at or below its own, and refuses anything newer, naming both versions |
|
|
30
39
|
| `compose_plugins.consent` | consent content rendered from the manifest alone, the granted set, the widening rule, and the append-only consent-record store |
|
|
@@ -33,10 +42,10 @@ that is not ComposeIO can use the library on its own.
|
|
|
33
42
|
| `compose_plugins.config` | config validated against `config_schema` before the plug-in is instantiated; invalid config parks loudly |
|
|
34
43
|
| `compose_plugins.derive` | `compose-plugin build` (writes `config_schema` and `bus` into `manifest.json` from the class) and the enable-time class/manifest drift check |
|
|
35
44
|
| `compose_plugins.runner` | running a plug-in in-process, or in a child process over an inherited `AF_UNIX` socketpair (never a network listener) |
|
|
36
|
-
| `compose_plugins.store` | the install records (the registry)
|
|
45
|
+
| `compose_plugins.store` | the install records (the registry), stored config, and the append-only install event log `InstallLog` with its findings |
|
|
37
46
|
| `compose_plugins.web` | the plain Plugin Manager: server-rendered HTML, a mountable WSGI app that is correct under any URL prefix, with the host's auth hook and CSRF defence |
|
|
38
47
|
| `compose_plugins.conformance` | the conformance script (below) |
|
|
39
|
-
| `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins |
|
|
48
|
+
| `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins, and `hello-world-eula` (contract 0.2, declares a EULA) |
|
|
40
49
|
|
|
41
50
|
```python
|
|
42
51
|
from compose_plugins.package import read_manifest
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
# compose-plugins
|
|
2
2
|
|
|
3
3
|
The shared plug-in contract library for ComposeIO's ComposeServer and for
|
|
4
|
-
Gnomon, implementing the Shared Plug-in Contract v0.
|
|
5
|
-
`[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24). It is the layer
|
|
6
|
-
INSTALLED and CONSENTED to, plus the shared manager that drives it.
|
|
4
|
+
Gnomon, implementing the Shared Plug-in Contract v0.2 (ComposeIO spec 95,
|
|
5
|
+
`[SPEC:CXC-PLUGIN-CONTRACT]`, revision r24 plus its v0.2 delta). It is the layer
|
|
6
|
+
a plug-in is INSTALLED and CONSENTED to, plus the shared manager that drives it.
|
|
7
|
+
|
|
8
|
+
Contract 0.2 is an additive MINOR over 0.1: optional manifest fields `license`
|
|
9
|
+
(an SPDX expression, informational) and `eula` (a package-relative UTF-8 text
|
|
10
|
+
file, shown verbatim at consent, its sha256 stored in the consent record);
|
|
11
|
+
`PluginManager.record_decline(prompt, *, decided_by)`; the append-only install
|
|
12
|
+
event log `installs.jsonl` and `PluginManager.install_log_findings()`; and a
|
|
13
|
+
confirm step in front of uninstall in the web manager. The one non-additive
|
|
14
|
+
change: the web manager's `POST .../uninstall` no longer uninstalls, it shows
|
|
15
|
+
the confirm screen.
|
|
7
16
|
|
|
8
17
|
One runtime dependency: `composebus==0.1.2` (the runtime `ComposePlugin` and
|
|
9
18
|
its `MessageType` names). No ComposeIO distribution is required, so a host
|
|
@@ -13,7 +22,7 @@ that is not ComposeIO can use the library on its own.
|
|
|
13
22
|
|
|
14
23
|
| module | what |
|
|
15
24
|
|---|---|
|
|
16
|
-
| `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON
|
|
25
|
+
| `compose_plugins.manifest` | the v0.1 manifest validator (authoritative) and the shipped JSON Schemas, one per contract (`schema/manifest-0.1.schema.json`, unchanged from 0.1.0, and `schema/manifest-0.2.schema.json`; `schema_for(manifest)` picks by the manifest's `contract`), generated from the validator's own patterns |
|
|
17
26
|
| `compose_plugins.package` | reading `manifest.json` from a directory or a wheel WITHOUT executing anything, and the `manifest_sha256` rule (exact bytes, no canonicalization) |
|
|
18
27
|
| `compose_plugins.version` | the contract version rule: a host accepts the same MAJOR and a MINOR at or below its own, and refuses anything newer, naming both versions |
|
|
19
28
|
| `compose_plugins.consent` | consent content rendered from the manifest alone, the granted set, the widening rule, and the append-only consent-record store |
|
|
@@ -22,10 +31,10 @@ that is not ComposeIO can use the library on its own.
|
|
|
22
31
|
| `compose_plugins.config` | config validated against `config_schema` before the plug-in is instantiated; invalid config parks loudly |
|
|
23
32
|
| `compose_plugins.derive` | `compose-plugin build` (writes `config_schema` and `bus` into `manifest.json` from the class) and the enable-time class/manifest drift check |
|
|
24
33
|
| `compose_plugins.runner` | running a plug-in in-process, or in a child process over an inherited `AF_UNIX` socketpair (never a network listener) |
|
|
25
|
-
| `compose_plugins.store` | the install records (the registry)
|
|
34
|
+
| `compose_plugins.store` | the install records (the registry), stored config, and the append-only install event log `InstallLog` with its findings |
|
|
26
35
|
| `compose_plugins.web` | the plain Plugin Manager: server-rendered HTML, a mountable WSGI app that is correct under any URL prefix, with the host's auth hook and CSRF defence |
|
|
27
36
|
| `compose_plugins.conformance` | the conformance script (below) |
|
|
28
|
-
| `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins |
|
|
37
|
+
| `compose_plugins.fixtures` | the hello-world v1 and v2 conformance plug-ins, and `hello-world-eula` (contract 0.2, declares a EULA) |
|
|
29
38
|
|
|
30
39
|
```python
|
|
31
40
|
from compose_plugins.package import read_manifest
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""compose_plugins — the shared plug-in contract library ([SPEC:CXC-PLUGIN-CONTRACT],
|
|
2
|
+
contract 0.2: spec 95 r24 plus its v0.2 delta, [DELTA:CXC-PLUGIN-CONTRACT-V0-2-DELTA]).
|
|
3
|
+
|
|
4
|
+
The manifest validator and JSON Schema (``manifest``), the no-execution manifest
|
|
5
|
+
and EULA reader and the manifest_sha256 rule (``package``), the version rule
|
|
6
|
+
(``version``), consent content, granted sets, widening and the consent-record
|
|
7
|
+
store (``consent``), the ``Host`` protocol (``host``), the lifecycle operations
|
|
8
|
+
and ``record_decline`` (``lifecycle``), config validation (``config``),
|
|
9
|
+
``compose-plugin build`` and the drift check (``derive``), the in-process and
|
|
10
|
+
subprocess runner (``runner``), the registry, config and install-event-log
|
|
11
|
+
stores (``store``), the plain web Plugin Manager (``web``), and the conformance
|
|
12
|
+
script (``conformance``) with its hello-world fixtures. See README.md.
|
|
13
|
+
|
|
14
|
+
Contract 0.2 adds these exports ([CXC-PC-V02-STORES-COMPAT] manager-signatures).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
__version__ = "0.2.0"
|
|
18
|
+
|
|
19
|
+
from .consent import eula_text_shown # noqa: E402
|
|
20
|
+
from .errors import ( # noqa: E402
|
|
21
|
+
EulaShaMismatch, InstallLogRefused, PromptNotPrepared, PromptStale,
|
|
22
|
+
)
|
|
23
|
+
from .store import InstallLog, InstallLogFinding # noqa: E402
|
|
24
|
+
|
|
25
|
+
__all__ = ["EulaShaMismatch", "InstallLog", "InstallLogFinding", "InstallLogRefused",
|
|
26
|
+
"PromptNotPrepared", "PromptStale", "__version__", "eula_text_shown"]
|
|
@@ -481,10 +481,18 @@ def _refused_at_install(r: Run, t, fixture: str, edit, must: "list[str]") -> Non
|
|
|
481
481
|
_nothing_installed(r, t)
|
|
482
482
|
|
|
483
483
|
|
|
484
|
+
def _next_minor(contract: str) -> str:
|
|
485
|
+
major, minor = contract.split(".")
|
|
486
|
+
return f"{major}.{int(minor) + 1}"
|
|
487
|
+
|
|
488
|
+
|
|
484
489
|
@_fresh
|
|
485
490
|
def nc3(r: Run, t) -> None:
|
|
486
|
-
|
|
487
|
-
|
|
491
|
+
# one MINOR newer than this host (spec 95 r24 wrote "0.2" for a 0.1 host;
|
|
492
|
+
# a 0.2 host accepts "0.2", so the control uses the next MINOR)
|
|
493
|
+
newer = _next_minor(HOST_CONTRACT)
|
|
494
|
+
_refused_at_install(r, t, "NC3", lambda d: d.update(contract=newer),
|
|
495
|
+
[newer, HOST_CONTRACT])
|
|
488
496
|
|
|
489
497
|
|
|
490
498
|
@_fresh
|
|
@@ -18,6 +18,7 @@ their grant strings; that is all it does with them.
|
|
|
18
18
|
"""
|
|
19
19
|
from __future__ import annotations
|
|
20
20
|
|
|
21
|
+
import html
|
|
21
22
|
import json
|
|
22
23
|
import os
|
|
23
24
|
import re
|
|
@@ -197,6 +198,24 @@ class ConsentLine:
|
|
|
197
198
|
return f"{mark}{self.value}"
|
|
198
199
|
|
|
199
200
|
|
|
201
|
+
#: [CXC-PC-V02-EULA-DISPLAY] the EULA block's heading and hash line (0.2)
|
|
202
|
+
EULA_HEADING = "License agreement (EULA) declared by the plug-in"
|
|
203
|
+
EULA_CHANGED = "EULA changed"
|
|
204
|
+
#: [CXC-PC-CONSENT-CONTENT] license-line (0.2)
|
|
205
|
+
LICENSE_SUFFIX = " (declared by the plug-in; not verified)"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@dataclass(frozen=True)
|
|
209
|
+
class ConsentEula:
|
|
210
|
+
"""A declared EULA in the consent content ([CXC-PC-V02-EULA-DISPLAY]):
|
|
211
|
+
``text`` is the file's bytes decoded as UTF-8 with NO change, ``sha256``
|
|
212
|
+
the digest of those exact bytes."""
|
|
213
|
+
|
|
214
|
+
path: str
|
|
215
|
+
text: str
|
|
216
|
+
sha256: str
|
|
217
|
+
|
|
218
|
+
|
|
200
219
|
@dataclass(frozen=True)
|
|
201
220
|
class ConsentContent:
|
|
202
221
|
domain: str
|
|
@@ -211,22 +230,53 @@ class ConsentContent:
|
|
|
211
230
|
widens: bool = False
|
|
212
231
|
#: the dialog title ([CXC-PC-CONSENT-CONTENT] dialog-title, r21)
|
|
213
232
|
title: str = ""
|
|
233
|
+
#: (0.2) the declared EULA, or None ([CXC-PC-V02-EULA-DISPLAY])
|
|
234
|
+
eula: "ConsentEula | None" = None
|
|
235
|
+
#: (0.2) True iff this upgrade's EULA differs from the consented one
|
|
236
|
+
#: ([CXC-PC-V02-EULA-RECONSENT] screen)
|
|
237
|
+
eula_changed: bool = False
|
|
214
238
|
|
|
215
239
|
def text(self) -> str:
|
|
216
|
-
"""The title, then the manifest summary below it, one line each
|
|
217
|
-
|
|
240
|
+
"""The title, then the manifest summary below it, one line each; then,
|
|
241
|
+
when a EULA is declared, its block: the heading, the text exactly as in
|
|
242
|
+
the file, and the hash line ([CXC-PC-V02-EULA-DISPLAY])."""
|
|
243
|
+
out = "\n".join([self.title] + [line.text() for line in self.lines])
|
|
244
|
+
if self.eula is not None:
|
|
245
|
+
changed = f"[ADDED] {EULA_CHANGED}\n" if self.eula_changed else ""
|
|
246
|
+
out += (f"\n{changed}{EULA_HEADING}:\n{self.eula.text}"
|
|
247
|
+
f"\nEULA sha256: {self.eula.sha256}")
|
|
248
|
+
return out
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def eula_text_shown(rendered: str, prompt: Any) -> bool:
|
|
252
|
+
"""[CXC-PC-V02-EULA-HOST-OBLIGATION] conformance-helper: True only if
|
|
253
|
+
``prompt.content.eula.text`` occurs in ``rendered`` as ONE contiguous,
|
|
254
|
+
unaltered substring, after HTML unescaping when ``rendered`` is an HTML
|
|
255
|
+
document. A truncated, summarised or re-flowed text gives False; so does a
|
|
256
|
+
prompt that declares no EULA (there is nothing to show)."""
|
|
257
|
+
eula = getattr(getattr(prompt, "content", None), "eula", None)
|
|
258
|
+
if eula is None or not isinstance(rendered, str):
|
|
259
|
+
return False
|
|
260
|
+
head = rendered.lstrip()[:15].lower()
|
|
261
|
+
if head.startswith("<!doctype html") or head.startswith("<html"):
|
|
262
|
+
rendered = html.unescape(rendered)
|
|
263
|
+
return eula.text in rendered
|
|
218
264
|
|
|
219
265
|
|
|
220
266
|
def render_consent(manifest: Manifest, *, host: str, runs_as: str,
|
|
221
267
|
render_host_section: HostSectionRenderer,
|
|
222
268
|
previous_granted: "Iterable[str] | None" = None,
|
|
223
|
-
previous_runs_as: "str | None" = None
|
|
269
|
+
previous_runs_as: "str | None" = None,
|
|
270
|
+
eula: "ConsentEula | None" = None,
|
|
271
|
+
eula_changed: bool = False) -> ConsentContent:
|
|
224
272
|
"""Render the consent content from the manifest ALONE.
|
|
225
273
|
|
|
226
274
|
``runs_as`` is the ACTUAL isolation level the host will use; it may not be
|
|
227
275
|
below the manifest's ``isolation_floor``. ``render_host_section`` renders
|
|
228
276
|
THIS host's own section. With ``previous_granted`` (an upgrade), lines whose
|
|
229
|
-
grant is new are marked ``added`` and ``widens`` is computed.
|
|
277
|
+
grant is new are marked ``added`` and ``widens`` is computed. ``eula`` is
|
|
278
|
+
the declared EULA as the package reader read it (0.2); ``eula_changed``
|
|
279
|
+
marks it as changed on a re-consent screen.
|
|
230
280
|
|
|
231
281
|
Makes no network call and imports nothing from the plug-in.
|
|
232
282
|
"""
|
|
@@ -262,6 +312,8 @@ def render_consent(manifest: Manifest, *, host: str, runs_as: str,
|
|
|
262
312
|
out.append(line("code owners", ", ".join(owners)
|
|
263
313
|
+ " (as declared by the package; not a verified publisher identity)"))
|
|
264
314
|
out.append(line("documentation", data["documentation"]))
|
|
315
|
+
if "license" in data: # 0.2 license-line: no line at all when not declared
|
|
316
|
+
out.append(line("license", data["license"] + LICENSE_SUFFIX))
|
|
265
317
|
out.append(line("run form", data["run"]["form"]))
|
|
266
318
|
dropped = prev is not None and level_drops(previous_runs_as, runs_as)
|
|
267
319
|
out.append(ConsentLine("runs as", runs_as if not dropped else
|
|
@@ -303,7 +355,7 @@ def render_consent(manifest: Manifest, *, host: str, runs_as: str,
|
|
|
303
355
|
domain=manifest.domain, version=manifest.version, host=host,
|
|
304
356
|
runs_as=runs_as, lines=tuple(out), granted=tuple(granted), added=added,
|
|
305
357
|
widens=prev is not None and upgrade_widens(prev, granted, previous_runs_as, runs_as),
|
|
306
|
-
title=dialog_title(manifest))
|
|
358
|
+
title=dialog_title(manifest), eula=eula, eula_changed=bool(eula and eula_changed))
|
|
307
359
|
|
|
308
360
|
|
|
309
361
|
# --------------------------------------------------------------------------- #
|
|
@@ -312,6 +364,9 @@ def render_consent(manifest: Manifest, *, host: str, runs_as: str,
|
|
|
312
364
|
DECISIONS = ("granted", "refused")
|
|
313
365
|
RECORD_KEYS = ("domain", "version", "manifest_sha256", "granted", "decided_by",
|
|
314
366
|
"decided_at", "host", "decision")
|
|
367
|
+
#: (0.2) [CXC-PC-CONSENT-RECORD] optional-keys: present only for a manifest that
|
|
368
|
+
#: declares ``eula``, never null
|
|
369
|
+
OPTIONAL_RECORD_KEYS = ("eula_sha256",)
|
|
315
370
|
_SHA_RE = re.compile(r"[0-9a-f]{64}")
|
|
316
371
|
|
|
317
372
|
|
|
@@ -381,9 +436,16 @@ class ConsentRecord:
|
|
|
381
436
|
decided_at: str
|
|
382
437
|
host: str
|
|
383
438
|
decision: str
|
|
439
|
+
#: (0.2) the sha256 of the EULA the operator was shown; None = no EULA
|
|
440
|
+
#: declared (the key is then OMITTED from the JSON, never null)
|
|
441
|
+
eula_sha256: "str | None" = None
|
|
384
442
|
|
|
385
443
|
def __post_init__(self) -> None:
|
|
386
444
|
problems = []
|
|
445
|
+
if self.eula_sha256 is not None and (not isinstance(self.eula_sha256, str)
|
|
446
|
+
or _SHA_RE.fullmatch(self.eula_sha256) is None):
|
|
447
|
+
problems.append(f"eula_sha256 must be 64 lowercase hex characters "
|
|
448
|
+
f"(got {self.eula_sha256!r})")
|
|
387
449
|
for k in RECORD_TEXT_FIELDS:
|
|
388
450
|
p = text_field_problem(k, getattr(self, k))
|
|
389
451
|
if p is not None:
|
|
@@ -415,21 +477,34 @@ class ConsentRecord:
|
|
|
415
477
|
def to_json(self) -> dict:
|
|
416
478
|
d = {k: getattr(self, k) for k in RECORD_KEYS}
|
|
417
479
|
d["granted"] = list(self.granted)
|
|
480
|
+
if self.eula_sha256 is not None:
|
|
481
|
+
d["eula_sha256"] = self.eula_sha256
|
|
418
482
|
return d
|
|
419
483
|
|
|
420
484
|
@classmethod
|
|
421
485
|
def from_json(cls, d: Any) -> "ConsentRecord":
|
|
422
|
-
|
|
486
|
+
keys = set(d) if isinstance(d, dict) else None
|
|
487
|
+
if keys is None or not set(RECORD_KEYS) <= keys \
|
|
488
|
+
or not keys <= set(RECORD_KEYS) | set(OPTIONAL_RECORD_KEYS):
|
|
423
489
|
got = sorted(d) if isinstance(d, dict) else type(d).__name__
|
|
490
|
+
extra = sorted(keys - set(RECORD_KEYS) - set(OPTIONAL_RECORD_KEYS)) if keys else []
|
|
424
491
|
raise ConsentRefused(f"consent record REFUSED: keys must be exactly "
|
|
425
|
-
f"{list(RECORD_KEYS)}
|
|
492
|
+
f"{list(RECORD_KEYS)}, plus optionally "
|
|
493
|
+
f"{list(OPTIONAL_RECORD_KEYS)} (got {got}"
|
|
494
|
+
+ (f"; unknown key(s) {extra}" if extra else "") + ")")
|
|
495
|
+
if "eula_sha256" in d and (not isinstance(d["eula_sha256"], str)
|
|
496
|
+
or _SHA_RE.fullmatch(d["eula_sha256"]) is None):
|
|
497
|
+
raise ConsentRefused(f"consent record REFUSED: eula_sha256 must be 64 lowercase "
|
|
498
|
+
f"hex characters when present, never null "
|
|
499
|
+
f"(got {d['eula_sha256']!r})")
|
|
426
500
|
g = d["granted"]
|
|
427
501
|
return cls(**{**d, "granted": tuple(g) if isinstance(g, list) else g})
|
|
428
502
|
|
|
429
503
|
|
|
430
504
|
def make_record(*, manifest: Manifest, manifest_sha256: str, granted: Iterable[str],
|
|
431
505
|
decided_by: str, host: str, decision: str,
|
|
432
|
-
clock: Callable[[], datetime] = utc_now
|
|
506
|
+
clock: Callable[[], datetime] = utc_now,
|
|
507
|
+
eula_sha256: "str | None" = None) -> ConsentRecord:
|
|
433
508
|
"""Build a record; ``decided_at`` is taken from ``clock`` (UTC, ISO 8601)."""
|
|
434
509
|
now = clock()
|
|
435
510
|
if now.tzinfo is None:
|
|
@@ -439,7 +514,8 @@ def make_record(*, manifest: Manifest, manifest_sha256: str, granted: Iterable[s
|
|
|
439
514
|
return ConsentRecord(
|
|
440
515
|
domain=manifest.domain, version=manifest.version,
|
|
441
516
|
manifest_sha256=manifest_sha256, granted=tuple(sorted(set(granted))),
|
|
442
|
-
decided_by=decided_by, decided_at=decided_at, host=host, decision=decision
|
|
517
|
+
decided_by=decided_by, decided_at=decided_at, host=host, decision=decision,
|
|
518
|
+
eula_sha256=eula_sha256)
|
|
443
519
|
|
|
444
520
|
|
|
445
521
|
class ConsentStore:
|
|
@@ -489,6 +565,8 @@ class ConsentStore:
|
|
|
489
565
|
__all__ = [
|
|
490
566
|
"DIALOG_TITLE_SUFFIX", "FILESYSTEM_GRANT_PREFIX", "NETWORK_GRANT_PREFIX",
|
|
491
567
|
"PERMISSIONS_HEADING", "dialog_title", "filesystem_grant", "network_grant",
|
|
568
|
+
"ConsentEula", "EULA_CHANGED", "EULA_HEADING", "LICENSE_SUFFIX", "OPTIONAL_RECORD_KEYS",
|
|
569
|
+
"eula_text_shown",
|
|
492
570
|
"ABSENT", "ConsentContent", "ConsentLine", "ConsentRecord", "ConsentStore",
|
|
493
571
|
"DECISIONS", "HostPermission", "HostSectionRenderer", "NONE_DECLARED",
|
|
494
572
|
"RECORD_KEYS", "RECORD_TEXT_FIELDS", "added_grants", "bus_publish_grant", "bus_subscribe_grant",
|
|
@@ -8,6 +8,7 @@ digests) as data, and its text says the same thing for a human.
|
|
|
8
8
|
"""
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
+
import re
|
|
11
12
|
from dataclasses import dataclass
|
|
12
13
|
|
|
13
14
|
|
|
@@ -101,3 +102,66 @@ class HostNameRefused(PluginContractRefusal):
|
|
|
101
102
|
class ConsentRefused(PluginContractRefusal):
|
|
102
103
|
"""A consent-layer input is malformed (for example a host grant without
|
|
103
104
|
its ``<host>:`` prefix, or an isolation level below the plug-in's floor)."""
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# --------------------------------------------------------------------------- #
|
|
108
|
+
# Contract 0.2 ([DELTA:CXC-PLUGIN-CONTRACT-V0-2-DELTA]).
|
|
109
|
+
# --------------------------------------------------------------------------- #
|
|
110
|
+
class EulaShaMismatch(PluginContractRefusal):
|
|
111
|
+
"""The EULA file is not the one shown at consent, or the caller's
|
|
112
|
+
``consented_eula_sha256`` is missing, malformed or given for a manifest
|
|
113
|
+
without ``eula`` ([CXC-PC-V02-EULA-HASH-RECORD] bound-to-the-shown-text).
|
|
114
|
+
Carries both digests (``expected`` is what the caller consented to)."""
|
|
115
|
+
|
|
116
|
+
def __init__(self, message: str, *, expected: object, actual: "str | None"):
|
|
117
|
+
self.expected = expected
|
|
118
|
+
self.actual = actual
|
|
119
|
+
super().__init__(message)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class PromptNotPrepared(PluginContractRefusal):
|
|
123
|
+
"""``record_decline`` was given a prompt this manager did not prepare
|
|
124
|
+
([CXC-PC-V02-RECORD-DECLINE-PROMPT-VALIDITY] prepared)."""
|
|
125
|
+
|
|
126
|
+
def __init__(self) -> None:
|
|
127
|
+
super().__init__("record_decline REFUSED: the prompt was not prepared by this manager")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class PromptStale(PluginContractRefusal):
|
|
131
|
+
"""``record_decline`` was given a prompt whose subject changed since it was
|
|
132
|
+
prepared, or that was already declined ([CXC-PC-V02-RECORD-DECLINE-PROMPT-VALIDITY])."""
|
|
133
|
+
|
|
134
|
+
def __init__(self, reason: str):
|
|
135
|
+
self.reason = reason
|
|
136
|
+
super().__init__(f"record_decline REFUSED: the prompt is stale: {reason}")
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
_IDENTIFIER_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
|
|
140
|
+
#: the token recorded for a class whose name is not an identifier (candidate
|
|
141
|
+
#: review A1, ruled: type("x y", (Exception,), {}) makes one)
|
|
142
|
+
NON_IDENTIFIER_CLASS = "NonIdentifierException"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def safe_class_name(exc: BaseException) -> str:
|
|
146
|
+
"""The exception's class name for install-log text
|
|
147
|
+
([CXC-PC-V02-INSTALL-LOG-FAILURE-TEXT]): ``type(exc).__name__`` when it is an
|
|
148
|
+
identifier (cut to 200 characters), else ``NonIdentifierException``, so
|
|
149
|
+
no other text of the class can reach the log, a finding or a message,
|
|
150
|
+
and an abort event can always be written."""
|
|
151
|
+
name = type(exc).__name__
|
|
152
|
+
if not isinstance(name, str) or _IDENTIFIER_RE.fullmatch(name) is None:
|
|
153
|
+
return NON_IDENTIFIER_CLASS
|
|
154
|
+
return name[:200]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class InstallLogRefused(PluginContractRefusal):
|
|
158
|
+
"""An event could not be appended to ``installs.jsonl``
|
|
159
|
+
([CXC-PC-V02-INSTALL-LOG-WRITE-ORDER] failure-of-the-append). The message
|
|
160
|
+
names the log path and the CLASS of the underlying error, never its text
|
|
161
|
+
([CXC-PC-V02-INSTALL-LOG-FAILURE-TEXT])."""
|
|
162
|
+
|
|
163
|
+
def __init__(self, path: object, error_class: str):
|
|
164
|
+
self.path = str(path)
|
|
165
|
+
self.error_class = error_class
|
|
166
|
+
super().__init__(f"install log REFUSED: an event could not be appended to "
|
|
167
|
+
f"{self.path} ({error_class}); nothing changed")
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
"""Conformance fixtures: hello-world v1 and v2 ([CXC-PC-HELLO-V1], [CXC-PC-HELLO-V2])
|
|
1
|
+
"""Conformance fixtures: hello-world v1 and v2 ([CXC-PC-HELLO-V1], [CXC-PC-HELLO-V2]),
|
|
2
|
+
and (contract 0.2) hello-world-eula ([CXC-PC-V02-EULA-HOST-OBLIGATION]): a
|
|
3
|
+
hello-world v1 manifest that states contract "0.2" and declares ``eula``.
|
|
2
4
|
|
|
3
5
|
Each ``hello_world_vN`` directory is a complete plug-in PACKAGE (a v0.1 package
|
|
4
6
|
source: a local directory) with ``manifest.json`` at its root, built by
|
|
@@ -10,8 +12,13 @@ from pathlib import Path
|
|
|
10
12
|
FIXTURES = Path(__file__).resolve().parent
|
|
11
13
|
|
|
12
14
|
|
|
15
|
+
#: fixture name -> package directory name
|
|
16
|
+
_DIRS = {"v1": "hello_world_v1", "v2": "hello_world_v2", "eula": "hello_world_eula",
|
|
17
|
+
"hello-world-eula": "hello_world_eula"}
|
|
18
|
+
|
|
19
|
+
|
|
13
20
|
def package_dir(version: str) -> Path:
|
|
14
|
-
"""'v1' or '
|
|
15
|
-
if version not in
|
|
21
|
+
"""'v1', 'v2' or 'hello-world-eula' (also 'eula') -> the package directory."""
|
|
22
|
+
if version not in _DIRS:
|
|
16
23
|
raise ValueError(f"unknown hello-world fixture {version!r}")
|
|
17
|
-
return FIXTURES /
|
|
24
|
+
return FIXTURES / _DIRS[version]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Hello World — end-user licence agreement (conformance fixture hello-world-eula)
|
|
2
|
+
|
|
3
|
+
1. Scope. This text exists so that a host can prove its consent screen shows a declared
|
|
4
|
+
EULA exactly and in full, before the accept control ([CXC-PC-V02-EULA-HOST-OBLIGATION]).
|
|
5
|
+
2. Grant. The fixture grants nothing and asks nothing; it greets on the bus and answers
|
|
6
|
+
each ping with a pong, exactly as hello-world v1 does.
|
|
7
|
+
3. Fidelity. A screen that truncates this text, summarises it, turns its line feeds into
|
|
8
|
+
spaces or shows a different text of the same length does not show this EULA.
|
|
9
|
+
4. Characters. The tab at the start of each clause, the em dash in the title and the
|
|
10
|
+
café in this sentence must survive the screen unchanged.
|
|
11
|
+
5. Length. The text is longer than one thousand characters, so that a screen showing
|
|
12
|
+
only the first thousand and a link is caught: the helper eula_text_shown returns
|
|
13
|
+
False for it, and True only when this whole text appears as one contiguous string.
|
|
14
|
+
6. No warranty. The fixture is provided as is, for tests only.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contract": "0.2",
|
|
3
|
+
"domain": "hello_world",
|
|
4
|
+
"name": "Hello World",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "The conformance fixture: greets on the bus and answers each ping with a pong.",
|
|
7
|
+
"documentation": "https://example.invalid/compose-plugins/hello_world",
|
|
8
|
+
"issue_tracker": "https://example.invalid/compose-plugins/hello_world/issues",
|
|
9
|
+
"codeowners": [
|
|
10
|
+
"@740Dave"
|
|
11
|
+
],
|
|
12
|
+
"requirements": [],
|
|
13
|
+
"run": {
|
|
14
|
+
"form": "python",
|
|
15
|
+
"entry": "hello_world.plugin:HelloWorld"
|
|
16
|
+
},
|
|
17
|
+
"isolation_floor": "inprocess",
|
|
18
|
+
"hosts": {
|
|
19
|
+
"composeio": {},
|
|
20
|
+
"gnomon": {}
|
|
21
|
+
},
|
|
22
|
+
"eula": "EULA.txt",
|
|
23
|
+
"config_schema": {
|
|
24
|
+
"properties": {
|
|
25
|
+
"greeting": {
|
|
26
|
+
"default": "hello",
|
|
27
|
+
"title": "Greeting",
|
|
28
|
+
"type": "string"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"title": "Config",
|
|
32
|
+
"type": "object"
|
|
33
|
+
},
|
|
34
|
+
"bus": {
|
|
35
|
+
"publishes": [
|
|
36
|
+
{
|
|
37
|
+
"namespace": "plugins/hello_world/greeting",
|
|
38
|
+
"type": "STATE"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"namespace": "plugins/hello_world/pong",
|
|
42
|
+
"type": "EVENT"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"subscribes": [
|
|
46
|
+
{
|
|
47
|
+
"namespace": "plugins/hello_world/ping",
|
|
48
|
+
"type": "EVENT"
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""hello-world v1 ([CXC-PC-HELLO-V1]).
|
|
2
|
+
|
|
3
|
+
Config ``greeting: str = "hello"``. Publishes STATE ``plugins/hello_world/greeting``
|
|
4
|
+
(the greeting text). Subscribes EVENT ``plugins/hello_world/ping``; each ping
|
|
5
|
+
publishes EVENT ``plugins/hello_world/pong`` with ``{greeting, n}``, where ``n``
|
|
6
|
+
counts pongs sent since THIS start, from 1 (a restart resets it).
|
|
7
|
+
``health_reason()`` returns "empty greeting" when ``greeting == ""``.
|
|
8
|
+
"""
|
|
9
|
+
from typing import ClassVar
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel
|
|
12
|
+
|
|
13
|
+
from composebus.plugin import ComposePlugin
|
|
14
|
+
|
|
15
|
+
GREETING = "plugins/hello_world/greeting"
|
|
16
|
+
PING = "plugins/hello_world/ping"
|
|
17
|
+
PONG = "plugins/hello_world/pong"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class HelloWorld(ComposePlugin):
|
|
21
|
+
class Config(BaseModel):
|
|
22
|
+
greeting: str = "hello"
|
|
23
|
+
|
|
24
|
+
name = "hello_world"
|
|
25
|
+
version = "1.0.0"
|
|
26
|
+
publishes = [GREETING, PONG]
|
|
27
|
+
subscribes = [PING]
|
|
28
|
+
bus_types: ClassVar[dict] = {GREETING: "STATE", PONG: "EVENT", PING: "EVENT"}
|
|
29
|
+
|
|
30
|
+
def start(self, bus):
|
|
31
|
+
self._bus = bus
|
|
32
|
+
self._n = 0
|
|
33
|
+
self._running = True
|
|
34
|
+
bus.publish_state(GREETING, self.config.greeting, source="plugin:hello_world")
|
|
35
|
+
bus.subscribe_events(PING, self._on_ping)
|
|
36
|
+
|
|
37
|
+
def _pongs_per_ping(self) -> int:
|
|
38
|
+
return 1
|
|
39
|
+
|
|
40
|
+
def _on_ping(self, namespace, event_type, data):
|
|
41
|
+
if not getattr(self, "_running", False):
|
|
42
|
+
return # a stopped instance never answers (no bus-level unsubscribe)
|
|
43
|
+
for _ in range(self._pongs_per_ping()):
|
|
44
|
+
self._n += 1
|
|
45
|
+
self._bus.publish_event(PONG, "pong",
|
|
46
|
+
{"greeting": self.config.greeting, "n": self._n},
|
|
47
|
+
source="plugin:hello_world")
|
|
48
|
+
|
|
49
|
+
def stop(self):
|
|
50
|
+
self._running = False
|
|
51
|
+
self._bus = None
|
|
52
|
+
|
|
53
|
+
def health_reason(self):
|
|
54
|
+
return "empty greeting" if self.config.greeting == "" else None
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""hello-world plug-in package (conformance fixture)."""
|