From a117fcbba669b4a1eea6dbb4af34e1cd8c51efa5 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Sat, 22 Mar 2025 03:01:38 +0100 Subject: [PATCH] Fix formatting --- .pre-commit-config.yaml | 4 +++- .rustfmt.toml | 2 ++ queries/src/lib.rs | 4 ++-- src/context.rs | 6 ++---- src/lldap.rs | 12 ++++++------ src/main.rs | 22 +++++++++++----------- src/resources/mod.rs | 5 ++--- src/resources/service_user.rs | 3 ++- 8 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e73bdb..9b4ee7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,10 +22,12 @@ repos: - id: fmt name: fmt description: Format files with cargo fmt. - entry: cargo fmt + entry: cargo +nightly fmt language: system types: [rust] args: ["--", "--check"] + # For some reason some formatting is different depending on how you invoke? + pass_filenames: false - id: clippy name: clippy 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/queries/src/lib.rs b/queries/src/lib.rs index 59d2987..74ce27b 100644 --- a/queries/src/lib.rs +++ b/queries/src/lib.rs @@ -88,9 +88,9 @@ pub struct GetGroups { #[cfg(test)] mod tests { + use cynic::{MutationBuilder, QueryBuilder}; + use super::*; - use cynic::MutationBuilder; - use cynic::QueryBuilder; #[test] fn delete_user_gql_output() { diff --git a/src/context.rs b/src/context.rs index 3b11436..cc265d6 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,9 +1,7 @@ use async_trait::async_trait; use k8s_openapi::api::core::v1::Secret; -use kube::{ - runtime::events::{Event, EventType, Recorder, Reporter}, - Resource, ResourceExt, -}; +use kube::runtime::events::{Event, EventType, Recorder, Reporter}; +use kube::{Resource, ResourceExt}; use crate::lldap::LldapConfig; diff --git a/src/lldap.rs b/src/lldap.rs index 256ac87..a3f4bd1 100644 --- a/src/lldap.rs +++ b/src/lldap.rs @@ -1,19 +1,19 @@ -use anyhow::Context; -use lldap_auth::opaque::AuthenticationError; -use lldap_auth::registration::ServerRegistrationStartResponse; -use lldap_auth::{opaque, registration}; -use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION}; use std::time::Duration; -use tracing::{debug, trace}; +use anyhow::Context; use cynic::http::{CynicReqwestError, ReqwestExt}; use cynic::{GraphQlError, GraphQlResponse, MutationBuilder, QueryBuilder}; use lldap_auth::login::{ClientSimpleLoginRequest, ServerLoginResponse}; +use lldap_auth::opaque::AuthenticationError; +use lldap_auth::registration::ServerRegistrationStartResponse; +use lldap_auth::{opaque, registration}; use queries::{ AddUserToGroup, AddUserToGroupVariables, CreateUser, CreateUserVariables, DeleteUser, DeleteUserVariables, GetGroups, GetUser, GetUserVariables, Group, RemoveUserFromGroup, RemoveUserFromGroupVariables, User, }; +use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue}; +use tracing::{debug, trace}; #[derive(thiserror::Error, Debug)] pub enum Error { diff --git a/src/main.rs b/src/main.rs index f6366bd..70b8203 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,18 @@ -use std::{sync::Arc, time::Duration}; +use std::sync::Arc; +use std::time::Duration; use futures::StreamExt; use k8s_openapi::api::core::v1::Secret; -use kube::{ - runtime::{controller::Action, Controller}, - Api, Client as KubeClient, -}; -use lldap_controller::{ - context::Context, - lldap::LldapConfig, - resources::{self, reconcile, ServiceUser}, -}; +use kube::runtime::Controller; +use kube::runtime::controller::Action; +use kube::{Api, Client as KubeClient}; +use lldap_controller::context::Context; +use lldap_controller::lldap::LldapConfig; +use lldap_controller::resources::{self, ServiceUser, reconcile}; use tracing::{debug, info, warn}; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry}; +use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::{EnvFilter, Registry}; fn error_policy(_obj: Arc, err: &resources::Error, _ctx: Arc) -> Action { warn!("error: {}", err); diff --git a/src/resources/mod.rs b/src/resources/mod.rs index b09f9a9..8a5ad1d 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -8,15 +8,14 @@ use k8s_openapi::NamespaceResourceScope; use kube::runtime::controller::Action; use kube::runtime::finalizer; use kube::{Api, Resource, ResourceExt}; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use tracing::{debug, instrument}; +pub use self::service_user::ServiceUser; use crate::context::Context; use crate::lldap; -pub use service_user::ServiceUser; - #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Failed to commit: {0}")] diff --git a/src/resources/service_user.rs b/src/resources/service_user.rs index 88ca83b..d4aaf93 100644 --- a/src/resources/service_user.rs +++ b/src/resources/service_user.rs @@ -229,9 +229,10 @@ impl Reconcile for ServiceUser { #[cfg(test)] mod tests { - use super::*; use kube::CustomResourceExt; + use super::*; + #[test] fn service_user_crd_output() { insta::assert_yaml_snapshot!(ServiceUser::crd());