-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Support user@host:port syntax for SSH Transport #6558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -825,6 +825,42 @@ internal static void ValidateSpecifiedAuthentication(PSCredential credential, st | |
|
||
#endregion | ||
|
||
/// <summary> | ||
/// Parse a hostname used with SSH Transport to get embedded | ||
/// username and/or port. | ||
/// </summary> | ||
/// <param name="hostname">host name to parse</param> | ||
/// <param name="host">resolved target host</param> | ||
/// <param name="userName">resolved target user name</param> | ||
/// <param name="port">resolved target port</param> | ||
protected void ParseSshHostName(string hostname, out string host, out string userName, out int port) | ||
{ | ||
host = hostname; | ||
userName = this.UserName; | ||
port = this.Port; | ||
try | ||
{ | ||
Uri uri = new System.Uri("ssh://" + hostname); | ||
host = ResolveComputerName(uri.Host); | ||
ValidateComputerName(new string[]{host}); | ||
if (uri.UserInfo != String.Empty) | ||
{ | ||
userName = uri.UserInfo; | ||
} | ||
if (uri.Port != -1) | ||
{ | ||
port = uri.Port; | ||
} | ||
} | ||
catch (UriFormatException) | ||
{ | ||
ThrowTerminatingError(new ErrorRecord( | ||
new ArgumentException(PSRemotingErrorInvariants.FormatResourceString( | ||
RemotingErrorIdStrings.InvalidComputerName)), "PSSessionInvalidComputerName", | ||
ErrorCategory.InvalidArgument, hostname)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Parse the Connection parameter HashTable array. | ||
/// </summary> | ||
|
@@ -856,8 +892,16 @@ internal SSHConnection[] ParseSSHConnectionHashTable() | |
if (paramName.Equals(ComputerNameParameter, StringComparison.OrdinalIgnoreCase) || paramName.Equals(HostNameAlias, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var resolvedComputerName = ResolveComputerName(GetSSHConnectionStringParameter(item[paramName])); | ||
ValidateComputerName(new string[] { resolvedComputerName }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to no longer validate the host name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose I can call ValidateComputerName after extracting the hostname |
||
connectionInfo.ComputerName = resolvedComputerName; | ||
ParseSshHostName(resolvedComputerName, out string host, out string userName, out int port); | ||
connectionInfo.ComputerName = host; | ||
if (userName != String.Empty) | ||
{ | ||
connectionInfo.UserName = userName; | ||
} | ||
if (port != -1) | ||
{ | ||
connectionInfo.Port = port; | ||
} | ||
} | ||
else if (paramName.Equals(UserNameParameter, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
|
@@ -1337,11 +1381,11 @@ protected virtual void CreateHelpersForSpecifiedComputerNames() | |
/// </summary> | ||
protected void CreateHelpersForSpecifiedSSHComputerNames() | ||
{ | ||
ValidateComputerName(ResolvedComputerNames); | ||
|
||
foreach (string computerName in ResolvedComputerNames) | ||
{ | ||
var sshConnectionInfo = new SSHConnectionInfo(this.UserName, computerName, this.KeyFilePath, this.Port); | ||
ParseSshHostName(computerName, out string host, out string userName, out int port); | ||
|
||
var sshConnectionInfo = new SSHConnectionInfo(userName, host, this.KeyFilePath, port); | ||
var typeTable = TypeTable.LoadDefaultTypeFiles(); | ||
var remoteRunspace = RunspaceFactory.CreateRunspace(sshConnectionInfo, this.Host, typeTable) as RemoteRunspace; | ||
var pipeline = CreatePipeline(remoteRunspace); | ||
|
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a static method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need access to
this
so can't be static