Skip to content

Commit 1ae79b0

Browse files
committed
Fixing output for profile types
1 parent a3ca5dc commit 1ae79b0

File tree

7 files changed

+156
-51
lines changed

7 files changed

+156
-51
lines changed

src/ResourceManager/Profile/AzureRM.Profile.psd1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ CmdletsToExport = '*'
7676
VariablesToExport = '*'
7777

7878
# Aliases to export from this module
79-
AliasesToExport = @()
79+
AliasesToExport = @(
80+
'Login-AzureRmAccount',
81+
'Select-AzureRmSubscription'
82+
)
8083

8184
# List of all modules packaged with this module
8285
ModuleList = @()

src/ResourceManager/Profile/Commands.Profile/Account/LoginAzureRMAccount.cs renamed to src/ResourceManager/Profile/Commands.Profile/Account/AddAzureRmAccount.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,24 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System.IO;
1516
using System.Management.Automation;
17+
using System.Reflection;
1618
using System.Security;
1719
using Microsoft.Azure.Common.Authentication.Models;
1820
using Microsoft.Azure.Commands.Profile.Models;
1921
using Microsoft.Azure.Commands.ResourceManager.Common;
22+
using Microsoft.Azure.Common.Authentication;
2023

2124
namespace Microsoft.Azure.Commands.Profile
2225
{
2326
/// <summary>
2427
/// Cmdlet to log into an environment and download the subscriptions
2528
/// </summary>
26-
[Cmdlet("Login", "AzureRmAccount", DefaultParameterSetName = "User")]
29+
[Cmdlet("Add", "AzureRmAccount", DefaultParameterSetName = "User")]
30+
[Alias("Login-AzureRmAccount")]
2731
[OutputType(typeof(PSAzureProfile))]
28-
public class LoginAzureRMAccountCommand : AzureRMCmdlet
32+
public class AddAzureRMAccountCommand : AzureRMCmdlet , IModuleAssemblyInitializer
2933
{
3034
[Parameter(Mandatory = false, HelpMessage = "Environment containing the account to log into")]
3135
[ValidateNotNullOrEmpty]
@@ -107,5 +111,26 @@ protected override void ProcessRecord()
107111

108112
WriteObject((PSAzureProfile)profileClient.Login(azureAccount, Environment, Tenant, SubscriptionId, password));
109113
}
114+
115+
/// <summary>
116+
/// Load global aliases for ARM
117+
/// </summary>
118+
public void OnImport()
119+
{
120+
try
121+
{
122+
System.Management.Automation.PowerShell invoker = null;
123+
invoker = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace);
124+
invoker.AddScript(File.ReadAllText(FileUtilities.GetContentFilePath(
125+
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
126+
"AzureRmProfileStartup.ps1")));
127+
invoker.Invoke();
128+
}
129+
catch
130+
{
131+
// This will throw exception for tests, ignore.
132+
}
133+
}
134+
110135
}
111136
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
@{
16+
"Login-AzureRmAccount" = "Add-AzureRmAccount";
17+
"Select-AzureRmSubscription" = "Set-AzureRmContext";
18+
}.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"

src/ResourceManager/Profile/Commands.Profile/Commands.Profile.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<Compile Include="Models\PSAzureSubscription.cs" />
144144
<Compile Include="Models\PSAzureTenant.cs" />
145145
<Compile Include="Subscription\GetAzureRMSubscription.cs" />
146-
<Compile Include="Account\LoginAzureRMAccount.cs" />
146+
<Compile Include="Account\AddAzureRmAccount.cs" />
147147
<Compile Include="Context\GetAzureRMContext.cs" />
148148
<Compile Include="Context\SetAzureRMContext.cs" />
149149
<Compile Include="Profile\SelectAzureRMProfile.cs" />
@@ -165,6 +165,9 @@
165165
<Link>AzureRM.Profile.psd1</Link>
166166
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
167167
</None>
168+
<None Include="AzureRmProfileStartup.ps1">
169+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
170+
</None>
168171
<None Include="MSSharedLibKey.snk" />
169172
<None Include="packages.config" />
170173
</ItemGroup>

src/ResourceManager/Profile/Commands.Profile/Microsoft.Azure.Commands.Profile.format.ps1xml

