Skip to content

Commit

Permalink
fix tracing feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
djkato committed Jan 3, 2025
1 parent a02190d commit 9d3471f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "saleor-app-sdk"
authors = ["Djkáťo <djkatovfx@gmail.com>"]
version = "0.6.1"
version = "0.6.2"
edition = "2021"
description = "Unofficial Saleor App SDK library, made to for Rust."
keywords = ["saleor", "sdk", "plugin"]
Expand Down
7 changes: 7 additions & 0 deletions sdk/src/apl/file_apl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::AuthData;
use super::{AplError, APL};
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
#[cfg(feature = "tracing")]
use tracing::debug;

#[derive(Clone, Debug)]
Expand All @@ -22,6 +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")]
debug!("reading from {:?}", &path);
let mut auths: FileStructure;
match path.is_file() {
Expand All @@ -36,6 +38,7 @@ impl APL for FileApl {

auths.insert(auth_data.saleor_api_url.clone(), auth_data);

#[cfg(feature = "tracing")]
debug!("writing to {:?}", &path);
std::fs::write(
path,
Expand All @@ -49,6 +52,7 @@ impl APL for FileApl {

async fn get(&self, saleor_api_url: &str) -> Result<crate::AuthData, AplError> {
let path = std::path::Path::new(&self.path);
#[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()))?,
Expand All @@ -64,6 +68,7 @@ impl APL for FileApl {

async fn get_all(&self) -> Result<Vec<crate::AuthData>, AplError> {
let path = std::path::Path::new(&self.path);
#[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()))?,
Expand All @@ -74,13 +79,15 @@ 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")]
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()))?,
)
.map_err(|e| AplError::Serialization(e.to_string()))?;
auths.remove(saleor_api_url);

#[cfg(feature = "tracing")]
debug!("writing to {:?}", &path);
std::fs::write(
path,
Expand Down
15 changes: 15 additions & 0 deletions sdk/src/apl/redis_apl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use async_trait::async_trait;
use std::time::Duration;

use redis::AsyncCommands;
#[cfg(feature = "tracing")]
use tracing::{debug, info};

use super::{AplError, APL};
Expand All @@ -16,6 +17,7 @@ pub struct RedisApl {
#[async_trait]
impl APL for RedisApl {
async fn get(&self, saleor_api_url: &str) -> Result<AuthData, AplError> {
#[cfg(feature = "tracing")]
debug!("get()");
let mut conn = self
.client
Expand All @@ -28,11 +30,13 @@ impl APL for RedisApl {
.map_err(|e| AplError::Connection(e.to_string()))?;
let val: AuthData =
serde_json::from_str(&val).map_err(|e| AplError::Serialization(e.to_string()))?;
#[cfg(feature = "tracing")]
info!("sucessful get");

Ok(val)
}
async fn set(&self, auth_data: AuthData) -> Result<(), AplError> {
#[cfg(feature = "tracing")]
debug!("set()");
let mut conn = self
.client
Expand All @@ -46,10 +50,12 @@ impl APL for RedisApl {
)
.await
.map_err(|e| AplError::Connection(e.to_string()))?;
#[cfg(feature = "tracing")]
info!("sucessful set");
Ok(())
}
async fn delete(&self, saleor_api_url: &str) -> Result<(), AplError> {
#[cfg(feature = "tracing")]
debug!("delete(), {}", saleor_api_url);
let mut conn = self
.client
Expand All @@ -61,11 +67,14 @@ impl APL for RedisApl {
.await
.map_err(|e| AplError::Connection(e.to_string()))?;

#[cfg(feature = "tracing")]
debug!("sucessful delete(), {}", val);
#[cfg(feature = "tracing")]
info!("sucessful del");
Ok(())
}
async fn is_ready(&self) -> Result<(), AplError> {
#[cfg(feature = "tracing")]
debug!("is_ready()");
let mut conn = self
.client
Expand All @@ -78,11 +87,14 @@ impl APL for RedisApl {
.await
.map_err(|e| AplError::Connection(e.to_string()))?;

#[cfg(feature = "tracing")]
debug!("sucessful is_ready(), info: {}", val);
#[cfg(feature = "tracing")]
info!("sucessful is_ready");
Ok(())
}
async fn is_configured(&self) -> Result<(), AplError> {
#[cfg(feature = "tracing")]
debug!("is_configured()");
let mut conn = self
.client
Expand All @@ -95,7 +107,9 @@ impl APL for RedisApl {
.await
.map_err(|e| AplError::Connection(e.to_string()))?;

#[cfg(feature = "tracing")]
debug!("sucessful is_configured(), info: {}", val);
#[cfg(feature = "tracing")]
info!("sucessful is_configured");
Ok(())
}
Expand All @@ -108,6 +122,7 @@ impl APL for RedisApl {

impl RedisApl {
pub fn new(redis_url: &str, app_api_base_url: &str) -> Result<Self, AplError> {
#[cfg(feature = "tracing")]
debug!("creating redis apl with {redis_url}...");
let client =
redis::Client::open(redis_url).map_err(|e| AplError::Connection(e.to_string()))?;
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub enum CreateSaleorAppError {
impl SaleorApp {
pub fn new(config: &Config) -> Result<SaleorApp, CreateSaleorAppError> {
use AplType::{File, Redis};
fn decide_apl(config: &Config) -> Result<Box<dyn APL>, AplError> {
fn decide_apl(config: &Config) -> Result<Box<dyn APL>, CreateSaleorAppError> {
match config.apl {
Redis => {
#[cfg(feature = "redis_apl")]
Expand All @@ -75,7 +75,7 @@ impl SaleorApp {

#[cfg(not(feature = "redis_apl"))]
{
return CreateSaleorAppError ::MissingFeature("Tried starting app with redis apl that wasn't present at compile time (cargo feature missing)");
return Err(CreateSaleorAppError ::MissingFeature("Tried starting app with redis apl that wasn't present at compile time (cargo feature missing)".to_string()));
}
}
File => {
Expand All @@ -85,7 +85,7 @@ impl SaleorApp {
}));
#[cfg(not(feature = "file_apl"))]
{
return CreateSaleorAppError ::MissingFeature("Tried starting app with file apl that wasn't present at compile time (cargo feature missing)");
return Err(CreateSaleorAppError ::MissingFeature("Tried starting app with file apl that wasn't present at compile time (cargo feature missing)".to_string()));
}
}
}
Expand Down

0 comments on commit 9d3471f

Please sign in to comment.