Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry(Configuration["ApplicationInsights:InstrumentationKey"]);

            services.AddControllers();

            services.AddLogging(configure => configure.AddConsole())
            //.Configure<LoggerFilterOptions>(options => options.MinLevel = LogLevel.Information)
            .AddSingleton <Runtime.Common.Configuration.IConfigurationManager, ApiHostConfigurationManager>()
            .AddTransient <SecretManagement.DataAccess.ISecretMetadataDataAccessProvider>(s =>
            {
                Runtime.Common.Configuration.IConfigurationManager cfg = s.GetRequiredService <Runtime.Common.Configuration.IConfigurationManager>();

                return(new SecretManagement.DataAccess.StorageAccount.SecretMetadataStorageAccountDataAccessProvider(
                           cfg.SecretManagementConnectionString, cfg));
            })
            .AddDbContext <Runtime.Tracking.SqlServer.Ef.TrackingDbContext>(options =>     // could turn into anon method, call options.GetRequiedService to get config, for now, we'll just short circuit
                                                                            options.UseSqlServer(Configuration["Tracking:ConnectionString"])
                                                                            )
            .AddScoped <Runtime.Common.Tracking.IProcessingTrackerDataAccessProvider>(s =>
            {
                //todo: construct DataAccessProvider here
                //Runtime.Common.Configuration.IConfigurationManager cfg = s.GetRequiredService<Runtime.Common.Configuration.IConfigurationManager>();

                return(new Runtime.Tracking.SqlServer.SqlServerProcessingTrackerDataAccessProvider(s.GetRequiredService <Runtime.Tracking.SqlServer.Ef.TrackingDbContext>()));
                //return new Runtime.Common.Tracking.ConsoleProcessingTrackerDataAccessProvider();
            })
            .AddScoped <Runtime.Common.Tracking.IProcessingTracker, Runtime.Common.Tracking.ProcessingTracker>()
            .AddScoped <Runtime.Host>()
            .AddHostedService <BgWorker.ProcessingHostBackgroundService>();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string appInsightsKey = "";

            var builder = new HostBuilder()
                          .ConfigureAppConfiguration((context, config) =>
            {
                var builtConfig = config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                  .AddEnvironmentVariables()
                                  .AddCommandLine(args)
                                  .Build();

                appInsightsKey = builtConfig["ApplicationInsights:InstrumentationKey"];

                ManagedIdentityKeyVaultConfig cfg = new ManagedIdentityKeyVaultConfig(builtConfig["KVConfig:KeyVaultName"]);


                ConfigurationOptions options = new ConfigurationOptions();
                options.DefaultConfig        = cfg;

                config.AddKeyVaultProxyConfigurationProvider(builtConfig, options);

                //context.Configuration = config.Build();
            }).ConfigureServices((context, services) =>
            {
                //todo: read from config
                services.AddLogging(configure => configure.AddConsole().AddApplicationInsights(appInsightsKey))
                //.Configure<LoggerFilterOptions>(options => options.MinLevel = LogLevel.Information)
                .AddSingleton <IConfiguration>(context.Configuration)
                .AddSingleton <Runtime.Common.Configuration.IConfigurationManager, HostConfigurationManager>()
                .AddTransient <SecretManagement.DataAccess.ISecretMetadataDataAccessProvider>(s =>
                {
                    Runtime.Common.Configuration.IConfigurationManager cfg = s.GetRequiredService <Runtime.Common.Configuration.IConfigurationManager>();

                    return(new SecretManagement.DataAccess.StorageAccount.SecretMetadataStorageAccountDataAccessProvider(
                               cfg.SecretManagementConnectionString, cfg));
                })
                //.AddApplicationInsightsTelemetryWorkerService("")
                .AddTransient <Runtime.Common.Tracking.IProcessingTrackerDataAccessProvider>(s =>
                {
                    //todo: construct DataAccessProvider here
                    Runtime.Common.Configuration.IConfigurationManager cfg = s.GetRequiredService <Runtime.Common.Configuration.IConfigurationManager>();

                    return(null);
                })
                .AddSingleton <Runtime.Common.Tracking.IProcessingTracker, Runtime.Common.Tracking.ProcessingTracker>()
                .AddTransient <Runtime.Host>();
            });

            var appHost = builder.Build();

            var host = appHost.Services.GetService <Runtime.Host>();

            //host.CreateSampleDataSetAsync(_cts.Token, true, false, false).Wait();

            host.StartAsync(_cts.Token).Wait();
        }
        public SecretMetadataManager(Runtime.Common.Configuration.IConfigurationManager config, ILogger logger)
        {
            //_dataProvider = dataProvider;
            _config = config;
            _logger = logger;

            _dataProvider = _config.ServiceProvider.GetRequiredService <DataAccess.ISecretMetadataDataAccessProvider>();
            //we need a data provider in order to read/write secret data...
        }