Lines changed: 95 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,103 @@
22
<Configuration>
33
<ViewDefinitions>
44
<View>
5-
<Name>Microsoft.Azure.Common.Authentication.Models.PSAzureAccount</Name>
5+
<Name>Microsoft.Azure.Commands.Profile.Models.PSAzureProfile</Name>
66
<ViewSelectedBy>
7-
<TypeName>Microsoft.Azure.Common.Authentication.Models.PSAzureAccount</TypeName>
7+
<TypeName>Microsoft.Azure.Commands.Profile.Models.PSAzureProfile</TypeName>
88
</ViewSelectedBy>
9-
<TableControl>
10-
<TableHeaders>
11-
<TableColumnHeader>
12-
<Label>Id</Label>
13-
<Width>30</Width>
14-
</TableColumnHeader>
15-
<TableColumnHeader>
16-
<Label>Type</Label>
17-
<Width>10</Width>
18-
</TableColumnHeader>
19-
<TableColumnHeader>
20-
<Label>Subscriptions</Label>
21-
</TableColumnHeader>
22-
<TableColumnHeader>
23-
<Label>Tenants</Label>
24-
</TableColumnHeader>
25-
</TableHeaders>
26-
<TableRowEntries>
27-
<TableRowEntry>
28-
<Wrap/>
29-
<TableColumnItems>
30-
<TableColumnItem>
31-
<PropertyName>Id</PropertyName>
32-
</TableColumnItem>
33-
<TableColumnItem>
34-
<PropertyName>Type</PropertyName>
35-
</TableColumnItem>
36-
<TableColumnItem>
37-
<PropertyName>Subscriptions</PropertyName>
38-
</TableColumnItem>
39-
<TableColumnItem>
40-
<PropertyName>Tenants</PropertyName>
41-
</TableColumnItem>
42-
</TableColumnItems>
43-
</TableRowEntry>
44-
</TableRowEntries>
45-
</TableControl>
9+
<ListControl>
10+
<ListEntries>
11+
<ListEntry>
12+
<ListItems>
13+
<ListItem>
14+
<Label>Environment</Label>
15+
<ScriptBlock>$_.Context.Environment.ToString()</ScriptBlock>
16+
</ListItem>
17+
<ListItem>
18+
<Label>Account</Label>
19+
<ScriptBlock>$_.Context.Account.ToString()</ScriptBlock>
20+
</ListItem>
21+
<ListItem>
22+
<Label>Tenant</Label>
23+
<ScriptBlock>$_.Context.Tenant.ToString()</ScriptBlock>
24+
</ListItem>
25+
<ListItem>
26+
<Label>Subscription</Label>
27+
<ScriptBlock>$_.Context.Subscription.ToString()</ScriptBlock>
28+
</ListItem>
29+
</ListItems>
30+
</ListEntry>
31+
</ListEntries>
32+
</ListControl>
33+
</View>
34+
<View>
35+
<Name>Microsoft.Azure.Commands.Profile.Models.PSAzureContext</Name>
36+
<ViewSelectedBy>
37+
<TypeName>Microsoft.Azure.Commands.Profile.Models.PSAzureContext</TypeName>
38+
</ViewSelectedBy>
39+
<ListControl>
40+
<ListEntries>
41+
<ListEntry>
42+
<ListItems>
43+
<ListItem>
44+
<PropertyName>Environment</PropertyName>
45+
</ListItem>
46+
<ListItem>
47+
<PropertyName>Account</PropertyName>
48+
</ListItem>
49+
<ListItem>
50+
<PropertyName>Tenant</PropertyName>
51+
</ListItem>
52+
<ListItem>
53+
<PropertyName>Subscription</PropertyName>
54+
</ListItem>
55+
</ListItems>
56+
</ListEntry>
57+
</ListEntries>
58+
</ListControl>
59+
</View>
60+
<View>
61+
<Name>Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription</Name>
62+
<ViewSelectedBy>
63+
<TypeName>Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription</TypeName>
64+
</ViewSelectedBy>
65+
<ListControl>
66+
<ListEntries>
67+
<ListEntry>
68+
<ListItems>
69+
<ListItem>
70+
<PropertyName>SubscriptionName</PropertyName>
71+
</ListItem>
72+
<ListItem>
73+
<PropertyName>SubscriptionId</PropertyName>
74+
</ListItem>
75+
<ListItem>
76+
<PropertyName>TenantId</PropertyName>
77+
</ListItem>
78+
</ListItems>
79+
</ListEntry>
80+
</ListEntries>
81+
</ListControl>
82+
</View>
83+
<View>
84+
<Name>Microsoft.Azure.Commands.Profile.Models.PSAzureTenant</Name>
85+
<ViewSelectedBy>
86+
<TypeName>Microsoft.Azure.Commands.Profile.Models.PSAzureTenant</TypeName>
87+
</ViewSelectedBy>
88+
<ListControl>
89+
<ListEntries>
90+
<ListEntry>
91+
<ListItems>
92+
<ListItem>
93+
<PropertyName>TenantId</PropertyName>
94+
</ListItem>
95+
<ListItem>
96+
<PropertyName>Domain</PropertyName>
97+
</ListItem>
98+
</ListItems>
99+
</ListEntry>
100+
</ListEntries>
101+
</ListControl>
46102
</View>
47103
</ViewDefinitions>
48104
</Configuration>

