Browse Source

Allow the configuration of some default values at compile time using environment variables

pull/47/head
Rodolphe Bréard 4 years ago
parent
commit
2a2e743f6a
  1. 6
      CHANGELOG.md
  2. 8
      README.md
  3. 20
      acmed/build.rs
  4. 10
      acmed/src/main.rs

6
CHANGELOG.md

@ -13,6 +13,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Allow the configuration of some default values at compile time using environment variables.
## [0.16.0] - 2020-11-11 ## [0.16.0] - 2020-11-11
### Added ### Added

8
README.md

@ -110,6 +110,14 @@ For example, you can build statically linked binaries using the `openssl_vendore
make FEATURES="openssl_vendored" TARGET="x86_64-unknown-linux-musl" make FEATURES="openssl_vendored" TARGET="x86_64-unknown-linux-musl"
``` ```
The following environment variables can be used to change default values at compile time:
- `ACMED_DEFAULT_ACCOUNTS_DIR`: directory where account files are stored (default to `/etc/acmed/accounts`)
- `ACMED_DEFAULT_CERT_DIR`: directory where certificates and private keys are stored (default to `/etc/acmed/certs`)
- `ACMED_DEFAULT_CERT_FORMAT`: format for certificates and private keys files names (default to `{{name}}_{{key_type}}.{{file_type}}.{{ext}}`)
- `ACMED_DEFAULT_CONFIG_FILE`: main configuration file (default to `/etc/acmed/acmed.toml`)
- `ACMED_DEFAULT_PID_FILE`: main process PID file (default to `/var/run/acmed.pid`)
### Packaging ### Packaging
Most of the time, when packaging, you want to install the program in a dedicated directory. This is possible using the `DESTDIR` variable. Most of the time, when packaging, you want to install the program in a dedicated directory. This is possible using the `DESTDIR` variable.

20
acmed/build.rs

@ -7,6 +7,14 @@ use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use std::path::PathBuf; use std::path::PathBuf;
macro_rules! set_env_var_if_absent {
($name: expr, $default_value: expr) => {{
if let Err(_) = env::var($name) {
set_rustc_env_var!($name, $default_value);
}
}};
}
macro_rules! set_rustc_env_var { macro_rules! set_rustc_env_var {
($name: expr, $value: expr) => {{ ($name: expr, $value: expr) => {{
println!("cargo:rustc-env={}={}", $name, $value); println!("cargo:rustc-env={}={}", $name, $value);
@ -73,7 +81,19 @@ fn set_target() {
}; };
} }
fn set_default_values() {
set_env_var_if_absent!("ACMED_DEFAULT_ACCOUNTS_DIR", "/etc/acmed/accounts");
set_env_var_if_absent!("ACMED_DEFAULT_CERT_DIR", "/etc/acmed/certs");
set_env_var_if_absent!(
"ACMED_DEFAULT_CERT_FORMAT",
"{{name}}_{{key_type}}.{{file_type}}.{{ext}}"
);
set_env_var_if_absent!("ACMED_DEFAULT_CONFIG_FILE", "/etc/acmed/acmed.toml");
set_env_var_if_absent!("ACMED_DEFAULT_PID_FILE", "/var/run/acmed.pid");
}
fn main() { fn main() {
set_target(); set_target();
set_lock(); set_lock();
set_default_values();
} }

10
acmed/src/main.rs

@ -23,11 +23,11 @@ mod storage;
pub const APP_NAME: &str = "ACMEd"; pub const APP_NAME: &str = "ACMEd";
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const DEFAULT_PID_FILE: &str = "/var/run/acmed.pid";
pub const DEFAULT_CONFIG_FILE: &str = "/etc/acmed/acmed.toml";
pub const DEFAULT_ACCOUNTS_DIR: &str = "/etc/acmed/accounts";
pub const DEFAULT_CERT_DIR: &str = "/etc/acmed/certs";
pub const DEFAULT_CERT_FORMAT: &str = "{{name}}_{{key_type}}.{{file_type}}.{{ext}}";
pub const DEFAULT_ACCOUNTS_DIR: &str = env!("ACMED_DEFAULT_ACCOUNTS_DIR");
pub const DEFAULT_CERT_DIR: &str = env!("ACMED_DEFAULT_CERT_DIR");
pub const DEFAULT_CERT_FORMAT: &str = env!("ACMED_DEFAULT_CERT_FORMAT");
pub const DEFAULT_CONFIG_FILE: &str = env!("ACMED_DEFAULT_CONFIG_FILE");
pub const DEFAULT_PID_FILE: &str = env!("ACMED_DEFAULT_PID_FILE");
pub const DEFAULT_SLEEP_TIME: u64 = 3600; pub const DEFAULT_SLEEP_TIME: u64 = 3600;
pub const DEFAULT_POOL_TIME: u64 = 5000; pub const DEFAULT_POOL_TIME: u64 = 5000;
pub const DEFAULT_CSR_DIGEST: HashFunction = HashFunction::Sha256; pub const DEFAULT_CSR_DIGEST: HashFunction = HashFunction::Sha256;

Loading…
Cancel
Save