Bases: BaseModel
Limits the HTTP requests a node makes to public IPv4 addresses, and bounds their size and duration.
The host that runs workflows for others sets it: for every run with set_default_egress_policy(), or for one run
with RunnableConfig.egress. The HTTP API call node applies it; without a policy it connects anywhere, as before.
Attributes:
| Name |
Type |
Description |
exempt_url_prefixes |
tuple[str, ...]
|
URLs on the host's private network that its own tools call, such as
"http://tools.internal/v1/conversations//". A request skips the address check when its scheme, host
and port match a prefix and its path is the prefix's path or below it. Every redirect is checked again.
|
timeout_seconds |
float
|
The most one request may take, redirects and reading the body included. It also caps the
node's own timeout.
|
max_response_bytes |
int
|
The most a response body may hold once decoded.
|
max_redirects |
int
|
The most redirects one request follows.
|
exempt_request_headers |
tuple[str, ...]
|
Header names an exempt request may carry besides the ones the clients set themselves,
those that describe the body, "Authorization" and "Cookie", such as "X-Api-Key". Names that frame a request
or that a front end routes by are refused.
|
Source code in dynamiq/types/egress.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 | class EgressPolicy(BaseModel):
"""Limits the HTTP requests a node makes to public IPv4 addresses, and bounds their size and duration.
The host that runs workflows for others sets it: for every run with `set_default_egress_policy()`, or for one run
with `RunnableConfig.egress`. The HTTP API call node applies it; without a policy it connects anywhere, as before.
Attributes:
exempt_url_prefixes: URLs on the host's private network that its own tools call, such as
"http://tools.internal/v1/conversations/<id>/". A request skips the address check when its scheme, host
and port match a prefix and its path is the prefix's path or below it. Every redirect is checked again.
timeout_seconds: The most one request may take, redirects and reading the body included. It also caps the
node's own timeout.
max_response_bytes: The most a response body may hold once decoded.
max_redirects: The most redirects one request follows.
exempt_request_headers: Header names an exempt request may carry besides the ones the clients set themselves,
those that describe the body, "Authorization" and "Cookie", such as "X-Api-Key". Names that frame a request
or that a front end routes by are refused.
"""
model_config = ConfigDict(frozen=True)
exempt_url_prefixes: tuple[str, ...] = ()
timeout_seconds: float = Field(default=120, gt=0)
max_response_bytes: int = Field(default=1024 * 1024, gt=0)
max_redirects: int = Field(default=10, ge=0)
exempt_request_headers: tuple[str, ...] = ()
@field_validator("exempt_url_prefixes")
@classmethod
def validate_exempt_url_prefixes(cls, prefixes: tuple[str, ...]) -> tuple[str, ...]:
for prefix in prefixes:
parts = urlsplit(prefix)
if _origin_and_path(prefix) is None or parts.query or parts.fragment or _has_ambiguous_segment(parts.path):
raise ValueError(
f"An exempt URL prefix must be an http or https URL with a host and a plain path: {prefix!r}."
)
return prefixes
@field_validator("exempt_request_headers")
@classmethod
def validate_exempt_request_headers(cls, names: tuple[str, ...]) -> tuple[str, ...]:
for name in names:
lowered = name.lower()
if (
not HEADER_NAME.match(name)
or lowered in ROUTING_HEADER_NAMES
or lowered.startswith(ROUTING_HEADER_PREFIXES)
):
raise ValueError(f"An exempt request may not be allowed the header {name!r}.")
return names
def is_exempt(self, url: str) -> bool:
"""Reports whether a request to url skips the address check."""
target = _origin_and_path(url)
if target is None or not self.exempt_url_prefixes:
return False
origin, path = target
if _has_ambiguous_segment(path):
return False
for prefix in self.exempt_url_prefixes:
prefix_origin, prefix_path = _origin_and_path(prefix)
prefix_path = prefix_path.rstrip("/")
if origin == prefix_origin and (path == prefix_path or path.startswith(prefix_path + "/")):
return True
return False
|
is_exempt(url)
Reports whether a request to url skips the address check.
Source code in dynamiq/types/egress.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126 | def is_exempt(self, url: str) -> bool:
"""Reports whether a request to url skips the address check."""
target = _origin_and_path(url)
if target is None or not self.exempt_url_prefixes:
return False
origin, path = target
if _has_ambiguous_segment(path):
return False
for prefix in self.exempt_url_prefixes:
prefix_origin, prefix_path = _origin_and_path(prefix)
prefix_path = prefix_path.rstrip("/")
if origin == prefix_origin and (path == prefix_path or path.startswith(prefix_path + "/")):
return True
return False
|