public DocDbClient(
            IKeyVaultClient kvClient,
            IOptions <VaultSettings> vaultSettings,
            DocDbSettings dbSettings,
            ILogger <DocDbClient> logger)
        {
            _settings = dbSettings;
            _logger   = logger;

            _logger.LogInformation($"Retrieving auth key '{_settings.AuthKeySecret}' from vault '{vaultSettings.Value.VaultName}'");
            var authKey = kvClient.GetSecretAsync(
                vaultSettings.Value.VaultUrl,
                _settings.AuthKeySecret).GetAwaiter().GetResult();

            Client = new DocumentClient(
                _settings.AccountUri,
                authKey.Value,
                desiredConsistencyLevel: ConsistencyLevel.Session,
                serializerSettings: new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            var database = Client.CreateDatabaseQuery().Where(db => db.Id == _settings.Db).AsEnumerable().First();

            Collection   = Client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == _settings.Collection).AsEnumerable().First();
            _feedOptions = new FeedOptions()
            {
                PopulateQueryMetrics = _settings.CollectMetrics
            };

            _logger.LogInformation($"Connected to doc db '{Collection.SelfLink}'");
        }
Ejemplo n.º 2
0
        public DocDbClient(
            IServiceProvider serviceProvider,
            ILoggerFactory loggerFactory,
            IOptions <DocDbSettings> docDbSettings)
        {
            var configuration = serviceProvider.GetRequiredService <IConfiguration>();

            _settings = docDbSettings.Value ?? configuration.GetConfiguredSettings <DocDbSettings>();
            _logger   = loggerFactory.CreateLogger <DocDbClient>();
            var vaultSettings = configuration.GetConfiguredSettings <VaultSettings>();
            var kvClient      = serviceProvider.GetRequiredService <IKeyVaultClient>();

            _logger.LogInformation(
                $"Retrieving auth key '{_settings.AuthKeySecret}' from vault '{vaultSettings.VaultName}'");
            var authKey = kvClient.GetSecretAsync(
                vaultSettings.VaultUrl,
                _settings.AuthKeySecret).GetAwaiter().GetResult();

            Client = new DocumentClient(
                _settings.AccountUri,
                authKey.Value,
                desiredConsistencyLevel: ConsistencyLevel.Session,
                serializerSettings: new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            var database = Client.CreateDatabaseQuery().Where(db => db.Id == _settings.Db).AsEnumerable().First();

            Collection = Client.CreateDocumentCollectionQuery(database.SelfLink)
                         .Where(c => c.Id == _settings.Collection).AsEnumerable().First();
            _feedOptions = new FeedOptions
            {
                PopulateQueryMetrics      = _settings.CollectMetrics,
                EnableCrossPartitionQuery = true
            };

            _logger.LogInformation($"Connected to doc db '{Collection.SelfLink}'");
        }