-
Notifications
You must be signed in to change notification settings - Fork 352
gws: add diff for google accounts #2445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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, | ||||||||
| } | ||||||||
|
|
||||||||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||||||||
|
|
@@ -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>, | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Otherwise the response contains |
||||||||
| } | ||||||||
|
|
||||||||
| #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that the function We could change the function like this: |
||
| GoogleWorkspace { | ||
| name: gws.first_name.clone(), | ||
| surname: gws.last_name.clone(), | ||
| account_handle: gws.account_handle.clone(), | ||
| } | ||
| }), | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -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, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| } | ||
| }), | ||
| }); | ||
| } | ||
| } | ||
|
|
@@ -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); | ||
| } | ||
|
|
||
| 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>>; | ||
| } |
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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! :)