diff --git a/ofborg/src/acl.rs b/ofborg/src/acl.rs index 5df12a7..69f77d0 100644 --- a/ofborg/src/acl.rs +++ b/ofborg/src/acl.rs @@ -1,3 +1,5 @@ +use ofborg::systems::System; + pub struct ACL { trusted_users: Vec, known_users: Vec, @@ -27,21 +29,29 @@ impl ACL { self.repos.contains(&name.to_lowercase()) } + pub fn build_job_architectures_for_user_repo(&self, user: &str, repo: &str) -> Vec { + if self.can_build_unrestricted(user, repo) { + vec![ + System::X8664Darwin, + System::X8664Linux, + System::Aarch64Linux, + ] + } else if self.can_build_restricted(user, repo) { + vec![System::X8664Linux, System::Aarch64Linux] + } else { + vec![] + } + } + pub fn build_job_destinations_for_user_repo( &self, user: &str, repo: &str, ) -> Vec<(Option, Option)> { - if self.can_build_unrestricted(user, repo) { - vec![(Some("build-jobs".to_owned()), None)] - } else if self.can_build_restricted(user, repo) { - vec![ - (None, Some("build-inputs-x86_64-linux".to_owned())), - (None, Some("build-inputs-aarch64-linux".to_owned())), - ] - } else { - vec![] - } + self.build_job_architectures_for_user_repo(user, repo) + .iter() + .map(|system| system.as_build_destination()) + .collect() } pub fn can_build_restricted(&self, user: &str, repo: &str) -> bool { diff --git a/ofborg/src/lib.rs b/ofborg/src/lib.rs index eae41fc..87ea893 100644 --- a/ofborg/src/lib.rs +++ b/ofborg/src/lib.rs @@ -45,6 +45,7 @@ pub mod nix; pub mod notifyworker; pub mod outpathdiff; pub mod stats; +pub mod systems; pub mod tagger; pub mod tasks; pub mod test_scratch; @@ -69,6 +70,7 @@ pub mod ofborg { pub use notifyworker; pub use outpathdiff; pub use stats; + pub use systems; pub use tagger; pub use tasks; pub use test_scratch; diff --git a/ofborg/src/systems.rs b/ofborg/src/systems.rs new file mode 100644 index 0000000..4bb1c05 --- /dev/null +++ b/ofborg/src/systems.rs @@ -0,0 +1,19 @@ +pub enum System { + X8664Linux, + Aarch64Linux, + X8664Darwin, +} + +impl System { + pub fn to_string(&self) -> String { + match self { + System::X8664Linux => String::from("x86_64-linux"), + System::Aarch64Linux => String::from("aarch64-linux"), + System::X8664Darwin => String::from("x86_64-darwin"), + } + } + + pub fn as_build_destination(&self) -> (Option, Option) { + (None, Some(format!("build-inputs-{}", self.to_string()))) + } +}