Skip to content
Open
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
10 changes: 10 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 name: String,
pub surname: String,
pub account_handle: String,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have a mismatch between these fields and the fields in the schema?
Isn't it easier if we call them the same? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, I can make them equal for simplicity! :)

}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
Expand All @@ -36,6 +45,7 @@ pub struct TeamMember {
pub is_lead: bool,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub roles: Vec<String>,
pub google_workspace: Option<GoogleWorkspace>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub google_workspace: Option<GoogleWorkspace>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_workspace: Option<GoogleWorkspace>,

Otherwise the response contains "google_workspace": null

}

#[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
10 changes: 4 additions & 6 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ 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,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -194,7 +193,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
19 changes: 18 additions & 1 deletion 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 @@ -539,6 +541,13 @@ fn convert_teams<'a>(
github_id: person.github_id(),
is_lead: leads.contains(github_name),
roles: website_roles.get(*github_name).cloned().unwrap_or_default(),
google_workspace: person.google_workspace().clone().map(|gws| {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the function google_workspace() returns &Option<Something>, but Option<&Something> is more idiomatic.

We could change the function like this:

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

GoogleWorkspace {
name: gws.first_name.clone(),
surname: gws.last_name.clone(),
account_handle: gws.account_handle.clone(),
}
}),
});
}
}
Expand All @@ -557,6 +566,13 @@ fn convert_teams<'a>(
.get(alum.github.as_str())
.cloned()
.unwrap_or_default(),
google_workspace: person.google_workspace().clone().map(|gws| {
GoogleWorkspace {
name: gws.first_name,
surname: gws.last_name,
account_handle: gws.account_handle,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is duplicated from above. Maybe we can have a From implementation or something like this?

}
}),
});
}
}
Expand Down Expand Up @@ -606,6 +622,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
40 changes: 40 additions & 0 deletions src/sync/gws/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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, PartialEq)]
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, PartialEq)]
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!("{}@rust-lang.org", gws.account_handle),
name: UserName {
given_name: gws.name.to_string(),
family_name: gws.surname.to_string(),
},
}
}
}

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