Skip to content
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
2 changes: 1 addition & 1 deletion src/scanners/blast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn run(
*stop_signal.lock().unwrap() = true;
print!("\r{}", utils::terminal::set_text_color("", utils::terminal::TerminalColor::Reset));
eprintln!(
"\n\nOops! It seems there are no uncommitted changes to scan in your project.\nPlease ensure you have made changes that need to be scanned.\n\n",
"\n\nOops! It seems there are no scannable uncommitted changes in your project.\nYou may have uncommitted changes, but none match the types of files we can scan.\n\n"
);
std::process::exit(1);
}
Expand Down
46 changes: 36 additions & 10 deletions src/utils/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,30 @@ pub fn upload_zip(
Err(err) => return Err(format!("Network error: Unable to reach the server. Please try again later. Error: {}", err).into()),
};
let response_status = response_object.status();
let response: HashMap<String, Value> = match response_object.json() {
Ok(json) => json,
Err(_) => return Err("Error getting server response, Please try again later.".into()),
};

let response_text = response_object.text()?;

if response_status != StatusCode::OK {
let message = response.get("message")
.and_then(Value::as_str)
.unwrap_or("An unknown error occurred. Please try again or contact support.");
return Err(format!("Request failed: {}", message).into());
debug(&format!("Initial scan request failed with status: {}. Response body: {}", response_status, response_text));

if response_status == StatusCode::BAD_REQUEST {
if let Ok(error_response) = serde_json::from_str::<HashMap<String, Value>>(&response_text) {
if let Some(message) = error_response.get("message").and_then(Value::as_str) {
return Err(format!("Request failed: {}", message).into());
}
}
return Err(format!("Request failed (400): {}", response_text).into());
}

return Err("Error getting server response, Please try again later.".into());
}

let response: HashMap<String, Value> = match serde_json::from_str(&response_text) {
Ok(json) => json,
Err(_) => {
debug(&format!("Failed to parse initial scan response as JSON. Response body: {}", response_text));
return Err("Error getting server response, Please try again later.".into());
},
};

let transfer_id = match response["transfer_id"].as_str() {
Some(transfer_id) => transfer_id,
Expand Down Expand Up @@ -170,9 +183,22 @@ pub fn upload_zip(
};
if !response.status().is_success() {
let status_code = response.status();
if status_code.is_client_error() && response.text().unwrap().contains("Invalid policy ids") {
let response_text = response.text().unwrap_or_else(|_| "Unable to read response body".to_string());
debug(&format!("Chunk upload failed with status: {}. Response body: {}", status_code, response_text));

if status_code.is_client_error() && response_text.contains("Invalid policy ids") {
return Err("Invalid policy ids passed. Please check the policy ids and try again.".into());
}

if status_code == StatusCode::BAD_REQUEST {
if let Ok(error_response) = serde_json::from_str::<HashMap<String, Value>>(&response_text) {
if let Some(message) = error_response.get("message").and_then(Value::as_str) {
return Err(format!("Upload failed: {}", message).into());
}
}
return Err(format!("Upload failed (400): {}", response_text).into());
}

return Err(format!("Failed to upload file: {}", status_code).into());

}
Expand Down
49 changes: 25 additions & 24 deletions src/utils/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ use std::fs::{self, File};
use std::env;
use git2::Repository;

// Global exclude globs used across multiple functions
const DEFAULT_EXCLUDE_GLOBS: &[&str] = &[
"**/tests/**",
"**/.corgea/**",
"**/test/**",
"**/spec/**",
"**/specs/**",
"**/node_modules/**",
"**/tmp/**",
"**/migrations/**",
"**/python*/site-packages/**",
"**/*.mmdb",
"**/*.css",
"**/*.less",
"**/*.scss",
"**/*.map",
"**/*.env",
"**/*.sh",
"**/.vs/**",
"**/.vscode/**",
"**/.idea/**",
];

pub fn create_zip_from_filtered_files<P: AsRef<Path>>(
directory: P,
exclude_globs: Option<&[&str]>,
Expand Down Expand Up @@ -38,24 +61,7 @@ pub fn create_zip_from_list_of_files<P: AsRef<Path>>(
output_zip: P,
exclude_globs: Option<&[&str]>,
) -> Result<(), Box<dyn std::error::Error>> {
let exclude_globs = exclude_globs.unwrap_or(&[
"**/tests/**",
"**/.corgea/**",
"**/test/**",
"**/spec/**",
"**/specs/**",
"**/node_modules/**",
"**/tmp/**",
"**/migrations/**",
"**/python*/site-packages/**",
"**/*.mmdb",
"**/*.css",
"**/*.less",
"**/*.scss",
"**/*.map",
"**/*.env",
"**/*.sh",
]);
let exclude_globs = exclude_globs.unwrap_or(DEFAULT_EXCLUDE_GLOBS);

let mut glob_builder = GlobSetBuilder::new();
for &pattern in exclude_globs {
Expand Down Expand Up @@ -97,13 +103,8 @@ pub fn get_untracked_and_modified_files(repo_path: &str) -> Result<Vec<String>,

let statuses = repo.statuses(None)?;

let globs_to_ignore = [
"**/.vs/**",
"**/.vscode/**",
"**/.idea/**",
];
let mut glob_builder = GlobSetBuilder::new();
for &pattern in &globs_to_ignore {
for &pattern in DEFAULT_EXCLUDE_GLOBS {
glob_builder.add(Glob::new(pattern).unwrap());
}
let glob_set = glob_builder.build().unwrap();
Expand Down
Loading