@@ -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,8 @@ 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+ let encryption = & app. config . gh_token_encryption ;
325+ add_team_owner ( & * app. github , conn, req_user, krate, login, encryption) . await
324326 } else {
325327 invite_user_owner ( app, conn, req_user, krate, login) . await
326328 }
@@ -363,6 +365,7 @@ async fn add_team_owner(
363365 req_user : & User ,
364366 krate : & Crate ,
365367 login : & str ,
368+ encryption : & GitHubTokenEncryption ,
366369) -> Result < NewOwnerInvite , OwnerAddError > {
367370 // github:rust-lang:owners
368371 let mut chunks = login. split ( ':' ) ;
@@ -381,9 +384,16 @@ async fn add_team_owner(
381384 } ) ?;
382385
383386 // Always recreate teams to get the most up-to-date GitHub ID
384- let team =
385- create_or_update_github_team ( gh_client, conn, & login. to_lowercase ( ) , org, team, req_user)
386- . await ?;
387+ let team = create_or_update_github_team (
388+ gh_client,
389+ conn,
390+ & login. to_lowercase ( ) ,
391+ org,
392+ team,
393+ req_user,
394+ encryption,
395+ )
396+ . await ?;
387397
388398 // Teams are added as owners immediately, since the above call ensures
389399 // the user is a team member.
@@ -408,6 +418,7 @@ pub async fn create_or_update_github_team(
408418 org_name : & str ,
409419 team_name : & str ,
410420 req_user : & User ,
421+ encryption : & GitHubTokenEncryption ,
411422) -> AppResult < Team > {
412423 // GET orgs/:org/teams
413424 // check that `team` is the `slug` in results, and grab its data
@@ -424,7 +435,14 @@ pub async fn create_or_update_github_team(
424435 ) ) ) ;
425436 }
426437
427- let token = AccessToken :: new ( req_user. gh_access_token . expose_secret ( ) . to_string ( ) ) ;
438+ let token = encryption
439+ . decrypt ( & req_user. gh_encrypted_token )
440+ . map_err ( |err| {
441+ custom (
442+ StatusCode :: INTERNAL_SERVER_ERROR ,
443+ format ! ( "Failed to decrypt GitHub token: {err}" ) ,
444+ )
445+ } ) ?;
428446 let team = gh_client. team_by_name ( org_name, team_name, & token) . await
429447 . map_err ( |_| {
430448 bad_request ( format_args ! (
0 commit comments