From 7ee0fa5742041e3719f5328b4fe43d7d2b152d4a Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Thu, 16 Sep 2021 22:34:05 +0100 Subject: [PATCH] Clean up SSH keys page --- Cargo.lock | 8 ++++++++ chartered-db/Cargo.toml | 2 ++ chartered-db/src/crates.rs | 14 ++++++++++---- chartered-db/src/users.rs | 23 ++++++++++++++++++++++- chartered-frontend/src/index.sass | 4 ++++ chartered-web/src/main.rs | 1 - chartered-frontend/src/pages/SingleCrate.tsx | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------- chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx | 35 ++++++++++++++++++++++++++--------- chartered-web/src/endpoints/web_api/crate_info.rs | 5 ++++- 9 files changed, 142 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82e042f..5ad4bfc 100644 --- a/Cargo.lock +++ a/Cargo.lock @@ -92,6 +92,12 @@ ] [[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] name = "base64ct" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -186,6 +192,7 @@ name = "chartered-db" version = "0.1.0" dependencies = [ + "base64", "bitflags", "chartered-fs", "chartered-types", @@ -193,6 +200,7 @@ "diesel", "displaydoc", "dotenv", + "hex", "itertools", "rand", "serde", diff --git a/chartered-db/Cargo.toml b/chartered-db/Cargo.toml index b3305ba..3f25c0e 100644 --- a/chartered-db/Cargo.toml +++ a/chartered-db/Cargo.toml @@ -9,10 +9,12 @@ chartered-fs = { path = "../chartered-fs" } chartered-types = { path = "../chartered-types" } +base64 = "0.13" bitflags = "1" chrono = "0.4" diesel = { version = "1", features = ["sqlite", "r2d2", "chrono"] } displaydoc = "0.2" +hex = "0.4" itertools = "0.10" rand = "0.8" serde = { version = "1", features = ["derive"] } diff --git a/chartered-db/src/crates.rs b/chartered-db/src/crates.rs index 5cf0abd..8c5f079 100644 --- a/chartered-db/src/crates.rs +++ a/chartered-db/src/crates.rs @@ -37,7 +37,13 @@ impl<'a> CrateVersion<'a> { #[must_use] - pub fn into_cargo_format(self, crate_: &'a Crate) -> (chartered_types::cargo::CrateVersion<'a>, chartered_types::cargo::CrateVersionMetadata) { + pub fn into_cargo_format( + self, + crate_: &'a Crate, + ) -> ( + chartered_types::cargo::CrateVersion<'a>, + chartered_types::cargo::CrateVersionMetadata, + ) { ( chartered_types::cargo::CrateVersion { name: crate_.name.as_str().into(), @@ -52,7 +58,7 @@ repository: self.repository, homepage: self.homepage, documentation: self.documentation, - } + }, ) } } @@ -183,8 +189,8 @@ metadata: chartered_types::cargo::CrateVersionMetadata, ) -> Result<()> { use crate::schema::crate_versions::dsl::{ - checksum, crate_id, crate_versions, dependencies, features, filesystem_object, links, - version, description, readme, repository, homepage, documentation, + checksum, crate_id, crate_versions, dependencies, description, documentation, features, + filesystem_object, homepage, links, readme, repository, version, }; tokio::task::spawn_blocking(move || { diff --git a/chartered-db/src/users.rs b/chartered-db/src/users.rs index f0e6c40..e62ce4a 100644 --- a/chartered-db/src/users.rs +++ a/chartered-db/src/users.rs @@ -84,8 +84,7 @@ let mut split = ssh_key.split_whitespace(); let key = match (split.next(), split.next()) { - (Some(_), Some(key)) => key, - (Some(key), None) => key, + (Some(_), Some(key)) | (Some(key), None) => key, _ => return Err(thrussh_keys::Error::CouldNotReadKey.into()), }; @@ -152,7 +151,25 @@ ( id, thrussh_keys::key::parse_public_key(&key) - .map(|v| v.fingerprint()) + .map_err(|e| e.into()) + .and_then(|v| { + let raw_hex = hex::encode( + base64::decode(&v.fingerprint()) + .map_err(|_| thrussh_keys::Error::CouldNotReadKey)?, + ); + let mut hex = + String::with_capacity(raw_hex.len() + (raw_hex.len() / 2 - 1)); + + for (i, c) in raw_hex.chars().enumerate() { + if i != 0 && i % 2 == 0 { + hex.push(':'); + } + + hex.push(c); + } + + Ok::<_, crate::Error>(hex) + }) .unwrap_or_else(|e| format!("INVALID: {}", e)), ) }) diff --git a/chartered-frontend/src/index.sass b/chartered-frontend/src/index.sass index 24de3bd..30c06c3 100644 --- a/chartered-frontend/src/index.sass +++ a/chartered-frontend/src/index.sass @@ -15,3 +15,7 @@ background: #f5f2f0 padding: .1rem .2rem border-radius: 3px + +td.fit, th.fit + width: 0.1% + white-space: nowrap diff --git a/chartered-web/src/main.rs b/chartered-web/src/main.rs index ae2c61b..75f6620 100644 --- a/chartered-web/src/main.rs +++ a/chartered-web/src/main.rs @@ -12,7 +12,6 @@ use tower::ServiceBuilder; use tower_http::cors::{Any, CorsLayer}; - #[allow(clippy::unused_async)] async fn hello_world() -> &'static str { "hello, world!" diff --git a/chartered-frontend/src/pages/SingleCrate.tsx b/chartered-frontend/src/pages/SingleCrate.tsx index 6beb4d2..b68829a 100644 --- a/chartered-frontend/src/pages/SingleCrate.tsx +++ a/chartered-frontend/src/pages/SingleCrate.tsx @@ -157,58 +157,77 @@ } function Members(props: { crateInfo: any }) { - return
-
- - -
- Johnny Davidson (that's you!)
- Owner -
-
- -
- - -
- Will Woodwood
- -
-
- -
- - -
- Ben Dover
- -
-
- -
- - -
- Eline Dover
- -
-
- -
- + const x = ["John Paul", "David Davidson", "Andrew Smith"]; + + return
+
+ + + {x.map(v => + + + + + + + + )} + + + + + + + + + +
+ + + {v}
+ (that's you!) +
+
+
+
+ + +
+ +
+ + +
+
+ +
+
+ + +
+ +
+ + +
+
+
+
+
+ +
+
; }diff --git a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx b/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx index 914f0e4..e2c9359 100644 --- a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx +++ a/chartered-frontend/src/pages/ssh-keys/ListSshKeys.tsx @@ -65,18 +65,29 @@
-
    - {sshKeys.keys.map(key => ( -
  • -
    -
    {key.fingerprint}
    -
    - -
    -
    -
  • - ))} -
+
+ + + {sshKeys.keys.map(key => ( + + + + + + ))} + +
+
{key.fingerprint}
+
+
Added on 10 May 2016
+
Last used within the last week
+
+
+ +
+
Add New diff --git a/chartered-web/src/endpoints/web_api/crate_info.rs b/chartered-web/src/endpoints/web_api/crate_info.rs index 8933fe0..3db842c 100644 --- a/chartered-web/src/endpoints/web_api/crate_info.rs +++ a/chartered-web/src/endpoints/web_api/crate_info.rs @@ -50,7 +50,10 @@ .into_iter() .map(|v| { let (inner, meta) = v.into_cargo_format(&crate_); - ResponseVersion { inner: inner.into_owned(), meta } + ResponseVersion { + inner: inner.into_owned(), + meta, + } }) .collect(), })) -- rgit 0.1.3