Skip to content

Commit

Permalink
* Add Target enum with platform detection
Browse files Browse the repository at this point in the history
* expose path dependending on target for wasm intergation
  • Loading branch information
paullegranddc committed Feb 6, 2025
1 parent faad98b commit e4d9bb2
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions library-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,36 +417,54 @@ pub struct Configurator {
debug_logs: bool,
}

impl Configurator {
pub const FLEET_STABLE_CONFIGURATION_PATH: &'static str = {
pub enum Target {
Linux,
Macos,
Windows,
}

impl Target {
#[cfg(any(target_os = "linux", target_os = "macos", windows))]
const fn current() -> Self {
#[cfg(target_os = "linux")]
{
"/etc/datadog-agent/managed/datadog-agent/stable/application_monitoring.yaml"
Self::Linux
}
#[cfg(target_os = "macos")]
{
"/opt/datadog-agent/etc/stable/application_monitoring.yaml"
Self::Macos
}
#[cfg(windows)]
{
"C:\\ProgramData\\Datadog\\managed\\datadog-agent\\stable\\application_monitoring.yaml"
Self::Windows
}
};
}
}

pub const LOCAL_STABLE_CONFIGURATION_PATH: &'static str = {
#[cfg(target_os = "linux")]
{
"/etc/datadog-agent/application_monitoring.yaml"
}
#[cfg(target_os = "macos")]
{
"/opt/datadog-agent/etc/application_monitoring.yaml"
impl Configurator {
#[cfg(any(target_os = "linux", target_os = "macos", windows))]
pub const FLEET_STABLE_CONFIGURATION_PATH: &'static str =
Self::fleet_stable_configuration_path(Target::current());

#[cfg(any(target_os = "linux", target_os = "macos", windows))]
pub const LOCAL_STABLE_CONFIGURATION_PATH: &'static str =
Self::local_stable_configuration_path(Target::current());

pub const fn local_stable_configuration_path(target: Target) -> &'static str {
match target {
Target::Linux => "/etc/datadog-agent/managed/datadog-agent/stable/application_monitoring.yaml",
Target::Macos => "/opt/datadog-agent/etc/stable/application_monitoring.yaml",
Target::Windows => "C:\\ProgramData\\Datadog\\managed\\datadog-agent\\stable\\application_monitoring.yaml",
}
#[cfg(windows)]
{
"C:\\ProgramData\\Datadog\\application_monitoring.yaml"
}

pub const fn fleet_stable_configuration_path(target: Target) -> &'static str {
match target {
Target::Linux => "/etc/datadog-agent/application_monitoring.yaml",
Target::Macos => "/opt/datadog-agent/etc/application_monitoring.yaml",
Target::Windows => "C:\\ProgramData\\Datadog\\application_monitoring.yaml",
}
};
}

pub fn new(debug_logs: bool) -> Self {
Self { debug_logs }
Expand Down

0 comments on commit e4d9bb2

Please sign in to comment.