yehoshuadimarsky edited a comment on issue #20660:
URL: https://github.com/apache/airflow/issues/20660#issuecomment-1006152110


   So I think I know how to fix it, but I'm at a loss how to test it. I've read 
all the Breeze stuff and the relevant test code.
   
   The fix:
   ```diff
   diff --git a/airflow/providers/google/cloud/hooks/cloud_sql.py 
b/airflow/providers/google/cloud/hooks/cloud_sql.py
   index 1b6766390..5275a46c3 100644
   --- a/airflow/providers/google/cloud/hooks/cloud_sql.py
   +++ b/airflow/providers/google/cloud/hooks/cloud_sql.py
   @@ -536,10 +536,10 @@ class CloudSqlProxyRunner(LoggingMixin):
                self.log.info(
                    "The credentials are not supplied by neither key_path nor "
                    "keyfile_dict of the gcp connection %s. Falling back to "
   -                "default activated account",
   +                "default activated account and using automatic IAM login",
                    self.gcp_conn_id,
                )
   -            credential_params = []
   +            credential_params = ["-enable_iam_login"]
    
            if not self.instance_specification:
                project_id = 
connection.extra_dejson.get('extra__google_cloud_platform__project')
   @@ -890,8 +890,6 @@ class CloudSQLDatabaseHook(BaseHook):
                raise AirflowException("The login parameter needs to be set in 
connection")
            if not self.public_ip:
                raise AirflowException("The location parameter needs to be set 
in connection")
   -        if not self.password:
   -            raise AirflowException("The password parameter needs to be set 
in connection")
            if not self.database:
                raise AirflowException("The database parameter needs to be set 
in connection")
   ```
   Ref: 
https://cloud.google.com/sql/docs/postgres/iam-logins#cloud-sql-auth-proxy
   
   Relevant parts of existing test code: 
   
https://github.com/apache/airflow/blob/68fa358c85d0ebe1aa22ace30b33867ad4e622a8/tests/providers/google/cloud/hooks/test_cloud_sql.py#L989-L1038
   and
   
https://github.com/apache/airflow/blob/68fa358c85d0ebe1aa22ace30b33867ad4e622a8/tests/providers/google/cloud/hooks/test_cloud_sql.py#L1122-L1135
   But I can't figure out how to test this kind of login within old-style 
`unittest` patching - any suggestions?


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