Skip to content

Commit 3df9b51

Browse files
committed
fix some comments
1 parent 4ccd007 commit 3df9b51

16 files changed

Lines changed: 645 additions & 559 deletions

File tree

agent-control/src/agent_control/version_updater/on_host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ where
136136
version: new_version,
137137
public_key_url: Some(self.pub_key_url.clone()),
138138
},
139-
postdownload: None,
139+
post_download_hook: None,
140140
}
141141
}
142142
}

agent-control/src/agent_type/definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn include_packages_variables(
328328
let package_data = PackageData {
329329
id: package_id.to_string(),
330330
oci: package.download.oci.clone(),
331-
postdownload: package.postdownload.clone(),
331+
post_download_hook: package.post_download_hook.clone(),
332332
};
333333
let path =
334334
get_package_path(Path::new(remote_dir), &agent_id, &package_data).map_err(|e| {

agent-control/src/agent_type/runtime_config/on_host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod tests {
169169
)),
170170
},
171171
},
172-
postdownload: None,
172+
post_download_hook: None,
173173
};
174174

175175
let expected_packages = HashMap::from([

agent-control/src/agent_type/runtime_config/on_host/package.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub mod rendered;
1515
pub(super) struct Package {
1616
/// Download defines the supported repository sources for the packages.
1717
pub download: Download,
18-
/// Postdownload script to execute after downloading and extracting the package.
18+
/// Post-download hook script to execute after downloading and extracting the package.
1919
/// All validations, checks, and installation steps should go here.
20-
pub postdownload: Option<Postdownload>,
20+
pub post_download_hook: Option<PostDownloadHook>,
2121
}
2222

2323
pub type PackageID = String;
@@ -40,36 +40,32 @@ pub struct Oci {
4040
}
4141

4242
#[derive(Debug, Deserialize, Clone, PartialEq)]
43-
pub struct Postdownload {
44-
/// Arguments where first element is the command/executable (e.g., "bash", "sh", "python3"),
45-
/// second element is the script path, followed by additional arguments.
46-
/// Example: ["bash", "postdownload.sh", "--verbose"]
43+
pub struct PostDownloadHook {
44+
/// Absolute path to the command/executable (e.g., "/bin/bash", "/usr/bin/python3").
45+
/// This is the interpreter or tool that will execute the script.
46+
pub path: TemplateableValue<String>,
47+
48+
/// Arguments passed to the command. First element should be the script path (absolute),
49+
/// followed by additional arguments for the script.
50+
/// Example: ["install.sh", "--check-dependencies", "--verbose"]
4751
pub args: Vec<TemplateableValue<String>>,
4852

4953
/// Environmental variables passed to the process.
5054
#[serde(default)]
5155
pub env: HashMap<String, TemplateableValue<String>>,
52-
53-
/// Maximum time to wait for the script to complete.
54-
#[serde(default = "default_postdownload_timeout")]
55-
pub timeout: TemplateableValue<String>,
56-
}
57-
58-
fn default_postdownload_timeout() -> TemplateableValue<String> {
59-
TemplateableValue::new("300s".to_string())
6056
}
6157

6258
impl Templateable for Package {
6359
type Output = rendered::Package;
6460
fn template_with(self, variables: &Variables) -> Result<Self::Output, AgentTypeError> {
65-
let postdownload = self
66-
.postdownload
61+
let post_download_hook = self
62+
.post_download_hook
6763
.map(|pd| pd.template_with(variables))
6864
.transpose()?;
6965

7066
Ok(Self::Output {
7167
download: self.download.template_with(variables)?,
72-
postdownload,
68+
post_download_hook,
7369
})
7470
}
7571
}
@@ -116,21 +112,20 @@ impl Templateable for Oci {
116112
}
117113
}
118114

119-
impl Templateable for Postdownload {
120-
type Output = rendered::Postdownload;
115+
impl Templateable for PostDownloadHook {
116+
type Output = rendered::PostDownloadHook;
121117
fn template_with(self, variables: &Variables) -> Result<Self::Output, AgentTypeError> {
122-
let timeout_str = self.timeout.template_with(variables)?;
118+
let path = self.path.template_with(variables)?;
123119

124120
let args: Vec<String> = self
125121
.args
126122
.into_iter()
127123
.map(|arg| arg.template_with(variables))
128124
.collect::<Result<Vec<String>, AgentTypeError>>()?;
129125

130-
if args.len() < 2 {
126+
if args.is_empty() {
131127
return Err(AgentTypeError::OCIReferenceParsingError(
132-
"postdownload args must have at least 2 elements: command and script path"
133-
.to_string(),
128+
"post_download_hook args must have at least 1 element: the script path".to_string(),
134129
));
135130
}
136131

@@ -140,11 +135,7 @@ impl Templateable for Postdownload {
140135
.map(|(k, v)| v.template_with(variables).map(|templated| (k, templated)))
141136
.collect::<Result<HashMap<_, _>, AgentTypeError>>()?;
142137

143-
let timeout = duration_str::parse(&timeout_str).map_err(|err| {
144-
AgentTypeError::OCIReferenceParsingError(format!("invalid timeout format: {err}"))
145-
})?;
146-
147-
Ok(Self::Output { args, env, timeout })
138+
Ok(Self::Output { path, args, env })
148139
}
149140
}
150141

agent-control/src/agent_type/runtime_config/on_host/package/rendered.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use oci_client::Reference;
22
use serde::{Deserialize, Serialize};
33
use std::collections::HashMap;
4-
use std::{fmt::Display, str::FromStr, time::Duration};
4+
use std::{fmt::Display, str::FromStr};
55
use url::Url;
66

77
use crate::agent_control::config::Registry;
@@ -13,8 +13,8 @@ const TAG_TOTAL_LENGTH_MAX: usize = 128;
1313
pub struct Package {
1414
/// Download defines the supported repository sources for the packages.
1515
pub download: Download,
16-
/// Postdownload script to execute after downloading and extracting the package.
17-
pub postdownload: Option<Postdownload>,
16+
/// Post-download hook script to execute after downloading and extracting the package.
17+
pub post_download_hook: Option<PostDownloadHook>,
1818
}
1919

2020
#[derive(Debug, Clone, PartialEq)]
@@ -31,15 +31,14 @@ pub struct Oci {
3131
}
3232

3333
#[derive(Debug, Clone, PartialEq)]
34-
pub struct Postdownload {
35-
/// Arguments where first element is the command/executable, second element is script path,
36-
/// followed by additional arguments.
37-
/// Example: ["bash", "postdownload.sh", "--verbose"]
34+
pub struct PostDownloadHook {
35+
/// Absolute path to the command/executable (e.g., "/bin/bash", "/usr/bin/python3")
36+
pub path: String,
37+
/// Arguments where first element is the script path, followed by additional arguments.
38+
/// Example: ["install.sh", "--check-dependencies", "--verbose"]
3839
pub args: Vec<String>,
3940
/// Environmental variables
4041
pub env: HashMap<String, String>,
41-
/// Timeout duration
42-
pub timeout: Duration,
4342
}
4443

4544
const DEFAULT_TAG: &str = "latest";

agent-control/src/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod manager;
22
pub mod oci;
3-
pub mod postdownload_executor;
3+
pub mod post_download_hook_executor;

agent-control/src/package/manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This module manages package operations such as installation, removal, and updates.
22
use crate::agent_control::agent_id::AgentID;
3-
use crate::agent_type::runtime_config::on_host::package::rendered::{Oci, Postdownload};
3+
use crate::agent_type::runtime_config::on_host::package::rendered::{Oci, PostDownloadHook};
44
use crate::package::oci::package_manager::OCIPackageManagerError;
55
use std::path::PathBuf;
66

@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
pub struct PackageData {
1010
pub id: String, // same type as the packages map on an agent type definition
1111
pub oci: Oci,
12-
pub postdownload: Option<Postdownload>,
12+
pub post_download_hook: Option<PostDownloadHook>,
1313
}
1414

1515
/// Information about an installed package

agent-control/src/package/oci/downloader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ pub mod tests {
168168
version: Version::from_str(VERSION).unwrap(),
169169
public_key_url,
170170
},
171+
post_download_hook: None,
171172
}
172173
}
173174

agent-control/src/package/oci/package_manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ mod tests {
404404
.unwrap(),
405405
public_key_url: None,
406406
},
407+
post_download_hook: None,
407408
}
408409
}
409410

@@ -419,6 +420,7 @@ mod tests {
419420
version: Version::from_str(version).unwrap(),
420421
public_key_url: None,
421422
},
423+
post_download_hook: None,
422424
}
423425
}
424426

0 commit comments

Comments
 (0)