Skip to content

Commit 5a88b9a

Browse files
committed
Merge pull request #2 from Azure/dev
merge from azure-powershell/dev
2 parents 14b5be8 + 04137b7 commit 5a88b9a

File tree

131 files changed

+5168
-1515
lines changed

Some content is hidden

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

131 files changed

+5168
-1515
lines changed

ChangeLog.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Select-AzureSubscription: fixed output types in default and PassThru mode
55
* Compute
66
* Get-AzureVMSqlServerExtension
7-
* New-AzureVMSqlServerExtension
87
* Set-AzureVMSqlServerExtension
98
* Remove-AzureVMSqlServerExtension
109
* HDInsight

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
</Reference>
7272
<Reference Include="Microsoft.WindowsAzure.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7373
<SpecificVersion>False</SpecificVersion>
74-
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
74+
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
7575
</Reference>
7676
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7777
<SpecificVersion>False</SpecificVersion>
78-
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
78+
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
7979
</Reference>
8080
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8181
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net45" />
88
<package id="Microsoft.Data.Services.Client" version="5.6.0" targetFramework="net45" />
99
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
10-
<package id="Microsoft.WindowsAzure.Common" version="1.4.0" targetFramework="net45" />
11-
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.0" targetFramework="net45" />
10+
<package id="Microsoft.WindowsAzure.Common" version="1.4.1" targetFramework="net45" />
11+
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.1" targetFramework="net45" />
1212
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
1313
<package id="Microsoft.WindowsAzure.Management.Storage" version="3.1.0" targetFramework="net45" />
1414
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@
8989
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
9090
<Reference Include="Microsoft.WindowsAzure.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9191
<SpecificVersion>False</SpecificVersion>
92-
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
92+
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
9393
</Reference>
9494
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9595
<SpecificVersion>False</SpecificVersion>
96-
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
96+
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
9797
</Reference>
9898
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9999
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>

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

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void ProfileMigratesAccountsAndDefaultSubscriptions()
109109
Assert.Equal("https://api-dogfood.resources.windows-int.net", client.Profile.Environments["Dogfood"].Endpoints[AzureEnvironment.Endpoint.ResourceManager]);
110110
Assert.Equal("https://management-preview.core.windows-int.net/", client.Profile.Environments["Dogfood"].Endpoints[AzureEnvironment.Endpoint.ServiceManagement]);
111111
Assert.Equal(".database.windows.net", client.Profile.Environments["Dogfood"].Endpoints[AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix]);
112-
112+
113113
// Verify subscriptions
114114
Assert.Equal(3, client.Profile.Subscriptions.Count);
115115
Assert.False(client.Profile.Subscriptions.ContainsKey(new Guid("06E3F6FD-A3AA-439A-8FC4-1F5C41D2AD1E")));
@@ -157,7 +157,7 @@ public void ProfileMigratesAccountsSkipsBadOnesAndBacksUpFile()
157157

158158
// Verify Environment migration
159159
Assert.Equal(2, client.Profile.Environments.Count);
160-
160+
161161
// Verify subscriptions
162162
Assert.Equal(3, client.Profile.Subscriptions.Count);
163163
Assert.True(client.Profile.Subscriptions.ContainsKey(new Guid("06E3F6FD-A3AA-439A-8FC4-1F5C41D2AD1F")));
@@ -168,7 +168,7 @@ public void ProfileMigratesAccountsSkipsBadOnesAndBacksUpFile()
168168

169169
Assert.True(client.Profile.Subscriptions.ContainsKey(new Guid("d1e52cbc-b073-42e2-a0a0-c2f547118a6f")));
170170
Assert.Equal("Test Bad Cert", client.Profile.Subscriptions[new Guid("d1e52cbc-b073-42e2-a0a0-c2f547118a6f")].Name);
171-
171+
172172
// Verify accounts
173173
Assert.Equal(2, client.Profile.Accounts.Count);
174174
Assert.Equal("[email protected]", client.Profile.Accounts["[email protected]"].Id);
@@ -204,10 +204,10 @@ public void ProfileMigratesCorruptedFileAndCreatedBackup()
204204

