diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-11 12:36:55 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-11 12:43:17 +0100 |
commit | ce6f9d77c80849d11b442cf4c6783ec972456521 (patch) | |
tree | 1f08e432477c2f76429a4ecb0753f4590331830e /src/commands/build.rs | |
parent | 0737188dd12a389c419e51d9c208647b4f6732e4 (diff) |
Add allowlist feature
This patch adds the "allowlist" feature for packages.
A package can have a list of allowed images to be built on - butido will
not execute the submit if one package is not allowed on the image
passed to butido.
This is the opposite of the denylist, of course.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/commands/build.rs')
-rw-r--r-- | src/commands/build.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/commands/build.rs b/src/commands/build.rs index ec04e8f..a46166d 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -13,6 +13,7 @@ use diesel::ExpressionMethods; use diesel::PgConnection; use diesel::QueryDsl; use diesel::RunQueryDsl; +use itertools::Itertools; use log::{debug, info, warn, trace}; use tokio::stream::StreamExt; use tokio::sync::RwLock; @@ -211,15 +212,19 @@ pub async fn build(repo_root: &Path, tree.all_packages() .into_iter() .map(|pkg| { + if let Some(allowlist) = pkg.allowed_images() { + if !allowlist.contains(&image_name) { + return Err(anyhow!("Package {} {} is only allowed on: {}", pkg.name(), pkg.version(), allowlist.iter().join(", "))) + } + } + if let Some(denylist) = pkg.deny_on_images() { if denylist.iter().any(|denied| image_name == *denied) { - Err(anyhow!("Package {} {} is not allowed to be built on {}", pkg.name(), pkg.version(), image_name)) - } else { - Ok(()) + return Err(anyhow!("Package {} {} is not allowed to be built on {}", pkg.name(), pkg.version(), image_name)) } - } else { - Ok(()) } + + Ok(()) }) .collect::<Result<Vec<()>>>()?; |