governed-objects 0.3.0__tar.gz → 0.3.1__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.
- {governed_objects-0.3.0 → governed_objects-0.3.1}/PKG-INFO +12 -6
- {governed_objects-0.3.0 → governed_objects-0.3.1}/README.md +11 -5
- {governed_objects-0.3.0 → governed_objects-0.3.1}/pyproject.toml +1 -1
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/resolver.py +11 -6
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/validator.py +8 -9
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/command.py +5 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/events/replay.py +25 -25
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/idempotency/store.py +8 -1
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/importer.py +41 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/types.py +10 -1
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/observations/validation.py +4 -4
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/policy/evaluator.py +39 -5
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/registration/service.py +2 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/runtime/runtime.py +107 -40
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/types/registry.py +38 -7
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/types/schema.py +41 -4
- {governed_objects-0.3.0 → governed_objects-0.3.1}/.gitignore +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/CONTRIBUTING.md +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/GOVERNANCE.md +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/LICENSE +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/LICENSING.md +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/NOTICE +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/PRINCIPLES.md +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/__init__.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/_version.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/adapters/base.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/adapters/context.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/adapters/mandate.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/adapters/registry.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/agent/session.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/applications/registry.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/authority/rules.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/configuration.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/mandate.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/materializer.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/projection.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/scope.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/service.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/__init__.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/actor_manifest.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/actors.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/clock.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/command_context.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/models.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/domain/traversal.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/events/lineage.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/events/reducers/__init__.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/events/reducers/mandate.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/__init__.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/artifact.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/export.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/governance.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/prc.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/__init__.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/loop.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/model.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/tools/registry.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/tools/results.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/tools/schemas.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/tools/surface.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/llm/trace.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/materialization/service.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/observations/__init__.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/observations/ingestion.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/observations/mapping.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/observations/models.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/observations/store.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/outbound/__init__.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/outbound/models.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/outbound/service.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/outbound/store.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/persistence/sqlite.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/policy/constraints.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/policy/context.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/policy/outcomes.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/policy/reasons.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/providers/base.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/providers/binding.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/providers/capabilities.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/providers/errors.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/providers/projection.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/providers/registry.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/query/service.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/query/traversal.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/reconciliation/service.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/registration/detach.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/relationships/canonical.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/relationships/sync.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/relationships/vocabulary.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/types/canonicalizers/base.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/types/extensions.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/types/lifecycle.py +0 -0
- {governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/types/validation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: governed-objects
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Governed Objects runtime — a reusable primitive for policy-aware organizational assets
|
|
5
5
|
Project-URL: Homepage, https://governedobjects.com/
|
|
6
6
|
Project-URL: Source, https://github.com/governedobjects/governed-objects-python
|
|
@@ -35,16 +35,16 @@ for the normative rules this runtime implements and tests against.
|
|
|
35
35
|
|
|
36
36
|
## Status
|
|
37
37
|
|
|
38
|
-
Experimental, version 0.3.
|
|
38
|
+
Experimental, version 0.3.1, `0.x`. This is not a production product,
|
|
39
39
|
conformance certification, or interoperability approval. It targets
|
|
40
40
|
specification revision `draft2.2` and self-reports 76/0/2/0 (pass/not
|
|
41
|
-
applicable/not executable/fail) against Core conformance suite 0.2.
|
|
41
|
+
applicable/not executable/fail) against Core conformance suite 0.2.1 for that revision;
|
|
42
42
|
see the conformance adapter below to reproduce that result yourself. The
|
|
43
43
|
suite's own claim text for that run:
|
|
44
44
|
|
|
45
|
-
> governed-objects-python 0.3.
|
|
46
|
-
> 0.2.
|
|
47
|
-
> executed by suite 0.2.
|
|
45
|
+
> governed-objects-python 0.3.1 passes the Governed Objects Conformance Suite
|
|
46
|
+
> 0.2.1 for v0alpha1 draft2.2 Core (self-attested; not certified). Not
|
|
47
|
+
> executed by suite 0.2.1: D22-CON-001, D22-CS4-003. Conditional capabilities
|
|
48
48
|
> claimed: create_with_relationships, governance_reconfiguration,
|
|
49
49
|
> mutable_objects, relationship_add, relationship_remove, replay, restart,
|
|
50
50
|
> restoration, semantic_portability_view, type_version_exposed,
|
|
@@ -167,6 +167,12 @@ WSL. The adapters are `bash` scripts.
|
|
|
167
167
|
- `governed_objects.interchange` (artifact export/import, PRC) is a
|
|
168
168
|
provisional, representation-limited, non-normative experiment, not an
|
|
169
169
|
official wire standard.
|
|
170
|
+
- Revoking a delegated mandate, or narrowing it, is governed by capability
|
|
171
|
+
and is not restricted to the mandate's principal: any actor holding the
|
|
172
|
+
required capability can do it.
|
|
173
|
+
- The built-in `CapabilityPolicyEvaluator` applies the constraints of every
|
|
174
|
+
principal in a delegation chain. A custom policy evaluator must enforce
|
|
175
|
+
principals' constraints itself.
|
|
170
176
|
- The SQLite store serializes operations on one store instance with a
|
|
171
177
|
per-instance connection guard, and `create`/`add_relationship`/
|
|
172
178
|
`remove_relationship`/transition commands re-check the expected Object
|
|
@@ -10,16 +10,16 @@ for the normative rules this runtime implements and tests against.
|
|
|
10
10
|
|
|
11
11
|
## Status
|
|
12
12
|
|
|
13
|
-
Experimental, version 0.3.
|
|
13
|
+
Experimental, version 0.3.1, `0.x`. This is not a production product,
|
|
14
14
|
conformance certification, or interoperability approval. It targets
|
|
15
15
|
specification revision `draft2.2` and self-reports 76/0/2/0 (pass/not
|
|
16
|
-
applicable/not executable/fail) against Core conformance suite 0.2.
|
|
16
|
+
applicable/not executable/fail) against Core conformance suite 0.2.1 for that revision;
|
|
17
17
|
see the conformance adapter below to reproduce that result yourself. The
|
|
18
18
|
suite's own claim text for that run:
|
|
19
19
|
|
|
20
|
-
> governed-objects-python 0.3.
|
|
21
|
-
> 0.2.
|
|
22
|
-
> executed by suite 0.2.
|
|
20
|
+
> governed-objects-python 0.3.1 passes the Governed Objects Conformance Suite
|
|
21
|
+
> 0.2.1 for v0alpha1 draft2.2 Core (self-attested; not certified). Not
|
|
22
|
+
> executed by suite 0.2.1: D22-CON-001, D22-CS4-003. Conditional capabilities
|
|
23
23
|
> claimed: create_with_relationships, governance_reconfiguration,
|
|
24
24
|
> mutable_objects, relationship_add, relationship_remove, replay, restart,
|
|
25
25
|
> restoration, semantic_portability_view, type_version_exposed,
|
|
@@ -142,6 +142,12 @@ WSL. The adapters are `bash` scripts.
|
|
|
142
142
|
- `governed_objects.interchange` (artifact export/import, PRC) is a
|
|
143
143
|
provisional, representation-limited, non-normative experiment, not an
|
|
144
144
|
official wire standard.
|
|
145
|
+
- Revoking a delegated mandate, or narrowing it, is governed by capability
|
|
146
|
+
and is not restricted to the mandate's principal: any actor holding the
|
|
147
|
+
required capability can do it.
|
|
148
|
+
- The built-in `CapabilityPolicyEvaluator` applies the constraints of every
|
|
149
|
+
principal in a delegation chain. A custom policy evaluator must enforce
|
|
150
|
+
principals' constraints itself.
|
|
145
151
|
- The SQLite store serializes operations on one store instance with a
|
|
146
152
|
per-instance connection guard, and `create`/`add_relationship`/
|
|
147
153
|
`remove_relationship`/transition commands re-check the expected Object
|
{governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/resolver.py
RENAMED
|
@@ -11,7 +11,7 @@ from governed_objects.delegation.mandate import DelegatedMandate, MandateStatus
|
|
|
11
11
|
from governed_objects.delegation.materializer import materialize_mandate
|
|
12
12
|
from governed_objects.delegation.scope import EffectiveScope, MandateScope
|
|
13
13
|
from governed_objects.domain.clock import Clock, SystemClock
|
|
14
|
-
from governed_objects.domain.models import GovernedObject
|
|
14
|
+
from governed_objects.domain.models import Actor, GovernedObject
|
|
15
15
|
from governed_objects.persistence.sqlite import SQLiteStore
|
|
16
16
|
from governed_objects.policy.reasons import DenyReason
|
|
17
17
|
|
|
@@ -34,6 +34,9 @@ class ResolvedMandateAuthority:
|
|
|
34
34
|
parent_mandate_ids: tuple[str, ...]
|
|
35
35
|
ancestor_ineffective_reason: DenyReason | None = None
|
|
36
36
|
purpose_restricted: bool = False
|
|
37
|
+
# The current local record of every principal in the chain, this mandate's
|
|
38
|
+
# first. Their constraints bound every use of the mandate.
|
|
39
|
+
principals: tuple[Actor, ...] = ()
|
|
37
40
|
|
|
38
41
|
def is_effective_at(self, when: datetime) -> tuple[bool, DenyReason | None]:
|
|
39
42
|
if self.ancestor_ineffective_reason is not None:
|
|
@@ -72,13 +75,13 @@ class MandateResolver:
|
|
|
72
75
|
clock: Clock | None = None,
|
|
73
76
|
validate_binding=None,
|
|
74
77
|
scope_decoder=None,
|
|
75
|
-
|
|
78
|
+
principal_source=None,
|
|
76
79
|
) -> None:
|
|
77
80
|
self._store = store
|
|
78
81
|
self._clock = clock or SystemClock()
|
|
79
82
|
self._validate_binding = validate_binding
|
|
80
83
|
self._scope_decoder = scope_decoder
|
|
81
|
-
self.
|
|
84
|
+
self._principal_source = principal_source
|
|
82
85
|
|
|
83
86
|
def get_object(self, mandate_id: str) -> GovernedObject | None:
|
|
84
87
|
if self._validate_binding is None:
|
|
@@ -143,11 +146,12 @@ class MandateResolver:
|
|
|
143
146
|
|
|
144
147
|
# No broader than any mandate in the chain, nor than what each of their
|
|
145
148
|
# principals holds now (DEL-NARROW-001).
|
|
146
|
-
if self.
|
|
149
|
+
if self._principal_source is None:
|
|
147
150
|
raise ValueError('delegation configuration unavailable')
|
|
151
|
+
principals = tuple(self._principal_source(bound.principal_id) for bound in bounds)
|
|
148
152
|
effective_caps = mandate.capabilities
|
|
149
|
-
for bound in bounds:
|
|
150
|
-
effective_caps &= bound.capabilities &
|
|
153
|
+
for bound, principal in zip(bounds, principals):
|
|
154
|
+
effective_caps &= bound.capabilities & frozenset(principal.capabilities)
|
|
151
155
|
effective_scope = EffectiveScope(tuple(bound.scope for bound in bounds))
|
|
152
156
|
purpose_bounds = [bound.purposes for bound in bounds if bound.purposes]
|
|
153
157
|
effective_purposes = frozenset.intersection(*purpose_bounds) if purpose_bounds else frozenset()
|
|
@@ -172,6 +176,7 @@ class MandateResolver:
|
|
|
172
176
|
parent_mandate_ids=tuple(parent_ids),
|
|
173
177
|
ancestor_ineffective_reason=ancestor_reason,
|
|
174
178
|
purpose_restricted=bool(purpose_bounds),
|
|
179
|
+
principals=principals,
|
|
175
180
|
)
|
|
176
181
|
|
|
177
182
|
|
{governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/delegation/validator.py
RENAMED
|
@@ -103,14 +103,12 @@ class DelegationValidator:
|
|
|
103
103
|
if not spec.capabilities.issubset(ceiling.capabilities):
|
|
104
104
|
violations.append(DelegationViolation.CAPABILITY_EXPANSION)
|
|
105
105
|
|
|
106
|
-
if not
|
|
106
|
+
if not scope_within(spec.scope, ceiling.scope, self._store):
|
|
107
107
|
violations.append(DelegationViolation.SCOPE_EXPANSION)
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
elif spec.purposes and parent_mandate is not None:
|
|
113
|
-
pass
|
|
109
|
+
# Naming no purpose would be broader than any named set.
|
|
110
|
+
if ceiling.purposes and (not spec.purposes or not spec.purposes.issubset(ceiling.purposes)):
|
|
111
|
+
violations.append(DelegationViolation.PURPOSE_EXPANSION)
|
|
114
112
|
|
|
115
113
|
if not _time_subset(
|
|
116
114
|
spec.valid_from,
|
|
@@ -129,16 +127,17 @@ def _time_subset(
|
|
|
129
127
|
parent_from: datetime | None,
|
|
130
128
|
parent_until: datetime | None,
|
|
131
129
|
) -> bool:
|
|
132
|
-
if parent_from is not None and child_from is
|
|
130
|
+
if parent_from is not None and (child_from is None or child_from < parent_from):
|
|
133
131
|
return False
|
|
134
132
|
if parent_until is not None and (child_until is None or child_until > parent_until):
|
|
135
133
|
return False
|
|
136
134
|
return True
|
|
137
135
|
|
|
138
136
|
|
|
139
|
-
def
|
|
137
|
+
def scope_within(child: MandateScope, parent: MandateScope | EffectiveScope, store: SQLiteStore) -> bool:
|
|
138
|
+
"""Whether the declared scope ``child`` is no broader than ``parent``."""
|
|
140
139
|
if isinstance(parent, EffectiveScope):
|
|
141
|
-
return all(
|
|
140
|
+
return all(scope_within(child, bound, store) for bound in parent.bounds)
|
|
142
141
|
if parent.is_empty():
|
|
143
142
|
return True
|
|
144
143
|
if child.is_empty():
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
from collections.abc import Iterable, Mapping
|
|
7
8
|
from dataclasses import dataclass, field
|
|
8
9
|
from pathlib import Path
|
|
9
10
|
from typing import Any
|
|
@@ -29,6 +30,10 @@ class CreateObject(Command):
|
|
|
29
30
|
metadata: dict[str, Any] | None = None,
|
|
30
31
|
relationships: list[dict[str, str]] | None = None,
|
|
31
32
|
) -> None:
|
|
33
|
+
# A single-pass iterable is read once, here, so that every later reader
|
|
34
|
+
# of the command sees the same relationships.
|
|
35
|
+
if isinstance(relationships, Iterable) and not isinstance(relationships, (str, bytes, Mapping, list)):
|
|
36
|
+
relationships = list(relationships)
|
|
32
37
|
object.__setattr__(self, "action", "create")
|
|
33
38
|
object.__setattr__(self, "object_id", object_id)
|
|
34
39
|
object.__setattr__(self, "object_type", object_type)
|
|
@@ -78,14 +78,12 @@ class EventReplayer:
|
|
|
78
78
|
reducer = self._extensions.reducer_for(stored.type)
|
|
79
79
|
if reducer is None:
|
|
80
80
|
raise ReplayRefused()
|
|
81
|
-
if not events:
|
|
82
|
-
return stored
|
|
83
|
-
|
|
84
81
|
type_version = stored.type_version
|
|
85
82
|
|
|
83
|
+
# The first accepted event must establish state (EVT-BASELINE-001).
|
|
86
84
|
state = reducer.reduce(None, events[0])
|
|
87
85
|
if state is None:
|
|
88
|
-
|
|
86
|
+
raise ReplayRefused()
|
|
89
87
|
self._check_result(stored, state)
|
|
90
88
|
|
|
91
89
|
version = events[0].object_version
|
|
@@ -103,8 +101,10 @@ class EventReplayer:
|
|
|
103
101
|
)
|
|
104
102
|
version = event.object_version
|
|
105
103
|
result = reducer.reduce(current_obj, event)
|
|
104
|
+
# An accepted event that yields no state cannot be skipped: the
|
|
105
|
+
# result would carry its version without its effect.
|
|
106
106
|
if result is None:
|
|
107
|
-
|
|
107
|
+
raise ReplayRefused()
|
|
108
108
|
self._check_result(stored, result)
|
|
109
109
|
current_state = result.state
|
|
110
110
|
data = result.data
|
|
@@ -138,6 +138,9 @@ class EventReplayer:
|
|
|
138
138
|
if not self.check_type_version_supported(stored):
|
|
139
139
|
raise ReplayRefused()
|
|
140
140
|
events = self._accepted_events(stored.id, allow_legacy)
|
|
141
|
+
# Without history there is nothing to reconstruct from.
|
|
142
|
+
if not events:
|
|
143
|
+
raise ReplayRefused()
|
|
141
144
|
# Preflight the whole selection before invoking any reducer or edge fold.
|
|
142
145
|
for event in events:
|
|
143
146
|
if (event.object_id, event.object_type, event.type_version) != (
|
|
@@ -179,31 +182,28 @@ class EventReplayer:
|
|
|
179
182
|
event: GovernanceEvent,
|
|
180
183
|
rel_index: dict[tuple[str, str], Relationship],
|
|
181
184
|
) -> None:
|
|
185
|
+
# Relationship history is replayed as recorded: a repeated addition or
|
|
186
|
+
# an absent removal is refused, never repaired (REL-COMPAT-001).
|
|
182
187
|
if event.action == "create":
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
)
|
|
190
|
-
|
|
188
|
+
added = event.details.get("relationships", [])
|
|
189
|
+
elif event.action == "add_relationship":
|
|
190
|
+
added = [event.details]
|
|
191
|
+
else:
|
|
192
|
+
if event.action == "remove_relationship":
|
|
193
|
+
key = (event.details["relation"], event.details["target_id"])
|
|
194
|
+
if rel_index.pop(key, None) is None:
|
|
195
|
+
raise ReplayRefused()
|
|
191
196
|
return
|
|
192
|
-
|
|
193
|
-
if event.action == "add_relationship":
|
|
194
|
-
details = event.details
|
|
197
|
+
for rel_data in added:
|
|
195
198
|
rel = canonical_relationship(
|
|
196
|
-
object_id,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
target_type=
|
|
199
|
+
rel_data.get("source_id", object_id),
|
|
200
|
+
rel_data["relation"],
|
|
201
|
+
rel_data["target_id"],
|
|
202
|
+
target_type=rel_data.get("target_type"),
|
|
200
203
|
)
|
|
204
|
+
if (rel.relation, rel.target_id) in rel_index:
|
|
205
|
+
raise ReplayRefused()
|
|
201
206
|
rel_index[(rel.relation, rel.target_id)] = rel
|
|
202
|
-
return
|
|
203
|
-
|
|
204
|
-
if event.action == "remove_relationship":
|
|
205
|
-
details = event.details
|
|
206
|
-
rel_index.pop((details["relation"], details["target_id"]), None)
|
|
207
207
|
|
|
208
208
|
def check_type_version_supported(self, obj: GovernedObject) -> bool:
|
|
209
209
|
return bound_type_definition(self._types, obj) is not None
|
|
@@ -13,6 +13,7 @@ from typing import Any
|
|
|
13
13
|
from governed_objects.domain.command import Command
|
|
14
14
|
from governed_objects.domain.command_context import CommandContext
|
|
15
15
|
from governed_objects.domain.models import Actor, CommandResult, Decision
|
|
16
|
+
from governed_objects.observations.validation import is_json_value
|
|
16
17
|
from governed_objects.persistence.sqlite import SQLiteStore, _connection_locked
|
|
17
18
|
|
|
18
19
|
|
|
@@ -24,7 +25,8 @@ class Receipt:
|
|
|
24
25
|
|
|
25
26
|
def request_fingerprint(command: Command, actor: Actor, context: CommandContext) -> str | None:
|
|
26
27
|
"""Canonical hash of everything a receipt is bound to, or None when the
|
|
27
|
-
payload
|
|
28
|
+
payload is not JSON-native: encoding would let distinct values, such as the
|
|
29
|
+
keys ``1`` and ``"1"``, share a hash."""
|
|
28
30
|
request = {
|
|
29
31
|
"object_id": command.object_id,
|
|
30
32
|
"actor_id": actor.id,
|
|
@@ -35,7 +37,12 @@ def request_fingerprint(command: Command, actor: Actor, context: CommandContext)
|
|
|
35
37
|
"object_type": command.object_type,
|
|
36
38
|
"payload": command.payload,
|
|
37
39
|
}
|
|
40
|
+
# Only when set, so an unconditional request hashes as it did before.
|
|
41
|
+
if context.expected_version is not None:
|
|
42
|
+
request["expected_version"] = context.expected_version
|
|
38
43
|
try:
|
|
44
|
+
if not is_json_value(command.payload, set()):
|
|
45
|
+
return None
|
|
39
46
|
encoded = json.dumps(request, sort_keys=True, separators=(",", ":"), allow_nan=False)
|
|
40
47
|
except (TypeError, ValueError, RecursionError):
|
|
41
48
|
return None
|
{governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/interchange/importer.py
RENAMED
|
@@ -308,6 +308,8 @@ class InterchangeImporter:
|
|
|
308
308
|
self._check_declarations(bundle)
|
|
309
309
|
if not bundle.objects:
|
|
310
310
|
raise ImportRefused(MALFORMED_ARTIFACT, "bundle contains no objects")
|
|
311
|
+
for obj in bundle.objects:
|
|
312
|
+
self._check_names(obj)
|
|
311
313
|
identities = [o.canonical_identity for o in bundle.objects]
|
|
312
314
|
for ident in identities:
|
|
313
315
|
if identities.count(ident) > 1:
|
|
@@ -388,6 +390,27 @@ class InterchangeImporter:
|
|
|
388
390
|
if bundle.profiles:
|
|
389
391
|
raise ImportRefused(UNSUPPORTED_SEMANTIC_FEATURE, "profile data is not supported")
|
|
390
392
|
|
|
393
|
+
@staticmethod
|
|
394
|
+
def _check_names(obj: ImportObject) -> None:
|
|
395
|
+
"""Every identity and relationship the bundle would create is named by
|
|
396
|
+
non-empty strings. The bundle may not have come through the decoder."""
|
|
397
|
+
ident = obj.canonical_identity
|
|
398
|
+
if not isinstance(ident, str) or not ident:
|
|
399
|
+
raise ImportRefused(MALFORMED_ARTIFACT, "canonical identity must be a non-empty string")
|
|
400
|
+
carried = [(r, None) for r in obj.relationships]
|
|
401
|
+
for e in obj.history:
|
|
402
|
+
carried += [(r, e.position) for r in e.baseline_relationships or ()]
|
|
403
|
+
if e.effect in (EFFECT_RELATIONSHIP_ADD, EFFECT_RELATIONSHIP_REMOVE) or e.relationship is not None:
|
|
404
|
+
carried.append((e.relationship, e.position))
|
|
405
|
+
for r, position in carried:
|
|
406
|
+
if not isinstance(r, ImportRelationship) or any(
|
|
407
|
+
not isinstance(value, str) or not value for value in r.key()
|
|
408
|
+
):
|
|
409
|
+
raise ImportRefused(
|
|
410
|
+
MALFORMED_ARTIFACT, "a relationship requires a non-empty string source, type and target",
|
|
411
|
+
ident, position,
|
|
412
|
+
)
|
|
413
|
+
|
|
391
414
|
def _portable(self, obj: ImportObject) -> Mapping[str, Any]:
|
|
392
415
|
ident = obj.canonical_identity
|
|
393
416
|
try:
|
|
@@ -452,6 +475,7 @@ class InterchangeImporter:
|
|
|
452
475
|
def _stage(self, obj: ImportObject, notes: list[str]) -> _Staged:
|
|
453
476
|
ident = obj.canonical_identity
|
|
454
477
|
portable = self._portable(obj)
|
|
478
|
+
type_def = self._types.get(obj.type_identity)
|
|
455
479
|
reference = self._check_governance(obj)
|
|
456
480
|
lc = lifecycle_field(portable)
|
|
457
481
|
actions = portable.get("actions", {})
|
|
@@ -479,6 +503,16 @@ class InterchangeImporter:
|
|
|
479
503
|
for e in obj.history:
|
|
480
504
|
if e.relationship is not None and e.relationship.source != ident:
|
|
481
505
|
raise ImportRefused(MALFORMED_ARTIFACT, "triple source is not the object", ident, e.position)
|
|
506
|
+
asserted = [(r, position) for _, rels, position in rel_lists for r in rels] + [
|
|
507
|
+
(e.relationship, e.position) for e in obj.history if e.relationship is not None
|
|
508
|
+
]
|
|
509
|
+
for r, position in asserted:
|
|
510
|
+
if not type_def.allows_relationship_type(r.type):
|
|
511
|
+
raise ImportRefused(
|
|
512
|
+
HISTORY_NOT_VALID_FOR_TYPE,
|
|
513
|
+
f"relationship type {r.type!r} is not declared by {obj.type_identity}@{obj.type_version}",
|
|
514
|
+
ident, position,
|
|
515
|
+
)
|
|
482
516
|
if any(r.has_evidence for _, rels, _ in rel_lists for r in rels) or any(
|
|
483
517
|
e.relationship is not None and e.relationship.has_evidence for e in obj.history
|
|
484
518
|
):
|
|
@@ -530,6 +564,13 @@ class InterchangeImporter:
|
|
|
530
564
|
if e.position != 1:
|
|
531
565
|
raise ImportRefused(HISTORY_INCONSISTENT, "creation entry after position 1", ident, e.position)
|
|
532
566
|
state = dict(e.post_image or {})
|
|
567
|
+
if lc and state.get(lc) != type_def.default_state():
|
|
568
|
+
raise ImportRefused(
|
|
569
|
+
HISTORY_NOT_VALID_FOR_TYPE,
|
|
570
|
+
f"creation in lifecycle state {state.get(lc)!r}; {obj.type_identity}@{obj.type_version} "
|
|
571
|
+
f"creates in {type_def.default_state()!r}",
|
|
572
|
+
ident, e.position,
|
|
573
|
+
)
|
|
533
574
|
rels = {r.key() for r in e.baseline_relationships or ()}
|
|
534
575
|
action = "create"
|
|
535
576
|
elif e.effect == EFFECT_STATE_CHANGE:
|
|
@@ -98,9 +98,18 @@ def build_type_definition(
|
|
|
98
98
|
lifecycle = portable["lifecycle"]
|
|
99
99
|
state_names = list(lifecycle["states"])
|
|
100
100
|
permitted = {(a, b) for a, b in lifecycle["transitions"]}
|
|
101
|
+
if not state_names:
|
|
102
|
+
raise PortableTypeError("lifecycle declares no states")
|
|
103
|
+
# Absent or empty means the first declared state.
|
|
104
|
+
initial = lifecycle.get("initial")
|
|
105
|
+
if initial is None or initial == "":
|
|
106
|
+
initial = state_names[0]
|
|
107
|
+
elif initial not in state_names:
|
|
108
|
+
raise PortableTypeError(f"initial state {initial!r} is not a declared state")
|
|
101
109
|
else:
|
|
102
110
|
state_names = [NO_LIFECYCLE_STATE]
|
|
103
111
|
permitted = set()
|
|
112
|
+
initial = NO_LIFECYCLE_STATE
|
|
104
113
|
|
|
105
114
|
def _action_def(requirement_key: str) -> ActionDef:
|
|
106
115
|
"""An empty requirement list denies, unless ``requirement_key`` is
|
|
@@ -146,7 +155,7 @@ def build_type_definition(
|
|
|
146
155
|
actions=native_actions,
|
|
147
156
|
read_requires=list(requirements["read"]),
|
|
148
157
|
read_open="read" in open_keys,
|
|
149
|
-
initial_state=
|
|
158
|
+
initial_state=initial,
|
|
150
159
|
extra={PORTABLE_TYPE_KEY: dict(portable)},
|
|
151
160
|
)
|
|
152
161
|
|
{governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/observations/validation.py
RENAMED
|
@@ -46,7 +46,7 @@ def candidate_image(obj: GovernedObject) -> CandidateImage:
|
|
|
46
46
|
return CandidateImage(obj.id, obj.type, obj.type_version, obj.state, deepcopy(obj.data))
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
def
|
|
49
|
+
def is_json_value(value: Any, active: set[int]) -> bool:
|
|
50
50
|
if value is None or type(value) in (str, bool, int):
|
|
51
51
|
return True
|
|
52
52
|
if type(value) is float:
|
|
@@ -56,8 +56,8 @@ def _json_value(value: Any, active: set[int]) -> bool:
|
|
|
56
56
|
active.add(id(value))
|
|
57
57
|
try:
|
|
58
58
|
if type(value) is dict:
|
|
59
|
-
return all(type(k) is str and
|
|
60
|
-
return all(
|
|
59
|
+
return all(type(k) is str and is_json_value(v, active) for k, v in value.items())
|
|
60
|
+
return all(is_json_value(v, active) for v in value)
|
|
61
61
|
finally:
|
|
62
62
|
active.remove(id(value))
|
|
63
63
|
|
|
@@ -90,7 +90,7 @@ def validate_candidate(
|
|
|
90
90
|
(current is not None and (candidate.identity, candidate.type_identity, candidate.type_version) !=
|
|
91
91
|
(current.identity, current.type_identity, current.type_version))):
|
|
92
92
|
return CandidateVerdict.INVALID
|
|
93
|
-
if not isinstance(candidate.state, str) or not candidate.state or not
|
|
93
|
+
if not isinstance(candidate.state, str) or not candidate.state or not is_json_value(candidate.data, set()):
|
|
94
94
|
return CandidateVerdict.INVALID
|
|
95
95
|
predicates = {
|
|
96
96
|
"string": lambda v: type(v) is str,
|
|
@@ -9,7 +9,8 @@ from typing import Protocol
|
|
|
9
9
|
from governed_objects.applications.registry import ApplicationDefinition
|
|
10
10
|
from governed_objects.delegation.mandate import DelegatedMandate, MandateStatus
|
|
11
11
|
from governed_objects.delegation.resolver import ResolvedMandateAuthority
|
|
12
|
-
from governed_objects.delegation.scope import scope_allows
|
|
12
|
+
from governed_objects.delegation.scope import MandateScope, scope_allows
|
|
13
|
+
from governed_objects.delegation.validator import scope_within
|
|
13
14
|
from governed_objects.domain.clock import Clock, SystemClock
|
|
14
15
|
from governed_objects.domain.models import Actor, Decision, GovernedObject
|
|
15
16
|
from governed_objects.persistence.sqlite import SQLiteStore
|
|
@@ -90,7 +91,11 @@ class CapabilityPolicyEvaluator:
|
|
|
90
91
|
mandate: DelegatedMandate | None = None,
|
|
91
92
|
resolved_mandate: ResolvedMandateAuthority | None = None,
|
|
92
93
|
purpose: str | None = None,
|
|
94
|
+
delegated_scope: MandateScope | None = None,
|
|
93
95
|
) -> PolicyDecision:
|
|
96
|
+
"""``delegated_scope`` is the scope declared by a child mandate being
|
|
97
|
+
created under the acting mandate: that create has no existing target,
|
|
98
|
+
so a scoped mandate bounds it by what the child declares."""
|
|
94
99
|
required = (
|
|
95
100
|
required_capabilities
|
|
96
101
|
if required_capabilities is not None
|
|
@@ -127,8 +132,7 @@ class CapabilityPolicyEvaluator:
|
|
|
127
132
|
deny_reason=DenyReason.MANDATE_INVALID)
|
|
128
133
|
|
|
129
134
|
for constraint in actor.constraints:
|
|
130
|
-
|
|
131
|
-
if handler is None or handler(actor, action, obj, type_def) is not True:
|
|
135
|
+
if not self._satisfies(constraint, actor, action, obj, type_def):
|
|
132
136
|
return PolicyDecision(
|
|
133
137
|
Decision.DENY,
|
|
134
138
|
f"actor constraint violated: {constraint}",
|
|
@@ -150,7 +154,8 @@ class CapabilityPolicyEvaluator:
|
|
|
150
154
|
|
|
151
155
|
if mandate is not None or resolved_mandate is not None:
|
|
152
156
|
mandate_deny = self._evaluate_mandate(
|
|
153
|
-
actor, mandate, resolved_mandate, required, purpose, obj,
|
|
157
|
+
actor, action, type_def, mandate, resolved_mandate, required, purpose, obj,
|
|
158
|
+
open_action=open_action, delegated_scope=delegated_scope,
|
|
154
159
|
)
|
|
155
160
|
if mandate_deny is not None:
|
|
156
161
|
return mandate_deny
|
|
@@ -174,9 +179,19 @@ class CapabilityPolicyEvaluator:
|
|
|
174
179
|
actor_decision.missing_capabilities,
|
|
175
180
|
)
|
|
176
181
|
|
|
182
|
+
def _satisfies(
|
|
183
|
+
self, constraint: str, actor: Actor, action: str, obj: GovernedObject | None,
|
|
184
|
+
type_def: ObjectTypeDefinition,
|
|
185
|
+
) -> bool:
|
|
186
|
+
"""A constraint without a configured handler is never satisfied."""
|
|
187
|
+
handler = self._constraint_handlers.get(constraint)
|
|
188
|
+
return handler is not None and handler(actor, action, obj, type_def) is True
|
|
189
|
+
|
|
177
190
|
def _evaluate_mandate(
|
|
178
191
|
self,
|
|
179
192
|
actor: Actor,
|
|
193
|
+
action: str,
|
|
194
|
+
type_def: ObjectTypeDefinition,
|
|
180
195
|
mandate: DelegatedMandate | None,
|
|
181
196
|
resolved: ResolvedMandateAuthority | None,
|
|
182
197
|
required: list[str],
|
|
@@ -184,6 +199,7 @@ class CapabilityPolicyEvaluator:
|
|
|
184
199
|
obj: GovernedObject | None,
|
|
185
200
|
*,
|
|
186
201
|
open_action: bool = False,
|
|
202
|
+
delegated_scope: MandateScope | None = None,
|
|
187
203
|
) -> PolicyDecision | None:
|
|
188
204
|
authority = resolved
|
|
189
205
|
if authority is None:
|
|
@@ -244,7 +260,13 @@ class CapabilityPolicyEvaluator:
|
|
|
244
260
|
return mandate_decision
|
|
245
261
|
|
|
246
262
|
if not authority.scope.is_empty():
|
|
247
|
-
if
|
|
263
|
+
if self._store is None:
|
|
264
|
+
in_scope = False
|
|
265
|
+
elif obj is not None:
|
|
266
|
+
in_scope = scope_allows(authority.scope, obj, self._store)
|
|
267
|
+
else:
|
|
268
|
+
in_scope = delegated_scope is not None and scope_within(delegated_scope, authority.scope, self._store)
|
|
269
|
+
if not in_scope:
|
|
248
270
|
return PolicyDecision(
|
|
249
271
|
Decision.DENY,
|
|
250
272
|
"mandate scope mismatch",
|
|
@@ -253,6 +275,18 @@ class CapabilityPolicyEvaluator:
|
|
|
253
275
|
required,
|
|
254
276
|
deny_reason=DenyReason.MANDATE_SCOPE_MISMATCH,
|
|
255
277
|
)
|
|
278
|
+
# Delegating never lifts a constraint on a principal (DEL-NARROW-001).
|
|
279
|
+
for principal in authority.principals:
|
|
280
|
+
for constraint in principal.constraints:
|
|
281
|
+
if not self._satisfies(constraint, principal, action, obj, type_def):
|
|
282
|
+
return PolicyDecision(
|
|
283
|
+
Decision.DENY,
|
|
284
|
+
"mandate principal constraint violated",
|
|
285
|
+
required,
|
|
286
|
+
[],
|
|
287
|
+
required,
|
|
288
|
+
deny_reason=DenyReason.CONSTRAINT_VIOLATION,
|
|
289
|
+
)
|
|
256
290
|
return None
|
|
257
291
|
|
|
258
292
|
@staticmethod
|
{governed_objects-0.3.0 → governed_objects-0.3.1}/src/governed_objects/registration/service.py
RENAMED
|
@@ -51,6 +51,8 @@ class RegistrationService:
|
|
|
51
51
|
|
|
52
52
|
def register_with_binding(self, governed_id: str, object_type: str, binding: ProviderBinding,
|
|
53
53
|
*, state: str | None = None, context: AdapterContext) -> GovernedObject:
|
|
54
|
+
if not isinstance(governed_id, str) or not governed_id:
|
|
55
|
+
raise RegistrationRefused()
|
|
54
56
|
definition = self._types.get(object_type)
|
|
55
57
|
if not definition.type_version or "type_version" not in definition.model_fields_set:
|
|
56
58
|
raise ValueError("registration requires a declared Type Version")
|