diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-02-04 16:32:43 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-02-04 16:32:43 +0200 |
| commit | 5bf3a7b36b3ccc7942f4e8e3fa227a38c04a8451 (patch) | |
| tree | 03019be5bddc677ddb440fa00affc9b7c24aa1ce /Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs | |
| parent | c6a0f97efd7fc804e761086db3179443d1414df7 (diff) | |
| download | Tango-5bf3a7b36b3ccc7942f4e8e3fa227a38c04a8451.tar.gz Tango-5bf3a7b36b3ccc7942f4e8e3fa227a38c04a8451.zip | |
Working on azure utils.
Diffstat (limited to 'Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs')
| -rw-r--r-- | Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs new file mode 100644 index 000000000..4e37be13f --- /dev/null +++ b/Software/Visual_Studio/Azure/Tango.AzureUtils/AzureUtilsAuthenticationFactory.cs @@ -0,0 +1,37 @@ +using Microsoft.Azure.Management.Fluent; +using Microsoft.Azure.Management.ResourceManager.Fluent; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.AzureUtils +{ + public class AzureUtilsAuthenticationFactory + { + private static IAzure _azure; + + public static Task<IAzure> AuthenticateOrGetAsync(AzureUtilsCredentials creds) + { + if (_azure == null) + { + return Task.Factory.StartNew<IAzure>(() => + { + var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal( + creds.ClientID, + creds.ClientSecret, + creds.TenantID, + AzureEnvironment.AzureGlobalCloud); + + _azure = Azure.Authenticate(credentials).WithSubscription(creds.SubscriptionID); + return _azure; + }); + } + else + { + return Task.FromResult(_azure); + } + } + } +} |
