From be56ca3f3759c258eedcaaf1d49eee74983b8dad Mon Sep 17 00:00:00 2001 From: Nicholas Dujay Date: Tue, 21 Feb 2023 13:04:50 -0500 Subject: [PATCH 1/4] implement show users --- src/admin.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/admin.rs b/src/admin.rs index 71d3e486..92f68661 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -100,6 +100,10 @@ where trace!("SHOW VERSION"); show_version(stream).await } + "USERS" => { + trace!("SHOW USERS"); + show_users(stream).await + } _ => error_response(stream, "Unsupported SHOW query against the admin database").await, }, _ => error_response(stream, "Unsupported query against the admin database").await, @@ -666,3 +670,30 @@ where } } } + +/// Show Users. +async fn show_users(stream: &mut T) -> Result<(), Error> +where + T: tokio::io::AsyncWrite + std::marker::Unpin, +{ + let res = BytesMut::new(); + + res.put(row_description(&vec![ + ("name", DataType::Text), + ("pool_mode", DataType::Text), + ])); + + for (user_pool, pool) in get_all_pools() { + let pool_config = &pool.settings; + let mut row = vec![user_pool.user.clone(), pool_config.pool_mode.to_string()]; + res.put(data_row(&row)); + } + + res.put(command_complete("SHOW")); + + res.put_u8(b'Z'); + res.put_i32(5); + res.put_u8(b'I'); + + write_all_half(stream, &res).await +} From f9ef5bd1984909ad428e02f2663f845339ded677 Mon Sep 17 00:00:00 2001 From: Nicholas Dujay Date: Tue, 21 Feb 2023 14:53:09 -0500 Subject: [PATCH 2/4] fix compile errors --- src/admin.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/admin.rs b/src/admin.rs index 92f68661..406b0fe0 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -676,7 +676,7 @@ async fn show_users(stream: &mut T) -> Result<(), Error> where T: tokio::io::AsyncWrite + std::marker::Unpin, { - let res = BytesMut::new(); + let mut res = BytesMut::new(); res.put(row_description(&vec![ ("name", DataType::Text), @@ -685,8 +685,10 @@ where for (user_pool, pool) in get_all_pools() { let pool_config = &pool.settings; - let mut row = vec![user_pool.user.clone(), pool_config.pool_mode.to_string()]; - res.put(data_row(&row)); + res.put(data_row(&vec![ + user_pool.user.clone(), + pool_config.pool_mode.to_string(), + ])); } res.put(command_complete("SHOW")); From 5d1aa1b4dc4eddcd78039f6a8bcb8fdbe3d4b763 Mon Sep 17 00:00:00 2001 From: Nicholas Dujay Date: Tue, 21 Feb 2023 15:54:19 -0500 Subject: [PATCH 3/4] add basic ruby test --- tests/ruby/admin_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/ruby/admin_spec.rb b/tests/ruby/admin_spec.rb index 2000e5d9..78364156 100644 --- a/tests/ruby/admin_spec.rb +++ b/tests/ruby/admin_spec.rb @@ -286,4 +286,14 @@ connections.map(&:close) end end + + describe "SHOW users" do + it "returns the right users" do + admin_conn = PG::connect(processes.pgcat.admin_connection_string) + results = admin_conn.async_exec("SHOW USERS")[0] + admin_conn.close + expect(results["name"]).to eq("sharding_user") + expect(results["pool_mode"]).to eq("transaction") + end + end end From a15f082187ae8c9a8677b25d7708ef2087215d10 Mon Sep 17 00:00:00 2001 From: Nicholas Dujay Date: Tue, 21 Feb 2023 15:54:54 -0500 Subject: [PATCH 4/4] gitignore things --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3c654539..cf28bffe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .idea /target *.deb -.vscode \ No newline at end of file +.vscode +.profraw +cov/ +lcov.info