Skip to content

Commit 35f1ace

Browse files
committed
refactor(activity-fly-http)!: Allow specifying null values for env vars
1 parent 5148488 commit 35f1ace

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

fly/activity-fly-http/fly-http-machine-config.json.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cat <<EOF
2626
"protocol": "tcp"
2727
}
2828
],
29-
"env": [ ["key", "val"], ["other", "otherval"] ],
29+
"env": [ ["key", "val"], ["other", null] ],
3030
"files": [
3131
{"guest-path":"/etc/info.txt", "raw-value":"$(echo -n "hello" | base64)"}
3232
],

fly/activity-fly-http/src/machine.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ pub(crate) mod env_serde {
1919

2020
pub fn deserialize<'de, D>(
2121
deserializer: D,
22-
) -> Result<Option<Vec<(String, String)>>, D::Error>
22+
) -> Result<Option<Vec<(String, Option<String>)>>, D::Error>
2323
where
2424
D: Deserializer<'de>,
2525
{
26-
let map: Option<BTreeMap<String, String>> = Option::deserialize(deserializer)?;
26+
let map: Option<BTreeMap<String, Option<String>>> = Option::deserialize(deserializer)?;
2727
Ok(map.map(|m| m.into_iter().collect()))
2828
}
2929

3030
pub fn serialize<S>(
31-
value: &Option<Vec<(String, String)>>,
31+
value: &Option<Vec<(String, Option<String>)>>,
3232
serializer: S,
3333
) -> Result<S::Ok, S::Error>
3434
where
@@ -37,8 +37,10 @@ pub(crate) mod env_serde {
3737
match value {
3838
None => serializer.serialize_none(),
3939
Some(pairs) => {
40-
let map: BTreeMap<&str, &str> =
41-
pairs.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect();
40+
let map: BTreeMap<&str, Option<&str>> = pairs
41+
.iter()
42+
.map(|(k, v)| (k.as_str(), v.as_deref()))
43+
.collect();
4244
map.serialize(serializer)
4345
}
4446
}
@@ -472,7 +474,7 @@ mod tests {
472474
"env": {
473475
"OBELISK__API__LISTENING_ADDR": "",
474476
"OBELISK__EXTERNAL__LISTENING_ADDR": "",
475-
"OBELISK__WEBUI__LISTENING_ADDR": ""
477+
"OBELISK__WEBUI__LISTENING_ADDR": null
476478
},
477479
"init": {
478480
"entrypoint": [

fly/activity-fly-http/src/snapshots/activity_fly_http__machine__tests__machine_deserialization.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ Machine {
4242
[
4343
(
4444
"OBELISK__API__LISTENING_ADDR",
45-
"",
45+
Some(
46+
"",
47+
),
4648
),
4749
(
4850
"OBELISK__EXTERNAL__LISTENING_ADDR",
49-
"",
51+
Some(
52+
"",
53+
),
5054
),
5155
(
5256
"OBELISK__WEBUI__LISTENING_ADDR",
53-
"",
57+
None,
5458
),
5559
],
5660
),

fly/activity-fly-http/wit/obelisk-flyio_activity-fly-http@1.0.0-beta/fly.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ interface machines {
117117
/// Destroy the VM after first exec
118118
auto-destroy: option<bool>,
119119
init: option<init-config>,
120-
env: option<list<tuple<string, string>>>,
120+
env: option<list<tuple<string, option<string>>>>,
121121
restart: option<machine-restart>,
122122
stop-config: option<stop-config>,
123123
mounts: option<list<mount>>,

0 commit comments

Comments
 (0)