Skip to content

Refactor Microsoft.Azure.Common.Extensions project #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions src/AzurePowershell.sln
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.StreamAnalytics",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commands.StreamAnalytics.Test", "ResourceManager\StreamAnalytics\Commands.StreamAnalytics.Test\Commands.StreamAnalytics.Test.csproj", "{7E6683BE-ECFF-4709-89EB-1325E9E70512}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Extensions", "Common\Azure.Common.Extensions\Common.Extensions.csproj", "{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -361,6 +363,10 @@ Global
{7E6683BE-ECFF-4709-89EB-1325E9E70512}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E6683BE-ECFF-4709-89EB-1325E9E70512}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E6683BE-ECFF-4709-89EB-1325E9E70512}.Release|Any CPU.Build.0 = Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B95C489C-8CB7-4DCF-8D5F-B9AEBDBBAF89}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

using System;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// Base class representing an exception that occurs when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
public class AccessTokenCredential : SubscriptionCloudCredentials
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using System;
using System.Linq;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// Class storing the configuration information needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Extensions.Models;
using Microsoft.Azure.Common.Extensions.Properties;
using System;
using System.Security;
using System.Windows.Forms;
using Microsoft.WindowsAzure.Commands.Common.Models;
using Microsoft.WindowsAzure.Commands.Common.Properties;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// A token provider that uses ADAL to retrieve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// An implementation of <see cref="IWin32Window"/> that gives the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// Class wrapping PInvoke signatures for Windows Credential store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

using System;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
public interface IAccessToken
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Extensions.Models;
using System.Security;
using Microsoft.WindowsAzure.Commands.Common.Models;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// This interface represents objects that can be used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
public enum LoginType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.IO;
using System.Security.Cryptography;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.WindowsAzure.Commands.Common;

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

private static readonly object fileLock = new object();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
using Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;

namespace Microsoft.WindowsAzure.Commands.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// Helper class to store service principal keys and retrieve them
Expand All @@ -27,7 +26,7 @@ namespace Microsoft.WindowsAzure.Commands.Common.Authentication
public static class ServicePrincipalKeyStore
{
private const string keyStoreUserName = "PowerShellServicePrincipalKey";
private const string targetNamePrefix = "AzurePowershell:target=";
private const string targetNamePrefix = "AzureSession:target=";

public static void SaveKey(string appId, string tenantId, SecureString serviceKey)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Extensions.Models;
using Microsoft.Azure.Common.Extensions.Properties;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.Collections.Generic;
using System.Security;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.WindowsAzure.Commands.Common.Authentication;
using Microsoft.WindowsAzure.Commands.Common.Models;
using Microsoft.WindowsAzure.Commands.Common.Properties;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
internal class ServicePrincipalTokenProvider : ITokenProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
public enum ShowDialog
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Extensions.Models;
using Microsoft.Azure.Common.Extensions.Properties;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Windows.Forms;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.WindowsAzure.Commands.Common.Models;
using Microsoft.WindowsAzure.Commands.Common.Properties;

namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
namespace Microsoft.Azure.Common.Extensions.Authentication
{
/// <summary>
/// A token provider that uses ADAL to retrieve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,32 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Common.Extensions.Factories;
using Microsoft.Azure.Common.Extensions.Models;
using Microsoft.Azure.Common.Extensions.Properties;
using System;
using System.Collections.Generic;
using Microsoft.WindowsAzure.Commands.Common.Common;
using Microsoft.WindowsAzure.Commands.Common.Factories;
using Microsoft.WindowsAzure.Commands.Common.Models;
using Microsoft.WindowsAzure.Commands.Common.Properties;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication;

namespace Microsoft.WindowsAzure.Commands.Common
using System.IO;

namespace Microsoft.Azure.Common.Extensions
{
public static class AzureSession
{
static AzureSession()
{
ClientFactory = new AzurePowerShellClientFactory();
ClientFactory = new ClientFactory();
AuthenticationFactory = new AuthenticationFactory();
CurrentContext = new AzureContext();
CurrentContext.Environment = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];
AzureSession.OldProfileFile = "WindowsAzureProfile.xml";
AzureSession.OldProfileFileBackup = "WindowsAzureProfile.xml.bak";
AzureSession.ProfileDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
Resources.AzureDirectoryName); ;
AzureSession.ProfileFile = "AzureProfile.json";
AzureSession.TokenCacheFile = "TokenCache.dat";
}

public static AzureContext CurrentContext {get; private set; }
public static AzureContext CurrentContext { get; private set; }

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

public static IAuthenticationFactory AuthenticationFactory { get; set; }

public static string ProfileDirectory { get; set; }

public static string TokenCacheFile { get; set; }

public static string ProfileFile { get; set; }

public static string OldProfileFileBackup { get; set; }

public static string OldProfileFile { get; set; }
}
}
Loading