mik-laj commented on a change in pull request #7439: [AIRFLOW-6204][depends on 
6763] Create GoogleSystemTest class
URL: https://github.com/apache/airflow/pull/7439#discussion_r380211437
 
 

 ##########
 File path: tests/test_utils/gcp_system_helpers.py
 ##########
 @@ -68,3 +77,92 @@ def provide_gcp_context(
     return provide_gcp_conn_and_credentials(
         key_file_path=key_file_path, scopes=scopes, project_id=project_id
     )
+
+
+class GoogleSystemTest(SystemTest):
+    @staticmethod
+    def _project_id():
+        return os.environ.get("GCP_PROJECT_ID")
+
+    @staticmethod
+    def _service_key():
+        return os.environ.get(CREDENTIALS)
+
+    @contextmanager
+    def authentication(self):
+        self.authenticate()
+        yield
+        self.revoke_authentication()
+
+    @classmethod
+    def authenticate(cls):
+        """
+        Authenticate with service account specified via key name.
+        Required only when we use gcloud / gsutil.
+        """
+        cls.executor.execute_cmd(
+            [
+                "gcloud",
+                "auth",
+                "activate-service-account",
+                f"--key-file={cls._service_key()}",
+                f"--project={cls._project_id()}",
+            ]
+        )
+
+    @classmethod
+    def revoke_authentication(cls):
+        """
+        Change default authentication to none - which is not existing one.
+        """
+        cls.executor.execute_cmd(
+            [
+                "gcloud",
+                "config",
+                "set",
+                "account",
+                "none",
+                f"--project={cls._project_id()}",
+            ]
+        )
+
+    @classmethod
+    def execute_with_ctx(cls, cmd: List[str], key: str = GCP_GCS_KEY):
+        """
+        Executes command with context created by provide_gcp_context and 
activated
+        service key.
+        """
+        with provide_gcp_context(key):
 
 Review comment:
   ```suggestion
           with provide_gcp_context(key), cls.authentication():
   ```

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


With regards,
Apache Git Services

Reply via email to