Skip to content

Commit cec4700

Browse files
ran rustfmt
1 parent 494e32f commit cec4700

File tree

10 files changed

+569
-358
lines changed

10 files changed

+569
-358
lines changed

src/aws_scanning.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
use crate::SecretScanner;
5454
use encoding::all::ASCII;
5555
use encoding::{DecoderTrap, Encoding};
56-
use log::{self, trace, error};
56+
use log::{self, error, trace};
5757
use s3::bucket::Bucket;
5858
use serde_derive::{Deserialize, Serialize};
5959
use simple_error::SimpleError;
@@ -87,7 +87,11 @@ impl S3Scanner {
8787
Self { secret_scanner }
8888
}
8989

90-
pub fn new() -> Self { Self { secret_scanner: SecretScanner::default() } }
90+
pub fn new() -> Self {
91+
Self {
92+
secret_scanner: SecretScanner::default(),
93+
}
94+
}
9195

9296
/// Takes an initialized [Bucket](https://durch.github.io/rust-s3/s3/bucket/struct.Bucket.html)
9397
/// object and an S3 object path in the format `s3://<path>` and returns a list of S3Finding

src/bin/ankamali_hog.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern crate yup_oauth2 as oauth2;
3232

3333
use clap::ArgMatches;
3434
use drive3::DriveHub;
35-
use log::{self, info, error};
35+
use log::{self, error, info};
3636
use oauth2::{
3737
ApplicationSecret, Authenticator, DefaultAuthenticatorDelegate, DiskTokenStorage, FlowType,
3838
};
@@ -63,7 +63,7 @@ fn main() {
6363
.get_matches();
6464
match run(&matches) {
6565
Ok(()) => {}
66-
Err(e) => error!( "Error running command: {}", e)
66+
Err(e) => error!("Error running command: {}", e),
6767
}
6868
}
6969

@@ -112,6 +112,9 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
112112
info!("Found {} secrets", findings.len());
113113
match gdrive_scanner.secret_scanner.output_findings(&findings) {
114114
Ok(_) => Ok(()),
115-
Err(err) => Err(SimpleError::with("failed to output findings", SimpleError::new(err.to_string())))
115+
Err(err) => Err(SimpleError::with(
116+
"failed to output findings",
117+
SimpleError::new(err.to_string()),
118+
)),
116119
}
117120
}

src/bin/berkshire_hog.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn main() {
6767
.get_matches();
6868
match run(&matches) {
6969
Ok(()) => {}
70-
Err(e) => error!( "Error running command: {}", e)
70+
Err(e) => error!("Error running command: {}", e),
7171
}
7272
}
7373

@@ -93,9 +93,7 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
9393
};
9494

9595
// Initialize our S3 variables
96-
let profile = arg_matches
97-
.value_of("PROFILE")
98-
.map(|x| x.to_string());
96+
let profile = arg_matches.value_of("PROFILE").map(|x| x.to_string());
9997
let credentials = Credentials::new(None, None, None, profile);
10098
debug!(
10199
"credentials: {:?} {:?} {:?}",
@@ -165,6 +163,9 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
165163
info!("Found {} secrets", findings.len());
166164
match s3scanner.secret_scanner.output_findings(&findings) {
167165
Ok(_) => Ok(()),
168-
Err(err) => Err(SimpleError::with("failed to output findings", SimpleError::new(err.to_string())))
166+
Err(err) => Err(SimpleError::with(
167+
"failed to output findings",
168+
SimpleError::new(err.to_string()),
169+
)),
169170
}
170171
}

src/bin/choctaw_hog.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ extern crate chrono;
4141
extern crate encoding;
4242

4343
use clap::ArgMatches;
44-
use log::{self, info, error};
44+
use log::{self, error, info};
4545
use simple_error::SimpleError;
4646
use std::str;
4747
use tempdir::TempDir;
4848

