Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow variables in platform property values #809

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions nativelink-config/src/cas_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::schedulers::SchedulerConfig;
use crate::serde_utils::{
convert_numeric_with_shellexpand, convert_optional_numeric_with_shellexpand,
convert_optional_string_with_shellexpand, convert_string_with_shellexpand,
convert_vec_string_with_shellexpand,
};
use crate::stores::{ClientTlsConfig, ConfigDigestHashFunction, StoreConfig, StoreRefName};

Expand Down Expand Up @@ -378,6 +379,7 @@ pub enum WorkerProperty {
/// List of static values.
/// Note: Generally there should only ever be 1 value, but if the platform
/// property key is PropertyType::Priority it may have more than one value.
#[serde(deserialize_with = "convert_vec_string_with_shellexpand")]
values(Vec<String>),

/// A dynamic configuration. The string will be executed as a command
Expand Down
14 changes: 14 additions & 0 deletions nativelink-config/src/serde_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ pub fn convert_string_with_shellexpand<'de, D: Deserializer<'de>>(
Ok((*(shellexpand::env(&value).map_err(de::Error::custom)?)).to_string())
}

/// Same as convert_string_with_shellexpand, but supports Vec<String>.
pub fn convert_vec_string_with_shellexpand<'de, D: Deserializer<'de>>(
deserializer: D,
) -> Result<Vec<String>, D::Error> {
let vec = Vec::<String>::deserialize(deserializer)?;
vec.into_iter()
.map(|s| {
shellexpand::env(&s)
.map_err(de::Error::custom)
.map(|expanded| expanded.into_owned())
})
.collect()
}

/// Same as convert_string_with_shellexpand, but supports Option<String>.
pub fn convert_optional_string_with_shellexpand<'de, D: Deserializer<'de>>(
deserializer: D,
Expand Down