11use crate :: background_jobs:: Environment ;
2- use crate :: git:: { Crate , Credentials } ;
2+ use crate :: git:: Crate ;
33use crate :: schema;
44use anyhow:: Context ;
55use chrono:: Utc ;
66use diesel:: prelude:: * ;
77use std:: fs:: { self , OpenOptions } ;
8- use std:: io:: prelude:: * ;
98use swirl:: PerformError ;
109
1110#[ swirl:: background_job]
@@ -99,23 +98,7 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
9998
10099 // Shell out to git because libgit2 does not currently support push leases
101100
102- let key = match & repo. credentials {
103- Credentials :: Ssh { key } => key,
104- Credentials :: Http { .. } => {
105- return Err ( String :: from ( "squash_index: Password auth not supported" ) . into ( ) )
106- }
107- _ => return Err ( String :: from ( "squash_index: Could not determine credentials" ) . into ( ) ) ,
108- } ;
109-
110- // When running on production, ensure the file is created in tmpfs and not persisted to disk
111- #[ cfg( target_os = "linux" ) ]
112- let mut temp_key_file = tempfile:: Builder :: new ( ) . tempfile_in ( "/dev/shm" ) ?;
113-
114- // For other platforms, default to std::env::tempdir()
115- #[ cfg( not( target_os = "linux" ) ) ]
116- let mut temp_key_file = tempfile:: Builder :: new ( ) . tempfile ( ) ?;
117-
118- temp_key_file. write_all ( key. as_bytes ( ) ) ?;
101+ let temp_key_path = repo. credentials . write_temporary_ssh_key ( ) ?;
119102
120103 let checkout_path = repo. checkout_path . path ( ) ;
121104 let output = std:: process:: Command :: new ( "git" )
@@ -124,7 +107,7 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
124107 "GIT_SSH_COMMAND" ,
125108 format ! (
126109 "ssh -o StrictHostKeyChecking=accept-new -i {}" ,
127- temp_key_file . path ( ) . display( )
110+ temp_key_path . display( )
128111 ) ,
129112 )
130113 . args ( & [
0 commit comments