fix(core): Stop relying on filesystem for SSH keys (#9217)
This commit is contained in:
@@ -79,6 +79,26 @@ export class SourceControlGitService {
|
||||
|
||||
sourceControlFoldersExistCheck([gitFolder, sshFolder]);
|
||||
|
||||
await this.setGitSshCommand(gitFolder, sshFolder);
|
||||
|
||||
if (!(await this.checkRepositorySetup())) {
|
||||
await (this.git as unknown as SimpleGit).init();
|
||||
}
|
||||
if (!(await this.hasRemote(sourceControlPreferences.repositoryUrl))) {
|
||||
if (sourceControlPreferences.connected && sourceControlPreferences.repositoryUrl) {
|
||||
const instanceOwner = await this.ownershipService.getInstanceOwner();
|
||||
await this.initRepository(sourceControlPreferences, instanceOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the SSH command with the path to the temp file containing the private key from the DB.
|
||||
*/
|
||||
async setGitSshCommand(
|
||||
gitFolder = this.sourceControlPreferencesService.gitFolder,
|
||||
sshFolder = this.sourceControlPreferencesService.sshFolder,
|
||||
) {
|
||||
const privateKeyPath = await this.sourceControlPreferencesService.getPrivateKeyPath();
|
||||
|
||||
const sshKnownHosts = path.join(sshFolder, 'known_hosts');
|
||||
@@ -94,21 +114,8 @@ export class SourceControlGitService {
|
||||
const { simpleGit } = await import('simple-git');
|
||||
|
||||
this.git = simpleGit(this.gitOptions)
|
||||
// Tell git not to ask for any information via the terminal like for
|
||||
// example the username. As nobody will be able to answer it would
|
||||
// n8n keep on waiting forever.
|
||||
.env('GIT_SSH_COMMAND', sshCommand)
|
||||
.env('GIT_TERMINAL_PROMPT', '0');
|
||||
|
||||
if (!(await this.checkRepositorySetup())) {
|
||||
await this.git.init();
|
||||
}
|
||||
if (!(await this.hasRemote(sourceControlPreferences.repositoryUrl))) {
|
||||
if (sourceControlPreferences.connected && sourceControlPreferences.repositoryUrl) {
|
||||
const instanceOwner = await this.ownershipService.getInstanceOwner();
|
||||
await this.initRepository(sourceControlPreferences, instanceOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resetService() {
|
||||
@@ -273,6 +280,7 @@ export class SourceControlGitService {
|
||||
if (!this.git) {
|
||||
throw new ApplicationError('Git is not initialized (fetch)');
|
||||
}
|
||||
await this.setGitSshCommand();
|
||||
return await this.git.fetch();
|
||||
}
|
||||
|
||||
@@ -280,6 +288,7 @@ export class SourceControlGitService {
|
||||
if (!this.git) {
|
||||
throw new ApplicationError('Git is not initialized (pull)');
|
||||
}
|
||||
await this.setGitSshCommand();
|
||||
const params = {};
|
||||
if (options.ffOnly) {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
@@ -298,6 +307,7 @@ export class SourceControlGitService {
|
||||
if (!this.git) {
|
||||
throw new ApplicationError('Git is not initialized ({)');
|
||||
}
|
||||
await this.setGitSshCommand();
|
||||
if (force) {
|
||||
return await this.git.push(SOURCE_CONTROL_ORIGIN, branch, ['-f']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user