Skip to content

Commit

Permalink
Changed configuration fields name
Browse files Browse the repository at this point in the history
  • Loading branch information
dayeon5470 committed Apr 2, 2024
1 parent cd49d58 commit 1dec5f7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).
`crusher.toml`, the temporary file is named as `crusher.toml.temp.toml`.
- If the reload trigger succeeds, the new configuration is applied from the
temporary file; otherwise, the temporary file is deleted.
- Changed configuration fields name.
- `roots` to `root`.
- `giganto_ingest_address` to `giganto_ingest_addr`.
- `giganto_publish_address` to `giganto_publish_addr`.
- `review_address` to `review_addr`.

## [0.3.2] - 2024-01-25

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ The following is key values in the TOML configuration file.

* `key`: Crusher's private key file.
* `cert`: Crusher's certificate file.
* `roots`: RootCA file. (for Giganto, Review)
* `root`: RootCA file. (for Giganto, Review)
* `giganto_name`: the name of the Giganto. This must match with the DNS name in
the certificate.
* `giganto_ingest_address`: IP address and port number of `Giganto ingest`.
* `giganto_publish_address`: IP address and port number of `Giganto publish`.
* `giganto_ingest_addr`: IP address and port number of `Giganto ingest`.
* `giganto_publish_addr`: IP address and port number of `Giganto publish`.
* `review_name`: the name of the review. This must match with the DNS name in
the certificate.
* `review_address`: IP address and port number of `review`.
* `review_addr`: IP address and port number of `review`.
* `last_timestamp_data`: File that stores the timestamp of the last time series
per `sampling policy`.
* `log_dir`: Path to the log file.
Expand All @@ -40,12 +40,12 @@ Example
```toml
key = "key.pem"
cert = "cert.pem"
roots = ["ca1.pem", "ca2.pem", "ca3.pem"]
root = ["ca1.pem", "ca2.pem", "ca3.pem"]
giganto_name = "localhost"
giganto_ingest_address = "127.0.0.1:38370"
giganto_publish_address = "127.0.0.1:38371"
giganto_ingest_addr = "127.0.0.1:38370"
giganto_publish_addr = "127.0.0.1:38371"
review_name = "localhost"
review_address ="127.0.0.1:38390"
review_addr ="127.0.0.1:38390"
last_timestamp_data = "tests/time_data.json"
log_dir = "/data/logs/apps"
```
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn main() -> Result<()> {
let key = to_private_key(&key_pem).context("cannot read private key")?;

let mut files: Vec<Vec<u8>> = Vec::new();
for root in &settings.roots {
for root in &settings.root {
let file = fs::read(root).expect("Failed to read file");
files.push(file);
}
Expand All @@ -80,7 +80,7 @@ async fn main() -> Result<()> {
async_channel::bounded::<RequestedPolicy>(REQUESTED_POLICY_CHANNEL_SIZE);

let request_client = request::Client::new(
settings.review_address,
settings.review_addr,
settings.review_name,
cert.clone(),
key.clone(),
Expand All @@ -98,8 +98,8 @@ async fn main() -> Result<()> {
));

let subscribe_client = subscribe::Client::new(
settings.giganto_ingest_address,
settings.giganto_publish_address,
settings.giganto_ingest_addr,
settings.giganto_publish_addr,
settings.giganto_name,
settings.last_timestamp_data,
cert,
Expand Down
54 changes: 27 additions & 27 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ use std::{
use toml_edit::{value, Document};

const DEFAULT_GIGANTO_NAME: &str = "localhost";
const DEFAULT_GIGANTO_INGEST_ADDRESS: &str = "[::]:38370";
const DEFAULT_GIGANTO_PUBLISH_ADDRESS: &str = "[::]:38371";
const DEFAULT_GIGANTO_INGEST_ADDR: &str = "[::]:38370";
const DEFAULT_GIGANTO_PUBLISH_ADDR: &str = "[::]:38371";
const DEFAULT_REVIEW_NAME: &str = "localhost";
const DEFAULT_REVIEW_ADDRESS: &str = "[::]:38390";
const DEFAULT_REVIEW_ADDR: &str = "[::]:38390";
pub const TEMP_TOML_POST_FIX: &str = ".temp.toml";

/// The application settings.
#[derive(Clone, Debug, Deserialize)]
pub struct Settings {
pub cert: PathBuf, // Path to the certificate file
pub key: PathBuf, // Path to the private key file
pub roots: Vec<PathBuf>, // Path to the rootCA file
pub root: Vec<PathBuf>, // Path to the rootCA file
pub giganto_name: String, // host name to giganto
#[serde(deserialize_with = "deserialize_socket_addr")]
pub giganto_ingest_address: SocketAddr, // IP address & port to giganto
pub giganto_ingest_addr: SocketAddr, // IP address & port to giganto
#[serde(deserialize_with = "deserialize_socket_addr")]
pub giganto_publish_address: SocketAddr, // IP address & port to giganto
pub giganto_publish_addr: SocketAddr, // IP address & port to giganto
pub review_name: String, // host name to review
#[serde(deserialize_with = "deserialize_socket_addr")]
pub review_address: SocketAddr, // IP address & port to review
pub review_addr: SocketAddr, // IP address & port to review
pub last_timestamp_data: PathBuf, // Path to the last series timestamp data file
pub log_dir: PathBuf,
}
Expand Down Expand Up @@ -82,13 +82,13 @@ fn default_config_builder() -> ConfigBuilder<DefaultState> {
.expect("default key dir")
.set_default("giganto_name", DEFAULT_GIGANTO_NAME)
.expect("valid name")
.set_default("giganto_ingest_address", DEFAULT_GIGANTO_INGEST_ADDRESS)
.set_default("giganto_ingest_addr", DEFAULT_GIGANTO_INGEST_ADDR)
.expect("valid address")
.set_default("giganto_publish_address", DEFAULT_GIGANTO_PUBLISH_ADDRESS)
.set_default("giganto_publish_addr", DEFAULT_GIGANTO_PUBLISH_ADDR)
.expect("valid address")
.set_default("review_name", DEFAULT_REVIEW_NAME)
.expect("valid name")
.set_default("review_address", DEFAULT_REVIEW_ADDRESS)
.set_default("review_addr", DEFAULT_REVIEW_ADDR)
.expect("valid address")
.set_default(
"last_timestamp_data",
Expand All @@ -115,29 +115,29 @@ pub fn get_config(config_path: &str) -> Result<Config> {
let toml = fs::read_to_string(config_path).context("toml not found")?;
let doc = toml.parse::<Document>()?;

let review_address = doc
.get("review_address")
.context("\"review_address\" not found")?
let review_addr = doc
.get("review_addr")
.context("\"review_addr\" not found")?
.to_string()
.trim_matches('\"')
.parse::<SocketAddr>()?;
let giganto_publish_address = doc
.get("giganto_publish_address")
.context("\"giganto_publish_address\" not found")?
let giganto_publish_addr = doc
.get("giganto_publish_addr")
.context("\"giganto_publish_addr\" not found")?
.to_string()
.trim_matches('\"')
.parse::<SocketAddr>()?;
let giganto_ingest_address = doc
.get("giganto_ingest_address")
.context("\"giganto_ingest_address\" not found")?
let giganto_ingest_addr = doc
.get("giganto_ingest_addr")
.context("\"giganto_ingest_addr\" not found")?
.to_string()
.trim_matches('\"')
.parse::<SocketAddr>()?;

Ok(Config::Crusher(CrusherConfig {
review_address,
giganto_publish_address: Some(giganto_publish_address),
giganto_ingest_address: Some(giganto_ingest_address),
review_address: review_addr,
giganto_publish_address: Some(giganto_publish_addr),
giganto_ingest_address: Some(giganto_ingest_addr),
}))
}

Expand All @@ -148,12 +148,12 @@ pub fn set_config(config: &Config, config_path: &str) -> Result<()> {
let mut doc = config_toml.parse::<Document>()?;

if let Config::Crusher(conf) = config {
doc["review_address"] = value(conf.review_address.to_string());
if let Some(giganto_ingest_address) = conf.giganto_ingest_address {
doc["giganto_ingest_address"] = value(giganto_ingest_address.to_string());
doc["review_addr"] = value(conf.review_address.to_string());
if let Some(giganto_ingest_addr) = conf.giganto_ingest_address {
doc["giganto_ingest_addr"] = value(giganto_ingest_addr.to_string());
}
if let Some(giganto_publish_address) = conf.giganto_publish_address {
doc["giganto_publish_address"] = value(giganto_publish_address.to_string());
if let Some(giganto_publish_addr) = conf.giganto_publish_address {
doc["giganto_publish_addr"] = value(giganto_publish_addr.to_string());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/subscribe/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ async fn handle_connection(conn: quinn::Connecting) {
fn config_server() -> ServerConfig {
let (cert, key, ca_certs) = cert_key();

let mut client_auth_roots = rustls::RootCertStore::empty();
let mut client_auth_root = rustls::RootCertStore::empty();
for ca_cert in ca_certs {
let root_cert: Vec<rustls::Certificate> = rustls_pemfile::certs(&mut &*ca_cert)
.unwrap()
.into_iter()
.map(rustls::Certificate)
.collect();
if let Some(cert) = root_cert.get(0) {
client_auth_roots.add(cert).unwrap();
client_auth_root.add(cert).unwrap();
}
}

let client_auth = rustls::server::AllowAnyAuthenticatedClient::new(client_auth_roots).boxed();
let client_auth = rustls::server::AllowAnyAuthenticatedClient::new(client_auth_root).boxed();
let server_crypto = rustls::ServerConfig::builder()
.with_safe_defaults()
.with_client_cert_verifier(client_auth)
Expand Down
8 changes: 4 additions & 4 deletions tests/config.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
key = "tests/key.pem"
cert = "tests/cert.pem"
roots = ["tests/root.pem"]
root = ["tests/root.pem"]
giganto_name = "localhost"
giganto_ingest_address = "127.0.0.1:38370"
giganto_publish_address = "127.0.0.1:38371"
giganto_ingest_addr = "127.0.0.1:38370"
giganto_publish_addr = "127.0.0.1:38371"
review_name = "localhost"
review_address ="127.0.0.1:38390"
review_addr ="127.0.0.1:38390"
last_timestamp_data = "tests/time_data.json"
log_dir = "tests/logs/apps"

0 comments on commit 1dec5f7

Please sign in to comment.