Skip to content

Commit 5e860b0

Browse files
committed
PR Clone fix
1 parent 1d53212 commit 5e860b0

File tree

6 files changed

+222
-150
lines changed

6 files changed

+222
-150
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
context: .
2929
file: ./Dockerfile
3030
push: true
31-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hela:v7
31+
tags: ${{ secrets.DOCKERHUB_USERNAME }}/hela:v8

src/scans/tools/license_tool.rs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
21
use std::{collections::HashMap, time::Instant};
32

43
use mongodb::bson::uuid;
54
use serde_json::json;
65

7-
use crate::{utils::{common::{execute_command, post_json_data}, file_utils::find_files_recursively}, scans::tools::sca_tool::SUPPORTED_MANIFESTS};
8-
6+
use crate::{
7+
scans::tools::sca_tool::SUPPORTED_MANIFESTS,
8+
utils::{common::execute_command, file_utils::find_files_recursively},
9+
};
910

1011
pub struct LicenseTool;
1112

1213
impl LicenseTool {
1314
pub fn new() -> Self {
1415
LicenseTool
1516
}
16-
17-
pub async fn run_scan(&self, _path: &str, _commit_id: Option<&str>, _branch: Option<&str>, verbose: bool) {
17+
18+
pub async fn run_scan(
19+
&self,
20+
_path: &str,
21+
_commit_id: Option<&str>,
22+
_branch: Option<&str>,
23+
verbose: bool,
24+
) {
1825
let start_time = Instant::now();
1926
if verbose {
2027
println!("[+] Running License compliance scan on path: {}", _path);
@@ -33,11 +40,11 @@ impl LicenseTool {
3340
if let Some(_branch) = _branch {
3441
let clone_command = format!("git clone -b {} {} /tmp/app", _branch, _path);
3542
execute_command(&clone_command, false).await;
36-
}else{
43+
} else {
3744
let clone_command = format!("git clone {} /tmp/app", _path);
3845
execute_command(&clone_command, false).await;
3946
}
40-
}else{
47+
} else {
4148
if verbose {
4249
println!("[+] Copying project to /tmp/app...");
4350
}
@@ -58,20 +65,27 @@ impl LicenseTool {
5865
// now run secret scan on /tmp/code folder
5966
_path = format!("/tmp/code");
6067
}
61-
let manifests = find_files_recursively(&_path, unsafe { SUPPORTED_MANIFESTS.to_vec() }, ignore_dirs).await;
68+
let manifests =
69+
find_files_recursively(&_path, unsafe { SUPPORTED_MANIFESTS.to_vec() }, ignore_dirs)
70+
.await;
6271
let mut manifest_license = HashMap::new();
6372
for manifest in manifests.iter() {
6473
let file_name = manifest.split("/").last().unwrap();
6574
let folder_path = manifest.replace(file_name, "");
6675
let random_file_name = format!("{}.json", uuid::Uuid::new().to_string());
6776
// if manifest ends with pom.xml then pass -t java otherwise nothing
68-
let mut license_command = format!("cd {} && cdxgen -o {}", folder_path, random_file_name);
77+
let mut license_command =
78+
format!("cd {} && cdxgen -o {}", folder_path, random_file_name);
6979
if file_name.ends_with("pom.xml") {
70-
license_command = format!("cd {} && cdxgen -o {} -t java", folder_path, random_file_name);
80+
license_command = format!(
81+
"cd {} && cdxgen -o {} -t java",
82+
folder_path, random_file_name
83+
);
7184
}
7285
execute_command(&license_command, false).await;
7386
// Read JSON file and parse data
74-
let license_json = std::fs::read_to_string(format!("{}/{}", folder_path, random_file_name)).unwrap();
87+
let license_json =
88+
std::fs::read_to_string(format!("{}/{}", folder_path, random_file_name)).unwrap();
7589
let json_data = serde_json::from_str::<serde_json::Value>(&license_json).unwrap();
7690
// extract license data from "components" key there will be list of components so grab licenses from there
7791
let components = json_data["components"].as_array().unwrap();
@@ -87,8 +101,14 @@ impl LicenseTool {
87101
license_names.push(license["id"].as_str().unwrap().to_string());
88102
}
89103
}
90-
component_licenses.insert(format!("{}@{}", component_name, component_version), license_names);
91-
manifest_license.insert(format!("{}/{}", folder_path, file_name), component_licenses.clone());
104+
component_licenses.insert(
105+
format!("{}@{}", component_name, component_version),
106+
license_names,
107+
);
108+
manifest_license.insert(
109+
format!("{}/{}", folder_path, file_name),
110+
component_licenses.clone(),
111+
);
92112
}
93113
}
94114
// save data in output.json and before that get json data from output.json file if it exists and then append new data to it
@@ -99,10 +119,17 @@ impl LicenseTool {
99119
output_json = serde_json::from_str::<serde_json::Value>(&output_json_data).unwrap();
100120
}
101121
output_json["license"] = json!(manifest_license);
102-
std::fs::write("/tmp/output.json", serde_json::to_string_pretty(&output_json).unwrap()).unwrap();
122+
std::fs::write(
123+
"/tmp/output.json",
124+
serde_json::to_string_pretty(&output_json).unwrap(),
125+
)
126+
.unwrap();
103127
let end_time = Instant::now();
104128
let elapsed_time = end_time - start_time;
105129
let elapsed_seconds = elapsed_time.as_secs_f64().round();
106-
println!("Execution time for License Compliance scan: {:?} seconds", elapsed_seconds);
130+
println!(
131+
"Execution time for License Compliance scan: {:?} seconds",
132+
elapsed_seconds
133+
);
107134
}
108-
}
135+
}

src/scans/tools/sast_tool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl SastTool {
2121
) {
2222
let start_time = Instant::now();
2323
if verbose {
24-
println!("[+] Running SAST scan on path: {}", _path.clone());
24+
println!("[+] Running SAST scan on path: {}", _path);
2525
}
2626
println!("Commit ID: {:?}", _commit_id);
2727
println!("Branch: {:?}", _branch);
@@ -54,7 +54,7 @@ impl SastTool {
5454
if verbose {
5555
println!("[+] Copying project to /tmp/app...");
5656
}
57-
let copy_command = format!("cp -r {} /tmp/app", _path.clone());
57+
let copy_command = format!("cp -r {} /tmp/app", _path);
5858
execute_command(&copy_command, true).await;
5959
}
6060
}

src/scans/tools/sca_tool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{collections::HashMap, fs, time::Instant};
33
use serde_json::{json, Value};
44

55
use crate::utils::{
6-
common::{checkout, execute_command, post_json_data},
6+
common::{checkout, execute_command},
77
file_utils::find_files_recursively,
88
};
99

@@ -251,7 +251,7 @@ impl ScaTool {
251251
if verbose {
252252
println!("[+] Copying project to /tmp/app...");
253253
}
254-
let copy_command = format!("cp -r {} /tmp/app", _path.clone());
254+
let copy_command = format!("cp -r {} /tmp/app", _path);
255255
execute_command(&copy_command, true).await;
256256
}
257257
}

src/scans/tools/secret_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl SecretTool {
3232
if verbose {
3333
println!("[+] Copying project to /tmp/app...");
3434
}
35-
let copy_command = format!("cp -r {} /tmp/app", _path.clone());
35+
let copy_command = format!("cp -r {} /tmp/app", _path);
3636
execute_command(&copy_command, true).await;
3737
}
3838
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy