Lee-W commented on code in PR #54102:
URL: https://github.com/apache/airflow/pull/54102#discussion_r2253279066
##########
airflow-core/src/airflow/example_dags/example_dag_decorator.py:
##########
@@ -22,13 +22,21 @@
import httpx
import pendulum
-
+import ipaddress
from airflow.providers.standard.operators.bash import BashOperator
from airflow.sdk import BaseOperator, dag, task
if TYPE_CHECKING:
from airflow.sdk import Context
+def is_ip(address: str) -> bool:
+ """Check if the provided address is a valid IP address (supports IPv4 and
IPv6)."""
+ try:
+ # Try to convert the address to an IP address (supports both IPv4 and
IPv6)
+ ipaddress.ip_address(address)
+ return True
+ except ValueError:
+ return False
Review Comment:
There was a discussion long ago (on Slack, so it's no longer there) about
not using `AirflowException` when not needed, as it's vague.
If any exception should do, then maybe we could try
```python
raise ValueError(f"Invalid IP address: '{external_ip}'.")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]