Skip to content

Commit

Permalink
feat: allow file-based executor
Browse files Browse the repository at this point in the history
Signed-off-by: Aisha M <[email protected]>

ExecConfig and PluginConfig added

fix: fix broken test

Signed-off-by: Andrew Lilley Brinker <[email protected]>

Config parsing enabled

Code cleanup

Exec Config added to CLI

Signed-off-by: Aisha M <[email protected]>

feat: allow file-based executor config

Signed-off-by: Aisha M <[email protected]>

Code cleanup

Signed-off-by: Aisha M <[email protected]>
  • Loading branch information
aamohd committed Dec 9, 2024
1 parent 51048ec commit 866ea2b
Show file tree
Hide file tree
Showing 9 changed files with 614 additions and 20 deletions.
7 changes: 7 additions & 0 deletions config/Config.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugin {
backoff-interval 100000
max-spawn-attempts 5
max-conn-attempts 5
jitter-percent 10
grpc-msg-buffer-size 10
}
22 changes: 21 additions & 1 deletion hipcheck/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
cache::repo::{RepoCacheDeleteScope, RepoCacheListScope, RepoCacheSort},
error::Context,
error::Result,
env,
hc_error,
plugin::Arch,
session::pm,
Expand Down Expand Up @@ -104,6 +105,16 @@ struct PathArgs {
long_help = "Path to the policy file."
)]
policy: Option<PathBuf>,

/// Path to the exec config file ADDED
#[arg(
short = 'e',
long = "exec",
global = true,
help_heading = "Path Flags",
long_help = "Path to the exec file."
)]
exec: Option<PathBuf>,
}

/// Soft-deprecated arguments, to be removed in a future version.
Expand Down Expand Up @@ -221,6 +232,11 @@ impl CliConfig {
self.deprecated_args.config.as_deref()
}

/// Get the path to the exec config file
pub fn exec(&self) -> Option<&Path> {
self.path_args.exec.as_deref()
}

/// Check if the `--print-home` flag was used.
pub fn print_home(&self) -> bool {
self.deprecated_args.print_home.unwrap_or(false)
Expand Down Expand Up @@ -259,6 +275,8 @@ impl CliConfig {
cache: hc_env_var("cache"),
// For now, we do not get this from the environment, so pass a None to never update this field
policy: None,
// For now, we don't get this from the environment
exec: None,
},
deprecated_args: DeprecatedArgs {
config: hc_env_var("config"),
Expand All @@ -277,8 +295,9 @@ impl CliConfig {
CliConfig {
path_args: PathArgs {
cache: platform_cache(),
// There is no central per-user or per-system location for the policy file, so pass a None to never update this field
// There is no central per-user or per-system location for the policy or exec file, so pass a None to never update this field
policy: None,
exec: None,
},
deprecated_args: DeprecatedArgs {
config: platform_config(),
Expand All @@ -296,6 +315,7 @@ impl CliConfig {
policy: std::env::current_dir()
.ok()
.map(|dir| pathbuf![&dir, "Hipcheck.kdl"]),
exec: env::current_dir().ok().map(|dir| pathbuf![&dir, "config/Config.kdl"]),
},
deprecated_args: DeprecatedArgs {
config: dirs::home_dir().map(|dir| pathbuf![&dir, "hipcheck", "config"]),
Expand Down
4 changes: 4 additions & 0 deletions hipcheck/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use crate::{
engine::HcEngine,
error::{Context, Result},
executor::ExecConfig,
hc_error,
policy::{
policy_file::{PolicyAnalysis, PolicyCategory, PolicyCategoryChild},
Expand Down Expand Up @@ -453,6 +454,9 @@ pub trait ConfigSource: salsa::Database {
/// Returns the location of the policy file
#[salsa::input]
fn policy_path(&self) -> Option<Rc<PathBuf>>;
/// Returns the input `Exec Config` struct
#[salsa::input]
fn exec_config(&self) -> Rc<ExecConfig>;
/// Returns the token set in HC_GITHUB_TOKEN env var
#[salsa::input]
fn github_api_token(&self) -> Option<Rc<String>>;
Expand Down
9 changes: 1 addition & 8 deletions hipcheck/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,8 @@ impl HcEngineImpl {
pub fn start_plugins(
policy_file: &PolicyFile,
plugin_cache: &HcPluginCache,
executor: PluginExecutor
) -> Result<Arc<HcPluginCore>> {
let executor = PluginExecutor::new(
/* max_spawn_attempts */ 3,
/* max_conn_attempts */ 5,
/* port_range */ 40000..u16::MAX,
/* backoff_interval_micros */ 100000,
/* jitter_percent */ 10,
)?;

let current_arch = get_current_arch();

// retrieve, verify and extract all required plugins
Expand Down
Loading

0 comments on commit 866ea2b

Please sign in to comment.