Skip to content

Commit bb08efc

Browse files
authored
feat: foundational Authority spec model and enums
2 parents ce8a95a + a18a131 commit bb08efc

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

netengine/spec/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
"""Spec parsing and models for NetEngine declarative specifications."""
2+
3+
from netengine.spec.authority import Authority, AuthorityKind, AuthorityScope, AuthoritySource
4+
5+
__all__ = [
6+
"Authority",
7+
"AuthorityKind",
8+
"AuthorityScope",
9+
"AuthoritySource",
10+
]

netengine/spec/authority.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Foundational authority primitives for NetEngine specifications."""
2+
3+
from enum import Enum
4+
from pydantic import Field
5+
6+
from netengine.spec.models import SpecModel
7+
8+
9+
class AuthorityKind(str, Enum):
10+
"""Kinds of authority recognized by NetEngine specs."""
11+
12+
WORLD_ROOT = "world_root"
13+
ROOT_NAMING = "root_naming"
14+
NUMBERING = "numbering"
15+
DOMAIN_REGISTRY = "domain_registry"
16+
REGISTRAR = "registrar"
17+
TRUST = "trust"
18+
PLATFORM_IDENTITY = "platform_identity"
19+
INWORLD_IDENTITY = "inworld_identity"
20+
TRANSIT = "transit"
21+
MAIL = "mail"
22+
SERVICE_CATALOG = "service_catalog"
23+
24+
25+
class AuthorityScope(str, Enum):
26+
"""Scope within which an authority is valid."""
27+
28+
WORLD = "world"
29+
PLATFORM = "platform"
30+
INWORLD = "inworld"
31+
ORG = "org"
32+
BOUNDARY = "boundary"
33+
PEER = "peer"
34+
EXTERNAL = "external"
35+
36+
37+
class AuthoritySource(str, Enum):
38+
"""Origin for an authority definition."""
39+
40+
LOCAL = "local"
41+
MIRRORED = "mirrored"
42+
IMPORTED_PEER = "imported_peer"
43+
EXTERNAL = "external"
44+
45+
46+
class Authority(SpecModel):
47+
"""Foundational model describing who controls a spec authority surface."""
48+
49+
id: str = Field(...)
50+
kind: AuthorityKind = Field(...)
51+
scope: AuthorityScope = Field(...)
52+
operator: str = Field(...)
53+
controls: list[str] = Field(...)
54+
description: str | None = Field(default=None)
55+
source: AuthoritySource = Field(default=AuthoritySource.LOCAL)

tests/test_authority_spec.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Tests for foundational authority spec primitives."""
2+
3+
import pytest
4+
from pydantic import ValidationError
5+
6+
from netengine.spec import Authority, AuthorityKind, AuthorityScope, AuthoritySource
7+
8+
9+
def test_authority_defaults_to_local_source() -> None:
10+
authority = Authority(
11+
id="world-root",
12+
kind=AuthorityKind.WORLD_ROOT,
13+
scope=AuthorityScope.WORLD,
14+
operator="root-operator",
15+
controls=["dns.root", "pki.root_ca"],
16+
)
17+
18+
assert authority.source == AuthoritySource.LOCAL
19+
assert authority.description is None
20+
21+
22+
def test_authority_accepts_enum_values() -> None:
23+
authority = Authority(
24+
id="mail-authority",
25+
kind="mail",
26+
scope="org",
27+
operator="mail-ops",
28+
controls=["mx.example.internal"],
29+
source="mirrored",
30+
)
31+
32+
assert authority.kind == AuthorityKind.MAIL
33+
assert authority.scope == AuthorityScope.ORG
34+
assert authority.source == AuthoritySource.MIRRORED
35+
36+
37+
def test_authority_model_is_frozen() -> None:
38+
authority = Authority(
39+
id="registry-authority",
40+
kind=AuthorityKind.DOMAIN_REGISTRY,
41+
scope=AuthorityScope.INWORLD,
42+
operator="registry-ops",
43+
controls=["domains"],
44+
)
45+
46+
with pytest.raises(ValidationError):
47+
authority.operator = "other-operator"

0 commit comments

Comments
 (0)