Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rust_team_data/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ pub struct Team {
pub github: Option<TeamGitHub>,
pub website_data: Option<TeamWebsite>,
pub roles: Vec<MemberRole>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_workspace_saml_group: Option<bool>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GoogleWorkspace {
pub first_name: String,
pub last_name: String,
pub account_handle: String,
Comment thread
marcoieni marked this conversation as resolved.
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand All @@ -36,6 +45,8 @@ pub struct TeamMember {
pub is_lead: bool,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub roles: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_workspace: Option<GoogleWorkspace>,
Comment thread
marcoieni marked this conversation as resolved.
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ mod static_api;
mod sync;
mod validate;

const AVAILABLE_SERVICES: &[&str] = &["github", "mailgun", "zulip", "crates-io"];
const AVAILABLE_SERVICES: &[&str] = &[
"github",
"google-workspace",
"mailgun",
"zulip",
"crates-io",
];

const USER_AGENT: &str = "https://github.com/rust-lang/team (infra@rust-lang.org)";

Expand Down
24 changes: 16 additions & 8 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,22 @@ pub(crate) struct Funding {
github_sponsors: bool,
}

#[allow(dead_code)]
#[derive(serde::Deserialize, Debug)]
#[derive(serde::Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub(crate) struct GoogleWorkspace {
first_name: String,
last_name: String,
account_handle: String,
pub first_name: String,
pub last_name: String,
pub account_handle: String,
}

impl From<GoogleWorkspace> for rust_team_data::v1::GoogleWorkspace {
fn from(gws: GoogleWorkspace) -> Self {
rust_team_data::v1::GoogleWorkspace {
first_name: gws.first_name,
last_name: gws.last_name,
account_handle: gws.account_handle,
}
}
}

#[allow(dead_code)]
Expand Down Expand Up @@ -157,8 +166,8 @@ impl Person {
&self.permissions
}

pub(crate) fn google_workspace(&self) -> &Option<GoogleWorkspace> {
&self.google_workspace
pub(crate) fn google_workspace(&self) -> Option<&GoogleWorkspace> {
self.google_workspace.as_ref()
}

pub(crate) fn validate(&self) -> Result<(), Error> {
Expand Down Expand Up @@ -194,7 +203,6 @@ impl std::fmt::Display for TeamKind {
}
}

#[allow(dead_code)]
#[derive(serde::Deserialize, Debug)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub(crate) struct Team {
Expand Down
17 changes: 14 additions & 3 deletions src/static_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use anyhow::{Context as _, Error, ensure};
use indexmap::IndexMap;
use log::info;
use rust_team_data::v1;
use rust_team_data::v1::{BranchProtectionMode, Crate, CrateTeamOwner, RepoMember};
use rust_team_data::v1::{
BranchProtectionMode, Crate, CrateTeamOwner, GoogleWorkspace, RepoMember,
};
use std::collections::HashMap;
use std::path::Path;

Expand Down Expand Up @@ -531,14 +533,18 @@ fn convert_teams<'a>(

let leads = team.leads();
let mut members = Vec::new();
for github_name in &team.members(data)? {
for github_name in team.members(data)? {
if let Some(person) = data.person(github_name) {
members.push(v1::TeamMember {
name: person.name().into(),
github: (*github_name).into(),
github_id: person.github_id(),
is_lead: leads.contains(github_name),
roles: website_roles.get(*github_name).cloned().unwrap_or_default(),
roles: website_roles.get(github_name).cloned().unwrap_or_default(),
google_workspace: person
.google_workspace()
.cloned()
.map(GoogleWorkspace::from),
});
}
}
Expand All @@ -557,6 +563,10 @@ fn convert_teams<'a>(
.get(alum.github.as_str())
.cloned()
.unwrap_or_default(),
google_workspace: person
.google_workspace()
.cloned()
.map(GoogleWorkspace::from),
});
}
}
Expand Down Expand Up @@ -606,6 +616,7 @@ fn convert_teams<'a>(
description: role.description.clone(),
})
.collect(),
google_workspace_saml_group: team.google_workspace_saml_group(),
};
team_map.insert(team.name().into(), team_data);
}
Expand Down
1 change: 1 addition & 0 deletions src/sync/github/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ impl From<TeamData> for v1::Team {
github: (!gh_teams.is_empty()).then_some(TeamGitHub { teams: gh_teams }),
website_data: None,
roles: vec![],
google_workspace_saml_group: None,
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/sync/gws/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::sync::gws::RUST_LANG_GWS_DOMAIN;
use async_trait::async_trait;
use rust_team_data::v1::GoogleWorkspace;

/// https://developers.google.com/workspace/admin/directory/reference/rest/v1/groups
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct Group {
pub name: String,
pub email: String,
}

/// https://developers.google.com/workspace/admin/directory/reference/rest/v1/users#UserName
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct UserName {
pub given_name: String,
pub family_name: String,
}

/// https://developers.google.com/workspace/admin/directory/reference/rest/v1/users
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub(crate) struct User {
pub name: UserName,
pub primary_email: String,
}

impl From<&GoogleWorkspace> for User {
fn from(gws: &GoogleWorkspace) -> Self {
Self {
primary_email: format!("{}@{}", gws.account_handle, RUST_LANG_GWS_DOMAIN),
name: UserName {
given_name: gws.first_name.to_string(),
family_name: gws.last_name.to_string(),
},
}
}
}

#[async_trait]
pub(crate) trait GoogleWorkspaceApiClient {
async fn get_users(&self) -> anyhow::Result<Vec<User>>;
}
Loading