205205
// Verify Environment migration
206206
Assert.Equal(2, client.Profile.Environments.Count);
207-
207+
208208
// Verify subscriptions
209209
Assert.Equal(0, client.Profile.Subscriptions.Count);
210-
210+
211211
// Verify accounts
212212
Assert.Equal(0, client.Profile.Accounts.Count);
213213

@@ -258,7 +258,7 @@ public void AddAzureAccountReturnsAccountWithAllSubscriptionsInRdfeMode()
258258
ProfileClient.DataStore = dataStore;
259259
ProfileClient client = new ProfileClient();
260260

261-
var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "test", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[ EnvironmentName.AzureCloud], null);
261+
var account = client.AddAccountAndLoadSubscriptions(new AzureAccount { Id = "test", Type = AzureAccount.AccountType.User }, AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud], null);
262262

263263
Assert.Equal("test", account.Id);
264264
Assert.Equal(3, account.GetSubscriptions(client.Profile).Count);
@@ -603,7 +603,7 @@ public void SetAzureEnvironmentUpdatesEnvironment()
603603
Assert.Equal(2, client.Profile.Environments.Count);
604604

605605
Assert.Throws<ArgumentNullException>(() => client.AddOrSetEnvironment(null));
606-
606+
607607
var env2 = client.AddOrSetEnvironment(azureEnvironment);
608608
Assert.Equal(env2.Name, azureEnvironment.Name);
609609
Assert.NotNull(env2.Endpoints[AzureEnvironment.Endpoint.ServiceManagement]);
@@ -672,7 +672,7 @@ public void AddOrSetAzureSubscriptionChecksAndUpdates()
672672
Assert.Equal(subscription, azureSubscription1);
673673
Assert.Throws<ArgumentNullException>(() => client.AddOrSetSubscription(null));
674674
Assert.Throws<ArgumentNullException>(() => client.AddOrSetSubscription(
675-
new AzureSubscription { Id = new Guid(), Environment = null, Name = "foo"}));
675+
new AzureSubscription { Id = new Guid(), Environment = null, Name = "foo" }));
676676
}
677677

678678
[Fact]
@@ -792,7 +792,7 @@ public void RefreshSubscriptionsWorksWithMooncake()
792792
MockDataStore dataStore = new MockDataStore();
793793
ProfileClient.DataStore = dataStore;
794794
ProfileClient client = new ProfileClient();
795-
795+
796796
client.Profile.Accounts[azureAccount.Id] = azureAccount;
797797

798798
var subscriptions = client.RefreshSubscriptions(client.Profile.Environments[EnvironmentName.AzureChinaCloud]);
@@ -878,7 +878,7 @@ public void SetAzureSubscriptionAsDefaultSetsDefaultAndCurrent()
878878
Assert.Equal(azureSubscription2.Id, client.Profile.DefaultSubscription.Id);
879879
Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id);
880880
Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsDefault("bad", null));
881-
Assert.Throws<ArgumentNullException>(() => client.SetSubscriptionAsDefault(null, null));
881+
Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsDefault(null, null));
882882
}
883883

884884
[Fact]
@@ -917,7 +917,7 @@ public void SetAzureSubscriptionAsCurrentSetsCurrent()
917917

918918
Assert.Equal(azureSubscription2.Id, AzureSession.CurrentContext.Subscription.Id);
919919
Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsCurrent("bad", null));
920-
Assert.Throws<ArgumentNullException>(() => client.SetSubscriptionAsCurrent(null, null));
920+
Assert.Throws<ArgumentException>(() => client.SetSubscriptionAsCurrent(null, null));
921921
}
922922

923923
[Fact]
@@ -1076,6 +1076,73 @@ public void ImportPublishSettingsUsesPassedInEnvironment()
10761076
Assert.Equal(7, client.Profile.Subscriptions.Count);
10771077
}
10781078

