Skip to content

Commit

Permalink
Updated clap to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Aug 3, 2023
1 parent 5377654 commit 9a48a8b
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 198 deletions.
159 changes: 94 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion limitador-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ actix-rt = "2"
paperclip = { version = "0.8.0", features = ["actix4"] }
serde = { version = "1", features = ["derive"] }
notify = "6.0.1"
clap = "3.2"
const_format = "0.2.31"
lazy_static = "1.4.0"
clap = "4.3"

[build-dependencies]
tonic-build = "0.9.2"
4 changes: 3 additions & 1 deletion limitador-server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ fn generate_protobuf() -> Result<(), Box<dyn Error>> {
}

fn set_features(env: &str) {
let mut features = vec![];
if cfg!(feature = "infinispan") {
println!("cargo:rustc-env={env}=[+infinispan]");
features.push("+infinispan");
}
println!("cargo:rustc-env={env}={features:?}");
}

fn set_profile(env: &str) {
Expand Down
33 changes: 33 additions & 0 deletions limitador-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ pub struct Configuration {
pub rate_limit_headers: RateLimitHeaders,
}

pub mod env {
use lazy_static::lazy_static;

lazy_static! {
pub static ref LIMITS_FILE: Option<&'static str> = value_for("LIMITS_FILE");
pub static ref ENVOY_RLS_HOST: Option<&'static str> = value_for("ENVOY_RLS_HOST");
pub static ref ENVOY_RLS_PORT: Option<&'static str> = value_for("ENVOY_RLS_PORT");
pub static ref HTTP_API_HOST: Option<&'static str> = value_for("HTTP_API_HOST");
pub static ref HTTP_API_PORT: Option<&'static str> = value_for("HTTP_API_PORT");
pub static ref DISK_PATH: Option<&'static str> = value_for("DISK_PATH");
pub static ref DISK_OPTIMIZE: Option<&'static str> = value_for("DISK_OPTIMIZE");
pub static ref REDIS_URL: Option<&'static str> = value_for("REDIS_URL");
pub static ref REDIS_LOCAL_CACHE_MAX_TTL_CACHED_COUNTERS_MS: Option<&'static str> =
value_for("REDIS_LOCAL_CACHE_MAX_TTL_CACHED_COUNTERS_MS");
pub static ref REDIS_LOCAL_CACHE_FLUSHING_PERIOD_MS: Option<&'static str> =
value_for("REDIS_LOCAL_CACHE_FLUSHING_PERIOD_MS");
pub static ref REDIS_LOCAL_CACHE_TTL_RATIO_CACHED_COUNTERS: Option<&'static str> =
value_for("REDIS_LOCAL_CACHE_TTL_RATIO_CACHED_COUNTERS");
pub static ref RATE_LIMIT_HEADERS: Option<&'static str> = value_for("RATE_LIMIT_HEADERS");
pub static ref INFINISPAN_CACHE_NAME: Option<&'static str> =
value_for("INFINISPAN_CACHE_NAME");
pub static ref INFINISPAN_COUNTERS_CONSISTENCY: Option<&'static str> =
value_for("INFINISPAN_COUNTERS_CONSISTENCY");
}

fn value_for(env_key: &'static str) -> Option<&'static str> {
match std::env::var(env_key) {
Ok(s) => Some(Box::leak(s.into_boxed_str())),
Err(_) => None,
}
}
}

impl Configuration {
pub const DEFAULT_RLS_PORT: &'static str = "8081";
pub const DEFAULT_HTTP_PORT: &'static str = "8080";
Expand Down
Loading

0 comments on commit 9a48a8b

Please sign in to comment.