Skip to content

implement show users #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea
/target
*.deb
.vscode
.vscode
.profraw
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these files were generated by the test suite when I ran them locally

cov/
lcov.info
33 changes: 33 additions & 0 deletions src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -666,3 +670,32 @@ where
}
}
}

/// Show Users.
async fn show_users<T>(stream: &mut T) -> Result<(), Error>
where
T: tokio::io::AsyncWrite + std::marker::Unpin,
{
let mut 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;
res.put(data_row(&vec![
user_pool.user.clone(),
pool_config.pool_mode.to_string(),
]));
}

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
}
10 changes: 10 additions & 0 deletions tests/ruby/admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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