1818from google .auth .transport .requests import Request
1919import logging
2020import google .cloud .logging
21- from iam_groups_authn .sync import groups_sync
21+ from iam_groups_authn .sync import GroupRoleMaxLengthError , groups_sync
2222
2323# define OAuth2 scopes
2424SCOPES = [
@@ -65,6 +65,13 @@ async def run_groups_authn():
6565 400 ,
6666 )
6767
68+ group_roles = body .get ("group_roles" , dict ())
69+ if type (group_roles ) is not dict :
70+ return (
71+ "Incorrect type for request parameter: `group_roles`, should be dict/JSON" ,
72+ 400 ,
73+ )
74+
6875 # try reading in private_ip param, default to False
6976 private_ip = body .get ("private_ip" , False )
7077 if type (private_ip ) is not bool :
@@ -83,7 +90,13 @@ async def run_groups_authn():
8390 request = Request ()
8491 creds .refresh (request )
8592
86- # sync IAM groups to Cloud SQL instances
87- await groups_sync (iam_groups , sql_instances , creds , private_ip )
88-
93+ try :
94+ # sync IAM groups to Cloud SQL instances
95+ await groups_sync (iam_groups , sql_instances , creds , group_roles , private_ip )
96+ except GroupRoleMaxLengthError as e :
97+ logging .exception (f"Error during sync: { str (e )} " )
98+ return (
99+ str (e ),
100+ 400 ,
101+ )
89102 return "Sync successful." , 200
0 commit comments