diff --git a/server/src/banner.rs b/server/src/banner.rs index be637e8df..90edee38d 100644 --- a/server/src/banner.rs +++ b/server/src/banner.rs @@ -27,7 +27,7 @@ pub fn print(config: &Config, meta: StorageMetadata) { let scheme = config.parseable.get_scheme(); status_info(config, &scheme, meta.deployment_id); storage_info(config); - about::print(); + about::print(meta); println!(); } @@ -95,6 +95,7 @@ pub mod about { use crossterm::style::Stylize; use std::fmt; + use crate::storage::StorageMetadata; use crate::utils::update; pub enum ParseableVersion { @@ -111,7 +112,11 @@ pub mod about { } } - pub fn print_about(current_version: semver::Version, commit_hash: String) { + pub fn print_about( + current_version: semver::Version, + commit_hash: String, + meta: StorageMetadata, + ) { eprint!( " {} @@ -120,7 +125,7 @@ pub mod about { current_version, ); - if let Ok(latest_release) = update::get_latest() { + if let Ok(latest_release) = update::get_latest(meta) { if latest_release.version > current_version { print_latest_release(latest_release); } @@ -144,13 +149,13 @@ pub mod about { eprint!("{}", fmt_latest_version.red()); } - pub fn print() { + pub fn print(meta: StorageMetadata) { // print current version let current = current(); match current.0 { ParseableVersion::Version(current_version) => { - print_about(current_version, current.1); + print_about(current_version, current.1, meta); } ParseableVersion::Prerelease(current_prerelease) => { eprintln!( diff --git a/server/src/utils.rs b/server/src/utils.rs index cabd71ff9..ca1e36881 100644 --- a/server/src/utils.rs +++ b/server/src/utils.rs @@ -134,10 +134,16 @@ pub mod uid { pub mod update { use crate::banner::about::current; + use std::env; use std::{path::Path, time::Duration}; use anyhow::anyhow; use chrono::{DateTime, Utc}; + use ulid::Ulid; + + use crate::storage::StorageMetadata; + + static K8S_ENV_TO_CHECK: &str = "KUBERNETES_SERVICE_HOST"; pub struct LatestRelease { pub version: semver::Version, @@ -151,22 +157,38 @@ pub mod update { "Native".to_string() } + fn is_k8s() -> String { + if env::var(K8S_ENV_TO_CHECK).is_ok() { + return "Kubernetes".to_string(); + } + "".to_string() + } + + fn platform() -> String { + let mut platform = is_k8s(); + if platform.is_empty() { + platform = is_docker(); + } + platform + } + // User Agent for Download API call - // Format: Parseable// (OS; Platform) - fn user_agent() -> String { + // Format: Parseable/// (; ) + fn user_agent(uid: Ulid) -> String { let info = os_info::get(); format!( - "Parseable/{}/{} ({}; {})", + "Parseable/{}/{}/{} ({}; {})", + uid, current().0, current().1, info.os_type(), - is_docker() + platform() ) } - pub fn get_latest() -> Result { + pub fn get_latest(meta: StorageMetadata) -> Result { let agent = ureq::builder() - .user_agent(user_agent().as_str()) + .user_agent(user_agent(meta.deployment_id).as_str()) .timeout(Duration::from_secs(8)) .build();