// constructors
 public AutoEncryptionLibMongoCryptController(
     IMongoClient client,
     CryptClient cryptClient,
     AutoEncryptionOptions autoEncryptionOptions)
     : base(
         Ensure.IsNotNull(cryptClient, nameof(cryptClient)),
         Ensure.IsNotNull(autoEncryptionOptions, nameof(autoEncryptionOptions)).KeyVaultClient ?? client,
         Ensure.IsNotNull(Ensure.IsNotNull(autoEncryptionOptions, nameof(autoEncryptionOptions)).KeyVaultNamespace, nameof(autoEncryptionOptions.KeyVaultNamespace)))
 {
     _client             = Ensure.IsNotNull(client, nameof(client)); // _client might not be fully constructed at this point, don't call any instance methods on it yet
     _mongocryptdFactory = new MongocryptdFactory(autoEncryptionOptions.ExtraOptions);
     _mongocryptdClient  = _mongocryptdFactory.CreateMongocryptdClient();
 }
Пример #2
0
 // constructors
 private AutoEncryptionLibMongoCryptController(
     IMongoClient internalClient,
     IMongoClient keyVaultClient,
     IMongoClient metadataClient,
     CryptClient cryptClient,
     AutoEncryptionOptions autoEncryptionOptions)
     : base(
         Ensure.IsNotNull(cryptClient, nameof(cryptClient)),
         Ensure.IsNotNull(keyVaultClient, nameof(keyVaultClient)),
         Ensure.IsNotNull(Ensure.IsNotNull(autoEncryptionOptions, nameof(autoEncryptionOptions)).KeyVaultNamespace, nameof(autoEncryptionOptions.KeyVaultNamespace)))
 {
     _internalClient     = internalClient; // can be null
     _metadataClient     = metadataClient; // can be null
     _mongocryptdFactory = new MongocryptdFactory(autoEncryptionOptions.ExtraOptions);
     _mongocryptdClient  = _mongocryptdFactory.CreateMongocryptdClient();
 }
Пример #3
0
        public static AutoEncryptionLibMongoCryptController Create(IMongoClient client, CryptClient cryptClient, AutoEncryptionOptions autoEncryptionOptions)
        {
            var lazyInternalClient = new Lazy <IMongoClient>(() => CreateInternalClient());
            var keyVaultClient     = autoEncryptionOptions.KeyVaultClient ?? lazyInternalClient.Value;
            var metadataClient     = autoEncryptionOptions.BypassAutoEncryption ? null : lazyInternalClient.Value;
            var internalClient     = lazyInternalClient.IsValueCreated ? lazyInternalClient.Value : null;

            return(new AutoEncryptionLibMongoCryptController(
                       internalClient,
                       keyVaultClient,
                       metadataClient,
                       cryptClient,
                       autoEncryptionOptions));

            IMongoClient CreateInternalClient()
            {
                var internalClientSettings = client.Settings.Clone();

                internalClientSettings.AutoEncryptionOptions = null;
                internalClientSettings.MinConnectionPoolSize = 0;
                return(new MongoClient(internalClientSettings));
            }
        }