-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,215 additions
and
1,434 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ log = "0.4.22" | |
assert_cmd = "2.0.14" | ||
predicates = "3.1.0" | ||
serial_test = "3.2.0" | ||
rstest = "0.23.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use crate::{fetch_license_infos, license_info::LicenseInfo, CheckOutput, CondaDenyCheckConfig}; | ||
use anyhow::{Context, Result}; | ||
use colored::Colorize; | ||
use log::debug; | ||
use std::io::Write; | ||
|
||
fn check_license_infos(config: &CondaDenyCheckConfig) -> Result<CheckOutput> { | ||
let license_infos = fetch_license_infos(config.lockfile_or_prefix.clone()) | ||
.with_context(|| "Fetching license information failed.")?; | ||
|
||
if config.osi { | ||
debug!("Checking licenses for OSI compliance"); | ||
Ok(license_infos.osi_check()) | ||
} else { | ||
debug!("Checking licenses against specified whitelist"); | ||
license_infos.check(config) | ||
} | ||
} | ||
|
||
pub fn check<W: Write>(check_config: CondaDenyCheckConfig, mut out: W) -> Result<()> { | ||
let (safe_dependencies, unsafe_dependencies) = check_license_infos(&check_config)?; | ||
|
||
writeln!( | ||
out, | ||
"{}", | ||
format_check_output( | ||
safe_dependencies, | ||
unsafe_dependencies.clone(), | ||
) | ||
)?; | ||
|
||
if !unsafe_dependencies.is_empty() { | ||
Err(anyhow::anyhow!("Unsafe licenses found")) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn format_check_output( | ||
safe_dependencies: Vec<LicenseInfo>, | ||
unsafe_dependencies: Vec<LicenseInfo>, | ||
) -> String { | ||
let mut output = String::new(); | ||
|
||
if !unsafe_dependencies.is_empty() { | ||
output.push_str( | ||
format!( | ||
"\n❌ {}:\n\n", | ||
"The following dependencies are unsafe".red() | ||
) | ||
.as_str(), | ||
); | ||
for license_info in &unsafe_dependencies { | ||
output.push_str(&license_info.pretty_print()) | ||
} | ||
} | ||
|
||
if unsafe_dependencies.is_empty() { | ||
output.push_str(&format!( | ||
"\n{}", | ||
"✅ No unsafe licenses found! ✅".to_string().green() | ||
)); | ||
} else { | ||
output.push_str(&format!( | ||
"\n{}", | ||
"❌ Unsafe licenses found! ❌".to_string().red() | ||
)); | ||
} | ||
|
||
output.push_str(&format!( | ||
"\nThere were {} safe licenses and {} unsafe licenses.\n", | ||
safe_dependencies.len().to_string().green(), | ||
unsafe_dependencies.len().to_string().red() | ||
)); | ||
|
||
output.push('\n'); | ||
|
||
output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.