@@ -964,13 +964,28 @@ def _list_account_groups(self, scim_attributes: str) -> list[iam.Group]:
964964 # TODO: we should avoid using this method, as it's not documented
965965 # get account-level groups even if they're not (yet) assigned to a workspace
966966 logger .info (f"Listing account groups with { scim_attributes } ..." )
967- account_groups = []
968- raw = self ._ws .api_client .do ("GET" , "/api/2.0/account/scim/v2/Groups" , query = {"attributes" : scim_attributes })
969- for resource in raw .get ("Resources" , []): # type: ignore[union-attr]
970- group = iam .Group .from_dict (resource )
971- if group .display_name in SYSTEM_GROUPS :
972- continue
973- account_groups .append (group )
967+ account_groups : list [iam .Group ] = []
968+ # Paginate through the undocumented workspace-level account SCIM endpoint,
969+ # mirroring the pagination logic in the SDK's AccountGroupsAPI.list().
970+ seen : set [str ] = set ()
971+ query : dict [str , str | int ] = {"attributes" : scim_attributes , "startIndex" : 1 , "count" : 10000 }
972+ while True :
973+ raw = self ._ws .api_client .do ("GET" , "/api/2.0/account/scim/v2/Groups" , query = query )
974+ resources = raw .get ("Resources" , []) # type: ignore[union-attr]
975+ if not resources :
976+ break
977+ for resource in resources :
978+ group = iam .Group .from_dict (resource )
979+ if group .id and group .id in seen :
980+ continue
981+ if group .id :
982+ seen .add (group .id )
983+ if group .display_name in SYSTEM_GROUPS :
984+ continue
985+ account_groups .append (group )
986+ if len (resources ) < int (query ["count" ]):
987+ break
988+ query ["startIndex" ] = int (query ["startIndex" ]) + len (resources )
974989 logger .info (f"Found { len (account_groups )} account groups" )
975990 sorted_groups : list [iam .Group ] = sorted (
976991 account_groups , key = lambda _ : _ .display_name if _ .display_name else ""
0 commit comments