Skip to content

Commit 23cb30d

Browse files
Renames
1 parent 6179334 commit 23cb30d

9 files changed

Lines changed: 77 additions & 77 deletions

File tree

src/sap_cloud_sdk/core/runtime_context/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
2020
In tests or scripts without a framework::
2121
22-
from sap_cloud_sdk.core.runtime_context import sdk_context, RequestContext, TENANT_ID
22+
from sap_cloud_sdk.core.runtime_context import sdk_context, RuntimeContext, TENANT_ID
2323
24-
with sdk_context(RequestContext({TENANT_ID: "test-tenant"})):
24+
with sdk_context(RuntimeContext({TENANT_ID: "test-tenant"})):
2525
...
2626
"""
2727

2828
from sap_cloud_sdk.core.runtime_context._context import (
29-
RequestContext,
29+
RuntimeContext,
3030
async_sdk_context,
3131
get_context,
3232
sdk_context,
@@ -54,7 +54,7 @@
5454
"HeaderContextProvider",
5555
"IAS_CLAIMS",
5656
"IASContextProvider",
57-
"RequestContext",
57+
"RuntimeContext",
5858
"RequestEnvelope",
5959
"TENANT_ID",
6060
"TRIGGER_TYPE",

src/sap_cloud_sdk/core/runtime_context/_context.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
T = TypeVar("T")
1010

1111

12-
class RequestContext:
12+
class RuntimeContext:
1313
"""Immutable typed bag of caller-identity values for the current execution.
1414
1515
Values are keyed by :class:`ContextKey` instances, which carry the
@@ -20,7 +20,7 @@ class RequestContext:
2020
2121
MY_KEY = ContextKey[str]("my_key")
2222
23-
ctx = RequestContext({MY_KEY: "hello"})
23+
ctx = RuntimeContext({MY_KEY: "hello"})
2424
ctx.get(MY_KEY) # -> "hello"
2525
"""
2626

@@ -31,41 +31,41 @@ def get(self, key: ContextKey[T]) -> Optional[T]:
3131
"""Return the value for *key*, or ``None`` if not set."""
3232
return self._values.get(key)
3333

34-
def with_value(self, key: ContextKey[T], value: T) -> "RequestContext":
35-
"""Return a new RequestContext with *key* set to *value*."""
36-
return RequestContext({**self._values, key: value})
34+
def with_value(self, key: ContextKey[T], value: T) -> "RuntimeContext":
35+
"""Return a new RuntimeContext with *key* set to *value*."""
36+
return RuntimeContext({**self._values, key: value})
3737

3838
def _raw(self) -> Dict[ContextKey, Any]:
3939
"""Return a shallow copy of the internal values dict."""
4040
return dict(self._values)
4141

4242
def __repr__(self) -> str:
4343
pairs = ", ".join(f"{k.name}={v!r}" for k, v in self._values.items())
44-
return f"RequestContext({{{pairs}}})"
44+
return f"RuntimeContext({{{pairs}}})"
4545

4646

47-
_EMPTY = RequestContext()
47+
_EMPTY = RuntimeContext()
4848

49-
_context_var: ContextVar[RequestContext] = ContextVar(
49+
_context_var: ContextVar[RuntimeContext] = ContextVar(
5050
"sap_sdk_request_context", default=_EMPTY
5151
)
5252

5353

54-
def set_context(ctx: RequestContext) -> None:
54+
def set_context(ctx: RuntimeContext) -> None:
5555
"""Set the runtime context for the current async/thread scope."""
5656
_context_var.set(ctx)
5757

5858

59-
def get_context() -> RequestContext:
59+
def get_context() -> RuntimeContext:
6060
"""Return the runtime context for the current async/thread scope.
6161
62-
Returns an empty :class:`RequestContext` when no context has been set.
62+
Returns an empty :class:`RuntimeContext` when no context has been set.
6363
"""
6464
return _context_var.get()
6565

6666

6767
@contextmanager
68-
def sdk_context(ctx: RequestContext) -> Generator[RequestContext, None, None]:
68+
def sdk_context(ctx: RuntimeContext) -> Generator[RuntimeContext, None, None]:
6969
"""Sync context manager that sets *ctx* for the duration of the block."""
7070
token = _context_var.set(ctx)
7171
try:
@@ -76,8 +76,8 @@ def sdk_context(ctx: RequestContext) -> Generator[RequestContext, None, None]:
7676

7777
@asynccontextmanager
7878
async def async_sdk_context(
79-
ctx: RequestContext,
80-
) -> AsyncGenerator[RequestContext, None]:
79+
ctx: RuntimeContext,
80+
) -> AsyncGenerator[RuntimeContext, None]:
8181
"""Async context manager that sets *ctx* for the duration of the block."""
8282
token = _context_var.set(ctx)
8383
try:

src/sap_cloud_sdk/core/runtime_context/_keys.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
"""Typed context key for RequestContext."""
1+
"""Typed context key for RuntimeContext."""
22

33
from typing import Generic, TypeVar
44

55
T = TypeVar("T")
66

77

88
class ContextKey(Generic[T]):
9-
"""A typed key for reading and writing values in a :class:`RequestContext`.
9+
"""A typed key for reading and writing values in a :class:`RuntimeContext`.
1010
1111
Each provider defines its own keys. The type parameter ensures consumers
12-
get the right type back from :meth:`RequestContext.get`.
12+
get the right type back from :meth:`RuntimeContext.get`.
1313
1414
Example::
1515
1616
MY_KEY = ContextKey[str]("my_key")
1717
18-
ctx = RequestContext({MY_KEY: "value"})
18+
ctx = RuntimeContext({MY_KEY: "value"})
1919
ctx.get(MY_KEY) # -> "value"
2020
"""
2121

