Page MenuHomePhabricator

[keyserver] rewrite getCommConfig in Rust
AbandonedPublic

Authored by varun on May 2 2023, 1:47 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 4, 2:32 AM
Unknown Object (File)
Feb 24 2024, 7:48 AM
Unknown Object (File)
Feb 24 2024, 7:48 AM
Unknown Object (File)
Feb 24 2024, 7:44 AM
Unknown Object (File)
Feb 24 2024, 6:21 AM
Unknown Object (File)
Feb 11 2024, 2:09 AM
Unknown Object (File)
Jan 17 2024, 8:08 AM
Unknown Object (File)
Jan 11 2024, 4:54 AM
Subscribers

Details

Reviewers
ashoat
jon
Summary

in order to configure keyserver to talk to prod/staging environments, we need to rewrite getCommConfig in Rust

Test Plan

see comments

Diff Detail

Repository
rCOMM Comm
Branch
new-master (branched from master)
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

tested by creating a file called src/main.rs and running cargo run

diff --git a/keyserver/addons/rust-node-addon/src/main.rs b/keyserver/addons/rust-node-addon/src/main.rs
new file mode 100644
index 000000000..4755eac9b
--- /dev/null
+++ b/keyserver/addons/rust-node-addon/src/main.rs
@@ -0,0 +1,10 @@
+use std::collections::HashMap;
+
+use crate::config::{get_comm_config, ConfigName};
+
+mod config;
+fn main() {
+  let json: Option<HashMap<String, String>> =
+    get_comm_config(ConfigName::Secrets("db_config".to_string()));
+  println!("{:?}", json);
+}

here was the output:

Some({"password": "REDACTED", "database": "comm", "dbType": "mariadb10.8", "host": "localhost", "user": "comm"})

varun requested review of this revision.May 2 2023, 2:06 PM

I think a better solution long term would be to have a struct which reflects the values specific to the config in question:

#[derive(Serialize, Deserialize)]
pub struct KeyserverConfig {
  password: String,
  database: String,
  dbType: String,
  host: String
  user: String
}

And just hold a reference to the config. I'm not sure who this is meant to be used from code, but I'm assuming something like:

get_key_for_config_name(ConfigName::Secrets("keyserver")).unwrap().password

would just be:

CONFIG.password
keyserver/addons/rust-node-addon/src/config.rs
6–27

Feel like this is more inline with what you're trying to express

filename is probably more appropriate than just name

56

can we at least use expect, so there's something to grep for if/when this does fail?

72–74

this seems really odd and just hardcoding current behavior

76–80

Pretty sure this should work.

jon requested changes to this revision.May 2 2023, 7:32 PM
This revision now requires changes to proceed.May 2 2023, 7:32 PM