static SingletonAzureComponentFactory()
        {
            var services = new ServiceCollection();

            services.AddAzureClientsCore();
            Instance = services.BuildServiceProvider().GetRequiredService <AzureComponentFactory>();
        }
 public ServiceManagerStore(IConfiguration configuration, ILoggerFactory loggerFactory, AzureComponentFactory azureComponentFactory, IEndpointRouter router = null)
 {
     this.loggerFactory     = loggerFactory;
     _azureComponentFactory = azureComponentFactory;
     this.configuration     = configuration;
     this.router            = router;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="StorageClientProvider{TClient, TClientOptions}"/> class that uses the registered Azure services.
        /// </summary>
        /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/>.</param>
        /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/>.</param>
        public StorageClientProvider(AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder)
        {
            _componentFactory = componentFactory;
            _logForwarder     = logForwarder;

            _logForwarder.Start();
        }
Beispiel #4
0
 public QueueServiceClientProvider(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     AzureEventSourceLogForwarder logForwarder,
     IOptions <QueuesOptions> queueOptions)
     : base(configuration, componentFactory, logForwarder)
 {
     _queuesOptions = queueOptions?.Value;
 }
 public ServiceBusClientFactory(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     MessagingProvider messagingProvider)
 {
     _configuration     = configuration;
     _componentFactory  = componentFactory;
     _messagingProvider = messagingProvider;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="StorageClientProvider{TClient, TClientOptions}"/> class that uses the registered Azure services.
        /// </summary>
        /// <param name="configuration">The configuration to use when creating Client-specific objects. <see cref="IConfiguration"/></param>
        /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/></param>
        /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/></param>
        /// <param name="logger">Logger used when there is an error creating a client</param>
        public StorageClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <TClient> logger)
        {
            _configuration    = configuration;
            _componentFactory = componentFactory;
            _logForwarder     = logForwarder;
            _logger           = logger;

            _logForwarder?.Start();
        }
        public OptionsSetup(IConfiguration configuration, AzureComponentFactory azureComponentFactory, string connectionStringKey)
        {
            if (string.IsNullOrWhiteSpace(connectionStringKey))
            {
                throw new ArgumentException($"'{nameof(connectionStringKey)}' cannot be null or whitespace", nameof(connectionStringKey));
            }

            _configuration         = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _azureComponentFactory = azureComponentFactory;
            _connectionStringKey   = connectionStringKey;
        }
Beispiel #8
0
 public ServiceBusClientFactory(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     MessagingProvider messagingProvider,
     AzureEventSourceLogForwarder logForwarder)
 {
     _configuration     = configuration;
     _componentFactory  = componentFactory;
     _messagingProvider = messagingProvider;
     logForwarder.Start();
 }
 public ServiceBusClientFactory(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     MessagingProvider messagingProvider,
     AzureEventSourceLogForwarder logForwarder,
     IOptions <ServiceBusOptions> options)
 {
     _configuration     = configuration;
     _componentFactory  = componentFactory;
     _messagingProvider = messagingProvider;
     _options           = options?.Value ?? throw new ArgumentNullException(nameof(options));
     logForwarder.Start();
 }
Beispiel #10
0
        public void UsesDefaultCredentialWhenNoneExists()
        {
            var configuration = GetConfiguration();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.UseCredential(new EnvironmentCredential()));

            ServiceProvider       provider   = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory    = provider.GetService <AzureComponentFactory>();
            TokenCredential       credential = factory.CreateTokenCredential(configuration);

            Assert.IsInstanceOf <EnvironmentCredential>(credential);
        }
Beispiel #11
0
        public void GlobalOptionsAppliedToAzureComponentFactoryCreateClientOptions()
        {
            var configuration = GetConfiguration();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClients(builder => builder.ConfigureDefaults(clientOptions => clientOptions.Diagnostics.ApplicationId = "AppId"));

            ServiceProvider       provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory  = provider.GetService <AzureComponentFactory>();
            TestClientOptions     options  = (TestClientOptions)factory.CreateClientOptions(typeof(TestClientOptions), configuration["TestClient"], null);

            Assert.AreEqual("AppId", options.Diagnostics.ApplicationId);
        }
 public QueueServiceClientProvider(
     IConfiguration configuration,
     AzureComponentFactory componentFactory,
     AzureEventSourceLogForwarder logForwarder,
     IOptions <QueuesOptions> queueOptions,
     ILoggerFactory loggerFactory,
     IQueueProcessorFactory queueProcessorFactory,
     SharedQueueWatcher messageEnqueuedWatcher)
     : base(configuration, componentFactory, logForwarder)
 {
     _queuesOptions          = queueOptions?.Value;
     _loggerFactory          = loggerFactory;
     _queueProcessorFactory  = queueProcessorFactory;
     _messageEnqueuedWatcher = messageEnqueuedWatcher;
 }
