How to use mongodb-client-encryption - 5 common examples

To help you get started, we’ve selected a few mongodb-client-encryption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / node-mongodb-native / test / tools / runner / filters / client_encryption_filter.js View on Github external
initializeFilter(client, context, callback) {
    const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;
    const AWS_SECRET_ACCESS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
    let mongodbClientEncryption;
    try {
      mongodbClientEncryption = require('mongodb-client-encryption').extension(mongodb);
    } catch (e) {
      // Do Nothing
    }

    this.enabled = !!(AWS_ACCESS_KEY_ID && AWS_SECRET_ACCESS_KEY && mongodbClientEncryption);

    // Adds these fields onto the context so that they can be reused by tests
    context.clientSideEncryption = {
      enabled: this.enabled,
      mongodbClientEncryption,
      AWS_ACCESS_KEY_ID,
      AWS_SECRET_ACCESS_KEY
    };

    callback();
  }
github Hanul / UPPERCASE / UPPERCASE-DB / node_modules / mongodb / lib / operations / connect.js View on Github external
}

    // setup for client side encryption
    let AutoEncrypter;
    try {
      require.resolve('mongodb-client-encryption');
    } catch (err) {
      callback(
        new MongoError(
          'Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project'
        )
      );
      return;
    }
    try {
      AutoEncrypter = require('mongodb-client-encryption')(require('../../index')).AutoEncrypter;
    } catch (err) {
      callback(err);
      return;
    }

    const mongoCryptOptions = Object.assign({}, options.autoEncryption);
    topology.s.options.autoEncrypter = new AutoEncrypter(mongoClient, mongoCryptOptions);
    topology.s.options.autoEncrypter.init(err => {
      if (err) return callback(err, null);
      callback(null, topology);
    });
  });
}
github mongodb / node-mongodb-native / lib / operations / connect.js View on Github external
topology.connect(options, (err, newTopology) => {
    if (err) {
      topology.close(true);
      return callback(err);
    }

    assignTopology(mongoClient, newTopology);
    if (options.autoEncryption == null) {
      callback(null, newTopology);
      return;
    }

    // setup for client side encryption
    let AutoEncrypter;
    try {
      AutoEncrypter = require('mongodb-client-encryption').AutoEncrypter;
    } catch (err) {
      callback(
        new MongoError(
          'Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project'
        )
      );

      return;
    }

    const MongoClient = loadClient();
    let connectionString;
    if (options.autoEncryption.extraOptions && options.autoEncryption.extraOptions.mongocryptURI) {
      connectionString = options.autoEncryption.extraOptions.mongocryptURI;
    } else if (os.platform() === 'win32') {
      connectionString = 'mongodb://localhost:27020/?serverSelectionTimeoutMS=1000';
github mongodb / node-mongodb-native / lib / operations / connect.js View on Github external
} catch (err) {
      callback(
        new MongoError(
          'Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project'
        )
      );
      return;
    }
    try {
      let mongodbClientEncryption = require('mongodb-client-encryption');
      if (typeof mongodbClientEncryption.extension !== 'function') {
        throw new MongoError(
          'loaded version of `mongodb-client-encryption` does not have property `extension`. Please make sure you are loading the correct version of `mongodb-client-encryption`'
        );
      }
      AutoEncrypter = mongodbClientEncryption.extension(require('../../index')).AutoEncrypter;
    } catch (err) {
      callback(err);
      return;
    }

    const mongoCryptOptions = Object.assign({}, options.autoEncryption);
    topology.s.options.autoEncrypter = new AutoEncrypter(mongoClient, mongoCryptOptions);
    topology.s.options.autoEncrypter.init(err => {
      if (err) return callback(err, null);
      callback(null, topology);
    });
  });
}
github qiuwenwu / mm_node / node_modules / mongodb / lib / operations / connect.js View on Github external
} catch (err) {
      callback(
        new MongoError(
          'Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project'
        )
      );
      return;
    }
    try {
      let mongodbClientEncryption = require('mongodb-client-encryption');
      if (typeof mongodbClientEncryption.extension !== 'function') {
        throw new MongoError(
          'loaded version of `mongodb-client-encryption` does not have property `extension`. Please make sure you are loading the correct version of `mongodb-client-encryption`'
        );
      }
      AutoEncrypter = mongodbClientEncryption.extension(require('../../index')).AutoEncrypter;
    } catch (err) {
      callback(err);
      return;
    }

    const mongoCryptOptions = Object.assign({}, options.autoEncryption);
    topology.s.options.autoEncrypter = new AutoEncrypter(mongoClient, mongoCryptOptions);
    topology.s.options.autoEncrypter.init(err => {
      if (err) return callback(err, null);
      callback(null, topology);
    });
  });
}

mongodb-client-encryption

Official client encryption module for the MongoDB Node.js driver

Apache-2.0
Latest version published 8 months ago

Package Health Score

77 / 100
Full package analysis

Similar packages