You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Nacl122 (via GitHub)" <gi...@apache.org> on 2025/08/04 17:45:13 UTC
[PR] Add function to check origin IP [airflow]
Nacl122 opened a new pull request, #54102:
URL: https://github.com/apache/airflow/pull/54102
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #54102:
URL: https://github.com/apache/airflow/pull/54102#discussion_r2253256658
##########
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:
would suggest adding a new exception instead of using AirflowException. something like `AirflowInvalidIPError`
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #54102:
URL: https://github.com/apache/airflow/pull/54102#discussion_r2253235142
##########
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:
Maybe try:
```
raise AirflowException(f"Invalid IP address: '{external_ip}'.")
```
##########
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:
UX wise and my personal take on this: for an invalid IP, there will be a silent failure and no real way for user to know that it is a bad practice being followed. I would rather that we raise this exception so that the task fails and it's evident what went wrong.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #54102:
URL: https://github.com/apache/airflow/pull/54102#discussion_r2253270119
##########
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:
I do not see a real reason to do that, any exception should do tbh. This is mostly a one-off case and adding a new type solely for that doesn't justify it to me
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on PR #54102:
URL: https://github.com/apache/airflow/pull/54102#issuecomment-3154376506
Also @Nacl122 the static tests on the PR are failing, setting up precommit locally helps a lot, you can repro CI failures locally and fix them. Here's a reference: https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #54102:
URL: https://github.com/apache/airflow/pull/54102#issuecomment-3151796318
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-pre-commit-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "amoghrajesh (via GitHub)" <gi...@apache.org>.
amoghrajesh commented on code in PR #54102:
URL: https://github.com/apache/airflow/pull/54102#discussion_r2253284959
##########
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:
Oh I do not recall that but it does make sense. ValueError works
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "Nacl122 (via GitHub)" <gi...@apache.org>.
Nacl122 closed pull request #54102: Add function to check origin IP
URL: https://github.com/apache/airflow/pull/54102
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add function to check origin IP [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #54102:
URL: https://github.com/apache/airflow/pull/54102#discussion_r2253244959
##########
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:
Agree with @amoghrajesh
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org