-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d94bb8
commit 262ec9c
Showing
2 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,8 +98,12 @@ export interface FileSystemConfig extends ConnectConfig { | |
sftpSudo?: string | boolean; | ||
/** The command(s) to run when a new SSH terminal gets created. Defaults to `$SHELL`. Internally the command `cd ...` is run first */ | ||
terminalCommand?: string | string[]; | ||
/** The command(s) to run when a `ssh-shell` gets run. Defaults to the placeholder `$COMMAND`. Internally the command `cd ...` is run first */ | ||
taskCommand?: string | string[]; | ||
/** The filemode to assign to created files */ | ||
newFileMode?: number | string; | ||
/** Whether this config was created from an instant connection string. Enables fuzzy matching for e.g. PuTTY, config-by-host, ... */ | ||
instantConnection?: boolean; | ||
/** Internal property saying where this config comes from. Undefined if this config is merged or something */ | ||
_location?: ConfigLocation; | ||
/** Internal property keeping track of where this config comes from (including merges) */ | ||
|
@@ -113,3 +117,35 @@ export function invalidConfigName(name: string) { | |
if (name.match(/^[\w_\\/.@\-+]+$/)) return null; | ||
return `A SSH FS name can only exists of lowercase alphanumeric characters, slashes and any of these: _.+-@`; | ||
} | ||
|
||
/** | ||
* https://regexr.com/5m3gl (mostly based on https://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04) | ||
* Supports several formats, the first one being the "full" format, with others being partial: | ||
* - `user;abc=def,[email protected]:22/some/file.ext` | ||
* - `[email protected]/directory` | ||
* - `server:22/directory` | ||
* - `user@server` | ||
* - `server` | ||
* - `@server/path` - Unlike OpenSSH, we allow a @ (and connection parameters) without a username | ||
* | ||
* The resulting FileSystemConfig will have as name basically the input, but without the path. If there is no | ||
* username given, the name will start with `@`, as to differentiate between connection strings and config names. | ||
*/ | ||
const CONNECTION_REGEX = /^((?<user>\w+)?(;[\w-]+=[\w\d-]+(,[\w\d-]+=[\w\d-]+)*)?@)?(?<host>[^@\\/:,=]+)(:(?<port>\d+))?(?<path>\/.*)?$/; | ||
|
||
export function parseConnectionString(input: string): [config: FileSystemConfig, path?: string] | string { | ||
input = input.trim(); | ||
const match = input.match(CONNECTION_REGEX); | ||
if (!match) return 'Invalid format, expected something like "[email protected]:22/some/path"'; | ||
const { user, host, path } = match.groups!; | ||
const portStr = match.groups!.port; | ||
const port = portStr ? Number.parseInt(portStr) : undefined; | ||
if (portStr && (!port || port < 1 || port > 65535)) return `The string '${port}' is not a valid port number`; | ||
const name = `${user || ''}@${host}${port ? `:${port}` : ''}${path || ''}`; | ||
return [{ | ||
name, host, port, | ||
instantConnection: true, | ||
username: user || '$USERNAME', | ||
_locations: [], | ||
}, path]; | ||
} |