microsandbox_utils/
env.rs

1//! Utility functions for working with environment variables.
2
3use std::path::PathBuf;
4
5use crate::{DEFAULT_MICROSANDBOX_HOME, DEFAULT_OCI_REGISTRY};
6
7//--------------------------------------------------------------------------------------------------
8// Constants
9//--------------------------------------------------------------------------------------------------
10
11/// Environment variable for the microsandbox home directory
12pub const MICROSANDBOX_HOME_ENV_VAR: &str = "MICROSANDBOX_HOME";
13
14/// Environment variable for the OCI registry domain
15pub const OCI_REGISTRY_ENV_VAR: &str = "OCI_REGISTRY_DOMAIN";
16
17/// Environment variable for the msbrun binary path
18pub const MSBRUN_EXE_ENV_VAR: &str = "MSBRUN_EXE";
19
20/// Environment variable for the msbserver binary path
21pub const MSBSERVER_EXE_ENV_VAR: &str = "MSBSERVER_EXE";
22
23//--------------------------------------------------------------------------------------------------
24// Functions
25//--------------------------------------------------------------------------------------------------
26
27/// Returns the path to the microsandbox home directory.
28/// If the MICROSANDBOX_HOME environment variable is set, returns that path.
29/// Otherwise, returns the default microsandbox home path.
30pub fn get_microsandbox_home_path() -> PathBuf {
31    if let Ok(microsandbox_home) = std::env::var(MICROSANDBOX_HOME_ENV_VAR) {
32        PathBuf::from(microsandbox_home)
33    } else {
34        DEFAULT_MICROSANDBOX_HOME.to_owned()
35    }
36}
37
38/// Returns the domain for the OCI registry.
39/// If the OCI_REGISTRY_DOMAIN environment variable is set, returns that value.
40/// Otherwise, returns the default OCI registry domain.
41pub fn get_oci_registry() -> String {
42    if let Ok(oci_registry_domain) = std::env::var(OCI_REGISTRY_ENV_VAR) {
43        oci_registry_domain
44    } else {
45        DEFAULT_OCI_REGISTRY.to_string()
46    }
47}