From 8222d39de11e2240b53b7f3839ad0b7ea42226ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Thu, 22 Aug 2019 17:26:26 +0200 Subject: [PATCH 1/2] fixed hostname and version fields in /api/0/info --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + src/endpoints/mod.rs | 8 ++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3cc06740..fac27ae6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,6 +55,7 @@ dependencies = [ "chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam_requests 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)", + "gethostname 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "jni 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", @@ -332,6 +333,15 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "gethostname" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "getrandom" version = "0.1.10" @@ -1536,6 +1546,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum gethostname 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4ab273ca2a31eb6ca40b15837ccf1aa59a43c5db69ac10c542be342fae2e01d" "checksum getrandom 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6171a6cc63fbabbe27c2b5ee268e8b7fe5dc1eb0dd2dfad537c1dfed6f69117e" "checksum groupable 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32619942b8be646939eaf3db0602b39f5229b74575b67efc897811ded1db4e57" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" diff --git a/Cargo.toml b/Cargo.toml index 258d3733..2037fb67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ lazy_static = "1.2" log = "0.4" fern = { version = "0.5", features = ["colored"] } toml = "0.5" +gethostname = "0.2" [target.'cfg(target_os="android")'.dependencies] jni = { version = "0.5", default-features = false } diff --git a/src/endpoints/mod.rs b/src/endpoints/mod.rs index eeebb864..61d21e5f 100644 --- a/src/endpoints/mod.rs +++ b/src/endpoints/mod.rs @@ -5,6 +5,7 @@ use rocket; use rocket::response::{NamedFile}; use rocket::State; use rocket_contrib::json::JsonValue; +use gethostname::gethostname; use crate::config::AWConfig; @@ -71,9 +72,12 @@ fn server_info() -> JsonValue { testing = false; } + let hostname = gethostname().into_string().unwrap_or("unknown".to_string()); + const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + json!({ - "hostname": "johan-desktop", - "version": "aw-server-rust_v0.1", + "hostname": hostname, + "version": format!("aw-server-rust v{}", VERSION), "testing": testing }) } From 88db8ab37acba6706f72cad1c95b1b6f97cfa1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Thu, 22 Aug 2019 17:51:40 +0200 Subject: [PATCH 2/2] added fallback for version/CARGO_PKG_VERSION in /api/0/info --- src/endpoints/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/endpoints/mod.rs b/src/endpoints/mod.rs index 61d21e5f..aee4d05b 100644 --- a/src/endpoints/mod.rs +++ b/src/endpoints/mod.rs @@ -73,11 +73,11 @@ fn server_info() -> JsonValue { } let hostname = gethostname().into_string().unwrap_or("unknown".to_string()); - const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); json!({ "hostname": hostname, - "version": format!("aw-server-rust v{}", VERSION), + "version": format!("aw-server-rust v{}", VERSION.unwrap_or("(unknown)")), "testing": testing }) }