From e21c9fd428091afde99ddeb91c9086a8b694d25f Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Wed, 16 Apr 2025 03:00:07 +0200 Subject: [PATCH] Reformat imports properly --- .rustfmt.toml | 2 ++ src/bin/generate_key.rs | 3 ++- src/helper/animals.rs | 3 ++- src/io/stats.rs | 14 ++++++-------- src/io/terminal_handle.rs | 9 ++++----- src/main.rs | 17 +++++++++-------- src/ssh/handler.rs | 24 ++++++++++++------------ src/ssh/mod.rs | 15 ++++++++++----- src/ssh/renderer.rs | 14 ++++++-------- src/tunnel/mod.rs | 9 ++++----- src/tunnel/registry.rs | 11 +++++------ src/web/auth.rs | 6 ++---- src/web/mod.rs | 25 ++++++++++++------------- src/web/response.rs | 3 ++- 14 files changed, 78 insertions(+), 77 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..3a3f3f1 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,2 @@ +imports_granularity = "Module" +group_imports = "StdExternalCrate" diff --git a/src/bin/generate_key.rs b/src/bin/generate_key.rs index f12c3d9..7b90853 100644 --- a/src/bin/generate_key.rs +++ b/src/bin/generate_key.rs @@ -2,7 +2,8 @@ use clap::Parser; use clio::Output; use color_eyre::eyre::Context; use rand::rngs::OsRng; -use russh::keys::ssh_key::{LineEnding, sec1::der::Writer}; +use russh::keys::ssh_key::LineEnding; +use russh::keys::ssh_key::sec1::der::Writer; /// Simple program to generate a new private key in the correct format #[derive(Debug, Parser)] diff --git a/src/helper/animals.rs b/src/helper/animals.rs index 6e5f2f8..3067f07 100644 --- a/src/helper/animals.rs +++ b/src/helper/animals.rs @@ -1,6 +1,7 @@ use std::sync::LazyLock; -use rand::{rngs::OsRng, seq::SliceRandom}; +use rand::rngs::OsRng; +use rand::seq::SliceRandom; pub fn get_animal_name() -> &'static str { static ANIMALS: LazyLock> = LazyLock::new(|| { diff --git a/src/io/stats.rs b/src/io/stats.rs index fb19e06..8f465a5 100644 --- a/src/io/stats.rs +++ b/src/io/stats.rs @@ -1,16 +1,14 @@ -use std::{ - pin::Pin, - sync::Arc, - task::{Context, Poll}, -}; +use std::pin::Pin; +use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::task::{Context, Poll}; use pin_project_lite::pin_project; -use russh::{ChannelStream, server::Msg}; +use russh::ChannelStream; +use russh::server::Msg; use crate::helper::Unit; -use std::sync::atomic::{AtomicUsize, Ordering}; - #[derive(Debug, Default)] pub struct Stats { connections: AtomicUsize, diff --git a/src/io/terminal_handle.rs b/src/io/terminal_handle.rs index 0bc83b0..0d9841f 100644 --- a/src/io/terminal_handle.rs +++ b/src/io/terminal_handle.rs @@ -1,8 +1,7 @@ -use crossterm::{ - execute, - terminal::{EnterAlternateScreen, LeaveAlternateScreen}, -}; -use russh::{ChannelId, server::Handle}; +use crossterm::execute; +use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen}; +use russh::ChannelId; +use russh::server::Handle; use tokio::sync::mpsc::{UnboundedSender, unbounded_channel}; use tracing::error; diff --git a/src/main.rs b/src/main.rs index e9a917b..b9d1139 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ -use std::{net::SocketAddr, path::Path}; +use std::net::SocketAddr; +use std::path::Path; use color_eyre::eyre::Context; use dotenvy::dotenv; @@ -7,13 +8,13 @@ use hyper_util::rt::TokioIo; use rand::rngs::OsRng; use tokio::net::TcpListener; use tracing::{error, info, warn}; -use tracing_subscriber::{EnvFilter, layer::SubscriberExt, util::SubscriberInitExt}; -use tunnel_rs::{ - ldap::Ldap, - ssh::Server, - tunnel::Registry, - web::{ForwardAuth, Service}, -}; +use tracing_subscriber::EnvFilter; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tunnel_rs::ldap::Ldap; +use tunnel_rs::ssh::Server; +use tunnel_rs::tunnel::Registry; +use tunnel_rs::web::{ForwardAuth, Service}; #[tokio::main] async fn main() -> color_eyre::Result<()> { diff --git a/src/ssh/handler.rs b/src/ssh/handler.rs index 36b270e..5d75766 100644 --- a/src/ssh/handler.rs +++ b/src/ssh/handler.rs @@ -1,19 +1,19 @@ -use std::{cmp::min, io::Write, iter::once}; +use std::cmp::min; +use std::io::Write; +use std::iter::once; use clap::Parser; -use ratatui::{Terminal, TerminalOptions, Viewport, layout::Rect, prelude::CrosstermBackend}; -use russh::{ - ChannelId, - keys::ssh_key::PublicKey, - server::{Auth, Msg, Session}, -}; +use ratatui::layout::Rect; +use ratatui::prelude::CrosstermBackend; +use ratatui::{Terminal, TerminalOptions, Viewport}; +use russh::ChannelId; +use russh::keys::ssh_key::PublicKey; +use russh::server::{Auth, Msg, Session}; use tracing::{debug, trace, warn}; -use crate::{ - io::{Input, TerminalHandle}, - ldap::{Ldap, LdapError}, - tunnel::{Registry, Tunnel, TunnelAccess}, -}; +use crate::io::{Input, TerminalHandle}; +use crate::ldap::{Ldap, LdapError}; +use crate::tunnel::{Registry, Tunnel, TunnelAccess}; /// Quickly create http tunnels for development #[derive(Parser, Debug)] diff --git a/src/ssh/mod.rs b/src/ssh/mod.rs index 58c7216..6b22bd7 100644 --- a/src/ssh/mod.rs +++ b/src/ssh/mod.rs @@ -1,15 +1,20 @@ mod handler; mod renderer; -use std::{net::SocketAddr, sync::Arc, time::Duration}; +use std::net::SocketAddr; +use std::sync::Arc; +use std::time::Duration; -use russh::{MethodKind, keys::PrivateKey, server::Server as _}; +use handler::Handler; +use renderer::Renderer; +use russh::MethodKind; +use russh::keys::PrivateKey; +use russh::server::Server as _; use tokio::net::ToSocketAddrs; use tracing::{debug, warn}; -use crate::{ldap::Ldap, tunnel::Registry}; -use handler::Handler; -use renderer::Renderer; +use crate::ldap::Ldap; +use crate::tunnel::Registry; pub struct Server { ldap: Ldap, diff --git a/src/ssh/renderer.rs b/src/ssh/renderer.rs index 9d157df..20f73c2 100644 --- a/src/ssh/renderer.rs +++ b/src/ssh/renderer.rs @@ -1,14 +1,12 @@ use std::cmp::{self, max}; use futures::StreamExt; -use ratatui::{ - Frame, - layout::{Constraint, Flex, Layout, Position, Rect}, - style::{Style, Stylize as _}, - text::{Line, Span, Text}, - widgets::{ - Block, BorderType, Cell, Clear, HighlightSpacing, Paragraph, Row, Table, TableState, - }, +use ratatui::Frame; +use ratatui::layout::{Constraint, Flex, Layout, Position, Rect}; +use ratatui::style::{Style, Stylize as _}; +use ratatui::text::{Line, Span, Text}; +use ratatui::widgets::{ + Block, BorderType, Cell, Clear, HighlightSpacing, Paragraph, Row, Table, TableState, }; use unicode_width::UnicodeWidthStr; diff --git a/src/tunnel/mod.rs b/src/tunnel/mod.rs index 477fdd1..3c92248 100644 --- a/src/tunnel/mod.rs +++ b/src/tunnel/mod.rs @@ -1,14 +1,13 @@ mod registry; mod tui; -use registry::RegistryEntry; use std::sync::Arc; -use tracing::trace; - -use russh::server::Handle; -use tokio::sync::{RwLock, RwLockReadGuard}; pub use registry::Registry; +use registry::RegistryEntry; +use russh::server::Handle; +use tokio::sync::{RwLock, RwLockReadGuard}; +use tracing::trace; use crate::io::{Stats, TrackStats}; diff --git a/src/tunnel/registry.rs b/src/tunnel/registry.rs index f053bae..cfc5fdf 100644 --- a/src/tunnel/registry.rs +++ b/src/tunnel/registry.rs @@ -1,14 +1,13 @@ -use std::{ - collections::{HashMap, hash_map::Entry}, - sync::Arc, -}; +use std::collections::HashMap; +use std::collections::hash_map::Entry; +use std::sync::Arc; use tokio::sync::RwLock; use tracing::trace; -use crate::{helper::get_animal_name, tunnel::Tunnel}; - use super::TunnelInner; +use crate::helper::get_animal_name; +use crate::tunnel::Tunnel; #[derive(Debug)] pub(crate) struct RegistryEntry { diff --git a/src/web/auth.rs b/src/web/auth.rs index e4d7d63..1e36398 100644 --- a/src/web/auth.rs +++ b/src/web/auth.rs @@ -1,7 +1,5 @@ -use hyper::{ - HeaderMap, Method, StatusCode, - header::{self, HeaderName, HeaderValue, ToStrError}, -}; +use hyper::header::{self, HeaderName, HeaderValue, ToStrError}; +use hyper::{HeaderMap, Method, StatusCode}; use reqwest::redirect::Policy; use tracing::{debug, error}; diff --git a/src/web/mod.rs b/src/web/mod.rs index 6718c57..58797a8 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -1,23 +1,22 @@ mod auth; mod response; -use crate::tunnel::Registry; -use std::{ops::Deref, pin::Pin}; +use std::ops::Deref; +use std::pin::Pin; -use bytes::Bytes; -use http_body_util::{BodyExt as _, Empty, combinators::BoxBody}; -use hyper::{ - Request, Response, StatusCode, - body::Incoming, - client::conn::http1::Builder, - header::{self, HOST}, -}; -use tracing::{debug, error, trace, warn}; - -use crate::tunnel::TunnelAccess; use auth::AuthStatus; pub use auth::ForwardAuth; +use bytes::Bytes; +use http_body_util::combinators::BoxBody; +use http_body_util::{BodyExt as _, Empty}; +use hyper::body::Incoming; +use hyper::client::conn::http1::Builder; +use hyper::header::{self, HOST}; +use hyper::{Request, Response, StatusCode}; use response::response; +use tracing::{debug, error, trace, warn}; + +use crate::tunnel::{Registry, TunnelAccess}; #[derive(Debug, Clone)] pub struct Service { diff --git a/src/web/response.rs b/src/web/response.rs index f470d12..8fbb72d 100644 --- a/src/web/response.rs +++ b/src/web/response.rs @@ -1,5 +1,6 @@ use bytes::Bytes; -use http_body_util::{BodyExt as _, Full, combinators::BoxBody}; +use http_body_util::combinators::BoxBody; +use http_body_util::{BodyExt as _, Full}; use hyper::{Response, StatusCode}; pub fn response(