Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions server/src/banner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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!(
"
{}
Expand All @@ -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);
}
Expand All @@ -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!(
Expand Down
34 changes: 28 additions & 6 deletions server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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/<version>/<commit_hash> (OS; Platform)
fn user_agent() -> String {
// Format: Parseable/<UID>/<version>/<commit_hash> (<OS>; <Platform>)
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<LatestRelease, anyhow::Error> {
pub fn get_latest(meta: StorageMetadata) -> Result<LatestRelease, anyhow::Error> {
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();

Expand Down