Skip to content

Commit

Permalink
Change set_giganto_config api to receive full configuration toml st…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
BLYKIM committed Aug 22, 2024
1 parent cbf5382 commit 6eaac91
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Remove migration code less than `0.15.3`
- Changed to support command line interface.
- Removed `cert`, `key`, `root` fields from config file.
- Changed `set_giganto_config` to receive toml-string with full configuration.

## [0.20.0] - 2024-05-17

Expand Down
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.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ serde_json = "1"
syn = "2.0"
tempfile = "3"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
toml = "0.8"
toml_edit = "0.22"
tracing = "0.1"
tracing-appender = "0.2"
Expand Down
33 changes: 3 additions & 30 deletions src/graphql/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ struct GigantoConfig {
ack_transmission_cnt: u16,
}

#[derive(InputObject)]
struct UserConfig {
ingest_srv_addr: Option<String>,
publish_srv_addr: Option<String>,
graphql_srv_addr: Option<String>,
retention: Option<String>,
max_open_files: Option<i32>,
max_mb_of_level_base: Option<u64>,
addr_to_peers: Option<String>,
peer_list: Option<Vec<PeerList>>,
ack_transmission_cnt: Option<u16>,
}

#[derive(Default)]
pub(super) struct GigantoStatusQuery;

Expand Down Expand Up @@ -201,26 +188,12 @@ impl GigantoConfigMutation {
async fn set_giganto_config<'ctx>(
&self,
ctx: &Context<'ctx>,
field: UserConfig,
config: String,
) -> Result<String> {
let cfg_path = ctx.data::<String>()?;
let new_path = copy_toml_file(cfg_path)?;
let mut doc = read_toml_file(&new_path)?;
insert_toml_element(CONFIG_INGEST_SRV_ADDR, &mut doc, field.ingest_srv_addr);
insert_toml_element(CONFIG_PUBLISH_SRV_ADDR, &mut doc, field.publish_srv_addr);
insert_toml_element(CONFIG_GRAPHQL_SRV_ADDR, &mut doc, field.graphql_srv_addr);
insert_toml_element(CONFIG_RETENTION, &mut doc, field.retention);
let convert_open_file = field.max_open_files.map(i64::from);
insert_toml_element(CONFIG_MAX_OPEN_FILES, &mut doc, convert_open_file);
let convert_level_base = field
.max_mb_of_level_base
.and_then(|x| i64::try_from(x).ok());
insert_toml_element(CONFIG_MAX_MB_OF_LEVEL_BASE, &mut doc, convert_level_base);
let convert_ack_trans_cnt = field.ack_transmission_cnt.map(i64::from);
insert_toml_element(CONFIG_ACK_TRANSMISSION, &mut doc, convert_ack_trans_cnt);
insert_toml_element(CONFIG_ADDR_TO_PEERS, &mut doc, field.addr_to_peers);
insert_toml_peers(&mut doc, field.peer_list)?;
write_toml_file(&doc, &new_path)?;

fs::write(new_path, config)?;

let reload_notify = ctx.data::<ReloadNotify>()?;
let config_reload = reload_notify.0.clone();
Expand Down

0 comments on commit 6eaac91

Please sign in to comment.