potiuk commented on a change in pull request #10591:
URL: https://github.com/apache/airflow/pull/10591#discussion_r483921549



##########
File path: setup.py
##########
@@ -687,6 +687,7 @@ def is_package_excluded(package: str, exclusion_list: 
List[str]):
 INSTALL_REQUIREMENTS = [
     'alembic>=1.2, <2.0',
     'argcomplete~=1.10',
+    'arrow==0.16.0',

Review comment:
       You should create a "plexus" extra and add "arrow" to the extra , rather 
than to install requirements.

##########
File path: airflow/providers/plexus/hooks/plexus.py
##########
@@ -0,0 +1,73 @@
+# 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.
+
+import jwt
+import arrow
+import requests
+from airflow.hooks.base_hook import BaseHook
+from airflow.models import Variable
+from airflow.exceptions import AirflowException
+
+
+class PlexusHook(BaseHook):
+    """
+    Used for jwt token generation and storage to
+    make Plexus API calls. Requires email and password
+    Airflow variables be created.
+
+    Example:
+        - export AIRFLOW_VAR_EMAIL = [email protected]
+        - export AIRFLOW_VAR_PASSWORD = *******
+
+    """
+
+    def __init__(self) -> None:
+        super().__init__()
+        self.__token = None
+        self.__token_exp = None
+        self.host = "https://apiplexus.corescientific.com/";
+        self.user_id = None
+
+    def _generate_token(self):
+        login = Variable.get("email")
+        pwd = Variable.get("password")
+        if login is None or pwd is None:
+            raise AirflowException("No valid email/password supplied.")
+        token_endpoint = self.host + "sso/jwt-token/"
+        response = requests.post(token_endpoint, data={"email": login, 
"password": pwd}, timeout=5)
+        if not response.ok:
+            raise AirflowException(
+                "Could not retrieve JWT Token. Status Code: [{}]. "
+                "Reason: {} - {}".format(response.status_code, 
response.reason, response.text)
+            )
+        token = response.json()["access"]
+        payload = jwt.decode(token, verify=False)
+        self.user_id = payload["user_id"]
+        self.__token_exp = payload["exp"]
+
+        return token
+
+    @property

Review comment:
       Nice!

##########
File path: tests/providers/plexus/operators/test_plexus.py
##########
@@ -0,0 +1,189 @@
+# 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.
+
+import mock
+import pytest
+from mock import Mock
+from requests.exceptions import Timeout
+from airflow.exceptions import AirflowException
+from airflow.providers.plexus.operators.job import PlexusJobOperator
+
+
+class TestPlexusOperator:
+    @pytest.fixture

Review comment:
       Nice! We do not use pytest fixtures too much (we allow both unit tests 
style and pytest ones). But I think it's good to have more examples of nice 
pytest fixtures.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to