mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Merge pull request #330 from Dokploy/fix/add-validation-git-source
fix(git): don't add to ssh known host when is a http or https url
This commit is contained in:
@@ -33,7 +33,9 @@ export const cloneGitRepository = async (
|
|||||||
const knownHostsPath = path.join(SSH_PATH, "known_hosts");
|
const knownHostsPath = path.join(SSH_PATH, "known_hosts");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await addHostToKnownHosts(customGitUrl);
|
if (!isHttpOrHttps(customGitUrl)) {
|
||||||
|
await addHostToKnownHosts(customGitUrl);
|
||||||
|
}
|
||||||
await recreateDirectory(outputPath);
|
await recreateDirectory(outputPath);
|
||||||
// const command = `GIT_SSH_COMMAND="ssh -i ${keyPath} -o UserKnownHostsFile=${knownHostsPath}" git clone --branch ${customGitBranch} --depth 1 ${customGitUrl} ${gitCopyPath} --progress`;
|
// const command = `GIT_SSH_COMMAND="ssh -i ${keyPath} -o UserKnownHostsFile=${knownHostsPath}" git clone --branch ${customGitBranch} --depth 1 ${customGitUrl} ${gitCopyPath} --progress`;
|
||||||
// const { stdout, stderr } = await execAsync(command);
|
// const { stdout, stderr } = await execAsync(command);
|
||||||
@@ -84,6 +86,11 @@ export const cloneGitRepository = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isHttpOrHttps = (url: string): boolean => {
|
||||||
|
const regex = /^https?:\/\//;
|
||||||
|
return regex.test(url);
|
||||||
|
};
|
||||||
|
|
||||||
const addHostToKnownHosts = async (repositoryURL: string) => {
|
const addHostToKnownHosts = async (repositoryURL: string) => {
|
||||||
const { domain, port } = sanitizeRepoPathSSH(repositoryURL);
|
const { domain, port } = sanitizeRepoPathSSH(repositoryURL);
|
||||||
const knownHostsPath = path.join(SSH_PATH, "known_hosts");
|
const knownHostsPath = path.join(SSH_PATH, "known_hosts");
|
||||||
@@ -121,7 +128,7 @@ const sanitizeRepoPathSSH = (input: string) => {
|
|||||||
return {
|
return {
|
||||||
user: found.groups?.user ?? "git",
|
user: found.groups?.user ?? "git",
|
||||||
domain: found.groups?.domain,
|
domain: found.groups?.domain,
|
||||||
port: 22,
|
port: Number(found.groups?.port ?? 22),
|
||||||
owner: found.groups?.owner ?? "",
|
owner: found.groups?.owner ?? "",
|
||||||
repo: found.groups?.repo,
|
repo: found.groups?.repo,
|
||||||
get repoPath() {
|
get repoPath() {
|
||||||
|
|||||||
Reference in New Issue
Block a user