1
1
use crate :: background_jobs:: Environment ;
2
- use crate :: git:: { Crate , Credentials } ;
2
+ use crate :: git:: Crate ;
3
3
use crate :: schema;
4
4
use anyhow:: Context ;
5
5
use chrono:: Utc ;
6
6
use diesel:: prelude:: * ;
7
7
use std:: fs:: { self , OpenOptions } ;
8
- use std:: io:: prelude:: * ;
9
8
use swirl:: PerformError ;
10
9
11
10
#[ swirl:: background_job]
@@ -99,23 +98,7 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
99
98
100
99
// Shell out to git because libgit2 does not currently support push leases
101
100
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 ( ) ?;
119
102
120
103
let checkout_path = repo. checkout_path . path ( ) ;
121
104
let output = std:: process:: Command :: new ( "git" )
@@ -124,7 +107,7 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
124
107
"GIT_SSH_COMMAND" ,
125
108
format ! (
126
109
"ssh -o StrictHostKeyChecking=accept-new -i {}" ,
127
- temp_key_file . path ( ) . display( )
110
+ temp_key_path . display( )
128
111
) ,
129
112
)
130
113
. args ( & [
0 commit comments