personalised welcome message in git
Diff
chartered-db/src/users.rs | 26 ++++++++++++++++++--------
chartered-git/src/main.rs | 10 ++++++++++
2 files changed, 23 insertions(+), 13 deletions(-)
@@ -7,8 +7,8 @@
#[derive(Identifiable, Queryable, Associations, PartialEq, Eq, Hash, Debug)]
pub struct User {
id: i32,
username: String,
pub id: i32,
pub username: String,
}
impl User {
@@ -37,6 +37,8 @@
) -> Result<Option<User>> {
use crate::schema::user_ssh_keys::dsl::*;
eprintln!("looking up by ssh key: {:x?}", given_ssh_key);
tokio::task::spawn_blocking(move || {
let conn = conn.get().unwrap();
@@ -54,24 +56,24 @@
#[derive(Identifiable, Queryable, Associations, PartialEq, Eq, Hash, Debug)]
#[belongs_to(User)]
pub struct UserApiKey {
id: i32,
user_id: i32,
api_key: String,
pub id: i32,
pub user_id: i32,
pub api_key: String,
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Eq, Hash, Debug)]
#[belongs_to(User)]
pub struct UserCratePermission {
id: i32,
user_id: i32,
crate_id: i32,
permissions: i32,
pub id: i32,
pub user_id: i32,
pub crate_id: i32,
pub permissions: i32,
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Eq, Hash, Debug)]
#[belongs_to(User)]
pub struct UserSshKey {
id: i32,
user_id: i32,
ssh_key: Vec<u8>,
pub id: i32,
pub user_id: i32,
pub ssh_key: Vec<u8>,
}
@@ -78,6 +78,13 @@
CryptoVec::from_slice(self.output_bytes.split().as_ref()),
);
}
fn user(&self) -> Result<&chartered_db::users::User, anyhow::Error> {
match self.user {
Some(ref user) => Ok(user),
None => anyhow::bail!("user not set after auth"),
}
}
}
type AsyncHandlerFn = Pin<
@@ -115,7 +122,8 @@
fn shell_request(mut self, channel: ChannelId, mut session: Session) -> Self::FutureUnit {
Box::pin(async move {
write!(&mut self.output_bytes, "Hi there! You've successfully authenticated, but chartered does not provide shell access.\r\n")?;
let username = self.user()?.username.clone();
write!(&mut self.output_bytes, "Hi there, {}! You've successfully authenticated, but chartered does not provide shell access.\r\n", username)?;
self.flush(&mut session, channel);
session.close(channel);
Ok((self, session))