Skip to content

Commit 8357303

Browse files
committed
Merge pull request #59 from ogail/common
Refactor Microsoft.Azure.Common.Extensions project
2 parents 016d848 + 1e28080 commit 8357303

File tree

375 files changed

+7093
-581
lines changed

Some content is hidden

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

375 files changed

+7093
-581
lines changed

src/AzurePowershell.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.StreamAnalytics",
151151
EndProject
152152
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.StreamAnalytics.Test", "ResourceManager\StreamAnalytics\Commands.StreamAnalytics.Test\Commands.StreamAnalytics.Test.csproj", "{7E6683BE-ECFF-4709-89EB-1325E9E70512}"
153153
EndProject
154+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Extensions", "Common\Azure.Common.Extensions\Common.Extensions.csproj", "{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}"
155+
EndProject
154156
Global
155157
GlobalSection(SolutionConfigurationPlatforms) = preSolution
156158
Debug|Any CPU = Debug|Any CPU
@@ -361,6 +363,10 @@ Global
361363
{7E6683BE-ECFF-4709-89EB-1325E9E70512}.Debug|Any CPU.Build.0 = Debug|Any CPU
362364
{7E6683BE-ECFF-4709-89EB-1325E9E70512}.Release|Any CPU.ActiveCfg = Release|Any CPU
363365
{7E6683BE-ECFF-4709-89EB-1325E9E70512}.Release|Any CPU.Build.0 = Release|Any CPU
366+
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
367+
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Debug|Any CPU.Build.0 = Debug|Any CPU
368+
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Release|Any CPU.ActiveCfg = Release|Any CPU
369+
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Release|Any CPU.Build.0 = Release|Any CPU
364370
EndGlobalSection
365371
GlobalSection(SolutionProperties) = preSolution
366372
HideSolutionNode = FALSE

src/Common/Commands.Common/Authentication/AadAuthenticationException.cs renamed to src/Common/Azure.Common.Extensions/Authentication/AadAuthenticationException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using System;
1616

