Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aamohd/file based config #662

Merged
merged 1 commit into from
Jan 10, 2025
Merged
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
7 changes: 7 additions & 0 deletions config/Exec.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugin {
backoff-interval 100000
max-spawn-attempts 3
max-conn-attempts 5
jitter-percent 10
grpc-msg-buffer-size 10
}
29 changes: 23 additions & 6 deletions hipcheck/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ struct PathArgs {
long_help = "Path to the policy file."
)]
policy: Option<PathBuf>,

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

/// Soft-deprecated arguments, to be removed in a future version.
Expand Down Expand Up @@ -221,6 +231,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 +274,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 +294,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 @@ -293,11 +311,10 @@ impl CliConfig {
CliConfig {
path_args: PathArgs {
cache: dirs::home_dir().map(|dir| pathbuf![&dir, "hipcheck", "cache"]),
policy: None, /* This can be re-enabled once `--config` is no longer the default
std::env::current_dir()
.ok()
.map(|dir| pathbuf![&dir, "Hipcheck.kdl"]),
*/
policy: std::env::current_dir()
.ok()
.map(|dir| pathbuf![&dir, "Hipcheck.kdl"]),
exec: None,
},
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},
exec::ExecConfig,
hc_error,
policy::{
policy_file::{PolicyAnalysis, PolicyCategory, PolicyCategoryChild},
Expand Down Expand Up @@ -452,6 +453,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
Loading