@@ -9,6 +9,7 @@ use crate::models::{
99 krate:: NewOwnerInvite , token:: EndpointScope ,
1010} ;
1111use crate :: util:: errors:: { AppResult , BoxedAppError , bad_request, crate_not_found, custom} ;
12+ use crate :: util:: gh_token_encryption:: GitHubTokenEncryption ;
1213use crate :: views:: EncodableOwner ;
1314use crate :: { App , app:: AppState } ;
1415use crate :: { auth:: AuthCheck , email:: EmailMessage } ;
@@ -199,7 +200,7 @@ async fn modify_owners(
199200
200201 let owners = krate. owners ( conn) . await ?;
201202
202- match Rights :: get ( user, & * app. github , & owners) . await ? {
203+ match Rights :: get ( user, & * app. github , & owners, & app . config . gh_token_encryption ) . await ? {
203204 Rights :: Full => { }
204205 // Yes!
205206 Rights :: Publish => {
@@ -320,7 +321,7 @@ async fn add_owner(
320321 login : & str ,
321322) -> Result < NewOwnerInvite , OwnerAddError > {
322323 if login. contains ( ':' ) {
323- add_team_owner ( & * app. github , conn, req_user, krate, login) . await
324+ add_team_owner ( & * app. github , conn, req_user, krate, login, & app . config . gh_token_encryption ) . await
324325 } else {
325326 invite_user_owner ( app, conn, req_user, krate, login) . await
326327 }
@@ -363,6 +364,7 @@ async fn add_team_owner(
363364 req_user : & User ,
364365 krate : & Crate ,
365366 login : & str ,
367+ encryption : & GitHubTokenEncryption ,
366368) -> Result < NewOwnerInvite , OwnerAddError > {
367369 // github:rust-lang:owners
368370 let mut chunks = login. split ( ':' ) ;
@@ -382,7 +384,7 @@ async fn add_team_owner(
382384
383385 // Always recreate teams to get the most up-to-date GitHub ID
384386 let team =
385- create_or_update_github_team ( gh_client, conn, & login. to_lowercase ( ) , org, team, req_user)
387+ create_or_update_github_team ( gh_client, conn, & login. to_lowercase ( ) , org, team, req_user, encryption )
386388 . await ?;
387389
388390 // Teams are added as owners immediately, since the above call ensures
@@ -408,6 +410,7 @@ pub async fn create_or_update_github_team(
408410 org_name : & str ,
409411 team_name : & str ,
410412 req_user : & User ,
413+ encryption : & GitHubTokenEncryption ,
411414) -> AppResult < Team > {
412415 // GET orgs/:org/teams
413416 // check that `team` is the `slug` in results, and grab its data
@@ -424,7 +427,9 @@ pub async fn create_or_update_github_team(
424427 ) ) ) ;
425428 }
426429
427- let token = AccessToken :: new ( req_user. gh_access_token . expose_secret ( ) . to_string ( ) ) ;
430+ let token = encryption
431+ . decrypt ( & req_user. gh_encrypted_token )
432+ . map_err ( |err| custom ( StatusCode :: INTERNAL_SERVER_ERROR , format ! ( "Failed to decrypt GitHub token: {err}" ) ) ) ?;
428433 let team = gh_client. team_by_name ( org_name, team_name, & token) . await
429434 . map_err ( |_| {
430435 bad_request ( format_args ! (
0 commit comments