Skip to content

Commit

Permalink
Cluster node roles
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Jan 12, 2025
1 parent de4584c commit 360b32a
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 103 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Stalwart Labs Ltd. <[email protected]>"]
license = "AGPL-3.0-only OR LicenseRef-SEL"
repository = "https://github.com/stalwartlabs/cli"
homepage = "https://github.com/stalwartlabs/cli"
version = "0.11.0"
version = "0.11.2"
edition = "2021"
readme = "README.md"
resolver = "2"
Expand Down
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "common"
version = "0.11.0"
version = "0.11.2"
edition = "2021"
resolver = "2"

Expand Down
52 changes: 50 additions & 2 deletions crates/common/src/config/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use std::time::Duration;

use crate::expr::{if_block::IfBlock, tokenizer::TokenMap};
use ahash::AHashSet;
use utils::config::{Config, Rate};

use super::*;

#[derive(Clone)]
pub struct Network {
pub node_id: u64,
pub roles: ClusterRoles,
pub server_name: String,
pub report_domain: String,
pub security: Security,
Expand All @@ -35,6 +37,15 @@ pub struct ContactForm {
pub field_honey_pot: Option<String>,
}

#[derive(Clone)]
pub struct ClusterRoles {
pub purge_stores: bool,
pub purge_accounts: bool,
pub renew_acme: bool,
pub calculate_metrics: bool,
pub push_metrics: bool,
}

#[derive(Clone, Default)]
pub enum AsnGeoLookupConfig {
Resource {
Expand Down Expand Up @@ -82,7 +93,7 @@ impl Default for Network {
Self {
security: Default::default(),
contact_form: None,
node_id: 0,
node_id: 1,
http_response_url: IfBlock::new::<()>(
"server.http.url",
[],
Expand All @@ -92,6 +103,13 @@ impl Default for Network {
asn_geo_lookup: AsnGeoLookupConfig::Disabled,
server_name: Default::default(),
report_domain: Default::default(),
roles: ClusterRoles {
purge_stores: true,
purge_accounts: true,
renew_acme: true,
calculate_metrics: true,
push_metrics: true,
},
}
}
}
Expand Down Expand Up @@ -180,7 +198,7 @@ impl Network {
});

let mut network = Network {
node_id: config.property("cluster.node-id").unwrap_or_default(),
node_id: config.property("cluster.node-id").unwrap_or(1),
report_domain,
server_name,
security: Security::parse(config),
Expand All @@ -190,6 +208,36 @@ impl Network {
};
let token_map = &TokenMap::default().with_variables(HTTP_VARS);

// Node roles
for (value, key) in [
(
&mut network.roles.purge_stores,
"cluster.roles.purge.stores",
),
(
&mut network.roles.purge_accounts,
"cluster.roles.purge.accounts",
),
(&mut network.roles.renew_acme, "cluster.roles.acme.renew"),
(
&mut network.roles.calculate_metrics,
"cluster.roles.metrics.calculate",
),
(
&mut network.roles.push_metrics,
"cluster.roles.metrics.push",
),
] {
let node_ids = config
.properties::<u64>(key)
.into_iter()
.map(|(_, v)| v)
.collect::<AHashSet<_>>();
if !node_ids.is_empty() && !node_ids.contains(&network.node_id) {
*value = false;
}
}

for (value, key) in [
(&mut network.http_response_url, "server.http.url"),
(
Expand Down
2 changes: 1 addition & 1 deletion crates/directory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "directory"
version = "0.11.0"
version = "0.11.2"
edition = "2021"
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion crates/imap-proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "imap_proto"
version = "0.11.0"
version = "0.11.2"
edition = "2021"
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion crates/imap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "imap"
version = "0.11.0"
version = "0.11.2"
edition = "2021"
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion crates/jmap-proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jmap_proto"
version = "0.11.0"
version = "0.11.2"
edition = "2021"
resolver = "2"

Expand Down
2 changes: 1 addition & 1 deletion crates/jmap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jmap"
version = "0.11.0"
version = "0.11.2"
edition = "2021"
resolver = "2"

Expand Down
Loading

0 comments on commit 360b32a

Please sign in to comment.