49-
use rusty_hogs::git_scanning::{GitScanner};
49+
use rusty_hogs::git_scanning::GitScanner;
5050
use rusty_hogs::{SecretScanner, SecretScannerBuilder};
5151

5252
/// Main entry function that uses the [clap crate](https://docs.rs/clap/2.33.0/clap/)
@@ -75,7 +75,7 @@ fn main() {
7575
.get_matches();
7676
match run(&matches) {
7777
Ok(()) => {}
78-
Err(e) => error!( "Error running command: {}", e)
78+
Err(e) => error!("Error running command: {}", e),
7979
}
8080
}
8181

@@ -93,8 +93,14 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
9393
let since_commit = arg_matches.value_of("SINCECOMMIT");
9494
let until_commit = arg_matches.value_of("UNTILCOMMIT");
9595
let recent_days: Option<u32> = match value_t!(arg_matches.value_of("RECENTDAYS"), u32) {
96-
Ok(d) => { if d == 0 { None } else { Some(d) } },
97-
Err(_e) => None
96+
Ok(d) => {
97+
if d == 0 {
98+
None
99+
} else {
100+
Some(d)
101+
}
102+
}
103+
Err(_e) => None,
98104
};
99105

100106
// Get Git objects
@@ -111,12 +117,15 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
111117
httpsuser,
112118
httpspass,
113119
);
114-
let findings = git_scanner.perform_scan(None, since_commit, until_commit, recent_days) ;
120+
let findings = git_scanner.perform_scan(None, since_commit, until_commit, recent_days);
115121

116122
// Output the results
117123
info!("Found {} secrets", findings.len());
118124
match git_scanner.secret_scanner.output_findings(&findings) {
119125
Ok(_) => Ok(()),
120-
Err(err) => Err(SimpleError::with("failed to output findings", SimpleError::new(err.to_string())))
126+
Err(err) => Err(SimpleError::with(
127+
"failed to output findings",
128+
SimpleError::new(err.to_string()),
129+
)),
121130
}
122131
}

src/bin/duroc_hog.rs

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ extern crate chrono;
3535
extern crate encoding;
3636

3737
use clap::ArgMatches;
38-
use log::{self, debug, info, error};
38+
use log::{self, debug, error, info};
3939
use serde::{Deserialize, Serialize};
4040
use simple_error::SimpleError;
4141
use std::fs::File;
4242
use std::io::{Cursor, Read};
4343
use std::path::{Path, PathBuf};
4444
use std::{io, str};
45-
use walkdir::{WalkDir};
45+
use walkdir::WalkDir;
4646

4747
use encoding::all::ASCII;
4848
use encoding::{DecoderTrap, Encoding};
49+
use path_clean::PathClean;
4950
use rusty_hogs::{SecretScanner, SecretScannerBuilder};
5051
use std::collections::HashSet;
51-
use path_clean::PathClean;
5252

5353
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Default)]
5454
/// `serde_json` object that represents a single found secret - finding
@@ -87,7 +87,7 @@ fn main() {
8787
.get_matches();
8888
match run(&matches) {
8989
Ok(()) => {}
90-
Err(e) => error!( "Error running command: {}", e)
90+
Err(e) => error!("Error running command: {}", e),
9191
}
9292
}
9393

@@ -116,7 +116,13 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
116116
let mut output: HashSet<FileFinding> = HashSet::new();
117117

118118
if Path::is_dir(fspath) {
119-
output.extend(scan_dir(fspath, output_file, &secret_scanner, recursive, unzip));
119+
output.extend(scan_dir(
120+
fspath,
121+
output_file,
122+
&secret_scanner,
123+
recursive,
124+
unzip,
125+
));
120126
} else {
121127
let f = File::open(fspath).unwrap();
122128
output.extend(scan_file(fspath, &secret_scanner, f, "", unzip));
@@ -125,7 +131,10 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
125131
info!("Found {} secrets", output.len());
126132
match secret_scanner.output_findings(&output) {
127133
Ok(_) => Ok(()),
128-
Err(err) => Err(SimpleError::with("failed to output findings", SimpleError::new(err.to_string())))
134+
Err(err) => Err(SimpleError::with(
135+
"failed to output findings",
136+
SimpleError::new(err.to_string()),
137+
)),
129138
}
130139
}
131140

