You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/11/27 05:46:50 UTC

[GitHub] [airflow] ephraimbuddy opened a new pull request #19851: Allow the use of Stable API in the CLI

ephraimbuddy opened a new pull request #19851:
URL: https://github.com/apache/airflow/pull/19851


   DETAILS LATER
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+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 [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
   


-- 
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



[GitHub] [airflow] ashb commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ashb commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-981788182


   It might be a bit of a chicken-and-egg when it comes to releasing but rather than writing another client we should use https://github.com/apache/airflow-client-python I think.


-- 
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



[GitHub] [airflow] ephraimbuddy commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-983505999


   > Prolly this `HTTPBasicAuth(user, password)`
   
   Didn't work
   
   


-- 
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



[GitHub] [airflow] ephraimbuddy commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-981790777


   > It might be a bit of a chicken-and-egg when it comes to releasing but rather than writing another client we should use https://github.com/apache/airflow-client-python I think.
   
   Yeah. The problem I'm currently facing is authentication. I'm trying to use it


-- 
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



[GitHub] [airflow] msumit commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
msumit commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-983472568


   > > @ephraimbuddy having `CLIENT_AUTH` as `None` in basic_auth seems like a bug to me. Maybe we can just fix that?
   > 
   > Yeah. It seems like a bug what I also don't understand is what should be there. In kerberos, there's something. I'm wondering what should be there for basic auth, likewise what other people using different other backends should have there. Here's kerberos:
   > 
   > https://github.com/apache/airflow/blob/43de625d4246af7014f64941f8effb09997731cb/airflow/api/auth/backend/kerberos_auth.py#L58
   
   Prolly this `HTTPBasicAuth(user, password)`


-- 
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



[GitHub] [airflow] msumit commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
msumit commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-983406072


   @ephraimbuddy having `CLIENT_AUTH` as `None` in basic_auth seems like a bug to me. Maybe we can just fix that?


-- 
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



[GitHub] [airflow] ephraimbuddy closed pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ephraimbuddy closed pull request #19851:
URL: https://github.com/apache/airflow/pull/19851


   


-- 
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



[GitHub] [airflow] ephraimbuddy commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-981799186


   > > > It might be a bit of a chicken-and-egg when it comes to releasing but rather than writing another client we should use https://github.com/apache/airflow-client-python I think.
   > > 
   > > 
   > > Yeah. The problem I'm currently facing is authentication. I'm trying to use it
   > 
   > Which authentication issue? I was able to do the POC without issues here -> https://github.com/msumit/airflow-cli
   
   In this one, I'm working towards having it as part of the existing CLI and having users choose whether to use LocalClient or RestAPI client. Now, I want it to work with the user-supplied auth_backend configuration


-- 
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



[GitHub] [airflow] ephraimbuddy commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-983443432


   > @ephraimbuddy having `CLIENT_AUTH` as `None` in basic_auth seems like a bug to me. Maybe we can just fix that?
   
   Yeah. It seems like a bug what I also don't understand is what should be there. In kerberos, there's something. I'm wondering what should be there for basic auth, likewise what other people using different other backends should have there.
   Here's kerberos: https://github.com/apache/airflow/blob/43de625d4246af7014f64941f8effb09997731cb/airflow/api/auth/backend/kerberos_auth.py#L58


-- 
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



[GitHub] [airflow] ephraimbuddy commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-992286436


   Closing for now


-- 
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



[GitHub] [airflow] uranusjr commented on a change in pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#discussion_r758145187



##########
File path: airflow/api/client/stable_api_client.py
##########
@@ -0,0 +1,114 @@
+# 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.
+
+from json.decoder import JSONDecodeError

Review comment:
       ```suggestion
   from json import JSONDecodeError
   ```

##########
File path: airflow/api/client/stable_api_client.py
##########
@@ -0,0 +1,114 @@
+# 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.
+
+from json.decoder import JSONDecodeError
+from typing import Optional
+from urllib.parse import urljoin
+
+from airflow.api.client import api_client
+from airflow.models import DagRun
+from airflow.utils.state import State
+
+
+class AirflowClient(api_client.Client):
+    """API Client using the stable REST API"""
+
+    def _request(self, url, method='GET', json=None):
+        params = {
+            'url': url,
+        }
+        if json is not None:
+            params['json'] = json
+        resp = getattr(self._session, method.lower())(**params)
+        if resp.is_error:
+            # It is justified here because there might be many resp types.
+            try:
+                data = resp.json()
+            except Exception:
+                data = {}
+            raise OSError(data.get('error', 'Server error'))
+        try:  # DELETE requests doesn't return a value
+            return resp.json()
+        except JSONDecodeError:
+            return resp.text

Review comment:
       Instead of trying to handle different methods differently, I’d just have a helper function `parse_response` that returns `str` (and raises on exception), and let the caller methods call `self._session` themselves. You can actually just do `self._session(method, url, ...)` directly (methods like `self._session.get()` are actually just convenience wrappers).

##########
File path: airflow/api/client/stable_api_client.py
##########
@@ -0,0 +1,114 @@
+# 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.
+
+from json.decoder import JSONDecodeError
+from typing import Optional
+from urllib.parse import urljoin
+
+from airflow.api.client import api_client
+from airflow.models import DagRun
+from airflow.utils.state import State
+
+
+class AirflowClient(api_client.Client):
+    """API Client using the stable REST API"""
+
+    def _request(self, url, method='GET', json=None):
+        params = {
+            'url': url,
+        }
+        if json is not None:
+            params['json'] = json
+        resp = getattr(self._session, method.lower())(**params)
+        if resp.is_error:
+            # It is justified here because there might be many resp types.
+            try:
+                data = resp.json()
+            except Exception:
+                data = {}
+            raise OSError(data.get('error', 'Server error'))
+        try:  # DELETE requests doesn't return a value
+            return resp.json()
+        except JSONDecodeError:
+            return resp.text
+
+    def trigger_dag(
+        self, *, dag_id, run_id=None, conf=None, execution_date=None, logical_date=None, state=State.QUEUED
+    ):
+        endpoint = f'/api/v1/dags/{dag_id}/dagRuns'
+        url = urljoin(self._api_base_url, endpoint)
+        data = self._request(
+            url,
+            method='POST',
+            json={
+                "dag_run_id": run_id,
+                "conf": conf or {},
+                "execution_date": execution_date,
+                "state": state,
+                "logical_date": logical_date,
+            },
+        )

Review comment:
       For example:
   
   ```python
   resp = self._session.request(
       "POST",
       urljoin(self._api_base_url, f"/api/v1/dags/{dag_id}/dagRuns"),
       json={
           "dag_run_id": run_id,
           "conf": conf or {},
           "state": state,
           "logical_date": logical_date,
       },
   )
   return json.loads(self._parse_response(resp))
   ```
   
   (BTW I think you only need `logical_date` here, `execution_date` is deprecated and just an alias to `execution_date`.)




-- 
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



[GitHub] [airflow] msumit commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
msumit commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-981793179


   > > It might be a bit of a chicken-and-egg when it comes to releasing but rather than writing another client we should use https://github.com/apache/airflow-client-python I think.
   > 
   > Yeah. The problem I'm currently facing is authentication. I'm trying to use it
   
   Which authentication issue? I was able to do the POC without issues here -> https://github.com/msumit/airflow-cli


-- 
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



[GitHub] [airflow] ephraimbuddy commented on pull request #19851: Allow the use of Stable API in the CLI

Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on pull request #19851:
URL: https://github.com/apache/airflow/pull/19851#issuecomment-983386280


   It looks like we can't possibly integrate the stable REST API into the current CLI because of authentication. I wonder if anyone knows what should be in auth backends CLIENT_AUTH. In basic auth backend it's `None` see https://github.com/apache/airflow/blob/d067cfea701b7077bfa6c0f2b5339848579ee184/airflow/api/auth/backend/basic_auth.py#L27
   
   This is supposed to be used by the REST API client as shown here https://github.com/apache/airflow/blob/d067cfea701b7077bfa6c0f2b5339848579ee184/airflow/api/client/__init__.py#L37
   
   @uranusjr @ashb @msumit will appreciate your guidance on this. Another option I'm thinking of now is creating an auth endpoint and having the airflow cli as a separate project that connects to airflow instance using the airflow rest client.
   
   
   


-- 
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