提交 5ddfcee8 authored 作者: Serhij S's avatar Serhij S

CLI works on PLC server

上级 57f366e2
...@@ -864,9 +864,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" ...@@ -864,9 +864,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]] [[package]]
name = "openssl" name = "openssl"
version = "0.10.64" version = "0.10.72"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da"
dependencies = [ dependencies = [
"bitflags 2.5.0", "bitflags 2.5.0",
"cfg-if", "cfg-if",
...@@ -894,14 +894,24 @@ version = "0.1.5" ...@@ -894,14 +894,24 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "300.4.2+3.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168ce4e058f975fe43e89d9ccf78ca668601887ae736090aacc23ae353c298e2"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "openssl-sys" name = "openssl-sys"
version = "0.9.102" version = "0.9.107"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" checksum = "8288979acd84749c744a9014b4382d42b8f7b2592847b5afb2ed29e5d16ede07"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
"openssl-src",
"pkg-config", "pkg-config",
"vcpkg", "vcpkg",
] ]
...@@ -1071,6 +1081,7 @@ dependencies = [ ...@@ -1071,6 +1081,7 @@ dependencies = [
"dirs", "dirs",
"futures-util", "futures-util",
"once_cell", "once_cell",
"openssl",
"prettytable-rs", "prettytable-rs",
"serde", "serde",
"serde_json", "serde_json",
......
...@@ -33,6 +33,7 @@ bma-ts = { version = "0.1.14", features = ["serde", "chrono"] } ...@@ -33,6 +33,7 @@ bma-ts = { version = "0.1.14", features = ["serde", "chrono"] }
prettytable-rs = "0.10.0" prettytable-rs = "0.10.0"
chrono = "0.4.39" chrono = "0.4.39"
url = "2.5.4" url = "2.5.4"
openssl = "0.10.72"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
ansi_term = "0.12.1" ansi_term = "0.12.1"
...@@ -42,3 +43,6 @@ termios = "0.3.3" ...@@ -42,3 +43,6 @@ termios = "0.3.3"
[profile.release] [profile.release]
strip = true strip = true
[features]
openssl-vendored = ["openssl/vendored"]
...@@ -85,3 +85,27 @@ pub fn get_global_remote(url: &str) -> Option<Remote> { ...@@ -85,3 +85,27 @@ pub fn get_global_remote(url: &str) -> Option<Remote> {
} }
} }
} }
#[derive(Deserialize)]
pub struct ServerConfig {
pub http: ServerHttpConfig,
pub aaa: ServerAaaConfig,
}
impl ServerConfig {
pub fn load() -> Result<Self, Box<dyn std::error::Error>> {
let s = fs::read_to_string("/etc/roboplc/manager.toml")?;
let config: ServerConfig = toml::from_str(&s)?;
Ok(config)
}
}
#[derive(Deserialize)]
pub struct ServerHttpConfig {
pub bind: String,
}
#[derive(Deserialize)]
pub struct ServerAaaConfig {
pub management_key: Option<String>,
}
...@@ -91,6 +91,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -91,6 +91,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
project::create(maybe_url, maybe_key, maybe_timeout, &opts)?; project::create(maybe_url, maybe_key, maybe_timeout, &opts)?;
return Ok(()); return Ok(());
} }
if maybe_url.is_none() {
// we may be on a server, try parsing local manager.toml
let server_config = match config::ServerConfig::load() {
Ok(config) => config,
Err(e) => {
return Err(format!(r"URL not specified in options or robo.toml, also tried to load the server /etc/roboplc/manager.toml but failed with {}", e).into());
}
};
if maybe_key.is_none() {
maybe_key = server_config.aaa.management_key;
}
let mut sp = server_config.http.bind.splitn(2, ':');
let mut host = sp.next().unwrap();
let port = sp.next().unwrap_or("7700");
if host == "0.0.0.0" {
host = "127.0.0.1";
}
maybe_url = Some(format!("http://{}:{}", host, port));
}
let url = maybe_url.ok_or("URL not specified")?; let url = maybe_url.ok_or("URL not specified")?;
let key = if let Some(k) = maybe_key { let key = if let Some(k) = maybe_key {
k k
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论