<commit_before>'use strict';

var async = require('async');

var common = require('./lib/common');
var Broker = require('./lib/broker');
var config = require('./config/meta-service-broker');
var azurestorageblob = require('./lib/services/azurestorageblob');
var azurerediscache = require('./lib/services/azurerediscache');
var azuredocdb = require('./lib/services/azuredocdb');

var broker = new Broker(config);

broker.log.info(
  'Validating and getting Azure credentials and subscript ID from environment variables...'
);
common.validateEnvironmentVariables();

var addListeners = function(serviceId, serviceModule) {
  broker.on('provision-' + serviceId, serviceModule.provision);
  broker.on('poll-' + serviceId, serviceModule.poll);
  broker.on('deprovision-' + serviceId, serviceModule.deprovision);
  broker.on('bind-' + serviceId, serviceModule.bind);
  broker.on('unbind-' + serviceId, serviceModule.unbind);
};

broker.log.info(
  'Starting to collect the service offering and plans of each service module...'
);

var params = {};
params.azure = common.getCredentialsAndSubscriptionId();

async.parallel([
    function(callback) {
      azurerediscache.catalog(broker.log, params, function(err, result) {
        if (err) {
          callback(err);
        } else {
          addListeners(result.id, azurerediscache);
          callback(null, result);
        }
      });
    },
    function(callback) {
      azuredocdb.catalog(broker.log, params, function(err, result) {
        if (err) {
          callback(err);
        } else {
          addListeners(result.id, azuredocdb);
          callback(null, result);
        }
      });
    },
    function(callback) {
      azurestorageblob.catalog(broker.log, params,
        function(err, result) {
          if (err) {
            callback(err);
          } else {
            addListeners(result.id, azurestorageblob);
            callback(null, result);
          }
        });
    }
  ],
  function(err, results) {
    if (err) {
      broker.log.error(err);
    } else {
      broker.log.info('All the service offerings and plans are collected.');
      broker.on('catalog', function(next) {
        var reply = {};
        reply.services = results;
        next(null, reply);
      });
    }
  });

broker.start();<commit_msg>Add all service modules in lib/services/ automatically<commit_after>'use strict';

var async = require('async');
var fs = require("fs");
var path = require("path");

var common = require('./lib/common');
var Broker = require('./lib/broker');
var config = require('./config/meta-service-broker');

var broker = new Broker(config);

broker.log.info(
  'Validating and getting Azure credentials and subscript ID from environment variables...'
);
common.validateEnvironmentVariables();

var addListeners = function(serviceId, serviceModule) {
  broker.on('provision-' + serviceId, serviceModule.provision);
  broker.on('poll-' + serviceId, serviceModule.poll);
  broker.on('deprovision-' + serviceId, serviceModule.deprovision);
  broker.on('bind-' + serviceId, serviceModule.bind);
  broker.on('unbind-' + serviceId, serviceModule.unbind);
};

broker.log.info(
  'Starting to collect the service offering and plans of each service module...'
);

var params = {};
params.azure = common.getCredentialsAndSubscriptionId();

var servicesPath = "./lib/services"
var services = [];

fs.readdir(servicesPath, function (err, files) {
    if (err) {
      throw err;
    }

    files.map(function (file) {
      return path.join(servicesPath, file);
    }).filter(function (file) {
      return fs.statSync(file).isDirectory();
    }).forEach(function (file) {
      var serviceModule = require('./' + file);
      serviceModule.catalog(broker.log, params, function(err, service) {
        if (err) {
          throw err;
        } else {
          addListeners(service.id, serviceModule);
          services.push(service);
        }
      });
    });
});

broker.on('catalog', function(next) {
  var reply = {};
  reply.services = services;
  next(null, reply);
});

broker.start();
{'fraction_non_alphanumeric': 0.14735547355473555, 'fraction_numerical': 0.0, 'mean_word_length': 3.1702564102564104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '269580', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1200, 'n_words': 266}