Skip to content

Commit 546bf08

Browse files
author
Hovsep Mkrtchyan
committed
Referencing latest Common.Authentication library
1 parent 3826235 commit 546bf08

File tree

160 files changed

+391
-1962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+391
-1962
lines changed

src/Common/Commands.Common.Storage/Commands.Common.Storage.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</Reference>
5959
<Reference Include="Microsoft.Azure.Common.Authentication">
6060
<SpecificVersion>False</SpecificVersion>
61-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
61+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6262
</Reference>
6363
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6464
<SpecificVersion>False</SpecificVersion>

src/Common/Commands.Common.Storage/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package id="Hyak.Common" version="1.0.1" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.0.1" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
6-
<package id="Microsoft.Azure.Common.Authentication" version="1.0.1-preview" targetFramework="net45" />
6+
<package id="Microsoft.Azure.Common.Authentication" version="1.0.2-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.12.0-preview" targetFramework="net45" />
88
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
99
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

src/Common/Commands.Common.Test/Commands.Common.Test.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
</Reference>
5757
<Reference Include="Microsoft.Azure.Common.Authentication">
5858
<SpecificVersion>False</SpecificVersion>
59-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
59+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6060
</Reference>
6161
<Reference Include="Microsoft.Azure.Common.NetFramework">
6262
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.1\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
@@ -154,7 +154,6 @@
154154
<ItemGroup>
155155
<Compile Include="Common\AuthenticationFactoryTests.cs" />
156156
<Compile Include="Common\ProfileCmdltsTests.cs" />
157-
<Compile Include="Common\ProfileClientTests.cs" />
158157
<Compile Include="Common\ServicePrincipalStoreTests.cs" />
159158
<Compile Include="Common\GeneralUtilitiesTests.cs" />
160159
<Compile Include="Common\Data.cs" />

src/Common/Commands.Common.Test/Common/AuthenticationFactoryTests.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ public void VerifySubscriptionTokenCacheRemove()
3434

3535
var subscriptionId = Guid.NewGuid();
3636

37-
var credential = authFactory.GetSubscriptionCloudCredentials(new AzureContext
38-
{
39-
Environment = AzureEnvironment.PublicEnvironments["AzureCloud"],
40-
Account = new AzureAccount
37+
var credential = authFactory.GetSubscriptionCloudCredentials(new AzureContext(
38+
new AzureSubscription
39+
{
40+
Id = subscriptionId,
41+
Properties = new Dictionary<AzureSubscription.Property, string>
42+
{
43+
{ AzureSubscription.Property.Tenants, "123"}
44+
}
45+
},
46+
new AzureAccount
4147
{
4248
Id = "testuser",
4349
Type = AzureAccount.AccountType.User,
@@ -46,16 +52,9 @@ public void VerifySubscriptionTokenCacheRemove()
4652
{ AzureAccount.Property.Tenants, "123" }
4753
}
4854
},
49-
Subscription = new AzureSubscription
50-
{
51-
Id = subscriptionId,
52-
Properties = new Dictionary<AzureSubscription.Property, string>
53-
{
54-
{ AzureSubscription.Property.Tenants, "123"}
55-
}
56-
}
55+
AzureEnvironment.PublicEnvironments["AzureCloud"]
5756

58-
});
57+
));
5958

6059
Assert.True(credential is AccessTokenCredential);
6160
Assert.Equal(subscriptionId, new Guid(((AccessTokenCredential)credential).SubscriptionId));

src/Common/Commands.Common.Test/Common/ProfileClientTests.cs

Lines changed: 0 additions & 1690 deletions
This file was deleted.

src/Common/Commands.Common.Test/Common/ProfileCmdltsTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ProfileCmdltsTests() : base()
4545
AzureSession.DataStore = dataStore;
4646
commandRuntimeMock = new MockCommandRuntime();
4747
SetMockData();
48-
AzureSession.SetCurrentContext(null, null, null);
48+
AzureSession.Profile = new AzureProfile();
4949
}
5050

5151
[Fact]
@@ -506,16 +506,16 @@ public void SelectAzureSubscriptionByNameUpdatesProfile()
506506
cmdlt.CommandRuntime = commandRuntimeMock;
507507
cmdlt.SetParameterSet("SelectSubscriptionByNameParameterSet");
508508
cmdlt.SubscriptionName = azureSubscription2.Name;
509-
Assert.Null(AzureSession.CurrentContext.Subscription);
509+
Assert.Null(AzureSession.Profile.CurrentContext.Subscription);
510510

511511
// Act
512512
cmdlt.InvokeBeginProcessing();
513513
cmdlt.ExecuteCmdlet();
514514
cmdlt.InvokeEndProcessing();
515515

