Permalink
Browse files

Auto merge of #398 - pietroalbini:team-repo, r=pietroalbini

Integrate the team repository with Crater

With this PR, craterbot will support fetching the ACL from [rust-lang/team](https://github.com/rust-lang/team).
  • Loading branch information...
bors committed Feb 8, 2019
2 parents 5433cd3 + c3b14cd commit 9588150e3b8eabb211b0085e633bbf95721b01ca

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -63,6 +63,7 @@ winapi = "0.3"
log = "0.4.6"
env_logger = "0.6.0"
openssl = "0.10.16"
rust_team_data = { git = "https://github.com/rust-lang/team" }

[dev-dependencies]
assert_cmd = "0.10.1"
@@ -1,13 +1,9 @@
[server]
[server.bot-acl]
# Allow rust team members defined in https://github.com/rust-lang/team
rust-teams = true
# The list of GitHub users allowed to interact with the GitHub bot
# You can mix usernames and teams
bot-acl = [
"rust-lang/infra",
"rust-lang/release",
"rust-lang/compiler",
"rust-lang/libs",
"rust-lang/rustdoc",
]
github = []

[server.labels]
# Remove all labels matching this regex when applying new labels
@@ -4366,7 +4362,6 @@ sciter-serde = { skip-tests = true } #automatic
scm = { skip = true } #automatic
scmp = { skip = true } #automatic
scoped_allocator = { skip = true } #automatic
scoped_log = { skip = true } #automatic
scopeguard = { skip-tests = true } #automatic
score = { skip = true } #automatic
scout = { skip-tests = true } #automatic
@@ -42,10 +42,17 @@ fn default_false() -> bool {
#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct ServerConfig {
pub bot_acl: Vec<String>,
pub bot_acl: BotACL,
pub labels: ServerLabels,
}

#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct BotACL {
pub rust_teams: bool,
pub github: Vec<String>,
}

#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct ServerLabels {
@@ -247,7 +254,10 @@ impl Default for Config {
build_log_max_lines: 1000,
},
server: ServerConfig {
bot_acl: Vec::new(),
bot_acl: BotACL {
rust_teams: false,
github: vec![],
},
labels: ServerLabels {
remove: Regex::new("^$").unwrap(),
experiment_queued: "".into(),
@@ -267,8 +277,9 @@ mod tests {
fn test_config() {
// A sample config file loaded from memory
let config = concat!(
"[server]\n",
"bot-acl = []\n",
"[server.bot-acl]\n",
"rust-teams = false\n",
"github = []\n",
"[server.labels]\n",
"remove = \"\"\n",
"experiment-queued = \"\"\n",
@@ -4,6 +4,7 @@ use crate::server::github::GitHubApi;
use crate::server::{Data, HttpError};
use http::header::{HeaderMap, AUTHORIZATION, USER_AGENT};
use regex::Regex;
use rust_team_data::v1 as team_data;
use std::collections::{HashMap, HashSet};
use std::sync::{Arc, RwLock};
use warp::{self, Filter, Rejection};
@@ -91,6 +92,7 @@ pub fn auth_filter(
#[derive(Debug, Clone)]
pub struct ACL {
cached_usernames: Arc<RwLock<HashSet<String>>>,
rust_teams: bool,
users: Vec<String>,
teams: Vec<(String, String)>,
}
@@ -100,7 +102,7 @@ impl ACL {
let mut users = Vec::new();
let mut teams = Vec::new();

for item in &config.server.bot_acl {
for item in &config.server.bot_acl.github {
if let Some(middle) = item.find('/') {
let org = item[..middle].to_string();
let team = item[middle + 1..].to_string();
@@ -112,6 +114,7 @@ impl ACL {

let acl = ACL {
cached_usernames: Arc::new(RwLock::new(HashSet::new())),
rust_teams: config.server.bot_acl.rust_teams,
users,
teams,
};
@@ -172,8 +175,15 @@ impl ACL {
Ok(())
}

pub fn allowed(&self, username: &str) -> bool {
self.cached_usernames.read().unwrap().contains(username)
pub fn allowed(&self, username: &str) -> Fallible<bool> {
if self.rust_teams {
let url = format!("{}/permissions/crater.json", team_data::BASE_URL);
let members: team_data::Permission = crate::utils::http::get_sync(&url)?.json()?;
if members.github_users.iter().any(|u| *u == username) {
return Ok(true);
}
}
Ok(self.cached_usernames.read().unwrap().contains(username))
}
}

@@ -71,7 +71,7 @@ fn process_command(
continue;
}

if !data.acl.allowed(sender) {
if !data.acl.allowed(sender)? {
Message::new()
.line(
"lock",
@@ -1,7 +1,6 @@
[server]
bot-acl = [
"pietroalbini",
]
[server.bot-acl]
rust-teams = true
github = ["pietroalbini"]

[server.labels]
remove = "^S-"
@@ -1,7 +1,6 @@
[server]
bot-acl = [
"pietroalbini",
]
[server.bot-acl]
rust-teams = true
github = ["pietroalbini"]

[server.labels]
remove = "^S-"
@@ -1,7 +1,6 @@
[server]
bot-acl = [
"pietroalbini",
]
[server.bot-acl]
rust-teams = true
github = ["pietroalbini"]

[server.labels]
remove = "^S-"
@@ -1,7 +1,6 @@
[server]
bot-acl = [
"pietroalbini",
]
[server.bot-acl]
rust-teams = true
github = ["pietroalbini"]

[server.labels]
remove = "^S-"
@@ -1,7 +1,6 @@
[server]
bot-acl = [
"pietroalbini",
]
[server.bot-acl]
rust-teams = true
github = ["pietroalbini"]

[server.labels]
remove = "^S-"
@@ -1,7 +1,6 @@
[server]
bot-acl = [
"pietroalbini",
]
[server.bot-acl]
rust-teams = true
github = ["pietroalbini"]

[server.labels]
remove = "^S-"
@@ -1,7 +1,6 @@
[server]
bot-acl = [
"pietroalbini",
]
[server.bot-acl]
rust-teams = true
github = ["pietroalbini"]

[server.labels]
remove = "^S-"
Oops, something went wrong.

0 comments on commit 9588150

Please sign in to comment.