Пример #1
0
 static Azure.IAuthenticated GetAzure(Creds creds)
 {
     return(Azure.Authenticate(new AzureCredentials(new ServicePrincipalLoginInformation
     {
         ClientId = creds.ClientId,
         ClientSecret = creds.ClientSecret
     }, creds.TenantId, AzureEnvironment.AzureGlobalCloud)));
 }
Пример #2
0
        async static Task <int> ProcessSubscriptionAsync(Creds creds, ISubscription sub)
        {
            try
            {
                var subApi = GetAzure(creds).WithSubscription(sub.SubscriptionId);
                var groups = await subApi.ResourceGroups.ListAsync();

                var all = await Task.WhenAll(groups.Select(g => ProcessResourceGroupAsync(subApi, sub, g)));

                return(all.Sum());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception getting resource groups: " + ex.Message);
                return(0);
            }
        }
Пример #3
0
        async static Task <int> ProcessCredsAsync(Creds creds)
        {
            try
            {
                var azure   = GetAzure(creds);
                var allSubs = await azure.Subscriptions.ListAsync();

                var all = await Task.WhenAll(allSubs.Select(s => ProcessSubscriptionAsync(creds, s)));

                return(all.Sum());
            }
            catch (Exception ex)
            {
                // todo...
                Console.WriteLine("Exception getting subs: " + ex.Message);
                return(0);
            }
        }