11//! Helper functions for submitting data to Zitadel
2- use std:: path:: PathBuf ;
2+ use std:: { path:: PathBuf , pin :: pin } ;
33
44use anyhow:: { anyhow, bail, Context , Result } ;
55use base64:: prelude:: { Engine , BASE64_STANDARD } ;
@@ -15,10 +15,10 @@ use zitadel_rust_client::{
1515 } ,
1616 pagination:: PaginationParams ,
1717 users:: {
18- AddHumanUserRequest , AndQuery , IdpLink , InUserEmailsQuery , ListUsersRequest ,
19- Organization , OrganizationIdQuery , SearchQuery , SetHumanEmail , SetHumanPhone ,
20- SetHumanProfile , SetMetadataEntry , TypeQuery , UpdateHumanUserRequest ,
21- User as ZitadelUser , UserFieldName , Userv2Type ,
18+ AddHumanUserRequest , AndQuery , IdpLink , InUserEmailsQuery , Organization ,
19+ OrganizationIdQuery , SearchQuery , SetHumanEmail , SetHumanPhone , SetHumanProfile ,
20+ SetMetadataEntry , TypeQuery , UpdateHumanUserRequest , User as ZitadelUser ,
21+ UserFieldName , Userv2Type ,
2222 } ,
2323 Zitadel as ZitadelClient ,
2424 } ,
@@ -77,24 +77,23 @@ impl Zitadel {
7777 & mut self ,
7878 emails : Vec < String > ,
7979 ) -> Result < impl Stream < Item = Result < ( ZitadelUserBuilder , String ) > > + Send > {
80- self . zitadel_client
80+ Ok ( self
81+ . zitadel_client
8182 . list_users (
82- ListUsersRequest :: new ( vec ! [
83+ Some ( PaginationParams :: DEFAULT . with_asc ( true ) ) ,
84+ Some ( UserFieldName :: NickName ) ,
85+ Some ( vec ! [
8386 SearchQuery :: new( ) . with_type_query( TypeQuery :: new( Userv2Type :: Human ) ) ,
8487 SearchQuery :: new( ) . with_in_user_emails_query(
8588 InUserEmailsQuery :: new( ) . with_user_emails( emails) ,
8689 ) ,
87- ] )
88- . with_asc ( true )
89- . with_sorting_column ( UserFieldName :: NickName ) ,
90- )
91- . map ( |stream| {
92- stream. map ( |user| {
93- let id = user. user_id ( ) . ok_or ( anyhow ! ( "Missing Zitadel user ID" ) ) ?. clone ( ) ;
94- let user = search_result_to_user ( user) ?;
95- Ok ( ( user, id) )
96- } )
97- } )
90+ ] ) ,
91+ ) ?
92+ . and_then ( |user| async {
93+ let id = user. user_id ( ) . ok_or ( anyhow ! ( "Missing Zitadel user ID" ) ) ?. clone ( ) ;
94+ let user = search_result_to_user ( user) ?;
95+ Ok ( ( user, id) )
96+ } ) )
9897 }
9998
10099 /// Return a stream of Zitadel users
@@ -107,18 +106,16 @@ impl Zitadel {
107106 Ok ( self
108107 . zitadel_client
109108 . list_users (
110- ListUsersRequest :: new ( vec ! [ SearchQuery :: new( ) . with_and_query(
111- AndQuery :: new( ) . with_queries( vec![
112- SearchQuery :: new( ) . with_type_query( TypeQuery :: new( Userv2Type :: Human ) ) ,
113- SearchQuery :: new( ) . with_organization_id_query( OrganizationIdQuery :: new(
114- self . zitadel_config. organization_id. clone( ) ,
115- ) ) ,
116- ] ) ,
117- ) ] )
118- . with_asc ( true )
119- . with_sorting_column ( UserFieldName :: NickName ) ,
109+ Some ( PaginationParams :: DEFAULT . with_asc ( true ) ) ,
110+ Some ( UserFieldName :: NickName ) ,
111+ Some ( vec ! [ SearchQuery :: new( ) . with_and_query( AndQuery :: new( ) . with_queries( vec![
112+ SearchQuery :: new( ) . with_type_query( TypeQuery :: new( Userv2Type :: Human ) ) ,
113+ SearchQuery :: new( ) . with_organization_id_query( OrganizationIdQuery :: new(
114+ self . zitadel_config. organization_id. clone( ) ,
115+ ) ) ,
116+ ] ) ) ] ) ,
120117 ) ?
121- . map ( |user| {
118+ . and_then ( |user| async {
122119 let id = user. user_id ( ) . context ( "Missing Zitadel user ID" ) ?. clone ( ) ;
123120 let user = search_result_to_user ( user) ?;
124121 Ok ( ( user, id) )
@@ -157,23 +154,18 @@ impl Zitadel {
157154 /// Return a vector of a random sample of Zitadel users
158155 /// We use this to determine the encoding of the external IDs
159156 pub async fn get_users_sample ( & mut self ) -> Result < Vec < User > > {
160- let mut stream = self
157+ let mut stream = pin ! ( self
161158 . zitadel_client
162159 . list_users(
163- ListUsersRequest :: new ( vec ! [
164- SearchQuery :: new( ) . with_type_query( TypeQuery :: new( Userv2Type :: Human ) )
165- ] )
166- . with_asc ( true )
167- . with_sorting_column ( UserFieldName :: NickName )
168- . with_page_size ( USER_SAMPLE_SIZE ) ,
169- )
170- . map ( |stream| {
171- stream. map ( |user| {
172- let id = user. user_id ( ) . ok_or ( anyhow ! ( "Missing Zitadel user ID" ) ) ?. clone ( ) ;
173- let user = search_result_to_user ( user) ?;
174- Ok ( ( user, id) )
175- } )
176- } ) ?;
160+ Some ( PaginationParams :: DEFAULT . with_asc( true ) . with_page_size( USER_SAMPLE_SIZE ) ) ,
161+ Some ( UserFieldName :: NickName ) ,
162+ Some ( vec![ SearchQuery :: new( ) . with_type_query( TypeQuery :: new( Userv2Type :: Human ) ) ] )
163+ ) ?
164+ . and_then( |user| async {
165+ let id = user. user_id( ) . ok_or( anyhow!( "Missing Zitadel user ID" ) ) ?. clone( ) ;
166+ let user = search_result_to_user( user) ?;
167+ Ok ( ( user, id) )
168+ } ) ) ;
177169
178170 let mut users = Vec :: new ( ) ;
179171
0 commit comments