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

added config validations #905

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod limits;
mod logging;
mod models;
mod output;
mod validations;
mod wrappers;

use std::{
Expand All @@ -26,10 +27,11 @@ use clap::Parser;

use commands::Commands;
use logging::Logger;
use sprinkles::contexts::{AnyContext, User};
use sprinkles::contexts::{AnyContext, ScoopContext, User};

#[cfg(feature = "contexts")]
use sprinkles::contexts::Global;
use validations::Validate;

shadow_rs::shadow!(shadow);

Expand Down Expand Up @@ -171,6 +173,8 @@ async fn main() -> anyhow::Result<()> {
COLOR_ENABLED.store(false, Ordering::Relaxed);
}

ctx.config().validate()?;

debug!("Running command: {:?}", args.command);

args.command.run(&ctx).await?;
Expand Down
5 changes: 5 additions & 0 deletions src/validations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod config;

pub trait Validate {
fn validate(&self) -> anyhow::Result<()>;
}
10 changes: 10 additions & 0 deletions src/validations/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
impl super::Validate for sprinkles::config::Scoop {
fn validate(&self) -> anyhow::Result<()> {
if self.no_junction {
anyhow::bail!("Junction links (symlinks) are required for sfsu to function currently. Please disable `no_junction` in your Scoop
config");
}

Ok(())
}
}
Comment on lines +1 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the search results from multiple approaches, we can see that:

  1. The Scoop config has fields like no_junction and virustotal_api_key
  2. The config is used for critical functionality like symlinks and VirusTotal API integration
  3. The validation implementation only checks no_junction
  4. The config can be saved and updated with timestamps

Additional validation needed for VirusTotal API key configuration

The current validation only checks no_junction, but the codebase shows that virustotal_api_key is a critical configuration field used in the VirusTotal command. This field should also be validated for proper format if present.

🔗 Analysis chain

Verify completeness of Scoop configuration validation

The implementation only validates the no_junction setting. Let's verify if there are other Scoop configuration settings that might affect the functionality of sfsu.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other Scoop config usages in the codebase
rg -g '!target/' -g '*.rs' 'config::Scoop' -A 5 -B 5

# Search for any TODO/FIXME comments related to Scoop config
rg -g '!target/' -g '*.rs' -i '(todo|fixme).*scoop.*config'

Length of output: 8865


Script:

#!/bin/bash
# Let's check the Scoop configuration struct definition to see all available fields
ast-grep --pattern 'struct Scoop {
  $$$
}'

# Also search for any usage of Scoop config fields
rg -g '!target/' -g '*.rs' 'self\.' -A 2 -B 2 src/validations/config.rs

Length of output: 411


Script:

#!/bin/bash
# Let's try to find the Scoop config struct definition in a different way
rg -g '!target/' -g '*.rs' 'pub struct Scoop' -A 20 -B 2

# Also search for any field access on Scoop config throughout the codebase
rg -g '!target/' -g '*.rs' 'config\.' -A 2 -B 2

Length of output: 2311


Script:

#!/bin/bash
# Let's try one more approach to find the Scoop config definition
fd -e rs -x grep -A 20 -B 2 'struct Scoop'

# Also search for any other validation implementations for Scoop config
rg -g '!target/' -g '*.rs' 'impl.*Validate.*Scoop'

Length of output: 175