Skip to content

Az.Ssh Preview 2 #3

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Ssh/Ssh.Test/ScenarioTests/Common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ function RandomString([bool]$allChars, [int32]$len) {
}
}

function Get-RandomArcName
function Get-ArcServerName
{
return 'arc-' + (RandomString -allChars $false -len 6)
return 'arc-' + (getAssetName)
}

function Get-RandomVmName
function Get-AzureVmName
{
return 'vm-' + (RandomString -allChars $false -len 6)
return 'vm-' + (getAssetName)
}

function Get-RandomResourceGroupName
function Get-ResourceGroupName
{
return 'rg-' + (RandomString -allChars $false -len 6)
return 'rg-' + (getAssetName)
}

function Get-PasswordForVM
Expand Down
4 changes: 2 additions & 2 deletions src/Ssh/Ssh.Test/ScenarioTests/GetAzSshConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public GetAzSshConfigTests(ITestOutputHelper output) : base(output)
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetArcConfig()
{
TestRunner.RunTestScript("Test-GetArcConfig");
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetVmConfig()
{
TestRunner.RunTestScript("Test-GetVmConfig");
Expand Down
17 changes: 11 additions & 6 deletions src/Ssh/Ssh.Test/ScenarioTests/GetAzSshConfigTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function Test-GetArcConfig
if ($IsMacOS) {
return
}
$MachineName = Get-RandomArcName
$ResourceGroupName = Get-RandomResourceGroupName
$MachineName = Get-ArcServerName
$ResourceGroupName = Get-ResourceGroupName
$SubscriptionId = (Get-AzContext).Subscription.Id
$TenantId = (Get-AzContext).Tenant.Id

Expand Down Expand Up @@ -48,7 +48,11 @@ function Test-GetArcConfig
$os = 'linux'
}

$proxyName = "sshProxy_" + $os + "_" + $arch +"_1_3_017634.exe"

$proxyName = "sshProxy_" + $os + "_" + $arch +"_1_3_017634"
if ($IsWindows) {
$proxyName = $proxyName + ".exe"
}
$proxyPath = Join-Path $HOME ".clientsshproxy" $proxyName

$relayPath = Join-Path (Split-Path ((Resolve-Path ./config).Path)) "az_ssh_config" "$ResourceGroupName-$MachineName" "$ResourceGroupName-$MachineName-relay_info"
Expand All @@ -71,8 +75,8 @@ Test Exporting SSH Config File for an Azure VM using Local User Login. Test over
#>
function Test-GetVmConfig
{
$VmName = Get-RandomVmName
$ResourceGroupName = Get-RandomResourceGroupName
$VmName = Get-AzureVmName
$ResourceGroupName = Get-ResourceGroupName
$SubscriptionId = (Get-AzContext).Subscription.Id
$TenantId = (Get-AzContext).Tenant.Id

Expand All @@ -82,9 +86,10 @@ function Test-GetVmConfig

New-AzResourceGroup -Name $ResourceGroupName -Location "eastus" | Out-Null

$domainlabel = "d1" + $ResourceGroupName
try
{
$vm = New-AzVM -ResourceGroupName $ResourceGroupName -Name $VmName -Location "eastus" -Image UbuntuLTS -Credential $cred
$vm = New-AzVM -ResourceGroupName $ResourceGroupName -Name $VmName -Location "eastus" -Credential $cred -DomainNameLabel $domainlabel
Remove-Item ./config -ErrorAction Ignore

Assert-NotNull $vm
Expand Down
15 changes: 3 additions & 12 deletions src/Ssh/Ssh.Test/ScenarioTests/SshTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,11 @@ protected SshTestRunner(ITestOutputHelper output)
{
helper.RMProfileModule,
helper.GetRMModulePath("Az.Ssh.psd1"),
helper.GetRMModulePath("AzureRM.Compute.psd1")
helper.GetRMModulePath("Az.Compute.psd1"),
})
.WithNewRecordMatcherArguments(
userAgentsToIgnore: new Dictionary<string, string>
{
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2017-05-10"},
{"Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient", "2016-09-01"},
},
resourceProviders: new Dictionary<string, string>
{
{"Microsoft.Resources", null},
{"Microsoft.Compute", null},
}
userAgentsToIgnore: new Dictionary<string, string>(),
resourceProviders: new Dictionary<string, string>()
)
.Build();
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Ssh/Ssh.Test/Ssh.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="57.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Compute" Version="60.0.0" />
</ItemGroup>

</Project>
22 changes: 20 additions & 2 deletions src/Ssh/Ssh.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31702.278
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ssh", "Ssh\Ssh.csproj", "{42656543-77AD-4968-BA4B-BE0778705625}"
EndProject
Expand All @@ -20,6 +20,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ssh.Helpers", "Ssh.Helpers\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ssh.Test", "Ssh.Test\Ssh.Test.csproj", "{D7433FFA-1008-4C8E-8E64-3419D20BDCCC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Compute", "..\Compute\Compute\Compute.csproj", "{AEFE94D4-CBA1-4B3A-AC7C-4946B6BE7A62}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Compute.AlcWrapper", "..\Compute\Compute.AlcWrapper\Compute.AlcWrapper.csproj", "{38A6AE2E-4F40-415A-9998-2049E145B27E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Compute.Helpers", "..\Compute\Compute.Helpers\Compute.Helpers.csproj", "{E5FD2EC8-264B-4A04-9650-A0E5A65AC4DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -62,6 +68,18 @@ Global
{D7433FFA-1008-4C8E-8E64-3419D20BDCCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7433FFA-1008-4C8E-8E64-3419D20BDCCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7433FFA-1008-4C8E-8E64-3419D20BDCCC}.Release|Any CPU.Build.0 = Release|Any CPU
{AEFE94D4-CBA1-4B3A-AC7C-4946B6BE7A62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEFE94D4-CBA1-4B3A-AC7C-4946B6BE7A62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEFE94D4-CBA1-4B3A-AC7C-4946B6BE7A62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEFE94D4-CBA1-4B3A-AC7C-4946B6BE7A62}.Release|Any CPU.Build.0 = Release|Any CPU
{38A6AE2E-4F40-415A-9998-2049E145B27E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38A6AE2E-4F40-415A-9998-2049E145B27E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38A6AE2E-4F40-415A-9998-2049E145B27E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38A6AE2E-4F40-415A-9998-2049E145B27E}.Release|Any CPU.Build.0 = Release|Any CPU
{E5FD2EC8-264B-4A04-9650-A0E5A65AC4DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5FD2EC8-264B-4A04-9650-A0E5A65AC4DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5FD2EC8-264B-4A04-9650-A0E5A65AC4DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5FD2EC8-264B-4A04-9650-A0E5A65AC4DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions src/Ssh/Ssh/AzureClients/HybridConnectivityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public HybridConnectivityClient(IAzureContext context)
{
}

public HybridConnectivityClient(IHybridConnectivityManagementAPIClient hybridComputeManagementClient)
public HybridConnectivityClient(IHybridConnectivityManagementAPIClient hybridConnectivityManagementClient)
{
this.HybridConectivityManagementClient = hybridComputeManagementClient;
this.HybridConectivityManagementClient = hybridConnectivityManagementClient;
}
}
}
6 changes: 6 additions & 0 deletions src/Ssh/Ssh/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
-->

## Upcoming Release
* Added support for the following Resource Types:
- Microsoft.ConnectedVMwarevSphere/virtualMachines
- Microsoft.ScVmm/virtualMachines
- Microsoft.AzureStackHCI/virtualMachines
* Added parameter -Rdp to Enter-AzVM
* Added Scenario tests for Export-AzSshConfig

## Version 0.1.0
* First preview release for module Az.Ssh
26 changes: 19 additions & 7 deletions src/Ssh/Ssh/Common/RelayInformationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Microsoft.Azure.PowerShell.Cmdlets.Ssh.AzureClients;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.PowerShell.Ssh.Helpers.HybridConnectivity.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Commands.Ssh.Properties;

namespace Microsoft.Azure.PowerShell.Cmdlets.Ssh.Common
{
Expand Down Expand Up @@ -56,11 +58,15 @@ public RelayInformationUtils(IAzureContext context)
}

#region Internal Methods
public EndpointAccessResource GetRelayInformation(string rgName, string vmName, out string exceptionMessage)
public EndpointAccessResource GetRelayInformation(string resourceGroupName, string resourceName, string resourceType, out string exceptionMessage)
{
// Make this not hardcoded in the future.
string id = $"/subscriptions/{_context.Subscription.Id}/resourceGroups/{rgName}/providers/Microsoft.HybridCompute/machines/{vmName}";
return GetRelayInformation(id, out exceptionMessage);
ResourceIdentifier id = new ResourceIdentifier();
id.ResourceGroupName = resourceGroupName;
id.Subscription = _context.Subscription.Id;
id.ResourceName = resourceName;
id.ResourceType = resourceType;

return GetRelayInformation(id.ToString(), out exceptionMessage);
}

internal EndpointAccessResource GetRelayInformation(string id, out string exceptionMessage)
Expand All @@ -79,7 +85,7 @@ internal EndpointAccessResource GetRelayInformation(string id, out string except

if (cred == null && string.IsNullOrEmpty(exceptionMessage))
{
exceptionMessage = $"ListCredentials operation failed with error code '{code.ToString()}'.";
exceptionMessage = String.Format(Resources.FailedToListCredentials, code.ToString());
}

return cred;
Expand Down Expand Up @@ -122,8 +128,14 @@ private bool CreateDefaultEndpoint(string id, out string exceptionMessage)
}
catch (ErrorResponseException exception)
{
exceptionMessage = $"Unable to create default endpoint for the target Arc Server with error: {exception}. " +
$"Contact Owner/Contributor of the resource.";
if (exception.Body.Error.Code == "AuthorizationFailed")
{
exceptionMessage = Resources.FailedToCreateDefaultEndpointUnauthorized;
}
else
{
exceptionMessage = String.Format(Resources.FailedToCreateDefaultEndpoint, exception);
}
}

return false;
Expand Down
Loading