david30907d commented on a change in pull request #19508:
URL: https://github.com/apache/airflow/pull/19508#discussion_r800051016



##########
File path: airflow/providers/google/cloud/hooks/bigquery.py
##########
@@ -173,14 +175,26 @@ def get_sqlalchemy_engine(self, engine_kwargs=None):
         :return: the created engine.
         """
         connection = self.get_connection(self.gcp_conn_id)
-        extras = connection.extra_dejson
-        credentials_path = 
extras.get("extra__google_cloud_platform__key_path", None)
-        if credentials_path is None:
-            raise AirflowException(
-                "For now, we only support instantiating SQLAlchemy engine by"
-                " using extra__google_cloud_platform__key_path"
+        if os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") is not None:
+            return create_engine(self.get_uri(), **engine_kwargs)
+        elif 
connection.extra_dejson.get("extra__google_cloud_platform__key_path"):
+            credentials_path = 
connection.extra_dejson['extra__google_cloud_platform__key_path']
+            return create_engine(self.get_uri(), 
credentials_path=credentials_path, **engine_kwargs)
+        elif 
connection.extra_dejson.get("extra__google_cloud_platform__keyfile_dict"):
+            credential_file_content = json.loads(
+                
connection.extra_dejson["extra__google_cloud_platform__keyfile_dict"]
             )
-        return create_engine(self.get_uri(), 
credentials_path=credentials_path, **engine_kwargs)
+            self.log.info("Saving credentials to %s", self.credentials_path)
+            with open(self.credentials_path, "w") as file:
+                json.dump(credential_file_content, file)
+            return create_engine(self.get_uri(), 
credentials_path=self.credentials_path, **engine_kwargs)

Review comment:
       done~




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


Reply via email to