public static string GetEndpointUrl(this Microsoft.Azure.Management.ResourceManager.Fluent.AzureEnvironment azureEnvironment, AzureEndpoint azureEndpoint) { if (azureEnvironment is null) { throw new ArgumentNullException(nameof(azureEnvironment)); } return(azureEndpoint switch { AzureEndpoint.ResourceManagerEndpoint => azureEnvironment.ResourceManagerEndpoint, AzureEndpoint.GraphEndpoint => azureEnvironment.GraphEndpoint, _ => throw new NotSupportedException($"The Azure endpoint {azureEndpoint} is not supported.") });
public IAzure CreateAzureClient() { var environment = string.IsNullOrEmpty(AzureEnvironment) || AzureEnvironment == "AzureCloud" ? AzureEnvironmentEnum.AzureGlobalCloud : AzureEnvironmentEnum.FromName(AzureEnvironment) ?? throw new InvalidOperationException($"Unknown environment name {AzureEnvironment}"); var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(ClientId, Password, TenantId, environment ); // to ensure the Azure API uses the appropriate web proxy var client = new HttpClient(new HttpClientHandler { Proxy = WebRequest.DefaultWebProxy }); return(Microsoft.Azure.Management.Fluent.Azure.Configure() .WithHttpClient(client) .Authenticate(credentials) .WithSubscription(SubscriptionNumber)); }