Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ on:
branches:
- main
- dev
- 'release/**'
- "release/**"
paths-ignore:
- "*.md"
- "LICENSE"
pull_request:
branches:
- main
- dev
- 'release/**'
- "release/**"
paths-ignore:
- "*.md"
- "LICENSE"
Expand All @@ -30,25 +30,34 @@ jobs:
steps:
- name: Debug
run: echo ${{ github.ref_name }}

- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install dependencies
run: apt-get update && apt-get -y install protobuf-compiler libnftnl-dev libmnl-dev

- name: Check format
run: |
rustup component add rustfmt
cargo fmt -- --check

- name: Run clippy linter
run: |
rustup component add clippy
cargo clippy --all-targets --all-features -- -D warnings

- name: Run cargo deny
uses: EmbarkStudios/cargo-deny-action@v2
run: |
cargo install cargo-deny
cargo deny check

- name: Run tests
run: cargo test --locked --no-fail-fast
16 changes: 14 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ use toml;

use crate::error::GatewayError;

fn default_log_level() -> String {
String::from("info")
}

fn default_syslog_socket() -> PathBuf {
PathBuf::from("/var/run/log")
}

#[derive(Debug, Parser, Clone, Deserialize)]
#[clap(about = "Defguard VPN gateway service")]
#[command(version)]
pub struct Config {
#[arg(long, short = 'l', env = "DEFGUARD_LOG_LEVEL", default_value = "info")]
#[serde(default = "default_log_level")]
pub log_level: String,

/// Token received from Defguard after completing the network wizard
Expand All @@ -21,6 +30,7 @@ pub struct Config {
env = "DEFGUARD_TOKEN",
default_value = ""
)]
#[serde(default)]
pub token: String,

#[arg(long, env = "DEFGUARD_GATEWAY_NAME")]
Expand All @@ -34,6 +44,7 @@ pub struct Config {
env = "DEFGUARD_GRPC_URL",
default_value = ""
)]
#[serde(default)]
pub grpc_url: String,

/// Use userspace WireGuard implementation e.g. wireguard-go
Expand Down Expand Up @@ -66,6 +77,7 @@ pub struct Config {

/// Syslog socket path
#[arg(long, default_value = "/var/run/log")]
#[serde(default = "default_syslog_socket")]
pub syslog_socket: PathBuf,

/// Configuration file path
Expand Down Expand Up @@ -116,7 +128,7 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
Self {
log_level: "info".to_string(),
log_level: "info".into(),
token: "TOKEN".into(),
name: None,
grpc_url: "http://localhost:50051".into(),
Expand Down Expand Up @@ -150,7 +162,7 @@ pub fn get_config() -> Result<Config, GatewayError> {
if let Some(config_path) = cli_config.config_path {
let config_toml = fs::read_to_string(config_path)
.map_err(|err| GatewayError::InvalidConfigFile(err.to_string()))?;
let file_config: Config = toml::from_str(&config_toml)
let file_config = toml::from_str(&config_toml)
.map_err(|err| GatewayError::InvalidConfigFile(err.message().to_string()))?;
return Ok(file_config);
}
Expand Down
1 change: 1 addition & 0 deletions src/enterprise/firewall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ pub enum FirewallError {
///
/// - In IPv4 this is the broadcast address.
/// - In IPv6 this is just the last address in the network.
#[must_use]
pub fn max_address(network: &IpNetwork) -> IpAddr {
match network {
IpNetwork::V4(network) => {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ async fn main() -> Result<(), GatewayError> {
}
} else {
let version = Version::parse(VERSION)?;
defguard_version::tracing::init(version, &config.log_level.to_string())?
};
defguard_version::tracing::init(version, &config.log_level)?;
}

if let Some(pre_up) = &config.pre_up {
log::info!("Executing specified PRE_UP command: {pre_up}");
Expand Down