src/ResourceManager/Profile/Commands.Profile/Subscription/GetAzureRMSubscription.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class GetAzureRMSubscriptionCommand : AzureRMCmdlet
3434
public string SubscriptionId { get; set; }
3535

3636
[Parameter(ParameterSetName = ListInTenantParameterSet, ValueFromPipelineByPropertyName = true, Mandatory = false)]
37-
public string Tenant { get; set; }
37+
public string TenantId { get; set; }
3838

3939
[Parameter(ParameterSetName = ListAllParameterSet, Mandatory = true)]
4040
public SwitchParameter All { get; set; }
@@ -70,7 +70,7 @@ protected override void ProcessRecord()
7070
{
7171
if (!this._client.TryGetSubscription(tenant, this.SubscriptionId, out result))
7272
{
73-
ThrowSubscriptionNotFoundError(this.Tenant, this.SubscriptionId);
73+
ThrowSubscriptionNotFoundError(this.TenantId, this.SubscriptionId);
7474
}
7575

7676
WriteObject((PSAzureSubscription)result);
@@ -109,7 +109,7 @@ private void ThrowTenantAuthenticationError(string tenant, AadAuthenticationExce
109109

110110
private string EnsureValidTenant()
111111
{
112-
var tenant = this.Tenant;
112+
var tenant = this.TenantId;
113113
if (string.IsNullOrWhiteSpace(tenant) && (DefaultContext.Tenant == null ||
114114
DefaultContext.Tenant.Id == null))
115115
{

src/ResourceManager/Profile/Commands.Profile/Tenant/GetAzureRMTenant.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ResourceManager.Common;
16-
using Microsoft.Azure.Common.Authentication.Models;
17-
using System.Collections.Generic;
15+
using System.Linq;
1816
using System.Management.Automation;
17+
using Microsoft.Azure.Commands.Profile.Models;
18+
using Microsoft.Azure.Commands.ResourceManager.Common;
1919

2020
namespace Microsoft.Azure.Commands.Profile
2121
{
@@ -24,7 +24,7 @@ namespace Microsoft.Azure.Commands.Profile
2424
/// </summary>
2525
[Cmdlet(VerbsCommon.Get, "AzureRmTenant")]
2626
[Alias("Get-AzureRmDomain")]
27-
[OutputType(typeof(List<AzureTenant>))]
27+
[OutputType(typeof(PSAzureTenant))]
2828
public class GetAzureRMTenantCommand : AzureRMCmdlet
2929
{
3030
[Parameter(Mandatory = false, Position = 0, ValueFromPipelineByPropertyName = true)]
@@ -36,7 +36,7 @@ protected override void ProcessRecord()
3636
{
3737
var profileClient = new RMProfileClient(AzureRMCmdlet.DefaultProfile);
3838

39-
WriteObject(profileClient.ListTenants(Tenant), enumerateCollection: true);
39+
WriteObject(profileClient.ListTenants(Tenant).Select((t) => (PSAzureTenant)t), enumerateCollection: true);
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)