src/sap_cloud_sdk/core/runtime_context/_protocol.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
from typing import Protocol, runtime_checkable
44

5-
from sap_cloud_sdk.core.runtime_context._context import RequestContext
5+
from sap_cloud_sdk.core.runtime_context._context import RuntimeContext
66
from sap_cloud_sdk.core.runtime_context._envelope import RequestEnvelope
77

88

99
@runtime_checkable
1010
class ContextProvider(Protocol):
11-
"""Extracts a :class:`RequestContext` from a :class:`RequestEnvelope`.
11+
"""Extracts a :class:`RuntimeContext` from a :class:`RequestEnvelope`.
1212
1313
Implement this to add a new auth provider or header convention. The envelope
1414
is framework-agnostic — providers never touch Starlette, Flask, or gRPC types.
@@ -18,10 +18,10 @@ class ContextProvider(Protocol):
1818
MY_KEY = ContextKey[str]("my_key")
1919
2020
class MyProvider(ContextProvider):
21-
def extract(self, envelope: RequestEnvelope) -> RequestContext:
21+
def extract(self, envelope: RequestEnvelope) -> RuntimeContext:
2222
value = envelope.headers.get("x-my-header", "")
23-
return RequestContext({MY_KEY: value} if value else {})
23+
return RuntimeContext({MY_KEY: value} if value else {})
2424
"""
2525

26-
def extract(self, envelope: RequestEnvelope) -> RequestContext: # pragma: no cover
26+
def extract(self, envelope: RequestEnvelope) -> RuntimeContext: # pragma: no cover
2727
...

src/sap_cloud_sdk/core/runtime_context/providers/_headers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""SAP standard headers context provider."""
22

3-
from sap_cloud_sdk.core.runtime_context._context import RequestContext
3+
from sap_cloud_sdk.core.runtime_context._context import RuntimeContext
44
from sap_cloud_sdk.core.runtime_context._envelope import RequestEnvelope
55
from sap_cloud_sdk.core.runtime_context._keys import TRIGGER_TYPE
66
from sap_cloud_sdk.core.runtime_context._protocol import ContextProvider
@@ -15,9 +15,9 @@ class HeaderContextProvider(ContextProvider):
1515
from ``x-sap-origin``
1616
"""
1717

18-
def extract(self, envelope: RequestEnvelope) -> RequestContext:
18+
def extract(self, envelope: RequestEnvelope) -> RuntimeContext:
1919
values = {}
2020
origin = envelope.headers.get("x-sap-origin")
2121
if origin:
2222
values[TRIGGER_TYPE] = origin
23-
return RequestContext(values)
23+
return RuntimeContext(values)

src/sap_cloud_sdk/core/runtime_context/providers/_ias.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""IAS context provider and its typed keys."""
22