17-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
17+
namespace Microsoft.Azure.Common.Extensions.Authentication
1818
{
1919
/// <summary>
2020
/// Base class representing an exception that occurs when

src/Common/Commands.Common/Authentication/AccessTokenCredential.cs renamed to src/Common/Azure.Common.Extensions/Authentication/AccessTokenCredential.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.WindowsAzure;
1516
using System;
1617
using System.Net.Http;
1718
using System.Net.Http.Headers;
1819
using System.Threading;
1920
using System.Threading.Tasks;
2021

21-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
22+
namespace Microsoft.Azure.Common.Extensions.Authentication
2223
{
2324
public class AccessTokenCredential : SubscriptionCloudCredentials
2425
{

src/Common/Commands.Common/Authentication/AdalConfiguration.cs renamed to src/Common/Azure.Common.Extensions/Authentication/AdalConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using System;
1616
using System.Linq;
1717

18-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
18+
namespace Microsoft.Azure.Common.Extensions.Authentication
1919
{
2020
/// <summary>
2121
/// Class storing the configuration information needed

src/Common/Commands.Common/Authentication/AdalTokenProvider.cs renamed to src/Common/Azure.Common.Extensions/Authentication/AdalTokenProvider.cs

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

15+
using Microsoft.Azure.Common.Extensions.Models;
16+
using Microsoft.Azure.Common.Extensions.Properties;
1517
using System;
1618
using System.Security;
1719
using System.Windows.Forms;
18-
using Microsoft.WindowsAzure.Commands.Common.Models;
19-
using Microsoft.WindowsAzure.Commands.Common.Properties;
2020

21-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
21+
namespace Microsoft.Azure.Common.Extensions.Authentication
2222
{
2323
/// <summary>
2424
/// A token provider that uses ADAL to retrieve

src/Common/Commands.Common/Authentication/ConsoleParentWindow.cs renamed to src/Common/Azure.Common.Extensions/Authentication/ConsoleParentWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Runtime.InteropServices;
1717
using System.Windows.Forms;
1818

19-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
19+
namespace Microsoft.Azure.Common.Extensions.Authentication
2020
{
2121
/// <summary>
2222
/// An implementation of <see cref="IWin32Window"/> that gives the

src/Common/Commands.Common/Authentication/CredStore.cs renamed to src/Common/Azure.Common.Extensions/Authentication/CredStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Runtime.ConstrainedExecution;
1717
using System.Runtime.InteropServices;
1818

19-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
19+
namespace Microsoft.Azure.Common.Extensions.Authentication
2020
{
2121
/// <summary>
2222
/// Class wrapping PInvoke signatures for Windows Credential store

src/Common/Commands.Common/Authentication/IAccessToken.cs renamed to src/Common/Azure.Common.Extensions/Authentication/IAccessToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using System;
1616

17-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
17+
namespace Microsoft.Azure.Common.Extensions.Authentication
1818
{
1919
public interface IAccessToken
2020
{

src/Common/Commands.Common/Authentication/ITokenProvider.cs renamed to src/Common/Azure.Common.Extensions/Authentication/ITokenProvider.cs

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

15+
using Microsoft.Azure.Common.Extensions.Models;
1516
using System.Security;
16-
using Microsoft.WindowsAzure.Commands.Common.Models;
1717

18-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
18+
namespace Microsoft.Azure.Common.Extensions.Authentication
1919
{
2020
/// <summary>
2121
/// This interface represents objects that can be used

src/Common/Commands.Common/Authentication/LoginType.cs renamed to src/Common/Azure.Common.Extensions/Authentication/LoginType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
15+
namespace Microsoft.Azure.Common.Extensions.Authentication
1616
{
1717
public enum LoginType
1818
{

src/Common/Commands.Common/Authentication/ProtectedFileTokenCache.cs renamed to src/Common/Azure.Common.Extensions/Authentication/ProtectedFileTokenCache.cs

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

15+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1516
using System;
1617
using System.IO;
1718
using System.Security.Cryptography;
18-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
19-
using Microsoft.WindowsAzure.Commands.Common;
2019

21-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
20+
namespace Microsoft.Azure.Common.Extensions.Authentication
2221
{
2322
/// <summary>
2423
/// An implementation of the Adal token cache that stores the cache items
2524
/// in the DPAPI-protected file.
2625
/// </summary>
2726
public class ProtectedFileTokenCache : TokenCache
2827
{
29-
private static readonly string CacheFileName = Path.Combine(AzurePowerShell.ProfileDirectory, "TokenCache.dat");
28+
private static readonly string CacheFileName = Path.Combine(AzureSession.ProfileDirectory, AzureSession.TokenCacheFile);
3029

3130
private static readonly object fileLock = new object();
3231

src/Common/Commands.Common/Authentication/ServicePrincipalKeyStore.cs renamed to src/Common/Azure.Common.Extensions/Authentication/ServicePrincipalKeyStore.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
using System;
1616
using System.Runtime.InteropServices;
1717
using System.Security;
18-
using Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication;
1918
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
2019

21-
namespace Microsoft.WindowsAzure.Commands.Common.Authentication
20+
namespace Microsoft.Azure.Common.Extensions.Authentication
2221
{
2322
/// <summary>
2423
/// Helper class to store service principal keys and retrieve them
@@ -27,7 +26,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.Authentication
2726
public static class ServicePrincipalKeyStore
2827
{
2928
private const string keyStoreUserName = "PowerShellServicePrincipalKey";
30-
private const string targetNamePrefix = "AzurePowershell:target=";
29+
private const string targetNamePrefix = "AzureSession:target=";
3130

3231
public static void SaveKey(string appId, string tenantId, SecureString serviceKey)
3332
{

src/Common/Commands.Common/Authentication/ServicePrincipalTokenProvider.cs renamed to src/Common/Azure.Common.Extensions/Authentication/ServicePrincipalTokenProvider.cs

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

15+
using Microsoft.Azure.Common.Extensions.Models;
16+
using Microsoft.Azure.Common.Extensions.Properties;
17+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1518
using System;
1619
using System.Collections.Generic;
1720
using System.Security;
18-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
19-
using Microsoft.WindowsAzure.Commands.Common.Authentication;
20-
using Microsoft.WindowsAzure.Commands.Common.Models;
21-
using Microsoft.WindowsAzure.Commands.Common.Properties;
2221

23-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
22+
namespace Microsoft.Azure.Common.Extensions.Authentication
2423
{
2524
internal class ServicePrincipalTokenProvider : ITokenProvider
2625
{

src/Common/Commands.Common/Authentication/ShowDialog.cs renamed to src/Common/Azure.Common.Extensions/Authentication/ShowDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
15+
namespace Microsoft.Azure.Common.Extensions.Authentication
1616
{
1717
public enum ShowDialog
1818
{

src/Common/Commands.Common/Authentication/UserTokenProvider.cs renamed to src/Common/Azure.Common.Extensions/Authentication/UserTokenProvider.cs

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

15+
using Microsoft.Azure.Common.Extensions.Models;
16+
using Microsoft.Azure.Common.Extensions.Properties;
17+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1518
using System;
1619
using System.Runtime.InteropServices;
1720
using System.Security;
1821
using System.Threading;
1922
using System.Windows.Forms;
20-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
21-
using Microsoft.WindowsAzure.Commands.Common.Models;
22-
using Microsoft.WindowsAzure.Commands.Common.Properties;
2323

24-
namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
24+
namespace Microsoft.Azure.Common.Extensions.Authentication
2525
{
2626
/// <summary>
2727
/// A token provider that uses ADAL to retrieve

src/Common/Commands.Common/AzureSession.cs renamed to src/Common/Azure.Common.Extensions/AzureSession.cs

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

15+
using Microsoft.Azure.Common.Extensions.Factories;
16+
using Microsoft.Azure.Common.Extensions.Models;
17+
using Microsoft.Azure.Common.Extensions.Properties;
1518
using System;
16-
using System.Collections.Generic;
17-
using Microsoft.WindowsAzure.Commands.Common.Common;
18-
using Microsoft.WindowsAzure.Commands.Common.Factories;
19-
using Microsoft.WindowsAzure.Commands.Common.Models;
20-
using Microsoft.WindowsAzure.Commands.Common.Properties;
21-
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22-
using Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication;
23-
24-
namespace Microsoft.WindowsAzure.Commands.Common
19+
using System.IO;
20+
21+
namespace Microsoft.Azure.Common.Extensions
2522
{
2623
public static class AzureSession
2724
{
2825
static AzureSession()
2926
{
30-
ClientFactory = new AzurePowerShellClientFactory();
27+
ClientFactory = new ClientFactory();
3128
AuthenticationFactory = new AuthenticationFactory();
3229
CurrentContext = new AzureContext();
3330
CurrentContext.Environment = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];
31+
AzureSession.OldProfileFile = "WindowsAzureProfile.xml";
32+
AzureSession.OldProfileFileBackup = "WindowsAzureProfile.xml.bak";
33+
AzureSession.ProfileDirectory = Path.Combine(
34+
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
35+
Resources.AzureDirectoryName); ;
36+
AzureSession.ProfileFile = "AzureProfile.json";
37+
AzureSession.TokenCacheFile = "TokenCache.dat";
3438
}
3539

36-
public static AzureContext CurrentContext {get; private set; }
40+
public static AzureContext CurrentContext { get; private set; }
3741

3842
public static void SetCurrentContext(AzureSubscription subscription, AzureEnvironment environment, AzureAccount account)
3943
{
@@ -89,5 +93,15 @@ public static void SetCurrentContext(AzureSubscription subscription, AzureEnviro
8993
public static IClientFactory ClientFactory { get; set; }
9094

9195
public static IAuthenticationFactory AuthenticationFactory { get; set; }
96+
97+
public static string ProfileDirectory { get; set; }
98+
99+
public static string TokenCacheFile { get; set; }
100+
101+
public static string ProfileFile { get; set; }
102+
103+
public static string OldProfileFileBackup { get; set; }
104+
105+
public static string OldProfileFile { get; set; }
92106
}
93107
}

0 commit comments

Comments
 (0)