Skip to content

Commit

Permalink
[AIRFLOW-5801] Get GCP credentials from file instead of JSON blob (#7869
Browse files Browse the repository at this point in the history
)

* fix assumption of getting gcp credentials from file instead of JSON blob

* fix deprecation warning
  • Loading branch information
ephraimbuddy authored Mar 26, 2020
1 parent a6fd74e commit 5f165f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions airflow/providers/google/cloud/hooks/cloud_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,12 @@ 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()
if GCP_CREDENTIALS_KEY_PATH in connection.extra_dejson:
if connection.extra_dejson.get(GCP_CREDENTIALS_KEY_PATH):
credential_params = [
'-credential_file',
connection.extra_dejson[GCP_CREDENTIALS_KEY_PATH]
]
elif GCP_CREDENTIALS_KEYFILE_DICT in connection.extra_dejson:
elif connection.extra_dejson.get(GCP_CREDENTIALS_KEYFILE_DICT):
credential_file_content = json.loads(
connection.extra_dejson[GCP_CREDENTIALS_KEYFILE_DICT])
self.log.info("Saving credentials to %s", self.credentials_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/google/cloud/hooks/test_cloud_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ def test_cloudsql_database_hook_get_database_hook(self, get_connection):

class TestCloudSqlDatabaseQueryHook(unittest.TestCase):

@mock.patch('airflow.contrib.hooks.gcp_sql_hook.CloudSQLDatabaseHook.get_connection')
@mock.patch('airflow.providers.google.cloud.hooks.cloud_sql.CloudSQLDatabaseHook.get_connection')
def setUp(self, m):
super().setUp()

Expand Down

0 comments on commit 5f165f3

Please sign in to comment.