cat_gateway/
build_info.rs

1//! Binary build info
2
3use build_info::{self as build_info_crate};
4use local_ip_address::list_afinet_netifas;
5use tracing::info;
6
7use crate::service::utilities;
8
9/// Formatted Binary build info
10pub(crate) const BUILD_INFO: &str = build_info_crate::format!("
11version: {},
12git info: {{{}}}
13compiler: {}
14build time: {}
15",
16    $.crate_info.version,
17    $.version_control,
18    $.compiler,
19    $.timestamp
20);
21
22build_info_crate::build_info!(fn build_info);
23
24/// Log Build Info to our logs.
25pub(crate) fn log_build_info() {
26    let info = build_info();
27    let timestamp = info.timestamp.to_rfc3339();
28    let profile = info.profile.clone();
29    let optimization_level = info.optimization_level.to_string();
30
31    let name = info.crate_info.name.clone();
32    let version = info.crate_info.version.to_string();
33    let features = info.crate_info.enabled_features.join(",");
34
35    let triple = info.target.triple.clone();
36    let family = info.target.family.clone();
37    let os = info.target.os.clone();
38    let cpu_arch = info.target.cpu.arch.clone();
39    let cpu_features = info.target.cpu.features.join(",");
40
41    let compiler_channel = info.compiler.channel.to_string();
42    let compiler_version = info.compiler.version.to_string();
43
44    let mut commit_id = "Unknown".to_string();
45    let mut commit_timestamp = "Unknown".to_string();
46    let mut branch = "Unknown".to_string();
47    let mut tags = "Unknown".to_string();
48
49    if let Some(ref vc) = info.version_control {
50        if let Some(git) = vc.git() {
51            commit_id.clone_from(&git.commit_short_id);
52            commit_timestamp = git.commit_timestamp.to_rfc3339();
53            if let Some(git_branch) = git.branch.clone() {
54                branch = git_branch;
55            }
56            tags = git.tags.join(",");
57        }
58    }
59
60    let ipv4 = utilities::net::get_public_ipv4().to_string();
61    let ipv6 = utilities::net::get_public_ipv6().to_string();
62
63    let mut interfaces: String = "Unknown".to_string();
64
65    // Get local IP address v4 and v6
66    if let Ok(network_interfaces) = list_afinet_netifas() {
67        if !network_interfaces.is_empty() {
68            interfaces.clear();
69            for iface in network_interfaces {
70                if !interfaces.is_empty() {
71                    interfaces.push(',');
72                }
73                interfaces.push_str(&format!("{}:{}", iface.0, iface.1));
74            }
75        }
76    }
77
78    info!(
79        BuildTime = timestamp,
80        Profile = profile,
81        OptimizationLevel = optimization_level,
82        Name = name,
83        Version = version,
84        Features = features,
85        TargetTriple = triple,
86        TargetFamily = family,
87        TargetOs = os,
88        CPUArch = cpu_arch,
89        CPUFeatures = cpu_features,
90        RustChannel = compiler_channel,
91        RustVersion = compiler_version,
92        GitCommitId = commit_id,
93        GitCommitTimestamp = commit_timestamp,
94        GitBranch = branch,
95        GitTags = tags,
96        PublicIPv4 = ipv4,
97        PublicIPv6 = ipv6,
98        NetworkInterfaces = interfaces,
99        "Catalyst Gateway"
100    );
101}
102
103#[cfg(test)]
104mod tests {
105    use super::*;
106
107    #[test]
108    fn build_info_test() {
109        println!("{BUILD_INFO}");
110    }
111}