@@ -66,14 +66,43 @@ impl UserManager {
66
66
Err ( ConnectionError :: ClusterAllNodesFailed ( error_buffer. join ( "\n " ) ) ) ?
67
67
}
68
68
69
- // pub fn all() -> Vec<User> {
70
- //
71
- // }
72
- // async fn run_failsafe<F, P, R>(&self, name: String, task: F) -> Result<R>
73
- // where
74
- // F: Fn(ServerDatabase, ServerConnection, bool) -> P,
75
- // P: Future<Output = Result<R>>,
76
- // {
77
- // Database::get(name, self.connection.clone()).await?.run_failsafe(&task).await
78
- // }
69
+ pub async fn create ( & self , username : String , password : String ) -> Result < ( ) > {
70
+ let mut error_buffer = Vec :: with_capacity ( self . connection . server_count ( ) ) ;
71
+ for server_connection in self . connection . connections ( ) {
72
+ match server_connection. create_user ( username. clone ( ) , password. clone ( ) ) . await {
73
+ Ok ( ( ) ) => {
74
+ return Ok ( ( ) ) ;
75
+ }
76
+ Err ( err) => error_buffer. push ( format ! ( "- {}: {}" , server_connection. address( ) , err) ) ,
77
+ }
78
+ }
79
+ Err ( ConnectionError :: ClusterAllNodesFailed ( error_buffer. join ( "\n " ) ) ) ?
80
+ }
81
+
82
+ pub async fn delete ( & self , username : String ) -> Result < ( ) > {
83
+ let mut error_buffer = Vec :: with_capacity ( self . connection . server_count ( ) ) ;
84
+ for server_connection in self . connection . connections ( ) {
85
+ match server_connection. delete_user ( username. clone ( ) ) . await {
86
+ Ok ( ( ) ) => {
87
+ return Ok ( ( ) ) ;
88
+ }
89
+ Err ( err) => error_buffer. push ( format ! ( "- {}: {}" , server_connection. address( ) , err) ) ,
90
+ }
91
+ }
92
+ Err ( ConnectionError :: ClusterAllNodesFailed ( error_buffer. join ( "\n " ) ) ) ?
93
+ }
94
+
95
+ pub async fn set_password ( & self , username : String , password : String ) -> Result < ( ) > {
96
+ let mut error_buffer = Vec :: with_capacity ( self . connection . server_count ( ) ) ;
97
+ for server_connection in self . connection . connections ( ) {
98
+ match server_connection. set_user_password ( username. clone ( ) , password. clone ( ) ) . await {
99
+ Ok ( ( ) ) => {
100
+ return Ok ( ( ) ) ;
101
+ }
102
+ Err ( err) => error_buffer. push ( format ! ( "- {}: {}" , server_connection. address( ) , err) ) ,
103
+ }
104
+ }
105
+ Err ( ConnectionError :: ClusterAllNodesFailed ( error_buffer. join ( "\n " ) ) ) ?
106
+ }
107
+
79
108
}
0 commit comments