@@ -155,24 +164,36 @@ fn scan_dir(
155164
output
156165
}
157166

158-
fn recursive_dir_scan<C>(fspath: &Path, output_file: &Path, mut closure: C) where C: FnMut(&Path) {
167+
fn recursive_dir_scan<C>(fspath: &Path, output_file: &Path, mut closure: C)
168+
where
169+
C: FnMut(&Path),
170+
{
159171
for entry in WalkDir::new(fspath).into_iter().filter_map(|e| e.ok()) {
160172
if entry.file_type().is_file() && &PathBuf::from(entry.path()).clean() != output_file {
161173
closure(&entry.path());
162174
}
163175
}
164176
}
165177

166-
fn flat_dir_scan<C>(fspath: &Path, output_file: &Path, mut closure: C) where C: FnMut(&Path) {
178+
fn flat_dir_scan<C>(fspath: &Path, output_file: &Path, mut closure: C)
179+
where
180+
C: FnMut(&Path),
181+
{
167182
let dir_contents: Vec<PathBuf> = fspath
168-
.read_dir()
169-
.expect("read_dir call failed")
170-
.filter_map(|e| e.ok())
171-
.filter(|e| e.file_type().unwrap().is_file())
172-
.map(|e| e.path())
173-
.inspect(|e| debug!("clean path: {:?}, output_file: {:?}", &e.clean(), output_file))
174-
.filter(|e| e.clean() != output_file)
175-
.collect();
183+
.read_dir()
184+
.expect("read_dir call failed")
185+
.filter_map(|e| e.ok())
186+
.filter(|e| e.file_type().unwrap().is_file())
187+
.map(|e| e.path())
188+
.inspect(|e| {
189+
debug!(
190+
"clean path: {:?}, output_file: {:?}",
191+
&e.clean(),
192+
output_file
193+
)
194+
})
195+
.filter(|e| e.clean() != output_file)
196+
.collect();
176197
debug!("dir_contents: {:?}", dir_contents);
177198

178199
for file_path in dir_contents {
@@ -204,7 +225,10 @@ fn scan_file<R: Read + io::Seek>(
204225
// and moving it (inefficient) *but* that means we can recursively decompress
205226
let mut innerdata: Vec<u8> = Vec::new();
206227
let read_result = innerfile.read_to_end(&mut innerdata);
207-
if read_result.is_err() { info!("read error within ZIP file"); continue; }
228+
if read_result.is_err() {
229+
info!("read error within ZIP file");
230+
continue;
231+
}
208232
let new_reader = Cursor::new(innerdata);
209233
let mut inner_findings = scan_file(
210234
innerfile.sanitized_name().as_path(),
@@ -226,7 +250,10 @@ fn scan_file<R: Read + io::Seek>(
226250
let mut inner_entry = entry_result.unwrap();
227251
let mut innerdata: Vec<u8> = Vec::new();
228252
let read_result = inner_entry.read_to_end(&mut innerdata);
229-
if read_result.is_err() { info!("read error within TAR file"); continue; }
253+
if read_result.is_err() {
254+
info!("read error within TAR file");
255+
continue;
256+
}
230257
let new_reader = Cursor::new(innerdata);
231258
let mut inner_findings = scan_file(
232259
inner_entry.path().unwrap().as_ref(),
@@ -245,21 +272,18 @@ fn scan_file<R: Read + io::Seek>(
245272
let mut decompressor = flate2::read::GzDecoder::new(reader);
246273
let mut innerdata: Vec<u8> = Vec::new();
247274
let read_result = decompressor.read_to_end(&mut innerdata);
248-
if read_result.is_err() { info!("read error within ZIP file"); return findings; }
275+
if read_result.is_err() {
276+
info!("read error within ZIP file");
277+
return findings;
278+
}
249279
let new_reader = Cursor::new(innerdata);
250280
let mut tempstring = String::from(file_path.file_stem().unwrap().to_str().unwrap());
251281
if ext.to_ascii_lowercase() == "tgz" {
252282
tempstring.push_str(".tar");
253283
}
254284
let inner_path: &Path = Path::new(&tempstring);
255285
info!("gunzip inner path: {:?}", inner_path);
256-
let mut inner_findings = scan_file(
257-
inner_path,
258-
ss,
259-
new_reader,
260-
&path_string,
261-
unzip,
262-
);
286+
let mut inner_findings = scan_file(inner_path, ss, new_reader, &path_string, unzip);
263287
for d in inner_findings.drain() {
264288
info!("FileFinding: {:?}", d);
265289
findings.insert(d);
@@ -268,7 +292,9 @@ fn scan_file<R: Read + io::Seek>(
268292
} else {
269293
let mut data = Vec::new();
270294
let read_result = reader.read_to_end(&mut data);
271-
if read_result.is_err() { info!("read error for file {}", path_string); }
295+
if read_result.is_err() {
296+
info!("read error for file {}", path_string);
297+
}
272298
scan_bytes(data, ss, path_string)
273299
}
274300
}
@@ -309,23 +335,17 @@ fn scan_bytes(input: Vec<u8>, ss: &SecretScanner, path: String) -> HashSet<FileF
309335
#[cfg(test)]
310336
mod tests {
311337
use super::*;
338+
use escargot::CargoBuild;
312339
use std::io::Result;
313-
use std::process::Output;
314340
use std::io::Write;
341+
use std::process::Output;
315342
use tempfile::{NamedTempFile, TempDir};
316-
use escargot::CargoBuild;
317343

318344
fn run_command_in_dir(dir: &TempDir, command: &str, args: &[&str]) -> Result<Output> {
319345
let dir_path = dir.path().to_str().unwrap();
320-
let binary = CargoBuild::new()
321-
.bin(command)
322-
.run()
323-
.unwrap();
324-
325-
binary.command()
326-
.current_dir(dir_path)
327-
.args(args)
328-
.output()
346+
let binary = CargoBuild::new().bin(command).run().unwrap();
347+
348+
binary.command().current_dir(dir_path).args(args).output()
329349
}
330350

331351
fn write_temp_file(dir: &TempDir, filename: &str, contents: &str) {
@@ -346,7 +366,11 @@ mod tests {
346366
fn does_not_scan_output_file() {
347367
let temp_dir = TempDir::new().unwrap();
348368

349-
write_temp_file(&temp_dir, "insecure-file.txt", "My email is username@mail.com");
369+
write_temp_file(
370+
&temp_dir,
371+
"insecure-file.txt",
372+
"My email is username@mail.com",
373+
);
350374

351375
let cmd_args = ["-o", "output_file.txt", "."];
352376

@@ -374,13 +398,20 @@ mod tests {
374398
}
375399
"#;
376400
write!(allowlist_temp_file, "{}", json).unwrap();
377-
write_temp_file(&temp_dir, "insecure-file.txt", "My email is username@mail.com");
401+
write_temp_file(
402+
&temp_dir,
403+
"insecure-file.txt",
404+
"My email is username@mail.com",
405+
);
378406

379-
let cmd_args = ["--allowlist", allowlist_temp_file.path().to_str().unwrap(), "."];
407+
let cmd_args = [
408+
"--allowlist",
409+
allowlist_temp_file.path().to_str().unwrap(),
410+
".",
411+
];
380412

381413
let output = run_command_in_dir(&temp_dir, "duroc_hog", &cmd_args).unwrap();
382414

383415
assert_eq!("[]\n", str::from_utf8(&output.stdout).unwrap());
384-
385416
}
386-
}
417+
}

0 commit comments

Comments
 (0)