fix conditional compilation
This commit is contained in:
parent
c9b233e78f
commit
c09a74bcca
4 changed files with 32 additions and 19 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2677,7 +2677,7 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "saleor-app-sdk"
|
name = "saleor-app-sdk"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
[toolchain]
|
[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"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "saleor-app-sdk"
|
name = "saleor-app-sdk"
|
||||||
authors = ["Djkáťo <djkatovfx@gmail.com>"]
|
authors = ["Djkáťo <djkatovfx@gmail.com>"]
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Unofficial Saleor App SDK like library, made to for Rust."
|
description = "Unofficial Saleor App SDK like library, made to for Rust."
|
||||||
keywords = ["saleor", "sdk", "plugin"]
|
keywords = ["saleor", "sdk", "plugin"]
|
||||||
|
@ -45,6 +45,7 @@ tracing-subscriber = { workspace = true, optional = true }
|
||||||
## Needed for webhooks
|
## Needed for webhooks
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
# default = []
|
||||||
default = ["middleware", "redis_apl", "webhook_utils", "tracing"]
|
default = ["middleware", "redis_apl", "webhook_utils", "tracing"]
|
||||||
middleware = [
|
middleware = [
|
||||||
"dep:axum",
|
"dep:axum",
|
||||||
|
|
|
@ -12,8 +12,10 @@ use config::Config;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::apl::env_apl::EnvApl;
|
use crate::apl::env_apl::EnvApl;
|
||||||
|
#[cfg(feature = "file_apl")]
|
||||||
|
use crate::apl::file_apl::FileApl;
|
||||||
#[cfg(feature = "redis_apl")]
|
#[cfg(feature = "redis_apl")]
|
||||||
use crate::apl::{file_apl::FileApl, redis_apl::RedisApl};
|
use crate::apl::redis_apl::RedisApl;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AuthToken {
|
pub struct AuthToken {
|
||||||
|
@ -52,28 +54,36 @@ pub struct SaleorApp {
|
||||||
impl SaleorApp {
|
impl SaleorApp {
|
||||||
pub fn new(config: &Config) -> anyhow::Result<SaleorApp> {
|
pub fn new(config: &Config) -> anyhow::Result<SaleorApp> {
|
||||||
use AplType::{Env, File, Redis};
|
use AplType::{Env, File, Redis};
|
||||||
Ok(SaleorApp {
|
fn decide_apl(config: &Config) -> anyhow::Result<Box<dyn APL>> {
|
||||||
apl: match config.apl {
|
match config.apl {
|
||||||
Redis => {
|
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");
|
dbg!("Tried starting app with apl that wasn't present at compile time (cargo feature missing). Falling back to env_apl");
|
||||||
Box::new(EnvApl {})
|
Ok(Box::new(EnvApl {}))
|
||||||
} else {
|
|
||||||
Box::new(RedisApl::new(&config.apl_url, &config.app_api_base_url)?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Env => Box::new(EnvApl {}),
|
Env => Ok(Box::new(EnvApl {})),
|
||||||
File => {
|
File => {
|
||||||
if cfg!(not(feature = "file_apl")) {
|
#[cfg(feature = "file_apl")]
|
||||||
dbg!("Tried starting app with apl that wasn't present at compile time (cargo feature missing). Falling back to env_apl");
|
return Ok(Box::new(FileApl {
|
||||||
Box::new(EnvApl {})
|
|
||||||
} else {
|
|
||||||
Box::new(FileApl {
|
|
||||||
path: "apl.txt".to_owned(),
|
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");
|
||||||
|
Ok(Box::new(EnvApl {}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
})
|
}
|
||||||
|
let apl = decide_apl(config)?;
|
||||||
|
Ok(SaleorApp { apl })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue