Skip to content

Commit

Permalink
basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3 committed Feb 15, 2021
1 parent 536c5d3 commit 26a2577
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ git2 = "0.13"
glob = "0.3.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
log = "0.4.11"

[lib]
name = "whitelists"
Expand Down
5 changes: 1 addition & 4 deletions src/allow.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::fs::File;
use std::io::BufReader;
use std::path::Path;

use glob::glob;
use serde_json::from_reader;

use serde::Deserialize;
use std::collections::HashMap;

#[derive(Deserialize, Debug)]
struct Greylist {
Expand Down Expand Up @@ -56,7 +53,7 @@ pub fn greylisted(name: &str, repo: &str) -> Result<Vec<Allowed>, String> {
let reader = BufReader::new(file);
let r: serde_json::error::Result<Greylist> = serde_json::from_reader(reader);
match r {
Ok(mut gl) => match gl.image_parent() {
Ok(gl) => match gl.image_parent() {
Some(p) => {
let mut x = vec![];
x.append(&mut greylisted(&p, repo).unwrap());
Expand Down
41 changes: 30 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
use clap::Clap;
use log::info;

use whitelists::allow;
use whitelists::repo;

const DCCSCR_REPO: &str = "https://repo1.dso.mil/dsop/dccscr-whitelists";

#[derive(Clap)]
#[clap(version = "v0.1.0")]
/// DCCSCR Whitelist Tool
/// DCCSCR Greylist Tool
struct Opts {
/// url of whiltelist repository
#[clap(
short,
long,
default_value = "https://repo1.dso.mil/dsop/dccscr-whitelists"
)]
/// url of greylist repository
#[clap(short, long, default_value = DCCSCR_REPO)]
url: String,

/// debug mode shows source of allow
#[clap(long, conflicts_with = "quiet")]
debug: bool,

/// quiet mode does not write to stdout
#[clap(short, long, conflicts_with = "debug")]
quiet: bool,

/// destination file writes cve list to file
#[clap(short, long)]
outfile: Option<String>,

/// image name excluding tag
image: String,
}
Expand All @@ -26,11 +37,19 @@ fn main() {
match allow::greylisted(&opts.image, repo.as_str()) {
Ok(list) => {
for i in list {
println!("{}", i.id);
eprintln!("{} ({})", i.id, i.by);
if !opts.quiet {
if opts.debug {
println!("{} ({})", i.id, i.by);
} else {
println!("{}", i.id);
}
}
if let Some(_f) = opts.outfile.as_ref() {
// todo;; write file
}
}
}
Err(e) => println!("Failure {}", e),
Err(e) => eprintln!("Failure {}", e),
}
eprintln!("sha: {}", sha)
info!("sha: {}", sha)
}

0 comments on commit 26a2577

Please sign in to comment.