feat(agents): add versioned offline driver packages
This commit is contained in:
1 parent
8d68a527a0
commit
79cd12d13a
29 files changed
+1372
-162
No files matched your search
@@ -3,9 +3,9 @@ use dbx_core::agent_manager::{
|
||||
JreInfo, DEFAULT_JRE_KEY,
|
||||
};
|
||||
use dbx_core::agent_service::{
|
||||
build_agent_list, clear_agent_download_cache, github_url_to_r2_path, import_agent_jar, import_agents_from_zip,
|
||||
is_app_version_compatible, jre_needs_install, local_agent_jar_candidates, replace_download, uninstall_agent_driver,
|
||||
AgentProgressEvent,
|
||||
build_agent_list, clear_agent_download_cache, github_url_to_r2_path, import_agent_driver, import_agent_jar,
|
||||
import_agents_from_zip, inspect_offline_zip, is_app_version_compatible, jre_needs_install,
|
||||
local_agent_jar_candidates, replace_download, uninstall_agent_driver, AgentProgressEvent,
|
||||
};
|
||||
|
||||
fn test_manager(name: &str) -> AgentManager {
|
||||
@@ -406,6 +406,51 @@ fn local_jar_import_rejects_corrupt_jar() {
|
||||
assert!(!manager.load_state().installed_drivers.contains_key("h2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_native_import_installs_current_platform_executable() {
|
||||
let manager = test_manager("local-native-import");
|
||||
let source = test_path("local-native-import-source").join(if cfg!(windows) {
|
||||
"dbx-agent-kingbase-windows.exe"
|
||||
} else {
|
||||
"dbx-agent-kingbase"
|
||||
});
|
||||
std::fs::create_dir_all(source.parent().unwrap()).unwrap();
|
||||
std::fs::write(&source, current_platform_native_binary()).unwrap();
|
||||
|
||||
import_agent_driver(&manager, "kingbase", &source).unwrap();
|
||||
|
||||
assert_eq!(std::fs::read(manager.driver_native_path("kingbase")).unwrap(), std::fs::read(&source).unwrap());
|
||||
assert!(!manager.driver_jar_path("kingbase").exists());
|
||||
assert_eq!(manager.load_state().installed_drivers["kingbase"].version, "0.1.0-local");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_native_import_rejects_wrong_platform_binary() {
|
||||
let manager = test_manager("local-native-import-invalid");
|
||||
let source = test_path("local-native-import-invalid-source").join("dbx-agent-kingbase");
|
||||
std::fs::create_dir_all(source.parent().unwrap()).unwrap();
|
||||
std::fs::write(&source, b"not-an-executable").unwrap();
|
||||
|
||||
let err = import_agent_driver(&manager, "kingbase", &source).unwrap_err();
|
||||
|
||||
assert!(err.contains(AgentManager::current_platform()));
|
||||
assert!(!manager.driver_native_path("kingbase").exists());
|
||||
assert!(!manager.load_state().installed_drivers.contains_key("kingbase"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_native_import_rejects_wrong_arch_binary() {
|
||||
let manager = test_manager("local-native-wrong-arch");
|
||||
let native_path = test_path("local-native-wrong-arch-file").join("agent");
|
||||
std::fs::create_dir_all(native_path.parent().unwrap()).unwrap();
|
||||
std::fs::write(&native_path, native_binary_for_arch(!cfg!(target_arch = "aarch64"))).unwrap();
|
||||
|
||||
let err = import_agent_driver(&manager, "kingbase", &native_path).unwrap_err();
|
||||
|
||||
assert!(err.contains("not a"));
|
||||
assert!(!manager.driver_native_path("kingbase").exists());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn uninstall_driver_removes_artifact_and_state() {
|
||||
let manager = test_manager("uninstall");
|
||||
@@ -511,6 +556,53 @@ fn offline_zip_import_installs_release_named_jre() {
|
||||
assert!(events.lock().unwrap().iter().any(|event| event.step == "jre-extract"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_preserves_existing_jre_when_archive_is_corrupt() {
|
||||
let manager = test_manager("offline-corrupt-jre-preserves-existing");
|
||||
let root = test_path("offline-corrupt-jre-preserves-existing-zip");
|
||||
let valid_zip = root.join("valid.zip");
|
||||
let corrupt_zip = root.join("corrupt.zip");
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
write_offline_driver_zip_with_jre(&valid_zip, "h2", "0.2.0", "21.0.12");
|
||||
import_agents_from_zip(&manager, &valid_zip, |_| {}).unwrap();
|
||||
let java_path = manager.jre_java_path(DEFAULT_JRE_KEY);
|
||||
let original_java = std::fs::read(&java_path).unwrap();
|
||||
|
||||
write_offline_driver_zip_with_jre_bytes(&corrupt_zip, "h2", "0.3.0", "21.0.13", b"not-a-tar-gz".to_vec());
|
||||
let err = import_agents_from_zip(&manager, &corrupt_zip, |_| {}).unwrap_err();
|
||||
|
||||
assert!(err.contains("Failed to extract JRE archive"));
|
||||
assert_eq!(std::fs::read(java_path).unwrap(), original_java);
|
||||
assert_eq!(manager.load_state().jre_versions.get(DEFAULT_JRE_KEY).map(String::as_str), Some("21.0.12"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_preserves_existing_jre_when_driver_is_corrupt() {
|
||||
let manager = test_manager("offline-corrupt-driver-preserves-jre");
|
||||
let root = test_path("offline-corrupt-driver-preserves-jre-zip");
|
||||
let valid_zip = root.join("valid.zip");
|
||||
let corrupt_zip = root.join("corrupt.zip");
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
write_offline_driver_zip_with_jre(&valid_zip, "h2", "0.2.0", "21.0.12");
|
||||
import_agents_from_zip(&manager, &valid_zip, |_| {}).unwrap();
|
||||
let java_path = manager.jre_java_path(DEFAULT_JRE_KEY);
|
||||
let original_java = std::fs::read(&java_path).unwrap();
|
||||
|
||||
write_offline_driver_zip_with_jre_and_jar_bytes(
|
||||
&corrupt_zip,
|
||||
"h2",
|
||||
"0.3.0",
|
||||
"21.0.13",
|
||||
test_jre_archive_bytes(),
|
||||
b"jar".to_vec(),
|
||||
);
|
||||
let err = import_agents_from_zip(&manager, &corrupt_zip, |_| {}).unwrap_err();
|
||||
|
||||
assert!(err.contains("invalid or corrupt"));
|
||||
assert_eq!(std::fs::read(java_path).unwrap(), original_java);
|
||||
assert_eq!(manager.load_state().jre_versions.get(DEFAULT_JRE_KEY).map(String::as_str), Some("21.0.12"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_rejects_corrupt_jar() {
|
||||
let manager = test_manager("offline-corrupt-driver");
|
||||
@@ -525,16 +617,284 @@ fn offline_zip_import_rejects_corrupt_jar() {
|
||||
assert!(!manager.load_state().installed_drivers.contains_key("h2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_preserves_existing_driver_when_jar_is_corrupt() {
|
||||
let manager = test_manager("offline-corrupt-driver-preserves-existing");
|
||||
let root = test_path("offline-corrupt-driver-preserves-existing-zip");
|
||||
let valid_zip = root.join("valid.zip");
|
||||
let corrupt_zip = root.join("corrupt.zip");
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
write_offline_driver_zip(&valid_zip, "h2", "0.2.0");
|
||||
import_agents_from_zip(&manager, &valid_zip, |_| {}).unwrap();
|
||||
let original = std::fs::read(manager.driver_jar_path("h2")).unwrap();
|
||||
|
||||
write_offline_driver_zip_with_jar(&corrupt_zip, "h2", "0.3.0", b"jar".to_vec());
|
||||
let err = import_agents_from_zip(&manager, &corrupt_zip, |_| {}).unwrap_err();
|
||||
|
||||
assert!(err.contains("invalid or corrupt"));
|
||||
assert_eq!(std::fs::read(manager.driver_jar_path("h2")).unwrap(), original);
|
||||
assert_eq!(manager.load_state().installed_drivers["h2"].version, "0.2.0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_keeps_legacy_unversioned_jar_compatibility() {
|
||||
let manager = test_manager("offline-legacy-jar-zip");
|
||||
let zip_path = test_path("offline-legacy-jar-zip").join("h2.zip");
|
||||
std::fs::create_dir_all(zip_path.parent().unwrap()).unwrap();
|
||||
let file = std::fs::File::create(&zip_path).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
let options = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
let jar = test_agent_jar_bytes();
|
||||
let registry = serde_json::json!({
|
||||
"drivers": {
|
||||
"h2": {
|
||||
"version": "0.1.9",
|
||||
"label": "H2",
|
||||
"min_app_version": "0.1.0",
|
||||
"jre": DEFAULT_JRE_KEY,
|
||||
"jar": { "url": "https://example.com/dbx-agent-h2.jar", "size": jar.len() }
|
||||
}
|
||||
}
|
||||
});
|
||||
zip.start_file("agent-registry.json", options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, registry.to_string().as_bytes()).unwrap();
|
||||
zip.start_file("drivers/dbx-agent-h2.jar", options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, &jar).unwrap();
|
||||
zip.finish().unwrap();
|
||||
|
||||
import_agents_from_zip(&manager, &zip_path, |_| {}).unwrap();
|
||||
|
||||
assert_eq!(manager.load_state().installed_drivers["h2"].version, "0.1.9");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_installs_versioned_native_driver_package() {
|
||||
let manager = test_manager("offline-native-driver-zip");
|
||||
let zip_path = test_path("offline-native-driver-zip").join("kingbase.zip");
|
||||
std::fs::create_dir_all(zip_path.parent().unwrap()).unwrap();
|
||||
write_offline_native_driver_zip(&zip_path, "kingbase", "0.1.34");
|
||||
|
||||
let result = import_agents_from_zip(&manager, &zip_path, |_| {}).unwrap();
|
||||
|
||||
assert_eq!(result.drivers_installed, vec!["kingbase"]);
|
||||
assert_eq!(manager.load_state().installed_drivers["kingbase"].version, "0.1.34");
|
||||
assert_eq!(std::fs::read(manager.driver_native_path("kingbase")).unwrap(), current_platform_native_binary());
|
||||
assert!(!manager.driver_jar_path("kingbase").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_rejects_native_driver_for_another_platform() {
|
||||
let manager = test_manager("offline-wrong-platform-native-driver-zip");
|
||||
let zip_path = test_path("offline-wrong-platform-native-driver-zip").join("kingbase.zip");
|
||||
std::fs::create_dir_all(zip_path.parent().unwrap()).unwrap();
|
||||
let other_platform = if AgentManager::current_platform() == "windows-x64" { "linux-x64" } else { "windows-x64" };
|
||||
write_offline_native_driver_zip_for_platform(&zip_path, "kingbase", "0.1.34", other_platform);
|
||||
|
||||
let err = import_agents_from_zip(&manager, &zip_path, |_| {}).unwrap_err();
|
||||
|
||||
assert!(err.contains("no drivers compatible"));
|
||||
assert!(err.contains(AgentManager::current_platform()));
|
||||
assert!(!manager.is_driver_installed("kingbase"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_preserves_existing_native_driver_when_binary_is_invalid() {
|
||||
let manager = test_manager("offline-invalid-native-preserves-existing");
|
||||
let root = test_path("offline-invalid-native-preserves-existing-zip");
|
||||
let valid_zip = root.join("valid.zip");
|
||||
let invalid_zip = root.join("invalid.zip");
|
||||
std::fs::create_dir_all(&root).unwrap();
|
||||
write_offline_native_driver_zip(&valid_zip, "kingbase", "0.1.34");
|
||||
import_agents_from_zip(&manager, &valid_zip, |_| {}).unwrap();
|
||||
let original = std::fs::read(manager.driver_native_path("kingbase")).unwrap();
|
||||
|
||||
write_offline_native_driver_zip_with_bytes(
|
||||
&invalid_zip,
|
||||
"kingbase",
|
||||
"0.1.35",
|
||||
AgentManager::current_platform(),
|
||||
b"not-a-native-agent".to_vec(),
|
||||
);
|
||||
let err = import_agents_from_zip(&manager, &invalid_zip, |_| {}).unwrap_err();
|
||||
|
||||
assert!(err.contains("not a"));
|
||||
assert_eq!(std::fs::read(manager.driver_native_path("kingbase")).unwrap(), original);
|
||||
assert_eq!(manager.load_state().installed_drivers["kingbase"].version, "0.1.34");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_inspection_reports_drivers_and_jre() {
|
||||
let zip_path = test_path("offline-inspection").join("agents.zip");
|
||||
std::fs::create_dir_all(zip_path.parent().unwrap()).unwrap();
|
||||
write_offline_driver_zip_with_jre(&zip_path, "h2", "0.2.0", "21.0.12");
|
||||
|
||||
let plan = inspect_offline_zip(&zip_path).unwrap();
|
||||
|
||||
assert_eq!(plan.driver_keys, vec!["h2"]);
|
||||
assert!(plan.includes_jre);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_rejects_unknown_driver_type() {
|
||||
let zip_path = test_path("offline-unknown-driver").join("agents.zip");
|
||||
std::fs::create_dir_all(zip_path.parent().unwrap()).unwrap();
|
||||
write_offline_driver_zip_with_jar(&zip_path, "unknown-driver", "0.1.0", test_agent_jar_bytes());
|
||||
|
||||
let err = inspect_offline_zip(&zip_path).unwrap_err();
|
||||
|
||||
assert!(err.contains("unknown driver type"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_rejects_unsafe_entry_path() {
|
||||
let zip_path = test_path("offline-unsafe-entry").join("agents.zip");
|
||||
std::fs::create_dir_all(zip_path.parent().unwrap()).unwrap();
|
||||
let file = std::fs::File::create(&zip_path).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
let options = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
zip.start_file("agent-registry.json", options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, br#"{"drivers":{}}"#).unwrap();
|
||||
zip.start_file("../escape", options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, b"escape").unwrap();
|
||||
zip.finish().unwrap();
|
||||
|
||||
let err = inspect_offline_zip(&zip_path).unwrap_err();
|
||||
|
||||
assert!(err.contains("unsafe path"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offline_zip_import_prefers_native_artifact_over_java_fallback() {
|
||||
let manager = test_manager("offline-native-preferred");
|
||||
let zip_path = test_path("offline-native-preferred-zip").join("kingbase.zip");
|
||||
std::fs::create_dir_all(zip_path.parent().unwrap()).unwrap();
|
||||
write_offline_hybrid_driver_zip(&zip_path, "kingbase", "0.1.34");
|
||||
|
||||
let plan = inspect_offline_zip(&zip_path).unwrap();
|
||||
let result = import_agents_from_zip(&manager, &zip_path, |_| {}).unwrap();
|
||||
|
||||
assert_eq!(plan.driver_keys, vec!["kingbase"]);
|
||||
assert_eq!(result.drivers_installed, vec!["kingbase"]);
|
||||
assert!(manager.driver_native_path("kingbase").exists());
|
||||
assert!(!manager.driver_jar_path("kingbase").exists());
|
||||
}
|
||||
|
||||
fn write_offline_driver_zip(path: &std::path::Path, db_type: &str, version: &str) {
|
||||
write_offline_driver_zip_with_jar(path, db_type, version, test_agent_jar_bytes());
|
||||
}
|
||||
|
||||
fn write_offline_driver_zip_with_jre(path: &std::path::Path, db_type: &str, version: &str, jre_version: &str) {
|
||||
fn write_offline_native_driver_zip(path: &std::path::Path, db_type: &str, version: &str) {
|
||||
write_offline_native_driver_zip_for_platform(path, db_type, version, AgentManager::current_platform());
|
||||
}
|
||||
|
||||
fn write_offline_native_driver_zip_for_platform(path: &std::path::Path, db_type: &str, version: &str, platform: &str) {
|
||||
write_offline_native_driver_zip_with_bytes(path, db_type, version, platform, current_platform_native_binary());
|
||||
}
|
||||
|
||||
fn write_offline_native_driver_zip_with_bytes(
|
||||
path: &std::path::Path,
|
||||
db_type: &str,
|
||||
version: &str,
|
||||
platform: &str,
|
||||
native: Vec<u8>,
|
||||
) {
|
||||
let file = std::fs::File::create(path).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
let options = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
let extension = if platform.starts_with("windows-") { ".exe" } else { "" };
|
||||
let filename = format!("dbx-agent-{db_type}-{version}-{platform}{extension}");
|
||||
let registry = serde_json::json!({
|
||||
"jres": {},
|
||||
"drivers": {
|
||||
db_type: {
|
||||
"version": version,
|
||||
"label": db_type,
|
||||
"min_app_version": "0.6.0",
|
||||
"jre": DEFAULT_JRE_KEY,
|
||||
"native": {
|
||||
platform: {
|
||||
"url": format!("https://example.com/{filename}"),
|
||||
"size": native.len()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
zip.start_file("agent-registry.json", options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, registry.to_string().as_bytes()).unwrap();
|
||||
zip.start_file(format!("drivers/{filename}"), options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, &native).unwrap();
|
||||
zip.finish().unwrap();
|
||||
}
|
||||
|
||||
fn write_offline_hybrid_driver_zip(path: &std::path::Path, db_type: &str, version: &str) {
|
||||
let file = std::fs::File::create(path).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
let options = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
let jar = test_agent_jar_bytes();
|
||||
let jre_archive = test_jre_archive_bytes();
|
||||
let native = current_platform_native_binary();
|
||||
let platform = AgentManager::current_platform();
|
||||
let extension = if platform.starts_with("windows-") { ".exe" } else { "" };
|
||||
let jar_filename = format!("dbx-agent-{db_type}-{version}.jar");
|
||||
let native_filename = format!("dbx-agent-{db_type}-{version}-{platform}{extension}");
|
||||
let registry = serde_json::json!({
|
||||
"jres": {},
|
||||
"drivers": {
|
||||
db_type: {
|
||||
"version": version,
|
||||
"label": db_type,
|
||||
"min_app_version": "0.1.0",
|
||||
"jre": DEFAULT_JRE_KEY,
|
||||
"jar": { "url": format!("https://example.com/{jar_filename}"), "size": jar.len() },
|
||||
"native": {
|
||||
platform: { "url": format!("https://example.com/{native_filename}"), "size": native.len() }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
zip.start_file("agent-registry.json", options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, registry.to_string().as_bytes()).unwrap();
|
||||
zip.start_file(format!("drivers/{jar_filename}"), options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, &jar).unwrap();
|
||||
zip.start_file(format!("drivers/{native_filename}"), options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, &native).unwrap();
|
||||
zip.finish().unwrap();
|
||||
}
|
||||
|
||||
fn write_offline_driver_zip_with_jre(path: &std::path::Path, db_type: &str, version: &str, jre_version: &str) {
|
||||
write_offline_driver_zip_with_jre_bytes(path, db_type, version, jre_version, test_jre_archive_bytes());
|
||||
}
|
||||
|
||||
fn write_offline_driver_zip_with_jre_bytes(
|
||||
path: &std::path::Path,
|
||||
db_type: &str,
|
||||
version: &str,
|
||||
jre_version: &str,
|
||||
jre_archive: Vec<u8>,
|
||||
) {
|
||||
write_offline_driver_zip_with_jre_and_jar_bytes(
|
||||
path,
|
||||
db_type,
|
||||
version,
|
||||
jre_version,
|
||||
jre_archive,
|
||||
test_agent_jar_bytes(),
|
||||
);
|
||||
}
|
||||
|
||||
fn write_offline_driver_zip_with_jre_and_jar_bytes(
|
||||
path: &std::path::Path,
|
||||
db_type: &str,
|
||||
version: &str,
|
||||
jre_version: &str,
|
||||
jre_archive: Vec<u8>,
|
||||
jar: Vec<u8>,
|
||||
) {
|
||||
let file = std::fs::File::create(path).unwrap();
|
||||
let mut zip = zip::ZipWriter::new(file);
|
||||
let options = zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Stored);
|
||||
let registry = serde_json::json!({
|
||||
"jres": {
|
||||
DEFAULT_JRE_KEY: {
|
||||
@@ -548,7 +908,7 @@ fn write_offline_driver_zip_with_jre(path: &std::path::Path, db_type: &str, vers
|
||||
"label": db_type,
|
||||
"min_app_version": "0.1.0",
|
||||
"jre": DEFAULT_JRE_KEY,
|
||||
"jar": { "url": format!("https://example.com/dbx-agent-{db_type}.jar"), "size": jar.len() }
|
||||
"jar": { "url": format!("https://example.com/dbx-agent-{db_type}-{version}.jar"), "size": jar.len() }
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -558,7 +918,7 @@ fn write_offline_driver_zip_with_jre(path: &std::path::Path, db_type: &str, vers
|
||||
zip.start_file(format!("jre/dbx-jre-{DEFAULT_JRE_KEY}-{}.tar.gz", AgentManager::current_platform()), options)
|
||||
.unwrap();
|
||||
std::io::Write::write_all(&mut zip, &jre_archive).unwrap();
|
||||
zip.start_file(format!("drivers/dbx-agent-{db_type}.jar"), options).unwrap();
|
||||
zip.start_file(format!("drivers/dbx-agent-{db_type}-{version}.jar"), options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, &jar).unwrap();
|
||||
zip.finish().unwrap();
|
||||
}
|
||||
@@ -598,14 +958,14 @@ fn write_offline_driver_zip_with_jar(path: &std::path::Path, db_type: &str, vers
|
||||
"label": db_type,
|
||||
"min_app_version": "0.1.0",
|
||||
"jre": DEFAULT_JRE_KEY,
|
||||
"jar": { "url": format!("https://example.com/dbx-agent-{db_type}.jar"), "size": jar.len() }
|
||||
"jar": { "url": format!("https://example.com/dbx-agent-{db_type}-{version}.jar"), "size": jar.len() }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
zip.start_file("agent-registry.json", options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, registry.to_string().as_bytes()).unwrap();
|
||||
zip.start_file(format!("drivers/dbx-agent-{db_type}.jar"), options).unwrap();
|
||||
zip.start_file(format!("drivers/dbx-agent-{db_type}-{version}.jar"), options).unwrap();
|
||||
std::io::Write::write_all(&mut zip, &jar).unwrap();
|
||||
zip.finish().unwrap();
|
||||
}
|
||||
@@ -623,3 +983,34 @@ fn test_agent_jar_bytes() -> Vec<u8> {
|
||||
std::io::Write::write_all(&mut zip, b"Manifest-Version: 1.0\nMain-Class: com.dbx.agent.TestAgent\n\n").unwrap();
|
||||
zip.finish().unwrap().into_inner()
|
||||
}
|
||||
|
||||
fn current_platform_native_binary() -> Vec<u8> {
|
||||
native_binary_for_arch(cfg!(target_arch = "aarch64"))
|
||||
}
|
||||
|
||||
fn native_binary_for_arch(aarch64: bool) -> Vec<u8> {
|
||||
if cfg!(windows) {
|
||||
let mut bytes = vec![0_u8; 0x48];
|
||||
bytes[..2].copy_from_slice(b"MZ");
|
||||
bytes[0x3c..0x40].copy_from_slice(&(0x40_u32).to_le_bytes());
|
||||
bytes[0x40..0x44].copy_from_slice(b"PE\0\0");
|
||||
let machine = if aarch64 { 0xaa64_u16 } else { 0x8664_u16 };
|
||||
bytes[0x44..0x46].copy_from_slice(&machine.to_le_bytes());
|
||||
bytes
|
||||
} else if cfg!(target_os = "linux") {
|
||||
let mut bytes = vec![0_u8; 20];
|
||||
bytes[..4].copy_from_slice(b"\x7fELF");
|
||||
bytes[4] = 2;
|
||||
bytes[5] = 1;
|
||||
let machine = if aarch64 { 183_u16 } else { 62_u16 };
|
||||
bytes[18..20].copy_from_slice(&machine.to_le_bytes());
|
||||
bytes
|
||||
} else if cfg!(target_os = "macos") {
|
||||
let mut bytes = vec![0xcf, 0xfa, 0xed, 0xfe];
|
||||
let cpu_type = if aarch64 { 0x0100_000c_u32 } else { 0x0100_0007_u32 };
|
||||
bytes.extend_from_slice(&cpu_type.to_le_bytes());
|
||||
bytes
|
||||
} else {
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user