fix conditional compilation

This commit is contained in:
Djkáťo 2024-05-23 01:07:04 +02:00
parent c9b233e78f
commit c09a74bcca
4 changed files with 32 additions and 19 deletions

2
Cargo.lock generated
View file

@ -2677,7 +2677,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]]
name = "saleor-app-sdk"
version = "0.2.2"
version = "0.2.3"
dependencies = [
"anyhow",
"async-trait",

View file

@ -1,3 +1,5 @@
[toolchain]
channel = "nightly-2024-03-23"
# channel = "nightly-2024-03-23"
## Toggle to this one for sdk releases
channel = "stable"
targets = ["x86_64-unknown-linux-gnu"]

View file

@ -1,7 +1,7 @@
[package]
name = "saleor-app-sdk"
authors = ["Djkáťo <djkatovfx@gmail.com>"]
version = "0.2.2"
version = "0.2.3"
edition = "2021"
description = "Unofficial Saleor App SDK like library, made to for Rust."
keywords = ["saleor", "sdk", "plugin"]
@ -45,6 +45,7 @@ tracing-subscriber = { workspace = true, optional = true }
## Needed for webhooks
[features]
# default = []
default = ["middleware", "redis_apl", "webhook_utils", "tracing"]
middleware = [
"dep:axum",

View file

@ -12,8 +12,10 @@ use config::Config;
use serde::{Deserialize, Serialize};
use crate::apl::env_apl::EnvApl;
#[cfg(feature = "file_apl")]
use crate::apl::file_apl::FileApl;
#[cfg(feature = "redis_apl")]
use crate::apl::{file_apl::FileApl, redis_apl::RedisApl};
use crate::apl::redis_apl::RedisApl;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthToken {
@ -52,28 +54,36 @@ pub struct SaleorApp {
impl SaleorApp {
pub fn new(config: &Config) -> anyhow::Result<SaleorApp> {
use AplType::{Env, File, Redis};
Ok(SaleorApp {
apl: match config.apl {
fn decide_apl(config: &Config) -> anyhow::Result<Box<dyn APL>> {
match config.apl {
Redis => {
if cfg!(not(feature = "redis_apl")) {
#[cfg(feature = "redis_apl")]
return Ok(Box::new(RedisApl::new(
&config.apl_url,
&config.app_api_base_url,
)?));
#[cfg(not(feature = "redis_apl"))]
{
dbg!("Tried starting app with apl that wasn't present at compile time (cargo feature missing). Falling back to env_apl");
Box::new(EnvApl {})
} else {
Box::new(RedisApl::new(&config.apl_url, &config.app_api_base_url)?)
Ok(Box::new(EnvApl {}))
}
}
Env => Box::new(EnvApl {}),
Env => Ok(Box::new(EnvApl {})),
File => {
if cfg!(not(feature = "file_apl")) {
#[cfg(feature = "file_apl")]
return Ok(Box::new(FileApl {
path: "apl.txt".to_owned(),
}));
#[cfg(not(feature = "file_apl"))]
{
dbg!("Tried starting app with apl that wasn't present at compile time (cargo feature missing). Falling back to env_apl");
Box::new(EnvApl {})
} else {
Box::new(FileApl {
path: "apl.txt".to_owned(),
})
Ok(Box::new(EnvApl {}))
}
}
},
})
}
}
let apl = decide_apl(config)?;
Ok(SaleorApp { apl })
}
}