Skip to content

Commit c2336d7

Browse files
authored
[SSH] Changes to prompts and error messages (#22181)
* Make proxy download prompt a ShouldContinue * Make relayInfo variable a private field in each cmdlet * Fix error messages and prompt messages
1 parent 833155d commit c2336d7

File tree

5 files changed

+29
-63
lines changed

5 files changed

+29
-63
lines changed

src/Ssh/Ssh/Common/SshBaseCmdlet.cs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
using Microsoft.Rest.Azure;
4141
using Microsoft.Azure.PowerShell.Cmdlets.Ssh.AzureClients;
4242
using Microsoft.Azure.PowerShell.Ssh.Helpers.HybridConnectivity;
43-
using System.Management.Automation.Host;
4443
using System.Management.Automation.Runspaces;
45-
using System.Collections.ObjectModel;
4644
using Microsoft.Azure.PowerShell.Ssh.Helpers.HybridCompute.Models;
4745
using Microsoft.Azure.PowerShell.Ssh.Helpers.HybridCompute;
4846

@@ -67,7 +65,6 @@ public abstract class SshBaseCmdlet : AzureRMCmdlet
6765
protected internal bool deleteCert;
6866
protected internal string proxyPath;
6967
protected internal ProgressRecord record;
70-
protected internal EndpointAccessResource relayInfo;
7168
protected internal bool createdServiceConfig;
7269

7370
protected internal readonly string[] supportedResourceTypes = {
@@ -342,7 +339,7 @@ private ResourceManagementClient ResourceManagementClient
342339
[Parameter(Mandatory = false)]
343340
public virtual SwitchParameter PassThru { get; set; }
344341

345-
[Parameter(Mandatory = false, HelpMessage = "When connecting to an Arc resource, do not ask for confirmation before updating the Service Configuration of the Connection Endpoint to match the target port.")]
342+
[Parameter(Mandatory = false, HelpMessage = "When connecting to Arc resources, do not prompt for confirmation before updating the Service Configuration of the Connection Endpoint to match the target port or to install Az.Ssh.ArcProxy module from Gallery, if needed.")]
346343
public SwitchParameter Force { get; set; }
347344

348345
#endregion
@@ -528,28 +525,21 @@ protected internal string GetProxyPath()
528525

529526
if (String.IsNullOrEmpty(proxyPath))
530527
{
531-
Collection<ChoiceDescription> choices = new Collection<ChoiceDescription> {
532-
new ChoiceDescription("N", "No"),
533-
new ChoiceDescription("Y", "Yes")
534-
};
535-
536-
int userChoice = this.Host.UI.PromptForChoice(
537-
caption: Resources.InstallProxyModuleCaption,
538-
message: Resources.InstallProxyModuleMessage,
539-
choices: choices,
540-
defaultChoice: 0);
541-
if (userChoice == 1)
528+
string caption = "Install Az.Ssh.ArcProxy module from the PowerShell Gallery";
529+
string query = Resources.InstallProxyModuleQuery;
530+
531+
if (Force || ShouldContinue(query, caption))
542532
{
543533
var installationResults = InvokeCommand.InvokeScript(
544534
script: "Install-module Az.Ssh.ArcProxy -Repository PsGallery -Scope CurrentUser -MaximumVersion 1.9.9 -AllowClobber -Force",
545535
useNewScope: true,
546536
writeToPipeline: PipelineResultTypes.Error,
547537
input: null,
548538
args: null);
549-
539+
550540
proxyPath = SearchForInstalledProxyPath();
551541
}
552-
542+
553543
}
554544

555545
if (!String.IsNullOrEmpty(proxyPath)) { return proxyPath; }
@@ -752,18 +742,16 @@ private bool ServiceConfigurationMatchesTargetPort()
752742
private void CreateServiceConfiguration()
753743
{
754744
// If the user doesn't provide a port, they might be trying to connect to port 22 or a different port set on ssh_config.
755-
string caption = Resources.ServiceConfigCreateConfirmCaptionDefaultPort;
745+
string query = Resources.ServiceConfigCreateConfirmQueryDefaultPort;
756746
int port = 22;
757747
if (Port != null)
758748
{
759749
port = Int32.Parse(Port);
760-
caption = String.Format(Resources.ServiceConfigCreateConfirmCaptionExplicitPort, port);
750+
query = String.Format(Resources.ServiceConfigCreateConfirmQueryExplicitPort, port);
761751
}
762752

763-
string query = String.Format(Resources.ServiceConfigCreateConfirmQuery, port);
764-
765753
// Need to come back to these messages
766-
if (!Force.IsPresent && !ShouldContinue(caption, query))
754+
if (!Force && !ShouldContinue(query, String.Format("Allow SSH connection to port {0}", port)))
767755
{
768756
throw new AzPSApplicationException(String.Format(Resources.ServiceConfigCreateConfirmationDenied, port));
769757
}

src/Ssh/Ssh/Properties/Resources.Designer.cs

Lines changed: 9 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Ssh/Ssh/Properties/Resources.resx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,8 @@
141141
<data name="FailedToListCredentials" xml:space="preserve">
142142
<value>ListCredentials operation failed with error: {0}</value>
143143
</data>
144-
<data name="InstallProxyModuleCaption" xml:space="preserve">
145-
<value>The required Az.Ssh.ArcProxy module is not installed in this machine. Would you like this cmdlet to attempt to install the Az.Ssh.ArcProxy module from the PowerShell Gallery in the current user scope?</value>
146-
</data>
147-
<data name="InstallProxyModuleMessage" xml:space="preserve">
148-
<value>The Az.Ssh.Proxy PowerShell module must be installed on the client machine in order to connect to Azure Arc resources. Installing the module to this machine is a one time operation, and you can choose to do it manually. You can find the module in the PowerShell Gallery (see: https://aka.ms/PowerShellGallery-Az.Ssh.ArcProxy).</value>
144+
<data name="InstallProxyModuleQuery" xml:space="preserve">
145+
<value>The Az.Ssh.Proxy PowerShell module must be installed on the client machine to connect to Azure Arc resources. Installing the module to this machine is a one time operation, and you can choose to do it manually. You can find the module in the PowerShell Gallery (see: https://aka.ms/PowerShellGallery-Az.Ssh.ArcProxy). The required Az.Ssh.ArcProxy module is not installed in this machine. Would you like this cmdlet to attempt to install the Az.Ssh.ArcProxy module from the PowerShell Gallery in the current user scope?</value>
149146
</data>
150147
<data name="KeysDestinationFolderWithKeys" xml:space="preserve">
151148
<value>KeysDestinationFolder can't be used in conjunction with PublicKeyFile or PrivateKeyFile. All generated keys are saved in the same directory as provided keys.</value>
@@ -183,14 +180,11 @@
183180
<data name="ServiceConfigCreateConfirmationDenied" xml:space="preserve">
184181
<value>SSH connection is not enabled in the target port {0}.</value>
185182
</data>
186-
<data name="ServiceConfigCreateConfirmCaptionDefaultPort" xml:space="preserve">
187-
<value>Port 22 is not allowed for SSH connections in this resource. You must have owner or contributor roles in this resource to be able to change the service configuration. If you would like this cmdlet to update the Service Configuration to allow connections to a different port, please provide the -Port parameter or manually set up the Service Configuration.</value>
188-
</data>
189-
<data name="ServiceConfigCreateConfirmCaptionExplicitPort" xml:space="preserve">
190-
<value>Port {0} is not allowed for SSH connections in this resource. You must have owner or contributor roles in this resource to be able to change the service configuration.</value>
183+
<data name="ServiceConfigCreateConfirmQueryDefaultPort" xml:space="preserve">
184+
<value>Port 22 is not allowed for SSH connections in this resource. You must have owner or contributor roles in this resource to be able to change the service configuration. If you would like this cmdlet to update the Service Configuration to allow connections to a different port, please provide the -Port parameter or manually set up the Service Configuration. Would you like to update the current Service Configuration in the endpoint to allow connections to port 22?</value>
191185
</data>
192-
<data name="ServiceConfigCreateConfirmQuery" xml:space="preserve">
193-
<value>Would you like to update the current Service Configuration in the endpoint to allow connections to port {0}?</value>
186+
<data name="ServiceConfigCreateConfirmQueryExplicitPort" xml:space="preserve">
187+
<value>Port {0} is not allowed for SSH connections in this resource. You must have owner or contributor roles in this resource to be able to change the service configuration. Would you like to update the current Service Configuration in the endpoint to allow connections to port {0}?</value>
194188
</data>
195189
<data name="ServiceConfigCreateForbidden" xml:space="preserve">
196190
<value>Client is not authorized to create or update the Service Configuration endpoint for {0} in the Resource Group {1}. This is an operation that must be performed by an account with Owner or Contributor role to allow SSH connections to the specified port {2}.</value>

src/Ssh/Ssh/SshCommands/EnterAzVMCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Threading;
2525
using System.Text.RegularExpressions;
2626
using Microsoft.Azure.Commands.Ssh.Properties;
27+
using Microsoft.Azure.PowerShell.Ssh.Helpers.HybridConnectivity.Models;
2728

2829
namespace Microsoft.Azure.Commands.Ssh
2930
{
@@ -55,6 +56,7 @@ public override string KeysDestinationFolder
5556

5657
#region fields
5758
private int rdpLocalPort;
59+
private EndpointAccessResource relayInfo;
5860
#endregion
5961

6062
#region constants
@@ -69,7 +71,7 @@ public override void ExecuteCmdlet()
6971
ValidateParameters();
7072
SetResourceType();
7173

72-
record = new ProgressRecord(0, "Prepare for starting SSH connection", "Start Preparing");
74+
record = new ProgressRecord(0, "Preparing for SSH connection", "Initiating connection setup");
7375
UpdateProgressBar(record, "Setup SSH connection", 0);
7476

7577
if (!IsArc() && !ParameterSetName.Equals(IpAddressParameterSet))

src/Ssh/Ssh/SshCommands/ExportAzSshConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public override void ExecuteCmdlet()
7979
{
8080
CheckIfAgentIsUpToDate();
8181
proxyPath = GetProxyPath();
82-
UpdateProgressBar(record, $"Downloaded proxy to {proxyPath}", 25);
82+
UpdateProgressBar(record, $"Retrieved path to Arc Proxy", 25);
8383
EndpointAccessResource relayInfo = GetRelayInformation();
8484
UpdateProgressBar(record, "Retrieved relay information", 50);
8585
CreateRelayInfoFile(relayInfo);

0 commit comments

Comments
 (0)