Skip to content

Commit

Permalink
refactor service names usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kmd-fl committed Jun 13, 2023
1 parent e8c043d commit d7f0df6
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 120 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

11 changes: 4 additions & 7 deletions crates/created-swarm/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,13 @@ pub struct SwarmConfig {
pub spell_base_dir: Option<PathBuf>,
pub timer_resolution: Duration,
pub allowed_binaries: Vec<String>,
pub disabled_system_services: Vec<String>,
pub disabled_system_services: Vec<server_config::system_services_config::ServiceKey>,
}

impl SwarmConfig {
pub fn new(bootstraps: Vec<Multiaddr>, listen_on: Multiaddr) -> Self {
use server_config::system_services_config::ServiceKey;

let transport = match listen_on.iter().next() {
Some(Protocol::Memory(_)) => Transport::Memory,
_ => Transport::Network,
Expand All @@ -246,12 +248,7 @@ impl SwarmConfig {
spell_base_dir: None,
timer_resolution: default_script_storage_timer_resolution(),
allowed_binaries: vec!["/usr/bin/ipfs".to_string(), "/usr/bin/curl".to_string()],
disabled_system_services: vec![
"decider".to_string(),
"aqua-ipfs".to_string(),
"registry".to_string(),
"trust-graph".to_string(),
],
disabled_system_services: ServiceKey::all_values(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/nox-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ now-millis = { path = "../now-millis" }
local-vm = { path = "../local-vm" }
control-macro = { path = "../control-macro" }
json-utils = { path = "../json-utils" }
server-config = { workspace = true }

log-utils = { workspace = true }
fluence-spell-dtos = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions crates/nox-tests/tests/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use now_millis::now_ms;
use particle_protocol::Particle;
use serde::Deserialize;
use serde_json::{json, Value as JValue};
use server_config::system_services_config::ServiceKey::Registry;
use service_modules::load_module;
use std::collections::HashMap;
use std::str::FromStr;
Expand Down Expand Up @@ -1540,7 +1541,7 @@ async fn sign_verify() {
async fn sign_invalid_tetraplets() {
let swarms = make_swarms_with_cfg(2, |mut cfg| {
cfg.disabled_system_services
.retain(|service| service != "registry");
.retain(|service| service != Registry);
cfg
})
.await;
Expand Down Expand Up @@ -1610,7 +1611,7 @@ async fn sign_invalid_tetraplets() {
async fn sig_verify_invalid_signature() {
let swarms = make_swarms_with_cfg(1, |mut cfg| {
cfg.disabled_system_services
.retain(|service| service != "registry");
.retain(|service| service != Registry);
cfg
})
.await;
Expand Down Expand Up @@ -1802,7 +1803,7 @@ async fn insecure_sign_verify() {
let kp = KeyPair::from_secret_key(INSECURE_KEYPAIR_SEED.collect(), KeyFormat::Ed25519).unwrap();
let swarms = make_swarms_with_cfg(1, |mut cfg| {
cfg.disabled_system_services
.retain(|service| service != "registry");
.retain(|service| service != Registry);
cfg
})
.await;
Expand Down
2 changes: 1 addition & 1 deletion crates/server-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod network_config;
mod node_config;
mod resolved_config;
mod services_config;
mod system_services_config;
pub mod system_services_config;

pub use defaults::{builtins_base_dir, *};
pub use resolved_config::load_config;
Expand Down
35 changes: 34 additions & 1 deletion crates/server-config/src/system_services_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,44 @@

use super::defaults::*;
use serde::{Deserialize, Serialize};
use std::fmt::Formatter;

#[non_exhaustive]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
pub enum ServiceKey {
AquaIpfs,
TrustGraph,
Registry,
Decider,
}

impl ServiceKey {
pub fn all_values() -> Vec<Self> {
vec![
Self::AquaIpfs,
Self::TrustGraph,
Self::Registry,
Self::Decider,
]
}
}

impl std::fmt::Display for ServiceKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::AquaIpfs => write!(f, "aqua-ipfs"),
Self::TrustGraph => write!(f, "trust-graph"),
Self::Registry => write!(f, "registry"),
Self::Decider => write!(f, "decider"),
}
}
}

#[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct SystemServicesConfig {
#[serde(default)]
pub disable: Vec<String>,
pub disable: Vec<ServiceKey>,
#[serde(default)]
pub aqua_ipfs: AquaIpfsConfig,
#[serde(default)]
Expand Down
Loading

0 comments on commit d7f0df6

Please sign in to comment.