1079+
[Fact]
1080+
public void SelectAzureSubscriptionByIdWorks()
1081+
{
1082+
MockDataStore dataStore = new MockDataStore();
1083+
ProfileClient.DataStore = dataStore;
1084+
ProfileClient client = new ProfileClient();
1085+
1086+
var tempSubscriptions = new List<AzureSubscription>
1087+
{
1088+
new AzureSubscription
1089+
{
1090+
Id = new Guid("11111111-1383-4740-8A69-748C5B63ADBA"),
1091+
Name = "Same Name Subscription",
1092+
Environment = azureEnvironment.Name,
1093+
Account = azureAccount.Id,
1094+
Properties = new Dictionary<AzureSubscription.Property, string>
1095+
{
1096+
{ AzureSubscription.Property.Default, "True" }
1097+
}
1098+
},
1099+
1100+
new AzureSubscription
1101+
{
1102+
Id = new Guid("22222222-1383-4740-8A69-748C5B63ADBA"),
1103+
Name = "Same Name Subscription",
1104+
Environment = azureEnvironment.Name,
1105+
Account = azureAccount.Id,
1106+
Properties = new Dictionary<AzureSubscription.Property, string>()
1107+
},
1108+
1109+
new AzureSubscription
1110+
{
1111+
Id = new Guid("33333333-1383-4740-8A69-748C5B63ADBA"),
1112+
Name = "Same Name Subscription",
1113+
Environment = azureEnvironment.Name,
1114+
Account = azureAccount.Id,
1115+
Properties = new Dictionary<AzureSubscription.Property, string>()
1116+
}
1117+
};
1118+
1119+
client.Profile.Accounts[azureAccount.Id] = azureAccount;
1120+
client.AddOrSetEnvironment(azureEnvironment);
1121+
1122+
foreach (var s in tempSubscriptions)
1123+
{
1124+
client.AddOrSetSubscription(s);
1125+
}
1126+
1127+
client.SetSubscriptionAsCurrent(tempSubscriptions[0].Name, tempSubscriptions[0].Account);
1128+
client.Profile.Save();
1129+
1130+
Assert.Equal(tempSubscriptions[0].Id, AzureSession.CurrentContext.Subscription.Id);
1131+
1132+
var cmdlt = new SelectAzureSubscriptionCommand();
1133+
1134+
cmdlt.CommandRuntime = new MockCommandRuntime();
1135+
cmdlt.SubscriptionId = tempSubscriptions[2].Id.ToString();
1136+
cmdlt.SetParameterSet("SelectSubscriptionByIdParameterSet");
1137+
1138+
// Act
1139+
cmdlt.InvokeBeginProcessing();
1140+
cmdlt.ExecuteCmdlet();
1141+
cmdlt.InvokeEndProcessing();
1142+
1143+
Assert.Equal(tempSubscriptions[2].Id, AzureSession.CurrentContext.Subscription.Id);
1144+
}
1145+
10791146
[Fact]
10801147
public void ImportPublishSettingsAddsSecondCertificate()
10811148
{

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ public void ClearAzureProfileClearsTokenCache()
149149
Assert.Equal(0, tokenCache.ReadItems().Count());
150150
}
151151

152+
[Fact]
153+
public void DeleteCorruptedTokenCache()
154+
{
155+
//setup
156+
string testFileName = @"c:\foobar\TokenCache.dat";
157+
ProfileClient.DataStore.WriteFile(testFileName, new byte[] { 0, 1 });
158+
159+
//Act
160+
ProtectedFileTokenCache tokenCache = new ProtectedFileTokenCache(testFileName);
161+
162+
//Assert
163+
Assert.False(ProfileClient.DataStore.FileExists(testFileName));
164+
}
165+
152166
[Fact]
153167
public void SetAzureSubscriptionAddsSubscriptionWithCertificate()
154168
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<package id="Microsoft.Data.Services.Client" version="5.6.0" targetFramework="net45" />
1111
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.11.10918.1222" targetFramework="net45" />
1212
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net45" />
13-
<package id="Microsoft.WindowsAzure.Common" version="1.4.0" targetFramework="net45" />
14-
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.0" targetFramework="net45" />
13+
<package id="Microsoft.WindowsAzure.Common" version="1.4.1" targetFramework="net45" />
14+
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.1" targetFramework="net45" />
1515
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
1616
<package id="Microsoft.WindowsAzure.Management" version="2.1.0" targetFramework="net45" />
1717
<package id="Microsoft.WindowsAzure.Management.Compute" version="6.0.0" targetFramework="net45" />

