🏡 index : ~doyle/chartered.git

author Jordan Doyle <jordan@doyle.la> 2021-09-07 14:27:24.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2021-09-07 14:27:24.0 +01:00:00
commit
5cce24952a862658807ee33498ed6f828bebe34a [patch]
tree
d5dbfbae20f2b57106527cefe27a634d7c309f8b
parent
f21d2bbcdc599c4bb77bbb3fcfc37ba29bcd7035
download
5cce24952a862658807ee33498ed6f828bebe34a.tar.gz

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(-)

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<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>,
}
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))