blob: 53a725047e4a0924b9dcef213ca1affd029fafcc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
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;
private static AzureUtilsCredentials credentials = new AzureUtilsCredentials()
{
ClientID = "be33437c-5052-449f-ab9d-a88d008eae24",
ClientSecret = "bf67fb6f-4d06-4893-988c-6b347aff23d6",
TenantID = "2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4",
SubscriptionID = "10c8aa60-3b15-4e0d-b412-6aeef90e5e91"
};
public static Task<IAzure> AuthenticateOrGetAsync()
{
if (_azure == null)
{
return Task.Factory.StartNew<IAzure>(() =>
{
var creds = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
credentials.ClientID,
credentials.ClientSecret,
credentials.TenantID,
AzureEnvironment.AzureGlobalCloud);
_azure = Azure.Authenticate(creds).WithSubscription(credentials.SubscriptionID);
return _azure;
});
}
else
{
return Task.FromResult(_azure);
}
}
public static AzureUtilsCredentials GetCredentials()
{
return credentials;
}
}
}
|