@@ -69,7 +69,6 @@ def asyncify_connection():
6969
7070 instance_name = os .environ .get ("CLOUD_SQL_INSTANCE_NAME" )
7171 user = os .environ .get ("CLOUD_SQL_USER" )
72- password = os .environ .get ("CLOUD_SQL_PASSWORD" )
7372 database = os .environ .get ("CLOUD_SQL_DATABASE" )
7473 use_iam_auth = get_bool_env ("CLOUD_SQL_IAM_AUTH" , True )
7574 ip_type = os .environ .get ("CLOUD_SQL_IP_TYPE" , "public" )
@@ -80,10 +79,11 @@ def asyncify_connection():
8079 "enable_iam_auth" : use_iam_auth ,
8180 "ip_type" : ip_type ,
8281 }
83- if use_iam_auth :
84- connect_kwargs ["password" ] = get_iam_login_token ()
85- else :
86- connect_kwargs ["password" ] = password
82+ if not use_iam_auth :
83+ raise RuntimeError (
84+ "CLOUD_SQL_IAM_AUTH must be true when DB_DRIVER=cloudsql."
85+ )
86+ connect_kwargs ["password" ] = get_iam_login_token ()
8787
8888 connection = connector .connect_async (instance_name , "asyncpg" , ** connect_kwargs )
8989
@@ -106,7 +106,6 @@ def asyncify_connection():
106106 def init_connection_pool (connector ):
107107 instance_name = os .environ .get ("CLOUD_SQL_INSTANCE_NAME" )
108108 user = os .environ .get ("CLOUD_SQL_USER" )
109- password = os .environ .get ("CLOUD_SQL_PASSWORD" )
110109 database = os .environ .get ("CLOUD_SQL_DATABASE" )
111110 use_iam_auth = get_bool_env ("CLOUD_SQL_IAM_AUTH" , True )
112111 ip_type = os .environ .get ("CLOUD_SQL_IP_TYPE" , "public" )
@@ -118,10 +117,11 @@ def getconn():
118117 "ip_type" : ip_type ,
119118 "enable_iam_auth" : use_iam_auth ,
120119 }
121- if use_iam_auth :
122- connect_kwargs ["password" ] = get_iam_login_token ()
123- else :
124- connect_kwargs ["password" ] = password
120+ if not use_iam_auth :
121+ raise RuntimeError (
122+ "CLOUD_SQL_IAM_AUTH must be true when DB_DRIVER=cloudsql."
123+ )
124+ connect_kwargs ["password" ] = get_iam_login_token ()
125125
126126 conn = connector .connect (
127127 instance_name , # The Cloud SQL instance name
0 commit comments