Skip to content

Commit 37e1c52

Browse files
authored
implement show users (#329)
* implement show users * fix compile errors * add basic ruby test * gitignore things
1 parent 28f2d19 commit 37e1c52

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
.idea
22
/target
33
*.deb
4-
.vscode
4+
.vscode
5+
.profraw
6+
cov/
7+
lcov.info

src/admin.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ where
100100
trace!("SHOW VERSION");
101101
show_version(stream).await
102102
}
103+
"USERS" => {
104+
trace!("SHOW USERS");
105+
show_users(stream).await
106+
}
103107
_ => error_response(stream, "Unsupported SHOW query against the admin database").await,
104108
},
105109
_ => error_response(stream, "Unsupported query against the admin database").await,
@@ -666,3 +670,32 @@ where
666670
}
667671
}
668672
}
673+
674+
/// Show Users.
675+
async fn show_users<T>(stream: &mut T) -> Result<(), Error>
676+
where
677+
T: tokio::io::AsyncWrite + std::marker::Unpin,
678+
{
679+
let mut res = BytesMut::new();
680+
681+
res.put(row_description(&vec![
682+
("name", DataType::Text),
683+
("pool_mode", DataType::Text),
684+
]));
685+
686+
for (user_pool, pool) in get_all_pools() {
687+
let pool_config = &pool.settings;
688+
res.put(data_row(&vec![
689+
user_pool.user.clone(),
690+
pool_config.pool_mode.to_string(),
691+
]));
692+
}
693+
694+
res.put(command_complete("SHOW"));
695+
696+
res.put_u8(b'Z');
697+
res.put_i32(5);
698+
res.put_u8(b'I');
699+
700+
write_all_half(stream, &res).await
701+
}

tests/ruby/admin_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,14 @@
286286
connections.map(&:close)
287287
end
288288
end
289+
290+
describe "SHOW users" do
291+
it "returns the right users" do
292+
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
293+
results = admin_conn.async_exec("SHOW USERS")[0]
294+
admin_conn.close
295+
expect(results["name"]).to eq("sharding_user")
296+
expect(results["pool_mode"]).to eq("transaction")
297+
end
298+
end
289299
end

0 commit comments

Comments
 (0)