/// <summary> /// Get subscription /// </summary> /// <param name="environment"></param> /// <returns></returns> private async Task <ISubscription> SelectSubscriptionAsync(string environment) { var credentials = await _creds.GetAzureCredentialsAsync( AzureEnvironmentEx.FromName(environment)); var authenticated = Azure .Configure() .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic) .Authenticate(credentials); var subscriptions = await authenticated.Subscriptions.ListAsync(); var name = _selector.SelectSubscription( subscriptions.Select(s => s.DisplayName)); ISubscription subscription = null; if (name != null) { subscription = subscriptions.First(s => s.DisplayName == name); } if (subscription == null) { subscription = subscriptions.First(s => s.State.AnyOfIgnoreCase("Enabled", "Warned")); } return(subscription); }
/// <summary> /// Environment of subscription /// </summary> public static async Task <AzureEnvironment> GetAzureEnvironmentAsync( this ISubscriptionInfo info) { return(AzureEnvironmentEx.FromName( await info.GetEnvironment())); }