public IServiceBusNamespace CreateClient(HealthCheckOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var azureClient = AzureClient.Configure()
                              .WithLogLevel(options)
                              .WithUserAgent(options)
                              .Authenticate(options.ServiceCredentials)
                              .WithSubscription(options);

            // TODO :: Use Async Overloads
            IServiceBusNamespace sbNamespace;

            if (Guid.TryParse(options.Namespace, out var _))
            {
                sbNamespace = azureClient.ServiceBusNamespaces.GetById(options.Namespace);
            }
            else
            {
                sbNamespace = azureClient.ServiceBusNamespaces.List().FirstOrDefault(x => x.Name.Equals(options.Namespace, StringComparison.OrdinalIgnoreCase));
            };

            if (sbNamespace == null)
            {
                throw new Exception($"Unable to locate service by namespace: '{options.Namespace}'");
            }

            return(sbNamespace);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets an authenticated Azure Client instance
        /// </summary>
        /// <returns>An authenticated Azure Client instance</returns>
        private static async Task <FluentAzure.IAuthenticated> GetAzureManagementClientAsync()
        {
            var accessToken = await GetAzureAccessTokenAsync();

            var azureCredentials = new AzureCredentials(new TokenCredentials(accessToken), null, null, AzureEnvironment.AzureGlobalCloud);
            var azureClient      = FluentAzure.Authenticate(azureCredentials);

            return(azureClient);
        }