Create a type for queue job system types, and express build jobs destinations in that form

This commit is contained in:
Graham Christensen 2019-01-24 16:50:03 -05:00
parent 3cd8ea8a1f
commit 6ddf619334
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 41 additions and 10 deletions

View file

@ -1,3 +1,5 @@
use ofborg::systems::System;
pub struct ACL {
trusted_users: Vec<String>,
known_users: Vec<String>,
@ -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<System> {
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<String>, Option<String>)> {
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 {

View file

@ -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;

19
ofborg/src/systems.rs Normal file
View file

@ -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<String>, Option<String>) {
(None, Some(format!("build-inputs-{}", self.to_string())))
}
}