Beispiel #13
0
        public void CanCreateClientWithoutRegistrationUsingConnectionString()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient", "http://localhost/"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClientsCore();

            ServiceProvider       provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory  = provider.GetService <AzureComponentFactory>();
            TestClient            client   = (TestClient)factory.CreateClient(typeof(TestClient), configuration.GetSection("TestClient"), null, new TestClientOptions());

            Assert.AreEqual("http://localhost/", client.ConnectionString);
        }
Beispiel #14
0
        public void CanReadClientOptionsFromConfiguration()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:Property", "client option value"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClientsCore();

            ServiceProvider       provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory  = provider.GetService <AzureComponentFactory>();
            TestClientOptions     options  = (TestClientOptions)factory.CreateClientOptions(typeof(TestClientOptions), null, configuration.GetSection("TestClient"));

            Assert.AreEqual("client option value", options.Property);
        }
Beispiel #15
0
        public void CanCreateClientWithoutRegistration()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:uri", "http://localhost/"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClientsCore();

            ServiceProvider           provider = serviceCollection.BuildServiceProvider();
            AzureComponentFactory     factory  = provider.GetService <AzureComponentFactory>();
            TestClientWithCredentials client   = (TestClientWithCredentials)factory.CreateClient(typeof(TestClientWithCredentials), configuration.GetSection("TestClient"), new EnvironmentCredential(), new TestClientOptions());

            Assert.AreEqual("http://localhost/", client.Uri.ToString());
            Assert.IsInstanceOf <EnvironmentCredential>(client.Credential);
        }
        public OptionsSetup(IConfiguration configuration, ILoggerFactory loggerFactory, AzureComponentFactory azureComponentFactory, string connectionStringKey)
        {
            if (loggerFactory is null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (string.IsNullOrWhiteSpace(connectionStringKey))
            {
                throw new ArgumentException($"'{nameof(connectionStringKey)}' cannot be null or whitespace", nameof(connectionStringKey));
            }

            this.configuration       = configuration ?? throw new ArgumentNullException(nameof(configuration));
            _azureComponentFactory   = azureComponentFactory;
            this.connectionStringKey = connectionStringKey;
            logger = loggerFactory.CreateLogger <OptionsSetup>();
        }
Beispiel #17
0
        public void CanCreateCredential()
        {
            var configuration = GetConfiguration(
                new KeyValuePair <string, string>("TestClient:clientId", "ConfigurationClientId"),
                new KeyValuePair <string, string>("TestClient:clientSecret", "ConfigurationClientSecret"),
                new KeyValuePair <string, string>("TestClient:tenantId", "ConfigurationTenantId"));

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddAzureClientsCore();

            ServiceProvider       provider   = serviceCollection.BuildServiceProvider();
            AzureComponentFactory factory    = provider.GetService <AzureComponentFactory>();
            TokenCredential       credential = factory.CreateTokenCredential(configuration.GetSection("TestClient"));

            Assert.IsInstanceOf <ClientSecretCredential>(credential);
            var clientSecretCredential = (ClientSecretCredential)credential;

            Assert.AreEqual("ConfigurationClientId", clientSecretCredential.ClientId);
            Assert.AreEqual("ConfigurationClientSecret", clientSecretCredential.ClientSecret);
            Assert.AreEqual("ConfigurationTenantId", clientSecretCredential.TenantId);
        }
Beispiel #18
0
        internal static EventHubClientFactory CreateFactory(IConfiguration configuration, EventHubOptions options, AzureComponentFactory componentFactory = null)
        {
            componentFactory ??= Mock.Of <AzureComponentFactory>();
            var loggerFactory = new NullLoggerFactory();
            var azureEventSourceLogForwarder = new AzureEventSourceLogForwarder(loggerFactory);

            return(new EventHubClientFactory(
                       configuration,
                       componentFactory,
                       Options.Create(options),
                       new DefaultNameResolver(configuration),
                       azureEventSourceLogForwarder,
                       new CheckpointClientProvider(configuration, componentFactory, azureEventSourceLogForwarder, loggerFactory.CreateLogger <BlobServiceClient>())));
        }
Beispiel #19
0
        public static IEnumerable <ServiceEndpoint> GetEndpoints(this IConfiguration config, AzureComponentFactory azureComponentFactory)
        {
            foreach (var child in config.GetChildren())
            {
                if (child.TryGetEndpointFromIdentity(azureComponentFactory, out var endpoint))
                {
                    yield return(endpoint);

                    continue;
                }

                foreach (var item in child.GetNamedEndpointsFromConnectionString())
                {
                    yield return(item);
                }
            }
        }
Beispiel #20
0
 public InstrumentedTableClientProvider(RecordedTestBase recording, IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <TableServiceClient> logger) : base(configuration, componentFactory, logForwarder, logger)
 {
     _recording = recording;
 }
 /// <summary>
 /// TODO.
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="componentFactory"></param>
 public StorageAccountProvider(IConfiguration configuration, AzureComponentFactory componentFactory)
 {
     _configuration    = configuration;
     _componentFactory = componentFactory;
 }
        public static bool TryGetNamedEndpointFromIdentity(this IConfigurationSection section, AzureComponentFactory azureComponentFactory, out ServiceEndpoint endpoint)
        {
            var text = section["ServiceUri"];

            if (text != null)
            {
                var key        = section.Key;
                var value      = section.GetValue("Type", EndpointType.Primary);
                var credential = azureComponentFactory.CreateTokenCredential(section);
                endpoint = new ServiceEndpoint(new Uri(text), credential, value, key);
                return(true);
            }

            endpoint = null;
            return(false);
        }
Beispiel #23
0
 public AzureClientsExtensionConfigProvider(AzureComponentFactory componentFactory, IConfiguration configuration, INameResolver nameResolver)
 {
     _componentFactory = componentFactory;
     _configuration    = configuration;
     _nameResolver     = nameResolver;
 }
Beispiel #24
0
        public static bool TryGetEndpointFromIdentity(this IConfigurationSection section, AzureComponentFactory azureComponentFactory, out ServiceEndpoint endpoint, bool isNamed = true)
        {
            var text = section[ServiceUriKey];

            if (text != null)
            {
                var key            = section.Key;
                var name           = isNamed ? key : string.Empty;
                var value          = section.GetValue(TypeKey, EndpointType.Primary);
                var credential     = azureComponentFactory.CreateTokenCredential(section);
                var serverEndpoint = section.GetValue <Uri>(ServerEndpointKey);
                var clientEndpoint = section.GetValue <Uri>(ClientEndpointKey);
                endpoint = new ServiceEndpoint(new Uri(text), credential, value, name, serverEndpoint, clientEndpoint);
                return(true);
            }

            endpoint = null;
            return(false);
        }
Beispiel #25
0
 public QueueServiceClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder)
     : base(configuration, componentFactory, logForwarder)
 {
 }
 public BlobServiceClientProvider(IConfiguration configuration, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder, ILogger <BlobServiceClient> logger)
     : base(configuration, componentFactory, logForwarder, logger)
 {
 }
