holon-sh 0.0.1.dev11__tar.gz → 0.0.1.dev12__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.
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/PKG-INFO +1 -1
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/context.py +19 -4
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/pyproject.toml +1 -1
- holon_sh-0.0.1.dev12/tests/test_context.py +71 -0
- holon_sh-0.0.1.dev11/tests/test_context.py +0 -52
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/.gitignore +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/LICENSE +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/README.md +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/client.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/__init__.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/events/__init__.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/events/_client.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/events/_server.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/events/_wire.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/files/__init__.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/files/_client.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/files/_server.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/ext/files/_wire.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/holon/py.typed +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/scripts/verify_distribution.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/tests/fixtures/caller/holon/apps/__init__.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/tests/test_elicit.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/tests/test_events.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/tests/test_files.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/tests/test_package.py +0 -0
- {holon_sh-0.0.1.dev11 → holon_sh-0.0.1.dev12}/tests/test_runtime.py +0 -0
|
@@ -54,17 +54,31 @@ class Principal:
|
|
|
54
54
|
actor: dict[str, Any] | None = None
|
|
55
55
|
|
|
56
56
|
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class Caller:
|
|
59
|
+
"""The app a request comes from. A lifecycle hook's job calls as its app."""
|
|
60
|
+
|
|
61
|
+
app: str # as named in holon.yaml
|
|
62
|
+
session: str # the namespace of the session both apps run in
|
|
63
|
+
|
|
64
|
+
|
|
57
65
|
@dataclass(frozen=True)
|
|
58
66
|
class RequestContext:
|
|
59
|
-
principal: Principal | None
|
|
67
|
+
principal: Principal | None # None when anonymous
|
|
68
|
+
caller: Caller | None # None when a person calls the app directly
|
|
60
69
|
|
|
61
70
|
|
|
62
71
|
def get_context() -> RequestContext:
|
|
63
|
-
"""
|
|
72
|
+
"""Who the current MCP request comes from: the person and the calling app."""
|
|
64
73
|
admitted = get_access_token()
|
|
65
74
|
extra = (admitted.claims or {}) if admitted else {}
|
|
75
|
+
# None for a person's direct call, and for an older runtime's raw mesh identity.
|
|
76
|
+
caller: Caller | None = None
|
|
77
|
+
match extra.get("caller"):
|
|
78
|
+
case {"app": str(app), "session": str(session)}:
|
|
79
|
+
caller = Caller(app, session)
|
|
66
80
|
if admitted is None or admitted.subject is None or "iss" not in extra:
|
|
67
|
-
return RequestContext(principal=None)
|
|
81
|
+
return RequestContext(principal=None, caller=caller)
|
|
68
82
|
return RequestContext(
|
|
69
83
|
Principal(
|
|
70
84
|
issuer=extra["iss"],
|
|
@@ -73,5 +87,6 @@ def get_context() -> RequestContext:
|
|
|
73
87
|
scopes=admitted.scopes,
|
|
74
88
|
claims=extra.get("claims", {}),
|
|
75
89
|
actor=extra.get("act"),
|
|
76
|
-
)
|
|
90
|
+
),
|
|
91
|
+
caller,
|
|
77
92
|
)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from mcp.server.auth.middleware.auth_context import auth_context_var
|
|
2
|
+
from mcp.server.auth.middleware.bearer_auth import AuthenticatedUser
|
|
3
|
+
from mcp.server.auth.provider import AccessToken
|
|
4
|
+
|
|
5
|
+
from holon.context import Caller, Principal, RequestContext, get_context
|
|
6
|
+
|
|
7
|
+
PROFILE = {"email": "user@example.com", "email_verified": True}
|
|
8
|
+
REPORTER = {"app": "reporter", "session": "session"}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_get_context_reads_the_caller_holon_admitted():
|
|
12
|
+
assert get_context() == RequestContext(principal=None, caller=None)
|
|
13
|
+
for client_id, scopes, extra, expected in [
|
|
14
|
+
(
|
|
15
|
+
"web",
|
|
16
|
+
["read", "write"],
|
|
17
|
+
{
|
|
18
|
+
"iss": "https://id.example",
|
|
19
|
+
"sub": "user",
|
|
20
|
+
"claims": PROFILE,
|
|
21
|
+
"act": {"sub": "agent"},
|
|
22
|
+
},
|
|
23
|
+
RequestContext(
|
|
24
|
+
Principal(
|
|
25
|
+
issuer="https://id.example",
|
|
26
|
+
subject="user",
|
|
27
|
+
client_id="web",
|
|
28
|
+
scopes=["read", "write"],
|
|
29
|
+
claims=PROFILE,
|
|
30
|
+
actor={"sub": "agent"},
|
|
31
|
+
),
|
|
32
|
+
caller=None,
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
# An app acting for a person, then an app or its lifecycle hook's job with nobody signed in.
|
|
36
|
+
(
|
|
37
|
+
"web",
|
|
38
|
+
[],
|
|
39
|
+
{"iss": "https://id.example", "sub": "user", "caller": REPORTER},
|
|
40
|
+
RequestContext(
|
|
41
|
+
Principal("https://id.example", "user", "web", [], {}),
|
|
42
|
+
Caller("reporter", "session"),
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
(
|
|
46
|
+
"",
|
|
47
|
+
[],
|
|
48
|
+
{"caller": REPORTER},
|
|
49
|
+
RequestContext(None, Caller("reporter", "session")),
|
|
50
|
+
),
|
|
51
|
+
# An older runtime passed the raw mesh identity, and a person needs an issuer.
|
|
52
|
+
(
|
|
53
|
+
"",
|
|
54
|
+
[],
|
|
55
|
+
{"caller": "spiffe://cluster.local/ns/session/sa/reporter"},
|
|
56
|
+
RequestContext(None, None),
|
|
57
|
+
),
|
|
58
|
+
("web", [], {"sub": "user"}, RequestContext(None, None)),
|
|
59
|
+
]:
|
|
60
|
+
token = AccessToken(
|
|
61
|
+
token="t",
|
|
62
|
+
client_id=client_id,
|
|
63
|
+
scopes=scopes,
|
|
64
|
+
subject=extra.get("sub"),
|
|
65
|
+
claims=extra,
|
|
66
|
+
)
|
|
67
|
+
admitted = auth_context_var.set(AuthenticatedUser(token))
|
|
68
|
+
try:
|
|
69
|
+
assert get_context() == expected
|
|
70
|
+
finally:
|
|
71
|
+
auth_context_var.reset(admitted)
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
from mcp.server.auth.middleware.auth_context import auth_context_var
|
|
2
|
-
from mcp.server.auth.middleware.bearer_auth import AuthenticatedUser
|
|
3
|
-
from mcp.server.auth.provider import AccessToken
|
|
4
|
-
|
|
5
|
-
from holon.context import Principal, get_context
|
|
6
|
-
|
|
7
|
-
PROFILE = {"email": "user@example.com", "email_verified": True}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def test_get_context_reads_the_caller_holon_admitted():
|
|
11
|
-
assert get_context().principal is None
|
|
12
|
-
for client_id, scopes, extra, expected in [
|
|
13
|
-
(
|
|
14
|
-
"web",
|
|
15
|
-
["read", "write"],
|
|
16
|
-
{
|
|
17
|
-
"iss": "https://id.example",
|
|
18
|
-
"sub": "user",
|
|
19
|
-
"claims": PROFILE,
|
|
20
|
-
"act": {"sub": "agent"},
|
|
21
|
-
},
|
|
22
|
-
Principal(
|
|
23
|
-
issuer="https://id.example",
|
|
24
|
-
subject="user",
|
|
25
|
-
client_id="web",
|
|
26
|
-
scopes=["read", "write"],
|
|
27
|
-
claims=PROFILE,
|
|
28
|
-
actor={"sub": "agent"},
|
|
29
|
-
),
|
|
30
|
-
),
|
|
31
|
-
(
|
|
32
|
-
"web",
|
|
33
|
-
[],
|
|
34
|
-
{"iss": "https://id.example", "sub": "user"},
|
|
35
|
-
Principal("https://id.example", "user", "web", [], {}),
|
|
36
|
-
),
|
|
37
|
-
# A hook call carries no user, and a caller needs an issuer.
|
|
38
|
-
("", [], {"hook": {"event": "installed"}}, None),
|
|
39
|
-
("web", [], {"sub": "user"}, None),
|
|
40
|
-
]:
|
|
41
|
-
token = AccessToken(
|
|
42
|
-
token="t",
|
|
43
|
-
client_id=client_id,
|
|
44
|
-
scopes=scopes,
|
|
45
|
-
subject=extra.get("sub"),
|
|
46
|
-
claims=extra,
|
|
47
|
-
)
|
|
48
|
-
admitted = auth_context_var.set(AuthenticatedUser(token))
|
|
49
|
-
try:
|
|
50
|
-
assert get_context().principal == expected
|
|
51
|
-
finally:
|
|
52
|
-
auth_context_var.reset(admitted)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|