This is an automated email from the ASF dual-hosted git repository.
amoghdesai pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 50234fa1043 Add IP validation to example_dag_decorator DAG (#54136)
50234fa1043 is described below
commit 50234fa1043ea616634464e409dbad92d5366da8
Author: Nacl122 <[email protected]>
AuthorDate: Thu Aug 7 14:30:41 2025 +0800
Add IP validation to example_dag_decorator DAG (#54136)
---
.../src/airflow/example_dags/example_dag_decorator.py | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/airflow-core/src/airflow/example_dags/example_dag_decorator.py
b/airflow-core/src/airflow/example_dags/example_dag_decorator.py
index 9216805a7f3..9f6e637c917 100644
--- a/airflow-core/src/airflow/example_dags/example_dag_decorator.py
+++ b/airflow-core/src/airflow/example_dags/example_dag_decorator.py
@@ -17,6 +17,8 @@
# under the License.
from __future__ import annotations
+import ipaddress
+
# [START dag_decorator_usage]
from typing import TYPE_CHECKING, Any
@@ -60,9 +62,13 @@ def example_dag_decorator(url: str =
"http://httpbin.org/get"):
@task(multiple_outputs=True)
def prepare_command(raw_json: dict[str, Any]) -> dict[str, str]:
external_ip = raw_json["origin"]
- return {
- "command": f"echo 'Seems like today your server executing Airflow
is connected from IP {external_ip}'",
- }
+ try:
+ ipaddress.ip_address(external_ip)
+ return {
+ "command": f"echo 'Seems like today your server executing
Airflow is connected from IP {external_ip}'",
+ }
+ except ValueError:
+ raise ValueError(f"Invalid IP address: '{external_ip}'.")
command_info = prepare_command(get_ip.output)