Sha256: 8ed6361d1b2e63493f543efcc6fa156dfae9acfa928652151583a603626f0f22

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

'use strict';

const spawn = require('child_process').spawn;

/**
 * @ignore
 * An internal class that handles spawning a mongocryptd.
 */
class MongocryptdManager {
  /**
   * @ignore
   * Creates a new Mongocryptd Manager
   * @param {AutoEncrypter~AutoEncryptionExtraOptions} [extraOptions] extra options that determine how/when to spawn a mongocryptd
   */
  constructor(extraOptions) {
    extraOptions = extraOptions || {};

    this.uri =
      typeof extraOptions.mongocryptdURI === 'string' && extraOptions.mongocryptdURI.length > 0
        ? extraOptions.mongocryptdURI
        : MongocryptdManager.DEFAULT_MONGOCRYPTD_URI;

    this.bypassSpawn = !!extraOptions.mongocryptdBypassSpawn;

    this.spawnPath = extraOptions.mongocryptdSpawnPath || '';
    this.spawnArgs = [];
    if (Array.isArray(extraOptions.mongocryptdSpawnArgs)) {
      this.spawnArgs = this.spawnArgs.concat(extraOptions.mongocryptdSpawnArgs);
    }
    if (
      this.spawnArgs
        .filter(arg => typeof arg === 'string')
        .every(arg => arg.indexOf('--idleShutdownTimeoutSecs') < 0)
    ) {
      this.spawnArgs.push('--idleShutdownTimeoutSecs', 60);
    }
  }

  /**
   * @ignore
   * Will check to see if a mongocryptd is up. If it is not up, it will attempt
   * to spawn a mongocryptd in a detached process, and then wait for it to be up.
   * @param {Function} callback Invoked when we think a mongocryptd is up
   */
  spawn(callback) {
    const cmdName = this.spawnPath || 'mongocryptd';

    // Spawned with stdio: ignore and detatched:true
    // to ensure child can outlive parent.
    this._child = spawn(cmdName, this.spawnArgs, {
      stdio: 'ignore',
      detached: true
    });

    this._child.on('error', () => {});

    // unref child to remove handle from event loop
    this._child.unref();

    process.nextTick(callback);
  }
}

MongocryptdManager.DEFAULT_MONGOCRYPTD_URI = 'mongodb://localhost:27020';

module.exports = { MongocryptdManager };

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
libmongocrypt-helper-1.8.0.0.1001 ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js
libmongocrypt-helper-1.7.4.0.1002 ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js
libmongocrypt-helper-1.7.4.0.1001 ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js
libmongocrypt-helper-1.7.4.0.1000 ext/libmongocrypt/libmongocrypt/bindings/node/lib/mongocryptdManager.js