Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions library/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct UpdateConfig {
pub file_provider: Box<dyn ExternalFileProvider>,
pub patch_public_key: Option<String>,
pub patch_verification: PatchVerificationMode,
pub module_version: Option<String>,
}

/// Returns Ok if the config was set successfully, Err if it was already set.
Expand Down Expand Up @@ -129,6 +130,7 @@ pub fn set_config(
file_provider,
patch_public_key: yaml.patch_public_key.to_owned(),
patch_verification: yaml.patch_verification.unwrap_or_default(),
module_version: yaml.module_version.to_owned(),
};
shorebird_debug!("Updater configured with: {:?}", new_config);
*config = Some(new_config);
Expand Down Expand Up @@ -198,6 +200,7 @@ mod tests {
base_url: Some("fake_base_url".to_string()),
patch_public_key: None,
patch_verification: None,
module_version: None,
}
}

Expand All @@ -223,6 +226,7 @@ mod tests {
base_url: Some("fake_base_url".to_string()),
patch_public_key: Some("patch_public_key".to_string()),
patch_verification: None,
module_version: None,
},
NetworkHooks::default(),
)?;
Expand Down
7 changes: 7 additions & 0 deletions library/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ pub struct PatchCheckRequest {
/// The unique ID of this device. This is a random UUID generated by Shorebird and _not_ the
/// device's UUID or any other identifier that has meaning outside of Shorebird.
pub client_id: String,
/// Module version for add-to-app releases (AAR/iOS framework).
/// When present, used instead of release_version for patch lookup.
/// The release_version still contains the host app's version for analytics.
#[serde(skip_serializing_if = "Option::is_none")]
pub module_version: Option<String>,
// We specifically do not send a patch number as part of this request because we always want to
// know what the latest available patch is.
}
Expand All @@ -260,6 +265,7 @@ impl PatchCheckRequest {
platform: current_platform().to_string(),
arch: current_arch().to_string(),
client_id: client_id.to_string(),
module_version: config.module_version.clone(),
}
}
}
Expand Down Expand Up @@ -404,6 +410,7 @@ mod tests {
platform: "".to_string(),
arch: "".to_string(),
client_id: "".to_string(),
module_version: None,
},
);
assert!(result.is_err());
Expand Down
15 changes: 15 additions & 0 deletions library/src/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct YamlConfig {
pub patch_public_key: Option<String>,
/// When to verify patch signatures. Defaults to "strict" (verify at boot time).
pub patch_verification: Option<PatchVerificationMode>,
/// Module version for add-to-app releases (AAR/iOS framework).
/// When present, used instead of release_version for patch lookup.
pub module_version: Option<String>,
}

impl YamlConfig {
Expand All @@ -42,6 +45,7 @@ impl YamlConfig {
let mut auto_update: Option<bool> = None;
let mut patch_public_key: Option<String> = None;
let mut patch_verification: Option<PatchVerificationMode> = None;
let mut module_version: Option<String> = None;

for line in yaml.lines() {
let line = line.trim();
Expand Down Expand Up @@ -75,6 +79,7 @@ impl YamlConfig {
}
});
}
"module_version" => module_version = Some(value.to_string()),
_ => {} // Ignore unknown keys for forward compatibility.
}
}
Expand All @@ -88,6 +93,7 @@ impl YamlConfig {
auto_update,
patch_public_key,
patch_verification,
module_version,
})
}
}
Expand Down Expand Up @@ -161,6 +167,7 @@ base_url: https://example.com
auto_update: false
patch_public_key: abc123
patch_verification: install_only
module_version: 1.2.3
"#;
let config = YamlConfig::from_yaml(yaml).unwrap();
assert_eq!(config.app_id, "my_app");
Expand All @@ -172,6 +179,14 @@ patch_verification: install_only
config.patch_verification,
Some(PatchVerificationMode::InstallOnly)
);
assert_eq!(config.module_version.as_deref(), Some("1.2.3"));
}

#[test]
fn module_version_defaults_to_none() {
let yaml = "app_id: test_app\n";
let config = YamlConfig::from_yaml(yaml).unwrap();
assert_eq!(config.module_version, None);
}

#[test]
Expand Down