datadog_agent_commons/platform/
mod.rs1#[cfg(target_os = "linux")]
4mod linux_impl;
5
6use std::path::{Path, PathBuf};
7
8#[cfg(target_os = "linux")]
9pub use self::linux_impl::*;
10
11#[cfg(target_os = "macos")]
12mod macos_impl;
13
14#[cfg(target_os = "macos")]
15pub use self::macos_impl::*;
16
17#[cfg(windows)]
18mod windows_impl;
19
20#[cfg(windows)]
21pub use self::windows_impl::*;
22
23pub const DATADOG_AGENT_ENV_VAR_PREFIX: &str = "DD";
25
26pub struct PlatformSettings;
28
29impl PlatformSettings {
30 pub fn get_config_dir_path() -> &'static Path {
32 get_config_dir_path()
33 }
34
35 pub fn get_config_file_path() -> PathBuf {
37 Self::get_config_dir_path().join("datadog.yaml")
38 }
39
40 pub fn get_auth_token_path() -> PathBuf {
42 Self::get_config_dir_path().join("auth_token")
43 }
44
45 pub fn get_ipc_cert_filename() -> &'static Path {
47 Path::new("ipc_cert.pem")
48 }
49
50 pub fn get_default_log_file_path() -> PathBuf {
52 Self::get_log_dir_path().join("agent-data-plane.log")
53 }
54
55 pub fn get_default_dogstatsd_log_file_path() -> PathBuf {
57 Self::get_log_dir_path()
58 .join("dogstatsd_info")
59 .join("dogstatsd-stats.log")
60 }
61
62 pub const fn get_default_syslog_uri() -> &'static str {
64 DATADOG_AGENT_DEFAULT_SYSLOG_URI
65 }
66
67 fn get_log_dir_path() -> &'static Path {
68 get_log_dir_path()
69 }
70
71 pub const fn get_env_var_prefix() -> &'static str {
73 DATADOG_AGENT_ENV_VAR_PREFIX
74 }
75}
76
77#[cfg(test)]
78mod tests {
79 use super::PlatformSettings;
80
81 #[test]
82 fn default_log_files_are_derived_from_platform_log_dir() {
83 assert_eq!(
84 PlatformSettings::get_default_log_file_path(),
85 PlatformSettings::get_log_dir_path().join("agent-data-plane.log")
86 );
87 assert_eq!(
88 PlatformSettings::get_default_dogstatsd_log_file_path(),
89 PlatformSettings::get_log_dir_path()
90 .join("dogstatsd_info")
91 .join("dogstatsd-stats.log")
92 );
93 }
94}