Beispiel #27
0
 public AzureClientValueProvider(Type clientType, AzureComponentFactory componentFactory, IConfigurationSection configuration)
 {
     _clientType       = clientType;
     _componentFactory = componentFactory;
     _configuration    = configuration;
 }
        public HostAzureBlobStorageProvider(IScriptHostManager scriptHostManager, IConfiguration configuration, IOptionsMonitor <JobHostInternalStorageOptions> options, ILogger <HostAzureBlobStorageProvider> logger, AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _storageOptions = options ?? throw new ArgumentNullException(nameof(options));
            _logger         = logger ?? throw new ArgumentNullException(nameof(logger));

            _blobServiceClientProvider = new BlobServiceClientProvider(componentFactory, logForwarder);

            if (FeatureFlags.IsEnabled(ScriptConstants.FeatureFlagDisableMergedWebHostScriptHostConfiguration))
            {
                Configuration = configuration;
            }
            else
            {
                if (scriptHostManager == null)
                {
                    throw new ArgumentNullException(nameof(scriptHostManager));
                }

                Configuration = new ConfigurationBuilder()
                                .Add(new ActiveHostConfigurationSource(scriptHostManager))
                                .AddConfiguration(configuration)
                                .Build();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BlobServiceClientProvider"/> class that uses the registered Azure services to create a BlobServiceClient.
 /// </summary>
 /// <param name="componentFactory">The Azure factory responsible for creating clients. <see cref="AzureComponentFactory"/></param>
 /// <param name="logForwarder">Log forwarder that forwards events to ILogger. <see cref="AzureEventSourceLogForwarder"/></param>
 public BlobServiceClientProvider(AzureComponentFactory componentFactory, AzureEventSourceLogForwarder logForwarder)
     : base(componentFactory, logForwarder)
 {
 }