ssh-config 4.3.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ssh-config.d.ts +18 -15
- package/src/ssh-config.js +50 -18
package/package.json
CHANGED
package/src/ssh-config.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
declare enum LineType {
|
|
1
|
+
export declare enum LineType {
|
|
2
2
|
DIRECTIVE = 1,
|
|
3
3
|
COMMENT = 2
|
|
4
4
|
}
|
|
5
|
-
type Separator = ' ' | '=' | '\t';
|
|
6
|
-
interface Directive {
|
|
5
|
+
export type Separator = ' ' | '=' | '\t';
|
|
6
|
+
export interface Directive {
|
|
7
7
|
type: LineType.DIRECTIVE;
|
|
8
8
|
before: string;
|
|
9
9
|
after: string;
|
|
@@ -12,29 +12,37 @@ interface Directive {
|
|
|
12
12
|
value: string | string[];
|
|
13
13
|
quoted?: boolean;
|
|
14
14
|
}
|
|
15
|
-
interface Section extends Directive {
|
|
15
|
+
export interface Section extends Directive {
|
|
16
16
|
config: SSHConfig;
|
|
17
17
|
}
|
|
18
|
-
interface Match extends Section {
|
|
18
|
+
export interface Match extends Section {
|
|
19
19
|
criteria: Record<string, string | string[]>;
|
|
20
20
|
}
|
|
21
|
-
interface Comment {
|
|
21
|
+
export interface Comment {
|
|
22
22
|
type: LineType.COMMENT;
|
|
23
23
|
before: string;
|
|
24
24
|
after: string;
|
|
25
25
|
content: string;
|
|
26
26
|
}
|
|
27
|
-
type Line = Match | Section | Directive | Comment;
|
|
28
|
-
interface FindOptions {
|
|
27
|
+
export type Line = Match | Section | Directive | Comment;
|
|
28
|
+
export interface FindOptions {
|
|
29
29
|
Host?: string;
|
|
30
30
|
}
|
|
31
|
-
interface MatchOptions {
|
|
31
|
+
export interface MatchOptions {
|
|
32
32
|
Host: string;
|
|
33
33
|
User?: string;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
export default class SSHConfig extends Array<Line> {
|
|
36
36
|
static readonly DIRECTIVE: LineType.DIRECTIVE;
|
|
37
37
|
static readonly COMMENT: LineType.COMMENT;
|
|
38
|
+
/**
|
|
39
|
+
* Parse SSH config text into structured object.
|
|
40
|
+
*/
|
|
41
|
+
static parse(text: string): SSHConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Stringify structured object into SSH config text.
|
|
44
|
+
*/
|
|
45
|
+
static stringify(config: SSHConfig): string;
|
|
38
46
|
/**
|
|
39
47
|
* Query SSH config by host.
|
|
40
48
|
*/
|
|
@@ -81,8 +89,3 @@ export declare function parse(text: string): SSHConfig;
|
|
|
81
89
|
* Stringify structured object into SSH config text.
|
|
82
90
|
*/
|
|
83
91
|
export declare function stringify(config: SSHConfig): string;
|
|
84
|
-
declare const _default: typeof SSHConfig & {
|
|
85
|
-
parse: typeof parse;
|
|
86
|
-
stringify: typeof stringify;
|
|
87
|
-
};
|
|
88
|
-
export default _default;
|
package/src/ssh-config.js
CHANGED
|
@@ -3,21 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.stringify = exports.parse = void 0;
|
|
6
|
+
exports.stringify = exports.parse = exports.LineType = void 0;
|
|
7
7
|
const glob_1 = __importDefault(require("./glob"));
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
10
10
|
const RE_SPACE = /\s/;
|
|
11
11
|
const RE_LINE_BREAK = /\r|\n/;
|
|
12
12
|
const RE_SECTION_DIRECTIVE = /^(Host|Match)$/i;
|
|
13
|
-
const RE_MULTI_VALUE_DIRECTIVE = /^(GlobalKnownHostsFile|Host|IPQoS|SendEnv|UserKnownHostsFile|ProxyCommand|Match)$/i;
|
|
13
|
+
const RE_MULTI_VALUE_DIRECTIVE = /^(GlobalKnownHostsFile|Host|IPQoS|SendEnv|UserKnownHostsFile|ProxyCommand|Match|CanonicalDomains)$/i;
|
|
14
14
|
const RE_QUOTE_DIRECTIVE = /^(?:CertificateFile|IdentityFile|IdentityAgent|User)$/i;
|
|
15
15
|
const RE_SINGLE_LINE_DIRECTIVE = /^(Include|IdentityFile)$/i;
|
|
16
16
|
var LineType;
|
|
17
17
|
(function (LineType) {
|
|
18
18
|
LineType[LineType["DIRECTIVE"] = 1] = "DIRECTIVE";
|
|
19
19
|
LineType[LineType["COMMENT"] = 2] = "COMMENT";
|
|
20
|
-
})(LineType || (LineType = {}));
|
|
20
|
+
})(LineType = exports.LineType || (exports.LineType = {}));
|
|
21
21
|
const MULTIPLE_VALUE_PROPS = [
|
|
22
22
|
'IdentityFile',
|
|
23
23
|
'LocalForward',
|
|
@@ -43,27 +43,27 @@ function getIndent(config) {
|
|
|
43
43
|
function match(criteria, context) {
|
|
44
44
|
const testCriterion = (key, criterion) => {
|
|
45
45
|
switch (key.toLowerCase()) {
|
|
46
|
-
case
|
|
46
|
+
case 'all':
|
|
47
47
|
return true;
|
|
48
|
-
case
|
|
48
|
+
case 'final':
|
|
49
49
|
if (context.inFinalPass) {
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
context.doFinalPass = true;
|
|
53
53
|
return false;
|
|
54
|
-
case
|
|
54
|
+
case 'exec':
|
|
55
55
|
const command = `function main {
|
|
56
56
|
${criterion}
|
|
57
57
|
}
|
|
58
58
|
main`;
|
|
59
59
|
return (0, child_process_1.spawnSync)(command, { shell: true }).status === 0;
|
|
60
|
-
case
|
|
60
|
+
case 'host':
|
|
61
61
|
return (0, glob_1.default)(criterion, context.params.HostName);
|
|
62
|
-
case
|
|
62
|
+
case 'originalhost':
|
|
63
63
|
return (0, glob_1.default)(criterion, context.params.OriginalHost);
|
|
64
|
-
case
|
|
64
|
+
case 'user':
|
|
65
65
|
return (0, glob_1.default)(criterion, context.params.User);
|
|
66
|
-
case
|
|
66
|
+
case 'localuser':
|
|
67
67
|
return (0, glob_1.default)(criterion, context.params.LocalUser);
|
|
68
68
|
}
|
|
69
69
|
};
|
|
@@ -76,6 +76,18 @@ function match(criteria, context) {
|
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
class SSHConfig extends Array {
|
|
79
|
+
/**
|
|
80
|
+
* Parse SSH config text into structured object.
|
|
81
|
+
*/
|
|
82
|
+
static parse(text) {
|
|
83
|
+
return parse(text);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Stringify structured object into SSH config text.
|
|
87
|
+
*/
|
|
88
|
+
static stringify(config) {
|
|
89
|
+
return stringify(config);
|
|
90
|
+
}
|
|
79
91
|
compute(opts) {
|
|
80
92
|
if (typeof opts === 'string')
|
|
81
93
|
opts = { Host: opts };
|
|
@@ -97,27 +109,47 @@ class SSHConfig extends Array {
|
|
|
97
109
|
list.push(value);
|
|
98
110
|
}
|
|
99
111
|
else if (obj[name] == null) {
|
|
100
|
-
if (name ===
|
|
112
|
+
if (name === 'HostName') {
|
|
101
113
|
context.params.HostName = value;
|
|
102
114
|
}
|
|
103
|
-
else if (name ===
|
|
115
|
+
else if (name === 'User') {
|
|
104
116
|
context.params.User = value;
|
|
105
117
|
}
|
|
106
118
|
obj[name] = value;
|
|
107
119
|
}
|
|
108
120
|
};
|
|
109
121
|
if (opts.User !== undefined) {
|
|
110
|
-
setProperty(
|
|
122
|
+
setProperty('User', opts.User);
|
|
111
123
|
}
|
|
112
124
|
const doPass = () => {
|
|
113
125
|
for (const line of this) {
|
|
114
126
|
if (line.type !== LineType.DIRECTIVE)
|
|
115
127
|
continue;
|
|
116
128
|
if (line.param === 'Host' && (0, glob_1.default)(line.value, context.params.Host)) {
|
|
129
|
+
let canonicalizeHostName = false;
|
|
130
|
+
let canonicalDomains = [];
|
|
117
131
|
setProperty(line.param, line.value);
|
|
118
132
|
for (const subline of line.config) {
|
|
119
133
|
if (subline.type === LineType.DIRECTIVE) {
|
|
120
134
|
setProperty(subline.param, subline.value);
|
|
135
|
+
if (/^CanonicalizeHostName$/i.test(subline.param) && subline.value === 'yes') {
|
|
136
|
+
canonicalizeHostName = true;
|
|
137
|
+
}
|
|
138
|
+
if (/^CanonicalDomains$/i.test(subline.param) && Array.isArray(subline.value)) {
|
|
139
|
+
canonicalDomains = subline.value;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (canonicalDomains.length > 0 && canonicalizeHostName) {
|
|
144
|
+
for (const domain of canonicalDomains) {
|
|
145
|
+
const host = `${line.value}.${domain}`;
|
|
146
|
+
const { stdout } = (0, child_process_1.spawnSync)('nslookup', [host]);
|
|
147
|
+
if (!/server can't find/.test(stdout.toString())) {
|
|
148
|
+
context.params.Host = host;
|
|
149
|
+
setProperty('Host', host);
|
|
150
|
+
doPass();
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
121
153
|
}
|
|
122
154
|
}
|
|
123
155
|
}
|
|
@@ -262,6 +294,7 @@ class SSHConfig extends Array {
|
|
|
262
294
|
return config;
|
|
263
295
|
}
|
|
264
296
|
}
|
|
297
|
+
exports.default = SSHConfig;
|
|
265
298
|
SSHConfig.DIRECTIVE = LineType.DIRECTIVE;
|
|
266
299
|
SSHConfig.COMMENT = LineType.COMMENT;
|
|
267
300
|
/**
|
|
@@ -402,16 +435,16 @@ function parse(text) {
|
|
|
402
435
|
delete result.quoted;
|
|
403
436
|
if (/^Match$/i.test(param)) {
|
|
404
437
|
const criteria = {};
|
|
405
|
-
if (typeof result.value ===
|
|
438
|
+
if (typeof result.value === 'string') {
|
|
406
439
|
result.value = [result.value];
|
|
407
440
|
}
|
|
408
441
|
let i = 0;
|
|
409
442
|
while (i < result.value.length) {
|
|
410
443
|
const keyword = result.value[i];
|
|
411
444
|
switch (keyword.toLowerCase()) {
|
|
412
|
-
case
|
|
413
|
-
case
|
|
414
|
-
case
|
|
445
|
+
case 'all':
|
|
446
|
+
case 'canonical':
|
|
447
|
+
case 'final':
|
|
415
448
|
criteria[keyword] = [];
|
|
416
449
|
i += 1;
|
|
417
450
|
break;
|
|
@@ -500,5 +533,4 @@ function stringify(config) {
|
|
|
500
533
|
return str;
|
|
501
534
|
}
|
|
502
535
|
exports.stringify = stringify;
|
|
503
|
-
exports.default = Object.assign(SSHConfig, { parse, stringify });
|
|
504
536
|
//# sourceMappingURL=ssh-config.js.map
|