516516
// Verify
517-
Assert.NotNull(AzureSession.CurrentContext.Subscription);
518-
Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id);
517+
Assert.NotNull(AzureSession.Profile.CurrentContext.Subscription);
518+
Assert.Equal(azureSubscription2.Id, AzureSession.Profile.CurrentContext.Subscription.Id);
519519
}
520520

521521
[Fact]
@@ -528,7 +528,7 @@ public void SelectAzureSubscriptionWithoutPassthroughDoesNotPrint()
528528
cmdlt.CommandRuntime = commandRuntimeMock;
529529
cmdlt.SetParameterSet("SelectSubscriptionByNameParameterSet");
530530
cmdlt.SubscriptionName = azureSubscription2.Name;
531-
Assert.Null(AzureSession.CurrentContext.Subscription);
531+
Assert.Null(AzureSession.Profile.CurrentContext.Subscription);
532532

533533
// Act
534534
cmdlt.InvokeBeginProcessing();
@@ -550,7 +550,7 @@ public void SelectAzureSubscriptionWithPassthroughPrintsSubscription()
550550
cmdlt.SetParameterSet("SelectSubscriptionByNameParameterSet");
551551
cmdlt.SubscriptionName = azureSubscription2.Name;
552552
cmdlt.PassThru = new SwitchParameter(true);
553-
Assert.Null(AzureSession.CurrentContext.Subscription);
553+
Assert.Null(AzureSession.Profile.CurrentContext.Subscription);
554554

555555
// Act
556556
cmdlt.InvokeBeginProcessing();
@@ -612,16 +612,16 @@ public void SelectAzureSubscriptionByIdAndNoCurrentUpdatesProfile()
612612
cmdlt.CommandRuntime = commandRuntimeMock;
613613
cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet");
614614
cmdlt.SubscriptionId = azureSubscription2.Id.ToString();
615-
Assert.Null(AzureSession.CurrentContext.Subscription);
615+
Assert.Null(AzureSession.Profile.CurrentContext.Subscription);
616616

617617
// Act
618618
cmdlt.InvokeBeginProcessing();
619619
cmdlt.ExecuteCmdlet();
620620
cmdlt.InvokeEndProcessing();
621621

622622
// Verify
623-
Assert.NotNull(AzureSession.CurrentContext.Subscription);
624-
Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id);
623+
Assert.NotNull(AzureSession.Profile.CurrentContext.Subscription);
624+
Assert.Equal(azureSubscription2.Id, AzureSession.Profile.CurrentContext.Subscription.Id);
625625

626626
cmdlt = new SelectAzureSubscriptionCommand();
627627

@@ -636,7 +636,7 @@ public void SelectAzureSubscriptionByIdAndNoCurrentUpdatesProfile()
636636
cmdlt.InvokeEndProcessing();
637637

638638
// Verify
639-
Assert.Null(AzureSession.CurrentContext.Subscription);
639+
Assert.Null(AzureSession.Profile.CurrentContext.Subscription);
640640
}
641641

642642
[Fact]
@@ -650,7 +650,7 @@ public void SelectAzureSubscriptionByInvalidIdThrowsException()
650650
cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet");
651651
string invalidGuid = Guid.NewGuid().ToString();
652652
cmdlt.SubscriptionId = invalidGuid;
653-
Assert.Null(AzureSession.CurrentContext.Subscription);
653+
Assert.Null(AzureSession.Profile.CurrentContext.Subscription);
654654

655655
// Act
656656
cmdlt.InvokeBeginProcessing();
@@ -676,7 +676,7 @@ public void SelectAzureSubscriptionByInvalidGuidThrowsException()
676676
cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet");
677677
string invalidGuid = "foo";
678678
cmdlt.SubscriptionId = invalidGuid;
679-
Assert.Null(AzureSession.CurrentContext.Subscription);
679+
Assert.Null(AzureSession.Profile.CurrentContext.Subscription);
680680

681681
// Act
682682
cmdlt.InvokeBeginProcessing();

src/Common/Commands.Common.Test/Common/TestBase.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,20 @@ public void BaseSetup()
4343
{
4444
AzureSession.DataStore = new MockDataStore();
4545
}
46-
if (AzureSession.CurrentContext.Subscription == null)
46+
if (AzureSession.Profile.CurrentContext.Subscription == null)
4747
{
4848
var newGuid = Guid.NewGuid();
49-
AzureSession.SetCurrentContext(
50-
new AzureSubscription { Id = newGuid, Name = "test", Environment = EnvironmentName.AzureCloud, Account = "test" },
51-
null,
52-
new AzureAccount
49+
AzureSession.Profile.Subscriptions[newGuid] = new AzureSubscription { Id = newGuid, Name = "test", Environment = EnvironmentName.AzureCloud, Account = "test" };
50+
AzureSession.Profile.Accounts["test"] = new AzureAccount
5351
{
5452
Id = "test",
5553
Type = AzureAccount.AccountType.User,
5654
Properties = new Dictionary<AzureAccount.Property, string>
5755
{
5856
{AzureAccount.Property.Subscriptions, newGuid.ToString()}
5957
}
60-
});
58+
};
59+
AzureSession.Profile.DefaultSubscription = AzureSession.Profile.Subscriptions[newGuid];
6160
}
6261
AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
6362
}

