Skip to content

Commit

Permalink
feat: don't create temp file for passphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Dec 8, 2023
1 parent 41b9bd7 commit f918e80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/main/java/io/kestra/plugin/git/AbstractGitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,8 @@ protected <T extends TransportCommand> T authentified(T command, RunContext runC
}

if (this.privateKey != null) {
Path privateKey = runContext.tempFile(
runContext.render(this.privateKey).getBytes(StandardCharsets.UTF_8),
null
);

Files.setPosixFilePermissions(privateKey, Set.of(PosixFilePermission.OWNER_READ));

command.setTransportConfigCallback(new SshTransportConfigCallback(
privateKey.toFile(),
runContext.render(this.privateKey).getBytes(StandardCharsets.UTF_8),
runContext.render(this.passphrase)
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@AllArgsConstructor
public class SshTransportConfigCallback implements TransportConfigCallback {
private File privateKey;
private byte[] privateKey;
private String passphrase;

@Override
Expand All @@ -35,11 +35,13 @@ protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException

if (passphrase != null) {
jsch.addIdentity(
privateKey.getAbsolutePath(),
"privateKey",
privateKey,
null,
passphrase.getBytes(StandardCharsets.UTF_8)
);
} else {
jsch.addIdentity(privateKey.getAbsolutePath());
jsch.addIdentity("privateKey", privateKey, null, null);
}

return jsch;
Expand Down

0 comments on commit f918e80

Please sign in to comment.