Skip to content

Commit

Permalink
fix(CloudSqlProxyRunner): don't query connections from Airflow DB (#1…
Browse files Browse the repository at this point in the history
…8006)

Instead of directly querying connections from Airflow DB we use
`get_connection()` which also support external secrets backends.

Fixes: #18003
  • Loading branch information
m1racoli committed Sep 3, 2021
1 parent 867e930 commit 21348c1
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions airflow/providers/google/cloud/hooks/cloud_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import httpx
from googleapiclient.discovery import Resource, build
from googleapiclient.errors import HttpError
from sqlalchemy.orm import Session

from airflow.exceptions import AirflowException

Expand All @@ -51,7 +50,6 @@
from airflow.providers.mysql.hooks.mysql import MySqlHook
from airflow.providers.postgres.hooks.postgres import PostgresHook
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.session import provide_session

UNIX_PATH_MAX = 108

Expand Down Expand Up @@ -516,10 +514,9 @@ def _download_sql_proxy_if_needed(self) -> None:
os.chmod(self.sql_proxy_path, 0o744) # Set executable bit
self.sql_proxy_was_downloaded = True

@provide_session
def _get_credential_parameters(self, session: Session) -> List[str]:
connection = session.query(Connection).filter(Connection.conn_id == self.gcp_conn_id).first()
session.expunge_all()
def _get_credential_parameters(self) -> List[str]:
connection = GoogleBaseHook.get_connection(conn_id=self.gcp_conn_id)

if connection.extra_dejson.get(GCP_CREDENTIALS_KEY_PATH):
credential_params = ['-credential_file', connection.extra_dejson[GCP_CREDENTIALS_KEY_PATH]]
elif connection.extra_dejson.get(GCP_CREDENTIALS_KEYFILE_DICT):
Expand Down

0 comments on commit 21348c1

Please sign in to comment.