Skip to content

Commit f01ca1b

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents 5e44daa + ef3d20b commit f01ca1b

22 files changed

+784
-82
lines changed

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/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/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
}

src/ServiceManagement/HDInsight/Commands.HDInsight/Cmdlet/GetAzureHDInsightJobOutputCmdlet.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,39 @@ protected override void EndProcessing()
136136
this.command.CurrentSubscription = this.GetCurrentSubscription(this.Subscription, this.Certificate);
137137
this.AssertTaskLogsDirectorySpecified(this.TaskLogsDirectory);
138138

139-
if (this.StandardError.IsPresent)
139+
int numSpecifiedOutputTypes = 0;
140+
string selectedOutputType = "Standard Output";
141+
this.command.OutputType = JobOutputType.StandardOutput;
142+
143+
if (this.StandardOutput.IsPresent)
140144
{
141-
this.command.OutputType = JobOutputType.StandardError;
145+
numSpecifiedOutputTypes++;
142146
}
143-
else if (this.TaskSummary.IsPresent)
147+
148+
if (this.DownloadTaskLogs.IsPresent)
149+
{
150+
this.command.OutputType = JobOutputType.TaskLogs;
151+
selectedOutputType = "Task Logs";
152+
numSpecifiedOutputTypes++;
153+
}
154+
155+
if (this.TaskSummary.IsPresent)
144156
{
145157
this.command.OutputType = JobOutputType.TaskSummary;
158+
selectedOutputType = "Task Summary";
159+
numSpecifiedOutputTypes++;
146160
}
147-
else if (this.DownloadTaskLogs.IsPresent)
161+
162+
if (this.StandardError.IsPresent)
148163
{
149-
this.command.OutputType = JobOutputType.TaskLogs;
164+
this.command.OutputType = JobOutputType.StandardError;
165+
selectedOutputType = "Standard Error";
166+
numSpecifiedOutputTypes++;
150167
}
151-
else
168+
169+
if (numSpecifiedOutputTypes > 1)
152170
{
153-
this.command.OutputType = JobOutputType.StandardOutput;
171+
this.WriteWarning(String.Format("This cmdlet supports specifying only one job output type. Only {0} will be returned", selectedOutputType));
154172
}
155173

156174
try

src/ServiceManagement/Services/Commands.Utilities/Commands.Utilities.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
</Reference>
120120
<Reference Include="Microsoft.WindowsAzure.Management.Scheduler, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
121121
<SpecificVersion>False</SpecificVersion>
122-
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Scheduler.3.0.2\lib\net40\Microsoft.WindowsAzure.Management.Scheduler.dll</HintPath>
122+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Scheduler.4.1.0\lib\net40\Microsoft.WindowsAzure.Management.Scheduler.dll</HintPath>
123123
</Reference>
124124
<Reference Include="Microsoft.WindowsAzure.Management.ServiceBus">
125125
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.ServiceBus.0.15.0-preview\lib\net40\Microsoft.WindowsAzure.Management.ServiceBus.dll</HintPath>
@@ -246,6 +246,9 @@
246246
<Compile Include="Scheduler\Common\Constants.cs" />
247247
<Compile Include="Scheduler\Common\ExtensionMethods.cs" />
248248
<Compile Include="Scheduler\Common\SchedulerUtils.cs" />
249+
<Compile Include="Scheduler\Model\PSAADOAuthenticationJobDetail.cs" />
250+
<Compile Include="Scheduler\Model\PSBasicAuthenticationJobDetail.cs" />
251+
<Compile Include="Scheduler\Model\PSClientCertAuthenticationJobDetail.cs" />
249252
<Compile Include="Scheduler\Model\PSCreateJobCollectionParams.cs" />
250253
<Compile Include="Scheduler\Model\PSCreateJobParams.cs" />
251254
<Compile Include="Scheduler\Model\PSHttpJobDetail.cs" />

0 commit comments

Comments
 (0)