src/Common/Commands.Common.Test/Mocks/MockClientFactory.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ public TClient CreateClient<TClient>(AzureSubscription subscription, AzureEnviro
5858
if (HttpMockServer.GetCurrentMode() != HttpRecorderMode.Playback)
5959
{
6060
ProfileClient profileClient = new ProfileClient();
61-
AzureContext context = new AzureContext()
62-
{
63-
Account = profileClient.GetAccount(subscription.Account),
64-
Environment = profileClient.GetEnvironmentOrDefault(subscription.Environment),
65-
Subscription = subscription
66-
};
61+
AzureContext context = new AzureContext(
62+
subscription,
63+
profileClient.GetAccount(subscription.Account),
64+
profileClient.GetEnvironmentOrDefault(subscription.Environment)
65+
);
6766

6867
creds = AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(context);
6968
}

src/Common/Commands.Common.Test/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package id="Hyak.Common" version="1.0.1" targetFramework="net45" />
44
<package id="Microsoft.Azure.Common" version="2.0.1" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
6-
<package id="Microsoft.Azure.Common.Authentication" version="1.0.1-preview" targetFramework="net45" />
6+
<package id="Microsoft.Azure.Common.Authentication" version="1.0.2-preview" targetFramework="net45" />
77
<package id="Microsoft.Azure.Management.Resources" version="2.12.0-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.0.5486.28526-prerelease" targetFramework="net45" />
99
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,17 @@ static AzurePSCmdlet()
3838

3939
public AzurePSCmdlet()
4040
{
41-
DefaultProfileClient = new ProfileClient();
42-
43-
if (AzureSession.CurrentContext.Subscription == null &&
44-
DefaultProfileClient.Profile.DefaultSubscription != null)
45-
{
46-
try
47-
{
48-
AzureSession.SetCurrentContext(
49-
DefaultProfileClient.Profile.DefaultSubscription,
50-
DefaultProfileClient.GetEnvironmentOrDefault(
51-
DefaultProfileClient.Profile.DefaultSubscription.Environment),
52-
DefaultProfileClient.GetAccountOrNull(DefaultProfileClient.Profile.DefaultSubscription.Account));
53-
}
54-
catch
55-
{
56-
// Ignore anything at this point
57-
}
58-
}
59-
41+
DefaultProfileClient = new ProfileClient(AzureSession.Profile);
6042
}
6143

6244
public AzureContext CurrentContext
6345
{
64-
get { return AzureSession.CurrentContext; }
46+
get { return AzureSession.Profile.CurrentContext; }
6547
}
6648

6749
public bool HasCurrentSubscription
6850
{
69-
get { return AzureSession.CurrentContext.Subscription != null; }
51+
get { return AzureSession.Profile.CurrentContext.Subscription != null; }
7052
}
7153

7254
public ProfileClient DefaultProfileClient { get; private set; }

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</Reference>
6161
<Reference Include="Microsoft.Azure.Common.Authentication">
6262
<SpecificVersion>False</SpecificVersion>
63-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
63+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6464
</Reference>
6565
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6666
<SpecificVersion>False</SpecificVersion>

src/Common/Commands.Common/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />
55
<package id="Microsoft.Azure.Common" version="2.0.1" targetFramework="net45" />
66
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
7-
<package id="Microsoft.Azure.Common.Authentication" version="1.0.1-preview" targetFramework="net45" />
7+
<package id="Microsoft.Azure.Common.Authentication" version="1.0.2-preview" targetFramework="net45" />
88
<package id="Microsoft.Azure.Management.Resources" version="2.12.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
1010
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />

src/Common/Commands.Profile/Commands.Profile.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</Reference>
5656
<Reference Include="Microsoft.Azure.Common.Authentication">
5757
<SpecificVersion>False</SpecificVersion>
58-
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
58+
<HintPath>..\..\packages\Microsoft.Azure.Common.Authentication.1.0.2-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
5959
</Reference>
6060
<Reference Include="Microsoft.Azure.Common.NetFramework">
6161
<HintPath>..\..\packages\Microsoft.Azure.Common.2.0.1\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>

src/Common/Commands.Profile/Subscription/GetAzureSubscription.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public override void ExecuteCmdlet()
6464
switch (ParameterSetName)
6565
{
6666
case "ByName":
67-
WriteSubscriptions(ProfileClient.RefreshSubscriptions(AzureSession.CurrentContext.Environment)
67+
WriteSubscriptions(ProfileClient.RefreshSubscriptions(AzureSession.Profile.CurrentContext.Environment)
6868
.Where(s => SubscriptionName == null || s.Name.Equals(SubscriptionName, StringComparison.InvariantCultureIgnoreCase)));
6969
break;
7070
case "ById":
@@ -103,7 +103,7 @@ public void GetCurrent()
103103
// since current is strictly in-memory and we want the real
104104
// current subscription.
105105
//
106-
if (AzureSession.CurrentContext.Subscription == null)
106+
if (AzureSession.Profile.CurrentContext.Subscription == null)
107107
{
108108
WriteError(new ErrorRecord(
109109
new InvalidOperationException(Resources.InvalidSelectedSubscription),
@@ -112,7 +112,7 @@ public void GetCurrent()
112112
}
113113
else
114114
{
115-
WriteSubscriptions(AzureSession.CurrentContext.Subscription);
115+
WriteSubscriptions(AzureSession.Profile.CurrentContext.Subscription);
116116
}
117117
}
118118

@@ -148,7 +148,7 @@ private PSAzureSubscription ConstructPsAzureSubscription(AzureSubscription subsc
148148
psObject.DefaultAccount = subscription.Account;
149149
psObject.Accounts = ProfileClient.Profile.Accounts.Values.Where(a => a.HasSubscription(subscription.Id)).ToArray();
150150
psObject.IsDefault = subscription.IsPropertySet(AzureSubscription.Property.Default);
151-
psObject.IsCurrent = AzureSession.CurrentContext.Subscription != null && AzureSession.CurrentContext.Subscription.Id == subscription.Id;
151+
psObject.IsCurrent = AzureSession.Profile.CurrentContext.Subscription != null && AzureSession.Profile.CurrentContext.Subscription.Id == subscription.Id;
152152
psObject.CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount);
153153
psObject.TenantId = subscription.GetPropertyAsArray(AzureSubscription.Property.Tenants).FirstOrDefault();
154154
return psObject;

src/Common/Commands.Profile/Subscription/ImportAzurePublishSettings.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ public override void ExecuteCmdlet()
5454
}
5555

5656
AzureSubscription defaultSubscription = ProfileClient.Profile.DefaultSubscription;
57-
Debug.Assert(AzureSession.CurrentContext != null);
58-
if (defaultSubscription != null && AzureSession.CurrentContext.Subscription == null)
59-
{
60-
AzureSession.SetCurrentContext(
61-
defaultSubscription,
62-
ProfileClient.Profile.Environments[defaultSubscription.Environment],
63-
ProfileClient.Profile.Accounts[defaultSubscription.Account]);
64-
}
57+
Debug.Assert(AzureSession.Profile.CurrentContext != null);
6558
}
6659

6760
private bool IsDirectory()

src/Common/Commands.Profile/Subscription/SelectAzureSubscription.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,25 @@ public override void ExecuteCmdlet()
9494
switch (ParameterSetName)
9595
{
9696
case SelectSubscriptionByNameParameterSet:
97-
azureSubscription = ProfileClient.SetSubscriptionAsCurrent(SubscriptionName, Account);
97+
azureSubscription = ProfileClient.SetSubscriptionAsDefault(SubscriptionName, Account);
9898
break;
9999

100100
case SelectSubscriptionByIdParameterSet:
101-
azureSubscription = ProfileClient.SetSubscriptionAsCurrent(SubscriptionIdAsGuid(), Account);
101+
azureSubscription = ProfileClient.SetSubscriptionAsDefault(SubscriptionIdAsGuid(), Account);
102102
break;
103103

104104
case SelectDefaultSubscriptionByNameParameterSet:
105105
azureSubscription = ProfileClient.SetSubscriptionAsDefault(SubscriptionName, Account);
106+
WriteWarning("Current and Default parameters have been deprecated. Select-AzureSubscription will always update the Default Subscription.");
106107
break;
107108

108109
case SelectDefaultSubscriptionByIdParameterSet:
109110
azureSubscription = ProfileClient.SetSubscriptionAsDefault(SubscriptionIdAsGuid(), Account);
111+
WriteWarning("Current and Default parameters have been deprecated. Select-AzureSubscription will always update the Default Subscription.");
110112
break;
111113

112114
case NoCurrentSubscriptionParameterSet:
113-
AzureSession.SetCurrentContext(null, null, null);
115+
WriteWarning("Current parameter set has been deprecated. Use Select-AzureSubscription -NoDefault instead.");
114116
break;
115117

116118
case NoDefaultSubscriptionParameterSet:

0 commit comments

Comments
 (0)