mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 13:17:08 +00:00
More work around comments
This commit is contained in:
parent
8dda7bee38
commit
9ffbc78362
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -143,6 +143,15 @@ dependencies = [
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indoc"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5a75aeaaef0ce18b58056d306c27b07436fbb34b8816c53094b76dd81803136"
|
||||
dependencies = [
|
||||
"unindent",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.1"
|
||||
@ -173,6 +182,7 @@ version = "1.0.0"
|
||||
dependencies = [
|
||||
"contrast",
|
||||
"hex",
|
||||
"indoc",
|
||||
"md-5",
|
||||
"napi",
|
||||
"napi-build",
|
||||
@ -425,6 +435,12 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "unindent"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.2.2"
|
||||
|
@ -18,6 +18,7 @@ contrast = "0"
|
||||
rgb = "0"
|
||||
md-5 = "0.8.0"
|
||||
hex = "0.4.3"
|
||||
indoc = "1.0"
|
||||
|
||||
[build-dependencies]
|
||||
napi-build = "1"
|
||||
|
@ -14,10 +14,12 @@ pub struct DefaultBridgeConfig {
|
||||
pub listeners: DefaultBridgeConfigItem<Vec<BridgeConfigListener>>,
|
||||
pub logging: DefaultBridgeConfigItem<BridgeConfigLogging>,
|
||||
pub queue: DefaultBridgeConfigItem<BridgeConfigMessageQueue>,
|
||||
pub passFile: DefaultBridgeConfigItem<String>,
|
||||
}
|
||||
|
||||
pub fn comment_multiline(comment: &String) -> String {
|
||||
let mut out = String::from("\n# ");
|
||||
let mut sentences = Vec::new();
|
||||
let mut out = String::new();
|
||||
let mut len = 0;
|
||||
for word in comment.split(' ') {
|
||||
if len > 0 {
|
||||
@ -27,10 +29,13 @@ pub fn comment_multiline(comment: &String) -> String {
|
||||
out.push_str(word);
|
||||
len += word.len();
|
||||
if len >= 70 {
|
||||
sentences.push(out);
|
||||
out = String::new();
|
||||
out.push_str("\n# ");
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
,
|
||||
out
|
||||
}
|
||||
|
||||
@ -60,14 +65,14 @@ impl DefaultBridgeConfig {
|
||||
pub fn new() -> Self {
|
||||
DefaultBridgeConfig {
|
||||
bot: DefaultBridgeConfigItem {
|
||||
comment: "foo".to_string(),
|
||||
comment: "Define profile information for the bot user".to_string(),
|
||||
v: BridgeConfigBot {
|
||||
displayname: Some("Hookshot Bot".to_string()),
|
||||
avatar: Some("mxc://example.com/foobar".to_string())
|
||||
avatar: Some("mxc://half-shot.uk/2876e89ccade4cb615e210c458e2a7a6883fe17d".to_string())
|
||||
}
|
||||
},
|
||||
bridge: DefaultBridgeConfigItem {
|
||||
comment: "ffoo".to_string(),
|
||||
comment: "Basic homeserver configuration".to_string(),
|
||||
v: BridgeConfigBridge {
|
||||
domain: "example.com".to_string(),
|
||||
port: 1234,
|
||||
@ -77,28 +82,39 @@ impl DefaultBridgeConfig {
|
||||
}
|
||||
},
|
||||
listeners: DefaultBridgeConfigItem {
|
||||
comment: "ffoo".to_string(),
|
||||
comment: indoc! {"
|
||||
HTTP Listener configuration.
|
||||
Bind resource endpoints to ports and addresses.
|
||||
'resources' may be any of webhooks, widgets, metrics, provisioning
|
||||
"}.to_string(),
|
||||
// TODO: Fill me in
|
||||
v: vec![]
|
||||
},
|
||||
logging: DefaultBridgeConfigItem {
|
||||
comment: "fooo".to_string(),
|
||||
comment: "Logging settings. You can have a severity debug,info,warn,error".to_string(),
|
||||
v: BridgeConfigLogging {
|
||||
level: "info".to_string(),
|
||||
}
|
||||
},
|
||||
queue: DefaultBridgeConfigItem {
|
||||
comment: "fooo".to_string(),
|
||||
comment: "Message queue / cache configuration options for large scale deployments".to_string(),
|
||||
v: BridgeConfigMessageQueue {
|
||||
monolithic: true,
|
||||
port: Some(6379),
|
||||
host: Some("localhost".to_string()),
|
||||
}
|
||||
}
|
||||
},
|
||||
passFile: DefaultBridgeConfigItem {
|
||||
comment: indoc! {"
|
||||
A passkey used to encrypt tokens stored inside the bridge.
|
||||
Run openssl genpkey -out passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096 to generate
|
||||
"}.to_string(),
|
||||
v: "passkey.pem".to_string()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_output<T: Serialize + Clone>(name: String, item: &DefaultBridgeConfigItem<T>) -> String {
|
||||
fn to_output<T: Serialize + Clone>(name: String, item: &DefaultBridgeConfigItem<T>) -> String {
|
||||
let mut output = String::new();
|
||||
output.push_str(&comment_multiline(&item.comment));
|
||||
let mut map = HashMap::new();
|
||||
@ -110,8 +126,8 @@ impl DefaultBridgeConfig {
|
||||
|
||||
pub fn output(&self) -> String {
|
||||
let mut output = String::new();
|
||||
output.push_str( &DefaultBridgeConfig::to_output("bot".to_string(),&self.bot));
|
||||
output.push_str( &DefaultBridgeConfig::to_output("bridge".to_string(),&self.bridge));
|
||||
output.push_str(&DefaultBridgeConfig::to_output("bot".to_string(),&self.bot));
|
||||
output.push_str(&DefaultBridgeConfig::to_output("bridge".to_string(),&self.bridge));
|
||||
output.push_str(&DefaultBridgeConfig::to_output("listeners".to_string(),&self.listeners));
|
||||
output.push_str(&DefaultBridgeConfig::to_output("logging".to_string(),&self.logging));
|
||||
output.push_str(&DefaultBridgeConfig::to_output("queue".to_string(),&self.queue));
|
||||
@ -127,6 +143,7 @@ impl From<DefaultBridgeConfig> for BridgeConfig {
|
||||
logging: d.logging.v,
|
||||
queue: Some(d.queue.v),
|
||||
listeners: d.listeners.v,
|
||||
passFile: d.passFile.v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,16 @@ use std::fs::File;
|
||||
use std::collections::HashMap;
|
||||
use napi::{Error, Status};
|
||||
|
||||
use self::config::{*};
|
||||
use self::{config::{*}, defaults::DefaultBridgeConfig};
|
||||
|
||||
pub mod config;
|
||||
pub mod defaults;
|
||||
|
||||
#[napi]
|
||||
pub fn get_default_config() -> String {
|
||||
DefaultBridgeConfig::new().output()
|
||||
}
|
||||
|
||||
|
||||
#[napi]
|
||||
impl BridgeConfig {
|
||||
|
@ -5,6 +5,9 @@ pub mod config;
|
||||
#[macro_use]
|
||||
extern crate napi_derive;
|
||||
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate serde_yaml;
|
||||
|
Loading…
x
Reference in New Issue
Block a user