src/Common/Commands.Common/Authentication/ProtectedFileTokenCache.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,39 @@ public static ProtectedFileTokenCache Instance
4444
// Initializes the cache against a local file.
4545
// If the file is already present, it loads its content in the ADAL cache
4646
private ProtectedFileTokenCache()
47+
{
48+
Initialize(CacheFileName);
49+
}
50+
51+
private void Initialize(string fileName)
4752
{
4853
AfterAccess = AfterAccessNotification;
4954
BeforeAccess = BeforeAccessNotification;
5055
lock (fileLock)
5156
{
52-
if (ProfileClient.DataStore.FileExists(CacheFileName))
57+
if (ProfileClient.DataStore.FileExists(fileName))
5358
{
54-
var existingData = ProfileClient.DataStore.ReadFileAsBytes(CacheFileName);
59+
var existingData = ProfileClient.DataStore.ReadFileAsBytes(fileName);
5560
if (existingData != null)
5661
{
57-
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
62+
try
63+
{
64+
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
65+
}
66+
catch (CryptographicException)
67+
{
68+
ProfileClient.DataStore.DeleteFile(fileName);
69+
}
5870
}
5971
}
6072
}
6173
}
6274

75+
public ProtectedFileTokenCache(string cacheFile)
76+
{
77+
Initialize(cacheFile);
78+
}
79+
6380
// Empties the persistent store.
6481
public override void Clear()
6582
{
@@ -81,7 +98,14 @@ void BeforeAccessNotification(TokenCacheNotificationArgs args)
8198
var existingData = ProfileClient.DataStore.ReadFileAsBytes(CacheFileName);
8299
if (existingData != null)
83100
{
84-
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
101+
try
102+
{
103+
Deserialize(ProtectedData.Unprotect(existingData, null, DataProtectionScope.CurrentUser));
104+
}
105+
catch (CryptographicException)
106+
{
107+
ProfileClient.DataStore.DeleteFile(CacheFileName);
108+
}
85109
}
86110
}
87111
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@
8585
</Reference>
8686
<Reference Include="Microsoft.WindowsAzure.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8787
<SpecificVersion>False</SpecificVersion>
88-
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
88+
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>
8989
</Reference>
9090
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9191
<SpecificVersion>False</SpecificVersion>
92-
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
92+
<HintPath>..\..\packages\Microsoft.WindowsAzure.Common.1.4.1\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
9393
</Reference>
9494
<Reference Include="Microsoft.WindowsAzure.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9595
<SpecificVersion>False</SpecificVersion>

src/Common/Commands.Common/Common/AzurePowerShellClientFactory.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,24 @@ private void RegisterServiceManagementProviders<T>(AzureContext context) where T
119119
}
120120
}
121121

122-
private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
122+
private void UpdateSubscriptionRegisteredProviders(AzureSubscription subscription, List<string> providers)
123123
{
124-
if (providers != null && providers.Count > 0)
125-
{
126-
subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
127-
providers.ToArray());
128-
ProfileClient profileClient = new ProfileClient();
129-
profileClient.AddOrSetSubscription(subscription);
130-
profileClient.Profile.Save();
131-
}
124+
     if (providers != null && providers.Count > 0)
125+
     {
126+
         subscription.SetOrAppendProperty(AzureSubscription.Property.RegisteredResourceProviders,
127+
             providers.ToArray());
128+
         try
129+
         {
130+
             ProfileClient profileClient = new ProfileClient();
131+
             profileClient.AddOrSetSubscription(subscription);
132+
             profileClient.Profile.Save();
133+
         }
134+
         catch (KeyNotFoundException)
135+
         {
136+
             // if using a subscription data file, do not write registration to disk
137+
             // long term solution is using -Profile parameter
138+
         }
139+
     }
132140
}
133141
}
134142
}

0 commit comments

Comments
 (0)