Ejemplo n.º 4
0
 public APIMManagementSecretManager(Runtime.Common.Configuration.IConfigurationManager config, ILogger logger) : base(config, logger)
 {
 }
Ejemplo n.º 5
0
 public SecretManager(Runtime.Common.Configuration.IConfigurationManager config)
 {
     Config = config;
 }
        public SecretMetadataStorageAccountDataAccessProvider(Runtime.Common.DataAccess.ConnectionStrings.CQRSStorageAccountConnectionString connectionString, Runtime.Common.Configuration.IConfigurationManager config) : base(connectionString)
        {
            //determine container uri from connectionString...

            _rootContainer = BlobClientHelper.CreateBlobContainerClient(config, connectionString.CommandConnectionString.ContainerName);
        }
Ejemplo n.º 7
0
 //private Runtime.Common.Configuration.IConfigurationManager _config;
 public SecretManagerFactory(Runtime.Common.Configuration.IConfigurationManager config, DataAccess.ISecretMetadataDataAccessProvider dataProvider, ILogger logger)
 {
     _config       = config;
     _dataProvider = dataProvider;
     _logger       = logger;
 }
 public StorageAccountSecretManager(Runtime.Common.Configuration.IConfigurationManager config, ILogger logger) : base(config, logger)
 {
 }
Ejemplo n.º 9
0
        public static Azure.Storage.Blobs.BlobContainerClient CreateBlobContainerClient(Uri containerUri, Runtime.Common.Configuration.IConfigurationManager config)
        {
            //todo: refactor to enable various crednetials...

            string cacheKey = containerUri.ToString().ToLower();

            if (_clientCache.ContainsKey(cacheKey))
            {
                return(_clientCache[cacheKey]);
            }

            return(EnsureClientCache(cacheKey, new Azure.Storage.Blobs.BlobContainerClient(containerUri, new DefaultAzureCredential())));
        }
Ejemplo n.º 10
0
        public static Azure.Storage.Blobs.BlobContainerClient CreateBlobContainerClient(Runtime.Common.Configuration.IConfigurationManager config, string containerName)
        {
            Runtime.Common.DataAccess.ConnectionStrings.StorageAccountConnectionString sacs = config.SecretManagementConnectionString.CommandConnectionString;

            string cacheKey = $"connection={sacs.ConnectionString.ToLower()};queue={containerName}";

            if (_clientCache.ContainsKey(cacheKey))
            {
                return(_clientCache[cacheKey]);
            }

            Uri uri = GetStorageBlobContainerUri(containerName, sacs);

            switch (sacs.KeyType)
            {
            case Runtime.Common.DataAccess.ConnectionStrings.StorageAccountConnectionString.AccountKeyType.None:
                return(EnsureClientCache(cacheKey, new Azure.Storage.Blobs.BlobContainerClient(uri, new DefaultAzureCredential())));

            case Runtime.Common.DataAccess.ConnectionStrings.StorageAccountConnectionString.AccountKeyType.SAS:
                return(EnsureClientCache(cacheKey, new Azure.Storage.Blobs.BlobContainerClient(uri)));

            case Runtime.Common.DataAccess.ConnectionStrings.StorageAccountConnectionString.AccountKeyType.AccountKey:
                return(EnsureClientCache(cacheKey, new Azure.Storage.Blobs.BlobContainerClient(sacs.ToStorageAccountFormat(), containerName)));
            }

            return(null);
        }
Ejemplo n.º 11
0
 public AzureSecretManager(Runtime.Common.Configuration.IConfigurationManager config, ILogger logger) : base(config)
 {
     Logger = logger;
 }