3-
from sap_cloud_sdk.core.runtime_context._context import RequestContext
3+
from sap_cloud_sdk.core.runtime_context._context import RuntimeContext
44
from sap_cloud_sdk.core.runtime_context._envelope import RequestEnvelope
55
from sap_cloud_sdk.core.runtime_context._keys import ContextKey
66
from sap_cloud_sdk.core.runtime_context._protocol import ContextProvider
@@ -24,7 +24,7 @@ class IASContextProvider(ContextProvider):
2424
- :data:`IAS_CLAIMS` full :class:`~sap_cloud_sdk.ias.IASClaims` object
2525
"""
2626

27-
def extract(self, envelope: RequestEnvelope) -> RequestContext:
27+
def extract(self, envelope: RequestEnvelope) -> RuntimeContext:
2828
auth = envelope.headers.get("authorization", "")
2929

3030
claims = None
@@ -42,4 +42,4 @@ def extract(self, envelope: RequestEnvelope) -> RequestContext:
4242
values[USER_ID] = claims.user_uuid
4343
values[IAS_CLAIMS] = claims
4444

45-
return RequestContext(values)
45+
return RuntimeContext(values)

src/sap_cloud_sdk/core/runtime_context/starlette.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, List
44

55
from sap_cloud_sdk.core.runtime_context._context import (
6-
RequestContext,
6+
RuntimeContext,
77
async_sdk_context,
88
)
99
from sap_cloud_sdk.core.runtime_context._envelope import RequestEnvelope
@@ -20,21 +20,21 @@
2020
) from exc
2121

2222

23-
def _merge(contexts: List[RequestContext]) -> RequestContext:
24-
"""Merge multiple RequestContexts — first writer wins per key."""
23+
def _merge(contexts: List[RuntimeContext]) -> RuntimeContext:
24+
"""Merge multiple RuntimeContexts — first writer wins per key."""
2525
merged: dict = {}
2626
for ctx in contexts:
2727
for key, value in ctx._raw().items():
2828
merged.setdefault(key, value)
29-
return RequestContext(merged)
29+
return RuntimeContext(merged)
3030

3131

3232
class StarletteContextMiddleware(BaseHTTPMiddleware):
3333
"""Starlette/FastAPI middleware that populates the SDK runtime context.
3434
3535
Builds a :class:`~sap_cloud_sdk.core.runtime_context.RequestEnvelope` from
3636
each inbound request, runs all *providers* against it, and merges the results
37-
into a single :class:`~sap_cloud_sdk.core.runtime_context.RequestContext`
37+
into a single :class:`~sap_cloud_sdk.core.runtime_context.RuntimeContext`
3838
available via :func:`~sap_cloud_sdk.core.runtime_context.get_context` for
3939
the duration of that request.
4040

src/sap_cloud_sdk/core/runtime_context/user-guide.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ information came from or what framework is running.
1313
```
1414
bootstrap(app)
1515
└─ registers middleware on your framework
16-
└─ on each invocation: providers extract → RequestContext set in ContextVar
16+
└─ on each invocation: providers extract → RuntimeContext set in ContextVar
1717
└─ anywhere: get_context().get(TENANT_ID)
1818
```
1919

@@ -73,7 +73,7 @@ keys. Always import the key from the module that defined it.
7373

7474
## Providers
7575

76-
A provider extracts a `RequestContext` from a `RequestEnvelope` — a
76+
A provider extracts a `RuntimeContext` from a `RequestEnvelope` — a
7777
framework-agnostic carrier of whatever signals were available at invocation time
7878
(headers, body, metadata). The provider doesn't know which framework built the
7979
envelope; the framework adapter doesn't know what the provider does with it.
@@ -94,15 +94,15 @@ metadata or a message queue envelope — as long as the adapter populates
9494

9595
```python
9696
from sap_cloud_sdk.core.runtime_context import (
97-
ContextKey, ContextProvider, RequestContext, RequestEnvelope
97+
ContextKey, ContextProvider, RuntimeContext, RequestEnvelope
9898
)
9999

100100
CORRELATION_ID = ContextKey[str]("correlation_id")
101101

102102
class CorrelationIdProvider(ContextProvider):
103-
def extract(self, envelope: RequestEnvelope) -> RequestContext:
103+
def extract(self, envelope: RequestEnvelope) -> RuntimeContext:
104104
value = envelope.headers.get("x-correlation-id")
105-
return RequestContext({CORRELATION_ID: value} if value else {})
105+
return RuntimeContext({CORRELATION_ID: value} if value else {})
106106
```
107107

108108
Pass it to `bootstrap`:
@@ -159,16 +159,16 @@ When there is no framework to bootstrap — unit tests, CLI tools, background
159159
jobs — set the context directly for the duration of a block:
160160

161161
```python
162-
from sap_cloud_sdk.core.runtime_context import sdk_context, RequestContext, TENANT_ID, USER_ID
162+
from sap_cloud_sdk.core.runtime_context import sdk_context, RuntimeContext, TENANT_ID, USER_ID
163163

164164
# Sync:
165-
with sdk_context(RequestContext({TENANT_ID: "test-tenant", USER_ID: "test-user"})):
165+
with sdk_context(RuntimeContext({TENANT_ID: "test-tenant", USER_ID: "test-user"})):
166166
result = some_sdk_call()
167167

168168
# Async:
169169
from sap_cloud_sdk.core.runtime_context import async_sdk_context
170170

171-
async with async_sdk_context(RequestContext({TENANT_ID: "test-tenant"})):
171+
async with async_sdk_context(RuntimeContext({TENANT_ID: "test-tenant"})):
172172
result = await some_async_sdk_call()
173173
```
174174

0 commit comments

Comments
 (0)