From 5cce24952a862658807ee33498ed6f828bebe34a Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Tue, 07 Sep 2021 14:27:24 +0100 Subject: [PATCH] personalised welcome message in git --- chartered-db/src/users.rs | 26 ++++++++++++++++++-------- chartered-git/src/main.rs | 10 ++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/chartered-db/src/users.rs b/chartered-db/src/users.rs index 16b1925..0d4ed6f 100644 --- a/chartered-db/src/users.rs +++ a/chartered-db/src/users.rs @@ -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> { 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, + pub id: i32, + pub user_id: i32, + pub ssh_key: Vec, } diff --git a/chartered-git/src/main.rs b/chartered-git/src/main.rs index 8a3dd58..9857680 100644 --- a/chartered-git/src/main.rs +++ a/chartered-git/src/main.rs @@ -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(); // todo + 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)) -- rgit 0.1.3