From 5a3dee2b8fcb7ee9cab8e2036af72dc0cb54c493 Mon Sep 17 00:00:00 2001 From: djkato Date: Fri, 10 Jan 2025 10:18:13 +0100 Subject: [PATCH] cargo clippy && cargo fmt --- app-template-ui/src/routes/api/webhooks.rs | 18 ++++++++++++++---- app-template/src/routes/manifest.rs | 2 +- bulk-price-manipulator/src/routes/register.rs | 5 +++-- bulk-price-manipulator/src/updater/mod.rs | 9 +++------ sdk/src/apl/file_apl.rs | 12 ++++++------ sdk/src/middleware/verify_webhook_signature.rs | 8 +++----- simple-payment-gateway/src/routes/manifest.rs | 2 +- sitemap-generator/src/tests/utils.rs | 7 ++++--- 8 files changed, 35 insertions(+), 28 deletions(-) diff --git a/app-template-ui/src/routes/api/webhooks.rs b/app-template-ui/src/routes/api/webhooks.rs index e432bfb..9735c52 100644 --- a/app-template-ui/src/routes/api/webhooks.rs +++ b/app-template-ui/src/routes/api/webhooks.rs @@ -4,7 +4,7 @@ use axum::{ }; use cynic::{http::SurfExt, MutationBuilder}; use saleor_app_sdk::{ - headers::{SALEOR_API_URL_HEADER,SALEOR_EVENT_HEADER}, + headers::{SALEOR_API_URL_HEADER, SALEOR_EVENT_HEADER}, webhooks::{ utils::{get_webhook_event_type, EitherWebhookType}, AsyncWebhookEventType, @@ -14,7 +14,15 @@ use saleor_app_sdk::{ use tracing::{debug, info}; use crate::{ - app::AppState, error_template::AxumError, queries::{event_products_updated::ProductUpdated, product_metadata_update::{MetadataInput, UpdateProductMetadata, UpdateProductMetadataVariables}} }; + app::AppState, + error_template::AxumError, + queries::{ + event_products_updated::ProductUpdated, + product_metadata_update::{ + MetadataInput, UpdateProductMetadata, UpdateProductMetadataVariables, + }, + }, +}; pub async fn webhooks( headers: HeaderMap, @@ -27,8 +35,10 @@ pub async fn webhooks( debug!("headers: {:?}", headers); let url = headers - .get(SALEOR_API_URL_HEADER).ok_or(AxumError::MissingHeader(SALEOR_API_URL_HEADER.to_owned()))?; - let event_type = get_webhook_event_type(&headers).map_err(|_|AxumError::MissingHeader(SALEOR_EVENT_HEADER.to_owned()))?; + .get(SALEOR_API_URL_HEADER) + .ok_or(AxumError::MissingHeader(SALEOR_API_URL_HEADER.to_owned()))?; + let event_type = get_webhook_event_type(&headers) + .map_err(|_| AxumError::MissingHeader(SALEOR_EVENT_HEADER.to_owned()))?; if let EitherWebhookType::Async(a) = event_type { match a { AsyncWebhookEventType::ProductUpdated diff --git a/app-template/src/routes/manifest.rs b/app-template/src/routes/manifest.rs index 3ab361c..481fa5c 100644 --- a/app-template/src/routes/manifest.rs +++ b/app-template/src/routes/manifest.rs @@ -1,5 +1,5 @@ use axum::{extract::State, Json}; -use saleor_app_sdk::{manifest::AppManifest}; +use saleor_app_sdk::manifest::AppManifest; use crate::app::{AppError, AppState}; diff --git a/bulk-price-manipulator/src/routes/register.rs b/bulk-price-manipulator/src/routes/register.rs index e84c610..7a9d8ea 100644 --- a/bulk-price-manipulator/src/routes/register.rs +++ b/bulk-price-manipulator/src/routes/register.rs @@ -45,10 +45,11 @@ pub async fn register( info!("Starting caching and generation process"); let cloned_state = state.clone(); - let _ = tokio::task::spawn(async { + std::mem::drop(tokio::task::spawn(async { if let Err(e) = update_prices(cloned_state, saleor_api_url).await { error!("{:?}", e); } - }); + })); + Ok(StatusCode::OK) } diff --git a/bulk-price-manipulator/src/updater/mod.rs b/bulk-price-manipulator/src/updater/mod.rs index e22167e..0042fdc 100644 --- a/bulk-price-manipulator/src/updater/mod.rs +++ b/bulk-price-manipulator/src/updater/mod.rs @@ -50,12 +50,9 @@ pub async fn update_prices(state: AppState, saleor_api_url: String) -> anyhow::R (Ok(price), Ok(cost_price)) => { let mut used_cost_price = None; if variant.channel_listings.is_some_and(|c| { - c.iter() - .find(|f| { - f.cost_price.is_some() - && f.channel.id.inner() == channel_id.inner() - }) - .is_some() + c.iter().any(|f| { + f.cost_price.is_some() && f.channel.id.inner() == channel_id.inner() + }) }) { used_cost_price = Some(cost_price as f32); }; diff --git a/sdk/src/apl/file_apl.rs b/sdk/src/apl/file_apl.rs index 8eb654c..512c2f9 100644 --- a/sdk/src/apl/file_apl.rs +++ b/sdk/src/apl/file_apl.rs @@ -23,7 +23,7 @@ pub struct FileApl { impl APL for FileApl { async fn set(&self, auth_data: crate::AuthData) -> Result<(), AplError> { let path = std::path::Path::new(&self.path); -#[cfg(feature = "tracing")] + #[cfg(feature = "tracing")] debug!("reading from {:?}", &path); let mut auths: FileStructure; match path.is_file() { @@ -38,7 +38,7 @@ impl APL for FileApl { auths.insert(auth_data.saleor_api_url.clone(), auth_data); -#[cfg(feature = "tracing")] + #[cfg(feature = "tracing")] debug!("writing to {:?}", &path); std::fs::write( path, @@ -52,7 +52,7 @@ impl APL for FileApl { async fn get(&self, saleor_api_url: &str) -> Result { let path = std::path::Path::new(&self.path); -#[cfg(feature = "tracing")] + #[cfg(feature = "tracing")] debug!("reading from {:?}", &path); let auth_data: FileStructure = serde_json::from_str( &std::fs::read_to_string(path).map_err(|e| AplError::IO(e.to_string()))?, @@ -68,7 +68,7 @@ impl APL for FileApl { async fn get_all(&self) -> Result, AplError> { let path = std::path::Path::new(&self.path); -#[cfg(feature = "tracing")] + #[cfg(feature = "tracing")] debug!("reading from {:?}", &path); let auth_data: FileStructure = serde_json::from_str( &std::fs::read_to_string(path).map_err(|e| AplError::IO(e.to_string()))?, @@ -79,7 +79,7 @@ impl APL for FileApl { async fn delete(&self, saleor_api_url: &str) -> Result<(), AplError> { let path = std::path::Path::new(&self.path); -#[cfg(feature = "tracing")] + #[cfg(feature = "tracing")] debug!("reading from {:?}", &path); let mut auths: FileStructure = serde_json::from_str( &std::fs::read_to_string(path).map_err(|e| AplError::IO(e.to_string()))?, @@ -87,7 +87,7 @@ impl APL for FileApl { .map_err(|e| AplError::Serialization(e.to_string()))?; auths.remove(saleor_api_url); -#[cfg(feature = "tracing")] + #[cfg(feature = "tracing")] debug!("writing to {:?}", &path); std::fs::write( path, diff --git a/sdk/src/middleware/verify_webhook_signature.rs b/sdk/src/middleware/verify_webhook_signature.rs index 1da0035..333119f 100644 --- a/sdk/src/middleware/verify_webhook_signature.rs +++ b/sdk/src/middleware/verify_webhook_signature.rs @@ -14,12 +14,10 @@ pub async fn webhook_signature_verifier(request: Request, next: Next) -> Respons let jwks_url = request .headers() - .get(SALEOR_API_URL_HEADER).and_then(|h| { - h.to_str() - .map_or(None, |h| url::Url::parse(h).ok()) - }); + .get(SALEOR_API_URL_HEADER) + .and_then(|h| h.to_str().map_or(None, |h| url::Url::parse(h).ok())); - debug!("request came from {:?}",jwks_url); + debug!("request came from {:?}", jwks_url); //get jwk from saleor api let jwks: Value = 'block: { if let Some(mut jwks_url) = jwks_url { diff --git a/simple-payment-gateway/src/routes/manifest.rs b/simple-payment-gateway/src/routes/manifest.rs index 3ab361c..481fa5c 100644 --- a/simple-payment-gateway/src/routes/manifest.rs +++ b/simple-payment-gateway/src/routes/manifest.rs @@ -1,5 +1,5 @@ use axum::{extract::State, Json}; -use saleor_app_sdk::{manifest::AppManifest}; +use saleor_app_sdk::manifest::AppManifest; use crate::app::{AppError, AppState}; diff --git a/sitemap-generator/src/tests/utils.rs b/sitemap-generator/src/tests/utils.rs index e3371ad..39e5b97 100644 --- a/sitemap-generator/src/tests/utils.rs +++ b/sitemap-generator/src/tests/utils.rs @@ -296,8 +296,9 @@ pub fn gen_random_url_set( // If there is a category url already, use that for relation instead of always a let mut is_using_existing_category = false; // new one - if res.iter().any(|r| r.1.data.typ == ItemType::Category) { - if rand::random::() == true { loop { + if res.iter().any(|r| r.1.data.typ == ItemType::Category) && rand::random::() + { + loop { let r = res.choose(&mut rand::thread_rng()).unwrap().clone(); if r.1.data.typ == ItemType::Category { rel_slug = r.1.data.slug; @@ -305,7 +306,7 @@ pub fn gen_random_url_set( is_using_existing_category = true; break; } - } }; + } } let product_updated = ProductUpdated { product: Some(Product {