Resolve VS Code config paths beside SSH config
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
This commit is contained in:
@@ -84,12 +84,13 @@ async function configureHost() {
|
|||||||
});
|
});
|
||||||
const sshDir = path.join(os.homedir(), '.ssh');
|
const sshDir = path.join(os.homedir(), '.ssh');
|
||||||
fs.mkdirSync(sshDir, { recursive: true });
|
fs.mkdirSync(sshDir, { recursive: true });
|
||||||
const generatedPath = expandHomePath(
|
const mainConfig = path.join(sshDir, 'config');
|
||||||
|
const generatedPath = resolveGeneratedSshConfigPath(
|
||||||
|
mainConfig,
|
||||||
config.get('generatedSshConfig') || path.join(sshDir, 'config.dosh'),
|
config.get('generatedSshConfig') || path.join(sshDir, 'config.dosh'),
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
process.platform
|
process.platform
|
||||||
);
|
);
|
||||||
const mainConfig = path.join(sshDir, 'config');
|
|
||||||
ensureInclude(mainConfig, sshIncludeTarget(mainConfig, generatedPath, process.platform));
|
ensureInclude(mainConfig, sshIncludeTarget(mainConfig, generatedPath, process.platform));
|
||||||
upsertBlock(generatedPath, alias, block);
|
upsertBlock(generatedPath, alias, block);
|
||||||
return { alias, generatedPath };
|
return { alias, generatedPath };
|
||||||
@@ -143,6 +144,18 @@ function sshIncludeTarget(mainConfigPath, generatedPath, platform = process.plat
|
|||||||
return sshConfigPathWord(includePath, platform);
|
return sshConfigPathWord(includePath, platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveGeneratedSshConfigPath(
|
||||||
|
mainConfigPath,
|
||||||
|
configuredPath,
|
||||||
|
home = os.homedir(),
|
||||||
|
platform = process.platform
|
||||||
|
) {
|
||||||
|
const pathApi = platform === 'win32' ? path.win32 : path;
|
||||||
|
const mainDir = pathApi.resolve(pathApi.dirname(mainConfigPath));
|
||||||
|
const expanded = expandHomePath(configuredPath, home, platform);
|
||||||
|
return pathApi.resolve(mainDir, expanded);
|
||||||
|
}
|
||||||
|
|
||||||
function upsertBlock(configPath, alias, block) {
|
function upsertBlock(configPath, alias, block) {
|
||||||
const dir = path.dirname(configPath);
|
const dir = path.dirname(configPath);
|
||||||
if (dir && dir !== '.') {
|
if (dir && dir !== '.') {
|
||||||
@@ -185,7 +198,9 @@ async function showSshConfig() {
|
|||||||
const api = requireVscode();
|
const api = requireVscode();
|
||||||
const config = api.workspace.getConfiguration('dosh');
|
const config = api.workspace.getConfiguration('dosh');
|
||||||
const sshDir = path.join(os.homedir(), '.ssh');
|
const sshDir = path.join(os.homedir(), '.ssh');
|
||||||
const generatedPath = expandHomePath(
|
const mainConfig = path.join(sshDir, 'config');
|
||||||
|
const generatedPath = resolveGeneratedSshConfigPath(
|
||||||
|
mainConfig,
|
||||||
config.get('generatedSshConfig') || path.join(sshDir, 'config.dosh'),
|
config.get('generatedSshConfig') || path.join(sshDir, 'config.dosh'),
|
||||||
os.homedir(),
|
os.homedir(),
|
||||||
process.platform
|
process.platform
|
||||||
@@ -270,6 +285,7 @@ module.exports = {
|
|||||||
deactivate,
|
deactivate,
|
||||||
expandHomePath,
|
expandHomePath,
|
||||||
ensureInclude,
|
ensureInclude,
|
||||||
|
resolveGeneratedSshConfigPath,
|
||||||
sshBlock,
|
sshBlock,
|
||||||
sshConfigPathWord,
|
sshConfigPathWord,
|
||||||
shellQuote,
|
shellQuote,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const path = require('node:path');
|
|||||||
const {
|
const {
|
||||||
expandHomePath,
|
expandHomePath,
|
||||||
ensureInclude,
|
ensureInclude,
|
||||||
|
resolveGeneratedSshConfigPath,
|
||||||
shellQuote,
|
shellQuote,
|
||||||
sshBlock,
|
sshBlock,
|
||||||
sshConfigPathWord,
|
sshConfigPathWord,
|
||||||
@@ -101,6 +102,27 @@ test('home-relative generated config paths expand for POSIX and Windows', () =>
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('relative generated config paths resolve beside the main ssh config', () => {
|
||||||
|
assert.equal(
|
||||||
|
resolveGeneratedSshConfigPath(
|
||||||
|
'/Users/palav/.ssh/config',
|
||||||
|
'config.dosh',
|
||||||
|
'/Users/palav',
|
||||||
|
'darwin'
|
||||||
|
),
|
||||||
|
'/Users/palav/.ssh/config.dosh'
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
resolveGeneratedSshConfigPath(
|
||||||
|
'C:\\Users\\palav\\.ssh\\config',
|
||||||
|
'dosh\\config.dosh',
|
||||||
|
'C:\\Users\\palav',
|
||||||
|
'win32'
|
||||||
|
),
|
||||||
|
'C:\\Users\\palav\\.ssh\\dosh\\config.dosh'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('config writers create missing parent directories', () => {
|
test('config writers create missing parent directories', () => {
|
||||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'dosh-vscode-'));
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'dosh-vscode-'));
|
||||||
const mainConfig = path.join(root, 'ssh', 'config');
|
const mainConfig = path.join(root, 'ssh', 'config');
|
||||||
|
|||||||
Reference in New Issue
Block a user