ssh-config 5.0.3 → 5.1.0
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/Readme.md +24 -0
- package/{src → dist}/glob.d.ts +2 -2
- package/{src → dist}/glob.js +2 -2
- package/dist/glob.js.map +1 -0
- package/dist/ssh-config.d.ts +199 -0
- package/dist/ssh-config.js +612 -0
- package/dist/ssh-config.js.map +1 -0
- package/lib/glob.d.ts +9 -0
- package/lib/glob.js +38 -0
- package/lib/glob.js.map +1 -0
- package/lib/ssh-config.d.ts +199 -0
- package/{src → lib}/ssh-config.js +65 -41
- package/lib/ssh-config.js.map +1 -0
- package/package.json +20 -13
- package/index.d.ts +0 -3
- package/index.js +0 -23
- package/src/ssh-config.d.ts +0 -99
package/Readme.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/ssh-config)
|
|
4
4
|
[](https://www.npmjs.com/package/ssh-config)
|
|
5
|
+

|
|
5
6
|
[](https://travis-ci.org/cyjake/ssh-config)
|
|
7
|
+
[](https://github.com/cyjake/ssh-config/actions/workflows/deno.yml)
|
|
6
8
|
[](https://github.com/cyjake/ssh-config/actions/workflows/nodejs.yml)
|
|
7
9
|
[](https://codecov.io/gh/cyjake/ssh-config)
|
|
8
10
|
|
|
@@ -93,6 +95,28 @@ suggested that the general settings shall be at the end of your config file.
|
|
|
93
95
|
The `IdentityFile` parameter always contain an array to make possible multiple
|
|
94
96
|
`IdentityFile` settings to be able to coexist.
|
|
95
97
|
|
|
98
|
+
#### Case-Insensitive Matching
|
|
99
|
+
|
|
100
|
+
OpenSSH treats configuration directives case-insensitively. By default, `compute()`
|
|
101
|
+
preserves the original case from the config file. To normalize directive names to
|
|
102
|
+
lowercase (matching OpenSSH behavior), use the `ignoreCase` option:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
const config = SSHConfig.parse(`
|
|
106
|
+
Host example
|
|
107
|
+
hOsTnaME 1.2.3.4
|
|
108
|
+
USER admin
|
|
109
|
+
`)
|
|
110
|
+
|
|
111
|
+
// Default - preserves original case
|
|
112
|
+
config.compute('example')
|
|
113
|
+
// => { hOsTnaME: '1.2.3.4', USER: 'admin' }
|
|
114
|
+
|
|
115
|
+
// With ignoreCase - lowercase to match OpenSSH
|
|
116
|
+
config.compute('example', { ignoreCase: true })
|
|
117
|
+
// => { hostname: '1.2.3.4', user: 'admin' }
|
|
118
|
+
```
|
|
119
|
+
|
|
96
120
|
### `.find` sections by Host or Match
|
|
97
121
|
|
|
98
122
|
**NOTICE**: This method is provided to find the corresponding section in the
|
package/{src → dist}/glob.d.ts
RENAMED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* A helper function to match input against [pattern-list](https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5#PATTERNS).
|
|
3
3
|
* According to `man ssh_config`, negated patterns shall be matched first.
|
|
4
4
|
*
|
|
5
|
-
* @param {string|string[]} patternList
|
|
6
|
-
* @param {string}
|
|
5
|
+
* @param {string|string[]} patternList one or more glob patterns to match
|
|
6
|
+
* @param {string} text the text to match
|
|
7
7
|
*/
|
|
8
8
|
declare function glob(patternList: string | string[], text: string): boolean;
|
|
9
9
|
export default glob;
|
package/{src → dist}/glob.js
RENAMED
|
@@ -17,8 +17,8 @@ function match(pattern, text) {
|
|
|
17
17
|
* A helper function to match input against [pattern-list](https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5#PATTERNS).
|
|
18
18
|
* According to `man ssh_config`, negated patterns shall be matched first.
|
|
19
19
|
*
|
|
20
|
-
* @param {string|string[]} patternList
|
|
21
|
-
* @param {string}
|
|
20
|
+
* @param {string|string[]} patternList one or more glob patterns to match
|
|
21
|
+
* @param {string} text the text to match
|
|
22
22
|
*/
|
|
23
23
|
function glob(patternList, text) {
|
|
24
24
|
const patterns = Array.isArray(patternList) ? patternList : patternList.split(/,/);
|
package/dist/glob.js.map
ADDED
|
@@ -0,0 +1 @@
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AC,EAAE,CAAC;YAChC,uFAAuF;YACvF,MAAM,GAAG,IAAI,CAAA;QACf,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,kBAAe,IAAI,CAAA"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import glob from './glob.ts';
|
|
3
|
+
/**
|
|
4
|
+
* A type of line in an ssh-config file. Differentiates between directives,
|
|
5
|
+
* comments, and empty lines.
|
|
6
|
+
*/
|
|
7
|
+
export declare enum LineType {
|
|
8
|
+
/** line with a directive in an ssh-config file */
|
|
9
|
+
DIRECTIVE = 1,
|
|
10
|
+
/** line with a comment in an ssh-config file */
|
|
11
|
+
COMMENT = 2,
|
|
12
|
+
/** empty line in an ssh-config file */
|
|
13
|
+
EMPTY = 3
|
|
14
|
+
}
|
|
15
|
+
/** A separator character in a directive. */
|
|
16
|
+
export type Separator = ' ' | '=' | '\t';
|
|
17
|
+
/**
|
|
18
|
+
* A directive in an ssh-config file. This is the main type of element in the
|
|
19
|
+
* file. The directive primarily consists of a
|
|
20
|
+
* {@link Directive.param | parameter}, and a {@link Directive.value | value},
|
|
21
|
+
* much like a key-value pair.
|
|
22
|
+
*
|
|
23
|
+
* We additionally keep track of a few other fields in order to print out a
|
|
24
|
+
* directive exactly as it was read, even though the used syntax is equivalent.
|
|
25
|
+
*/
|
|
26
|
+
export interface Directive {
|
|
27
|
+
/** type of line, always {@link LineType.DIRECTIVE} */
|
|
28
|
+
type: LineType.DIRECTIVE;
|
|
29
|
+
/** unrelated string encountered before this directive */
|
|
30
|
+
before: string;
|
|
31
|
+
/** unrelated string encountered after this directive */
|
|
32
|
+
after: string;
|
|
33
|
+
/** parameter name of this directive */
|
|
34
|
+
param: string;
|
|
35
|
+
/** separator char used in this directive */
|
|
36
|
+
separator: Separator;
|
|
37
|
+
/** the actual value of this directive */
|
|
38
|
+
value: string | {
|
|
39
|
+
val: string;
|
|
40
|
+
separator: string;
|
|
41
|
+
quoted?: boolean;
|
|
42
|
+
}[];
|
|
43
|
+
/** whether or not quotes were used for the directive value */
|
|
44
|
+
quoted?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A section is a Host or Match directive in an ssh-config file. It includes a
|
|
48
|
+
* reference to the contained config via {@link Section.config}.
|
|
49
|
+
*/
|
|
50
|
+
export interface Section extends Directive {
|
|
51
|
+
/** the config contained in this section */
|
|
52
|
+
config: SSHConfig;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Represents a Match directive in an ssh-config file. It includes a reference
|
|
56
|
+
* to the contained config via {@link Section.config}, and a map of all match
|
|
57
|
+
* criteria via {@link Match.criteria}.
|
|
58
|
+
*/
|
|
59
|
+
export interface Match extends Section {
|
|
60
|
+
/** the match criteria contained in this Match section */
|
|
61
|
+
criteria: Record<string, string | {
|
|
62
|
+
/** the value of this match criterion */
|
|
63
|
+
val: string;
|
|
64
|
+
/** separator used for this match criterion */
|
|
65
|
+
separator: string;
|
|
66
|
+
/** whether this match criterion was quoted */
|
|
67
|
+
quoted?: boolean;
|
|
68
|
+
}[]>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A comment in an ssh-config file. Stores the content of the comment as a
|
|
72
|
+
* string in {@link Comment.content}.
|
|
73
|
+
*/
|
|
74
|
+
export interface Comment {
|
|
75
|
+
/** type of line, always {@link LineType.COMMENT} */
|
|
76
|
+
type: LineType.COMMENT;
|
|
77
|
+
/** unrelated string encountered before this directive */
|
|
78
|
+
before: string;
|
|
79
|
+
/** unrelated string encountered after this directive */
|
|
80
|
+
after: string;
|
|
81
|
+
/** content of the comment */
|
|
82
|
+
content: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* An empty or whitespace-only line in an ssh-config file. This is mainly used
|
|
86
|
+
* to represent empty config ssh-config files. The actual whitespace characters
|
|
87
|
+
* is usually stored in the {@link Empty.before | before} field. Storing it in
|
|
88
|
+
* the {@link Empty.after | after} field is permitted, too.
|
|
89
|
+
*/
|
|
90
|
+
export interface Empty {
|
|
91
|
+
/** type of line, always {@link LineType.COMMENT} */
|
|
92
|
+
type: LineType.EMPTY;
|
|
93
|
+
/** unrelated string encountered before this directive */
|
|
94
|
+
before: string;
|
|
95
|
+
/** unrelated string encountered after this directive */
|
|
96
|
+
after: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A single line in an ssh-config file. The union can be discrimiated via its
|
|
100
|
+
* `type` property of type {@link LineType}.
|
|
101
|
+
*/
|
|
102
|
+
export type Line = Match | Section | Directive | Comment | Empty;
|
|
103
|
+
/**
|
|
104
|
+
* Options for finding a {@link Section} via Host or Match.
|
|
105
|
+
*/
|
|
106
|
+
export interface FindOptions {
|
|
107
|
+
/** the host to look for */
|
|
108
|
+
Host?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Options for querying an SSH config via host and user.
|
|
112
|
+
*/
|
|
113
|
+
export interface MatchOptions {
|
|
114
|
+
/** the host of the query */
|
|
115
|
+
Host: string;
|
|
116
|
+
/** the user of the query */
|
|
117
|
+
User?: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Options for computing SSH config results.
|
|
121
|
+
*/
|
|
122
|
+
export interface ComputeOptions {
|
|
123
|
+
/** when true, normalizes directive names to lowercase to match OpenSSH behavior */
|
|
124
|
+
ignoreCase?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Represents parsed SSH config. Main element of this library.
|
|
128
|
+
*
|
|
129
|
+
* A parsed SSH config is modelled as an array of {@link Line}s.
|
|
130
|
+
*/
|
|
131
|
+
export default class SSHConfig extends Array<Line> {
|
|
132
|
+
/** shortcut to access {@link LineType.DIRECTIVE} */
|
|
133
|
+
static readonly DIRECTIVE: LineType.DIRECTIVE;
|
|
134
|
+
/** shortcut to access {@link LineType.COMMENT} */
|
|
135
|
+
static readonly COMMENT: LineType.COMMENT;
|
|
136
|
+
/** shortcut to access {@link LineType.EMPTY} */
|
|
137
|
+
static readonly EMPTY: LineType.EMPTY;
|
|
138
|
+
/**
|
|
139
|
+
* Parse SSH config text into structured object.
|
|
140
|
+
*/
|
|
141
|
+
static parse(text: string | Buffer): SSHConfig;
|
|
142
|
+
/**
|
|
143
|
+
* Stringify structured object into SSH config text.
|
|
144
|
+
*/
|
|
145
|
+
static stringify(config: SSHConfig): string;
|
|
146
|
+
/**
|
|
147
|
+
* Query SSH config by host.
|
|
148
|
+
*/
|
|
149
|
+
compute(host: string): Record<string, string | string[]>;
|
|
150
|
+
/**
|
|
151
|
+
* Query SSH config by host and user.
|
|
152
|
+
*/
|
|
153
|
+
compute(opts: MatchOptions, computeOpts?: ComputeOptions): Record<string, string | string[]>;
|
|
154
|
+
/**
|
|
155
|
+
* Query SSH config by host with options.
|
|
156
|
+
*/
|
|
157
|
+
compute(host: string, computeOpts?: ComputeOptions): Record<string, string | string[]>;
|
|
158
|
+
/**
|
|
159
|
+
* Find by Host or Match.
|
|
160
|
+
*/
|
|
161
|
+
find(opts: FindOptions): Line | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Find by search function.
|
|
164
|
+
* @param predicate Function to check against each line; should return a truthy value when a
|
|
165
|
+
* matching line is given.
|
|
166
|
+
*/
|
|
167
|
+
find(predicate: (line: Line, index: number, config: Line[]) => unknown): Line | undefined;
|
|
168
|
+
/**
|
|
169
|
+
* Remove section by Host or Match.
|
|
170
|
+
*/
|
|
171
|
+
remove(opts: FindOptions): Line[] | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Remove section by search function.
|
|
174
|
+
* @param predicate Function to check against each line; should return a truthy value when a
|
|
175
|
+
* matching line is given.
|
|
176
|
+
*/
|
|
177
|
+
remove(predicate: (line: Line, index: number, config: Line[]) => unknown): Line[] | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* Convert this SSH config to its textual presentation via {@link stringify}.
|
|
180
|
+
*/
|
|
181
|
+
toString(): string;
|
|
182
|
+
/**
|
|
183
|
+
* Append new section to existing SSH config.
|
|
184
|
+
*/
|
|
185
|
+
append(opts: Record<string, string | string[]>): SSHConfig;
|
|
186
|
+
/**
|
|
187
|
+
* Prepend new section to existing SSH config.
|
|
188
|
+
*/
|
|
189
|
+
prepend(opts: Record<string, string | string[]>, beforeFirstSection?: boolean): SSHConfig;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Parse SSH config text into structured object.
|
|
193
|
+
*/
|
|
194
|
+
export declare function parse(text: string | Buffer): SSHConfig;
|
|
195
|
+
/**
|
|
196
|
+
* Stringify structured object into SSH config text.
|
|
197
|
+
*/
|
|
198
|
+
export declare function stringify(config: SSHConfig): string;
|
|
199
|
+
export { glob, SSHConfig };
|