potiuk commented on a change in pull request #4500: [AIRFLOW-3681] All GCP
operators have now optional GCP Project ID
URL: https://github.com/apache/airflow/pull/4500#discussion_r247326239
##########
File path: airflow/contrib/hooks/gcp_sql_hook.py
##########
@@ -682,15 +703,22 @@ class CloudSqlDatabaseHook(BaseHook):
* **sslcert** - Path to client certificate to authenticate when SSL is
used.
* **sslkey** - Path to client private key to authenticate when SSL is used.
* **sslrootcert** - Path to server's certificate to authenticate when SSL
is used.
+
+ :param gcp_cloudsql_conn_id: URL of the connection
+ :type gcp_cloudsql_conn_id: str
+ :param default_gcp_project_id: Default project id used if project_id not
specified
+ in the connection URL
+ :type default_gcp_project_id: str
"""
_conn = None
- def __init__(self, gcp_cloudsql_conn_id='google_cloud_sql_default'):
+ def __init__(self, gcp_cloudsql_conn_id='google_cloud_sql_default',
+ default_gcp_project_id=None):
super(CloudSqlDatabaseHook, self).__init__(source=None)
self.gcp_cloudsql_conn_id = gcp_cloudsql_conn_id
self.cloudsql_connection =
self.get_connection(self.gcp_cloudsql_conn_id)
self.extras = self.cloudsql_connection.extra_dejson
- self.project_id = self.extras.get('project_id')
+ self.project_id = self.extras.get('project_id', default_gcp_project_id)
Review comment:
Not really. This case is different. Cloud SQL query can have project_id
specified in "extras" - so for example
cloudsql://host:port/dbname?project_id=xx&sslcert=xxx....
If this is not specified, then we should take it from the GCP connection.
There are two different connections passed to cloud SQL query operation - one
is the "DB" cloudsql://" connection and the other is the GCP connection that is
used to start Cloud SQL Proxy (if needed) - The 'cloud sql proxy' authenticates
using a GCP connection (google_cloud_default by default).
The default project id is exactly for that reason - it is passed from the
GCP connection as separate "default" parameter.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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