export const SSH_PORT = Number(process.env.SSH_PORT ?? 2222);
export const SSH_LISTEN_HOST = process.env.SSH_LISTEN_HOST ?? "0.0.0.0";
export const SSH_ENABLED = process.env.SSH_DISABLED !== "1";
/** Host shown in SSH clone URLs: SSH_HOST, or the host the web UI was reached on. */
export function sshHost(webHost: string) {
if (process.env.SSH_HOST) return process.env.SSH_HOST;
return webHost.replace(/:\d+$/, "").replace(/^\[(.*)\]$/, "$1");
}
export function sshCloneUrl(webHost: string, repoPath: string) {
const host = sshHost(webHost);
return SSH_PORT === 22 ? `git@${host}:${repoPath}` : `ssh://git@${host}:${SSH_PORT}/${repoPath}`;
}
export function sshTestCommand(webHost: string) {
const host = sshHost(webHost);
return SSH_PORT === 22 ? `ssh -T git@${host}` : `ssh -T -p ${SSH_PORT} git@${host}`;
}