Example #1
0
  return Promise.try(function () {
    const label = 'dbfilter';
    // The modify callback must return a Promise.
    const objects = util.traverse(json, label, function modify(err, data) {
      // Change the nested object data into a bool query
      if (err) {
        throw err;
      }

      const queryId = data.queryid;
      const queryVariableName = data.queryVariableName;
      const path = data.path;
      const entity = data.entity;
      const negate = data.negate;

      if (queryId === undefined) {
        throw new Error('Missing queryid field in the dbfilter object: ' + data);
      }
      if (queryVariableName === undefined) {
        throw new Error('Missing queryVariableName in the dbfilter object: ' + data);
      }
      if (path === undefined) {
        throw new Error('Missing path field in the dbfilter object: ' + data);
      }

      const options = {
        selectedDocuments: [ entity ]
      };
      if (credentials) {
        options.credentials = credentials;
      }

      return queryEngine.getIdsFromQueries([ { queryId, queryVariableName } ], options)
      .then(function createObject([ query ]) {
        const filter = {};
        const clause = negate ? 'must_not' : 'should';

        if (query.ids.length === 0) {
          // empty bool
          // GH-117: need to put here a filter that will match nothing
          filter[clause] = [
            {
              term: {
                snxrcngu: 'tevfuxnvfpbzcyrgrylpenfl'
              }
            }
          ];
        } else {
          filter[clause] = [
            {
              terms: {
                [ path ]: query.ids
              }
            }
          ];
        }
        return [
          query.queryId,
          query.label,
          { bool: filter }
        ];
      });
    });

    return Promise.map(objects, object => object.value)
    .then(function (data) {
      for (let i = 0; i < data.length; i++) {
        const [ queryId, queryLabel, esFilter ] = data[i];
        const path = objects[i].path;
        const oldBucketLabel = path.pop();
        const newBucketLabel = oldBucketLabel.replace(queryId, `${queryId} - ${queryLabel}`);
        util.replace(json, path, oldBucketLabel, newBucketLabel, esFilter);
      }
      return json;
    });
  });
Example #2
0
    const layerNames = this.serverless.service.getAllLayers();
    artifactFilePaths = artifactFilePaths.concat(_.map(layerNames, (name) => {
      const layerObject = this.serverless.service.getLayer(name);

      if (layerObject.package && layerObject.package.artifact) {
        return layerObject.package.artifact;
      }

      return path.join(this.packagePath, this.provider.naming.getLayerArtifactName(name));
    }));

    return BbPromise.map(artifactFilePaths, (artifactFilePath) => {
      const stats = fs.statSync(artifactFilePath);
      const fileName = path.basename(artifactFilePath);
      this.serverless.cli.log(
          `Uploading service ${fileName} file to S3 (${filesize(stats.size)})...`
      );
      return this.uploadZipFile(artifactFilePath);
    }, { concurrency: NUM_CONCURRENT_UPLOADS }
    );
  },
};

function setServersideEncryptionOptions(putParams, deploymentBucketOptions) {
  const encryptionFields = [
    ['serverSideEncryption', 'ServerSideEncryption'],
    ['sseCustomerAlgorithim', 'SSECustomerAlgorithm'],
    ['sseCustomerKey', 'SSECustomerKey'],
    ['sseCustomerKeyMD5', 'SSECustomerKeyMD5'],
    ['sseKMSKeyId', 'SSEKMSKeyId'],
  ];
Example #3
0
function start() {
  Promise.map(urls, function(url) {
    return getSinglePage(url)
  }, {concurrency: 10});
}
var Promise = require('bluebird');
var fs      = Promise.promisifyAll(require("fs"));
var files   = ['config.json'];

Promise.map(files, function(filename) {
  var path = './config/' + filename;

  return fs.existsAsync(path)
    .then(function(){
      console.log("Creating config file:", filename);
      fs.createReadStream(path + '.example')
        .pipe(fs.createWriteStream(path));
    })
    .error(function(e) {
      console.log("Config file exists:", filename);
    });

}).then(function(){
  console.log('Done.');
  console.log('enter the db credentials then run \'npm start\'');
});
 beforeEach((done) => {
   Promise.map([{ name: 'Lev Yashin' }, { name: 'Valentin Ivanov' }], (attrs) => Player.createWithEigenTeam(attrs))
     .then(done);
 });
        .then(function(files) {
            return Promise.map(files, function(file) {
                var blobName = uploadDirectory + '/' + file;
                var mimeLookup = getMimeType(blobName);
                var contentType = mimeLookup.type;
                var compress = mimeLookup.compress;
                var contentEncoding = compress ? 'gzip' : undefined;
                var etag;

                totalFiles++;

                return readFile(file)
                .then(function(content) {
                    return compress ? gzip(content) : content;
                })
                .then(function(content) {
                    // compute hash and etag
                    var hash = crypto.createHash('md5').update(content).digest('hex');
                    etag = crypto.createHash('md5').update(content).digest('base64');

                    var index = existingBlobs.indexOf(blobName);
                    if (index <= -1) {
                        return content;
                    }

                    // remove files as we find them on disk
                    existingBlobs.splice(index, 1);

                    // get file info
                    return s3.headObjectAsync({
                        Bucket : bucketName,
                        Key : blobName
                    })
                    .then(function(data) {
                        if (data.ETag !== ('"' + hash + '"') ||
                            data.CacheControl !== cacheControl ||
                            data.ContentType !== contentType ||
                            data.ContentEncoding !== contentEncoding) {
                            return content;
                        }

                        // We don't need to upload this file again
                        skipped++;
                        return undefined;
                    })
                    .catch(function(error) {
                        errors.push(error);
                    });
                })
                .then(function(content) {
                    if (!content) {
                        return;
                    }

                    console.log('Uploading ' + blobName + '...');
                    var params = {
                        Bucket : bucketName,
                        Key : blobName,
                        Body : content,
                        ContentMD5 : etag,
                        ContentType : contentType,
                        ContentEncoding : contentEncoding,
                        CacheControl : cacheControl
                    };

                    return s3.putObjectAsync(params).then(function() {
                        uploaded++;
                    })
                    .catch(function(error) {
                        errors.push(error);
                    });
                });
            }, {concurrency : concurrencyLimit});
        })
/**
    @param {Object} flowConfig An object containing functions and their dependencies.
    @returns {Promise} Promise that resolves in an object containing all results.
*/
function props (flowConfig, concurrency) {
    
    // By setting concurrency to n, you restrict PFC.props to only run n functions at the same time
    concurrency = _.isInteger(concurrency) && concurrency > 0 ? concurrency : Infinity;

    // We need to have two different stores here because one of the functions could 
    // return "undefined", which we can not differenciate from an unmet dependency.
    var identifierHasBeenResolvedStore = {};
    var identifierToResultsStore = {};
    
    // Prevent calling a function twice: 
    var identifierToPromiseStore = {};

    // Reducing ['depA', 'depB'] => {depA: resultOfDepA, debB: resultOfDepB}
    var getResultsOfDependencies = function (identifiers) {
        return _.reduce(identifiers, function (results, identifier) {
            results[identifier] = identifierToResultsStore[identifier];
            return results;
        }, {});
    };

    var processTask = function (fnOrArray, identifier) {

        // If we did not get passed an array, make it one
        if (_.isArray(fnOrArray) === false) {
            fnOrArray = [fnOrArray];
        }

        // If dependencies are passed, the function gets passed as the last object in the array
        var fn = _.last(fnOrArray);
        var dependencies = fnOrArray.slice(0, fnOrArray.length - 1);

        // If last item in the array is not a function, we treat it as the result of this process
        // That way you can pass in something like {foo : 'bar'}
        if (_.isFunction(fn) === false) {
            fn = _.constant(fn);
        }

        // Check if all dependencies exist
        var nonExistentDependencies = _.filter(dependencies, function (dependencyIdentifier) {
            return flowConfig[dependencyIdentifier] === undefined; 
        });

        if (nonExistentDependencies.length > 0) {
            return Promise.reject(PFCError(PFC.ERRORS.NON_EXISTENT_DEPENDENCIES, nonExistentDependencies));
        } 

        // Check for cyclic dependencies
        var cycylicDependencies = _.filter(dependencies, function (dependencyIdentifier) {
            var config = flowConfig[dependencyIdentifier];
            return _.isArray(config) && config.indexOf(identifier) !== -1;
        });

        if (cycylicDependencies.length > 0) {
            return Promise.reject(PFCError(PFC.ERRORS.CYCLIC_DEPENDENCIES, cycylicDependencies));
        }

        // Note: _.every also returns true for empty arrays
        var allDependenciesAreResolved = _.every(dependencies, function (dependencyIdentifier) {
            return identifierHasBeenResolvedStore[dependencyIdentifier] === true;
        });

        // If there are unresolved dependencies we have to filter out the unmet dependencies 
        // and resolve them before we can finally call our function
        if (allDependenciesAreResolved === false) {
            return Promise
                .resolve(dependencies)
                .filter(function (dependencyIdentifier) {
                    // Don't compare to false here, as the value might be undefined for unseen identifiers
                    return identifierHasBeenResolvedStore[dependencyIdentifier] !== true;
                })
                // Now we have all unresolved dependencies
                .map(function (dependencyIdentifier) {
                    return processTask(flowConfig[dependencyIdentifier], dependencyIdentifier);
                }, {concurrency: concurrency})
                // Now all dependencies are resolved
                .then(function() {
                    // After our dependencies are resolved, we just call processTask again
                    // This time allDependenciesAreResolved will be true
                    return processTask(fnOrArray, identifier);
                });
        }

        // If all dependencies are resolved, we can call the provided function with the resolved 
        // results of the dependencies
        identifierToPromiseStore[identifier] = 
            identifierToPromiseStore[identifier] || // Prevent calling functions twice by checking for identifierToPromiseStore first
            Promise.try(function () {
                return fn(getResultsOfDependencies(dependencies));
            });

        return identifierToPromiseStore[identifier].then(function (result) {

            // Save result for other functions that have this function as a dependency
            identifierToResultsStore[identifier] = result;
            identifierHasBeenResolvedStore[identifier] = true;

            // Final return
            // It does not matter what we return here, as the last .then callback in the chain
            // will get the results from the identifierToResultsStore store.
            return undefined;
        });

    };

    var identifiers = _.keys(flowConfig);
    return Promise
        .map(identifiers, function (identifier) {
            return processTask(flowConfig[identifier], identifier);
        }, {concurrency: concurrency})
        .then(function () {
            return getResultsOfDependencies(identifiers);
        });
};
 getAllWithBuilds() {
   return Promise.map(
     this.redis.zrevrange(getKey('build'), 0, -1), 
     this.get.bind(this)
   );
 }
Example #9
0
		addExtraPolicies = function () {
			return Promise.map(policyFiles(), function (fileName) {
				var policyName = path.basename(fileName).replace(/[^A-z0-9]/g, '-');
				return addPolicy(policyName, roleMetadata.Role.RoleName, fileName);
			});
		},
 }).then(function () {
     return Promise.map(removeDirs, function (dir) {
         return fileIO.rimraf(dir);
     });
 }).catch(function (e) {
const alist = require('./a.json'),
  { spawn } = require('child_process'),
  Promise = require('bluebird'),
  url = require('url')

Promise.map(alist, function(href){
  return new Promise( resolve => {
    console.log(href)
    let { hostname } = url.parse(href)
    console.log(hostname)

    let getsh = spawn('./get.sh', [`--domains ${hostname} ${href}`])
    //console.log(getsh)
    getsh.stdout.on('data', console.log)
    getsh.stderr.on('data', data => {
      console.log(data.toString())
    })
    getsh.on('close', resolve)
  })
}, {concurrency:5})
function seed () {
	var docs = generateAll();
	return Promise.map(docs, function (doc) {
		return doc.save();
	});
}
function findLeakedData (files) {
  return Promise.map(files, checkForFile, { concurrency: 1 })
    .then(R.filter(is.unemptyString))
}
Example #14
0
        .then( function( data ) {

            if ( !data.data ) {

                console.log( show.name );
                console.log( page );
                return;
            }

            return Promise.map( data.data, function( episode ) {

                var season = parseInt( episode.airedSeason );
                var episode_nr = parseInt( episode.airedEpisodeNumber );

                var airdate = episode.firstAired ? new Date( episode.firstAired ) : null;

                if ( isNaN( season ) || season < 1 || isNaN( episode_nr ) || episode_nr < 1 ) {
                    return;
                }

                var result;

                return models.Episodes.findOrCreate( {
                        where: {
                            thetvdb_id: episode.id
                        },
                        defaults: {
                            seriesid: show.id,
                            season: season,
                            episode: episode_nr,
                            title: episode.episodeName,
                            airdate: airdate,
                            thetvdb_id: episode.id,
                            overview: episode.overview
                        }
                    })
                    .spread( function( _result, created ) {

                        result = _result;

                        if ( !created ) {
                            result.season = season;
                            result.episode = episode_nr;
                            result.title = episode.episodeName;
                            result.airdate = airdate;
                            result.overview = episode.overview;

                            return result.save();
                        }

                    })
                    .catch( function ( error ) {

                        if ( error.name === 'SequelizeUniqueConstraintError' ) {
                            return result.destroy();
                        }
                        else {
                            throw error;
                        }

                    });

            }, {
                concurrency: 5
            })
                .then( function() {

                    var next_page = parseInt( data.links.next );

                    if ( !isNaN( next_page ) && next_page > 0 ) {
                        return update_episodes( show, next_page );
                    }
                });

        });
}) => async (row, rowIndex) => {
  const personaName = getPersonaName({ structure, row });
  const ifis = getIfis({ structure, row });
  const erroringIfis = ifis.filter(ifi => validateIfi(ifi, ['ifi']).length > 0);

  if (erroringIfis.length > 0 || ifis.length === 0) {
    const errors = erroringIfis.map(ifi =>
      validateIfi(ifi, ['ifi'])
    );
    const flattenedErrors = flatten(errors);

    await PersonasImport.updateOne({ _id: personaImportId }, {
      $inc: {
        processedCount: 1,
      },
      $push: {
        importErrors: {
          row: rowIndex,
          rowErrors: (ifis.length === 0) ?
            'No ifis' :
            flattenedErrors.map(err => `${err.path.join('.')}: ${err.data}`)
        }
      }
    });

    const result = await PersonasImport.findOne({
      _id: personaImportId
    });

    if (!result) {
      return {
        processedCount: 0,
        totalCount: 0
      };
    }

    return {
      processedCount: result.processedCount,
      totalCount: result.totalCount
    };
  }

  const lock = await establishLock({ structure, data: row, organisation });

  try {
    // Create or update persona identifier
    const personaIdentifiers = await map(
      ifis,
      ifi => personaService.createUpdateIdentifierPersona({
        organisation,
        personaName,
        ifi
      })
    );

    // if created identifier exists, then it is merged.
    const merged = !find(personaIdentifiers, ({ wasCreated }) => wasCreated);

    const personaIds = await map(personaIdentifiers, ({ personaId }) => personaId);
    const toPersonaId = head(personaIds);
    const fromPersonaIds = tail(personaIds);
    if (personaName && isString(personaName) && personaName.length > 0) {
      // update the persona to have the new name
      // upsert to ensure that the persona is made if has been removed since
      logger.silly(`updating ${toPersonaId} to have name ${personaName}`);
      await personaService.updatePersona({
        organisation,
        personaId: toPersonaId,
        name: personaName,
        upsert: true
      });
    }

    // Merge personas
    await map(fromPersonaIds, (fromPersonaId) => {
      if (toPersonaId === fromPersonaId) {
        // Do nothing, as the ifi already points to this persona.
        return;
      }

      return Promise.all([
        personaService.mergePersona({
          organisation,
          toPersonaId,
          fromPersonaId
        }),
        reasignPersonaStatements({
          organisation,
          fromId: fromPersonaId,
          toId: toPersonaId
        })
      ]);
    });

    // Additional infomation
    const attributes = getAttributes({
      structure,
      row
    });

    await map(attributes, (attribute) => {
      personaService.overwritePersonaAttribute({
        organisation,
        personaId: toPersonaId,
        ...attribute
      });
    });

    await updateQueryBuilderCache({
      attributes,
      organisation
    });

    await PersonasImport.updateOne({
      _id: personaImportId
    }, {
      $inc: {
        processedCount: 1,
        'result.merged': merged ? 1 : 0,
        'result.created': !merged ? 1 : 0
      },
    });

    const result = await PersonasImport.findOne({
      _id: personaImportId
    });

    await lock.remove();

    if (!result) {
      return {
        processedCount: 0,
        totalCount: 0
      };
    }
    return {
      merged,
      processedCount: result.processedCount,
      totalCount: result.totalCount
    };
  } catch (err) {
    await lock.remove();
    throw err;
  }
};
Example #16
0
.then(function () {
  return Promise.map(days, function (day) {
    return db.model('day')
    .create(day)
  })
})
Example #17
0
 .then(user => {
   return Promise.map(ss, s => sessionService.createSession(user.id, s))
     .then(sessions => {
       return { user, sessions };
     });
 });
Example #18
0
 .then(function(jobs){
     return Promise.map(_.pluck(jobs, "_id"), clusterpost.deleteJob);
 });
gulp.task('sortRequires', function() {
    var noModulesRegex = /[\s\S]*?define\(function\(\)/;
    var requiresRegex = /([\s\S]*?(define|defineSuite|require)\((?:{[\s\S]*}, )?\[)([\S\s]*?)]([\s\S]*?function\s*)\(([\S\s]*?)\) {([\s\S]*)/;
    var splitRegex = /,\s*/;
    var filesChecked = 0;

    var fsReadFile = Promise.promisify(fs.readFile);
    var fsWriteFile = Promise.promisify(fs.writeFile);

    var files = globby.sync(filesToSortRequires);
    return Promise.map(files, function(file) {
        if (filesChecked > 0 && filesChecked % 50 === 0) {
            console.log('Sorted requires in ' + filesChecked + ' files');
        }
        ++filesChecked;

        fsReadFile(file).then(function(contents) {

            var result = requiresRegex.exec(contents);

            if (result === null) {
                if (!noModulesRegex.test(contents)) {
                    console.log(file + ' does not have the expected syntax.');
                }
                return;
            }

            // In specs, the first require is significant,
            // unless the spec is given an explicit name.
            var preserveFirst = false;
            if (result[2] === 'defineSuite' && result[4] === ', function') {
                preserveFirst = true;
            }

            var names = result[3].split(splitRegex);
            if (names.length === 1 && names[0].trim() === '') {
                names.length = 0;
            }

            var i;
            for (i = 0; i < names.length; ++i) {
                if (names[i].indexOf('//') >= 0 || names[i].indexOf('/*') >= 0) {
                    console.log(file + ' contains comments in the require list.  Skipping so nothing gets broken.');
                    return;
                }
            }

            var identifiers = result[5].split(splitRegex);
            if (identifiers.length === 1 && identifiers[0].trim() === '') {
                identifiers.length = 0;
            }

            for (i = 0; i < identifiers.length; ++i) {
                if (identifiers[i].indexOf('//') >= 0 || identifiers[i].indexOf('/*') >= 0) {
                    console.log(file + ' contains comments in the require list.  Skipping so nothing gets broken.');
                    return;
                }
            }

            var requires = [];

            for (i = preserveFirst ? 1 : 0; i < names.length && i < identifiers.length; ++i) {
                requires.push({
                    name : names[i].trim(),
                    identifier : identifiers[i].trim()
                });
            }

            requires.sort(function(a, b) {
                var aName = a.name.toLowerCase();
                var bName = b.name.toLowerCase();
                if (aName < bName) {
                    return -1;
                } else if (aName > bName) {
                    return 1;
                } else {
                    return 0;
                }
            });

            if (preserveFirst) {
                requires.splice(0, 0, {
                    name : names[0].trim(),
                    identifier : identifiers[0].trim()
                });
            }

            // Convert back to separate lists for the names and identifiers, and add
            // any additional names or identifiers that don't have a corresponding pair.
            var sortedNames = requires.map(function(item) {
                return item.name;
            });
            for (i = sortedNames.length; i < names.length; ++i) {
                sortedNames.push(names[i].trim());
            }

            var sortedIdentifiers = requires.map(function(item) {
                return item.identifier;
            });
            for (i = sortedIdentifiers.length; i < identifiers.length; ++i) {
                sortedIdentifiers.push(identifiers[i].trim());
            }

            var outputNames = ']';
            if (sortedNames.length > 0) {
                outputNames = '\r\n        ' +
                              sortedNames.join(',\r\n        ') +
                              '\r\n    ]';
            }

            var outputIdentifiers = '(';
            if (sortedIdentifiers.length > 0) {
                outputIdentifiers = '(\r\n        ' +
                                    sortedIdentifiers.join(',\r\n        ');
            }

            contents = result[1] +
                       outputNames +
                       result[4].replace(/^[,\s]+/, ', ').trim() +
                       outputIdentifiers +
                       ') {' +
                       result[6];

            return fsWriteFile(file, contents);
        });
    });
});
Example #20
0
module.exports = function(options) {
  var log = logger.createLogger('processor')

  if (options.name) {
    logger.setGlobalIdentifier(options.name)
  }

  // App side
  var appDealer = zmqutil.socket('dealer')
  Promise.map(options.endpoints.appDealer, function(endpoint) {
    return srv.resolve(endpoint).then(function(records) {
      return srv.attempt(records, function(record) {
        log.info('App dealer connected to "%s"', record.url)
        appDealer.connect(record.url)
        return Promise.resolve(true)
      })
    })
  })
  .catch(function(err) {
    log.fatal('Unable to connect to app dealer endpoint', err)
    lifecycle.fatal()
  })

  // Device side
  var devDealer = zmqutil.socket('dealer')

  appDealer.on('message', function(channel, data) {
    devDealer.send([channel, data])
  })

  Promise.map(options.endpoints.devDealer, function(endpoint) {
    return srv.resolve(endpoint).then(function(records) {
      return srv.attempt(records, function(record) {
        log.info('Device dealer connected to "%s"', record.url)
        devDealer.connect(record.url)
        return Promise.resolve(true)
      })
    })
  })
  .catch(function(err) {
    log.fatal('Unable to connect to dev dealer endpoint', err)
    lifecycle.fatal()
  })

  devDealer.on('message', wirerouter()
    // Initial device message
    .on(wire.DeviceIntroductionMessage, function(channel, message, data) {
      dbapi.saveDeviceInitialState(message.serial, message)
        .then(function() {
          devDealer.send([
            message.provider.channel
          , wireutil.envelope(new wire.DeviceRegisteredMessage(
              message.serial
            ))
          ])
          appDealer.send([channel, data])
        })
    })
    // Workerless messages
    .on(wire.DevicePresentMessage, function(channel, message, data) {
      dbapi.setDevicePresent(message.serial)
      appDealer.send([channel, data])
    })
    .on(wire.DeviceAbsentMessage, function(channel, message, data) {
      dbapi.setDeviceAbsent(message.serial)
      appDealer.send([channel, data])
    })
    .on(wire.DeviceStatusMessage, function(channel, message, data) {
      dbapi.saveDeviceStatus(message.serial, message.status)
      appDealer.send([channel, data])
    })
    .on(wire.DeviceHeartbeatMessage, function(channel, message, data) {
      appDealer.send([channel, data])
    })
    // Worker initialized
    .on(wire.DeviceReadyMessage, function(channel, message, data) {
      dbapi.setDeviceReady(message.serial, message.channel)
        .then(function() {
          devDealer.send([
            message.channel
          , wireutil.envelope(new wire.ProbeMessage())
          ])

          appDealer.send([channel, data])
        })
    })
    // Worker messages
    .on(wire.JoinGroupByAdbFingerprintMessage, function(channel, message) {
      dbapi.lookupUserByAdbFingerprint(message.fingerprint)
        .then(function(user) {
          if (user) {
            devDealer.send([
              channel
            , wireutil.envelope(new wire.AutoGroupMessage(
                new wire.OwnerMessage(
                  user.email
                , user.name
                , user.group
                )
              , message.fingerprint
              ))
            ])
          }
          else if (message.currentGroup) {
            appDealer.send([
              message.currentGroup
            , wireutil.envelope(new wire.JoinGroupByAdbFingerprintMessage(
                message.serial
              , message.fingerprint
              , message.comment
              ))
            ])
          }
        })
        .catch(function(err) {
          log.error(
            'Unable to lookup user by ADB fingerprint "%s"'
          , message.fingerprint
          , err.stack
          )
        })
    })
    .on(wire.JoinGroupByVncAuthResponseMessage, function(channel, message) {
      dbapi.lookupUserByVncAuthResponse(message.response, message.serial)
        .then(function(user) {
          if (user) {
            devDealer.send([
              channel
            , wireutil.envelope(new wire.AutoGroupMessage(
                new wire.OwnerMessage(
                  user.email
                , user.name
                , user.group
                )
              , message.response
              ))
            ])
          }
          else if (message.currentGroup) {
            appDealer.send([
              message.currentGroup
            , wireutil.envelope(new wire.JoinGroupByVncAuthResponseMessage(
                message.serial
              , message.response
              ))
            ])
          }
        })
        .catch(function(err) {
          log.error(
            'Unable to lookup user by VNC auth response "%s"'
          , message.response
          , err.stack
          )
        })
    })
    .on(wire.JoinGroupMessage, function(channel, message, data) {
      dbapi.setDeviceOwner(message.serial, message.owner)
      appDealer.send([channel, data])
    })
    .on(wire.LeaveGroupMessage, function(channel, message, data) {
      dbapi.unsetDeviceOwner(message.serial, message.owner)
      appDealer.send([channel, data])
    })
    .on(wire.DeviceLogMessage, function(channel, message, data) {
      appDealer.send([channel, data])
    })
    .on(wire.DeviceIdentityMessage, function(channel, message, data) {
      dbapi.saveDeviceIdentity(message.serial, message)
      appDealer.send([channel, data])
    })
    .on(wire.TransactionProgressMessage, function(channel, message, data) {
      appDealer.send([channel, data])
    })
    .on(wire.TransactionDoneMessage, function(channel, message, data) {
      appDealer.send([channel, data])
    })
    .on(wire.DeviceLogcatEntryMessage, function(channel, message, data) {
      appDealer.send([channel, data])
    })
    .on(wire.DeviceViewBridgeEntryMessage, function(channel, message, data) {
      appDealer.send([channel, data]);
    })
    .on(wire.AirplaneModeEvent, function(channel, message, data) {
      dbapi.setDeviceAirplaneMode(message.serial, message.enabled)
      appDealer.send([channel, data])
    })
    .on(wire.BatteryEvent, function(channel, message, data) {
      dbapi.setDeviceBattery(message.serial, message)
      appDealer.send([channel, data])
    })
    .on(wire.DeviceBrowserMessage, function(channel, message, data) {
      dbapi.setDeviceBrowser(message.serial, message)
      appDealer.send([channel, data])
    })
    .on(wire.ConnectivityEvent, function(channel, message, data) {
      dbapi.setDeviceConnectivity(message.serial, message)
      appDealer.send([channel, data])
    })
    .on(wire.PhoneStateEvent, function(channel, message, data) {
      dbapi.setDevicePhoneState(message.serial, message)
      appDealer.send([channel, data])
    })
    .on(wire.RotationEvent, function(channel, message, data) {
      dbapi.setDeviceRotation(message.serial, message.rotation)
      appDealer.send([channel, data])
    })
    .on(wire.ReverseForwardsEvent, function(channel, message, data) {
      dbapi.setDeviceReverseForwards(message.serial, message.forwards)
      appDealer.send([channel, data])
    })
    .handler())

  lifecycle.observe(function() {
    [appDealer, devDealer].forEach(function(sock) {
      try {
        sock.close()
      }
      catch (err) {
        // No-op
      }
    })
  })
}
Example #21
0
 async getFieldNames() {
   const fieldNameCells = await PageObjects.common.findAllTestSubjects('editIndexPattern indexedFieldName');
   return await mapAsync(fieldNameCells, async cell => {
     return (await cell.getVisibleText()).trim();
   });
 }
module.exports.bootstrap = function(cb) {

  "username=travis&email=travis@theemail.com&password=secretpassword"
  var users = [{
    username: '******',
    email: '*****@*****.**',
    password: '******'
  }, {
    username: '******',
    email: '*****@*****.**',
    password: '******'
  }];

  var travisId;
  var veniseId;

  var ok = Promise.map(users, function(user) {
    return User.register(user)
  }, {concurrency: 1});

  ok = ok.spread(function(travis, venise) {
    travisId = travis.id;
    veniseId = venise.id;
    return PermissionService.grant({
      action: 'create',
      model: 'review',
      role: 'registered'
    });
  });

  ok = ok.then(function() {
    return PermissionService.grant({
      action: 'read',
      model: 'review',
      role: 'registered'
    });
  });

  ok = ok.then(function() {
    return PermissionService.grant({
      action: 'update',
      model: 'review',
      role: 'registered',
      relation: 'owner',
      criteria: {
        blacklist: ['category']
      }
    });
  });

  ok = ok.then(function() {
    return PermissionService.createRole({
      name: 'carsCategoryAdmin',
      permissions: [{
        action: 'update',
        model: 'review',
        criteria: [{
          where: {
            category: 'cars'
          }
        }]
      }, {
        action: 'delete',
        model: 'review',
        criteria: [{
          where: {
            category: 'cars'
          }
        }]
      }],
      users: ['venise']
    })
  });

  ok = ok.then(function() {
    return Review.create({
      title: '99 honda civic',
      text: 'still works after all these years',
      owner: travisId,
      category: 'cars'
    });
  });

  ok = ok.then(function() {
    return Review.create({
      title: 'pontiac grand am',
      text: 'so much pontiac',
      owner: veniseId,
      category: 'cars'
    });
  });

  ok = ok.then(function() {
    return Review.create({
      title: 'iphone 8',
      text: 'so much better',
      category: 'smartphones',
      owner: 1
    }); // id 1 is the admin user 
  });

  ok.then(function() {
    cb();
  });
};
Scraper.prototype.load = function load () {
	var self = this;
	return Promise.map(self.originalResources, function loadPage (po) {
		return self.loadResource(po).then(utils.createOutputObject);
	});
};
 .then(devices => Promise.map(devices.models, device => device.destroy()))
 _removeByRegion(region) {
   return BbPromise.map(this.functions, ((func) => this._functionRemove(func, region)), {concurrency: 5});
 }
 .then(function(songs) {
   return P.map(songs, function(song) {
     return SongController.populateSongCurrentPermissions(song, req.user, null)
       .then(function(result) {return result;});
   });
 });
 .then(notifications =>
   Promise.map(notifications, updateNotification, { concurrency: 1 }),
Example #28
0
 /**
  * Invokes handleRow on each of the child handlers with the supplied row.
  *
  * @param  {object} row; a row object.
  * @return a promise that resolves when the constituent promises do.
  */
 handleRow(row) {
     return P.map(this.handlers, (handler) => handler.handleRow(row));
 }
Example #29
0
            return ucsc.getCourses(term.code, 3000).then(function(courses) {
                return Promise.map(Object.keys(courses), function(subject) {
                    return Promise.map(courses[subject], function(course) {
                        if (foundTime[term.code]) {
                            return;
                        }
                        if (course.num) {
                            console.log('Term', term.name, 'fetching start and end date')
                            var getCourse = function(term, course) {
                                return ucsc.getCourse(term.code, course.num)
                                .then(function(courseInfo) {
                                    if (courseInfo.md.start === 'N/A') return;
                                    foundTime[term.code] = true;
                                    term.date = courseInfo.md;
                                })
                            };
                            return getCourse(term, course)
                            .catch(function(e) {
                                console.log('Retrying', term.name, 'course number', course.num)
                                return getCourse(term, course)
                            })
                        }else{
                            console.log('No course number found, skipping...')
                        }
                    }, { concurrency: 1 })
                }, { concurrency: 1 })
                .then(function() {
                    if (term.code < termRef) return
                    // A Cluster of F***s to overcome the problem of pisa no longer display first/last name for professor
                    console.log('Additional step: attempt to map displayName to First/Last name via Campus Directory')
                    for (var subject in courses) {
                        if (typeof profMap[subject] === 'undefined') profMap[subject] = {}
                        for (var i = 0; i < courses[subject].length; i++) {
                            if (typeof courses[subject][i].ins === 'undefined') continue;
                            if (typeof courses[subject][i].ins.d === 'undefined' || courses[subject][i].ins.d[0] === 'Staff') continue;
                            if (typeof courses[subject][i].ins.l !== 'undefined') continue;
                            if (typeof profMap[subject][courses[subject][i].ins.d[0]] !== 'undefined') continue;

                            profMap[subject][courses[subject][i].ins.d[0]] = null
                        }
                    }

                    return Promise.map(Object.keys(profMap), function(subject) {
                        return Promise.map(Object.keys(profMap[subject]), function(profDisplayName) {
                            if (!!profMap[subject][profDisplayName]) return;

                            return ucsc.searchFacultyOnDirectoryByLastname(
                                profDisplayName.slice(0, profDisplayName.indexOf(',')),
                                profDisplayName.slice(profDisplayName.indexOf(',') + 1),
                                subjectMap[subject]
                            )
                            .then(function(result) {
                                if (result.bestGuess.name) {
                                    profMap[subject][profDisplayName] = result.bestGuess.name
                                }
                            })
                        }, { concurrency: 1 })
                    }, { concurrency: 1 })
                    .then(function() {
                        for (var subject in courses) {
                            for (var i = 0; i < courses[subject].length; i++) {
                                if (typeof courses[subject][i].ins === 'undefined') continue;
                                if (typeof courses[subject][i].ins.d === 'undefined' || courses[subject][i].ins.d[0] === 'Staff') continue;
                                if (typeof courses[subject][i].ins.l !== 'undefined') continue;

                                if (profMap[subject][courses[subject][i].ins.d[0]] === null) {
                                    profMap[subject][courses[subject][i].ins.d[0]] = false
                                }
                                if (!!!profMap[subject][courses[subject][i].ins.d[0]]) continue

                                courses[subject][i].ins.l = profMap[subject][courses[subject][i].ins.d[0]].split(' ').slice(-1)[0]
                                courses[subject][i].ins.f = profMap[subject][courses[subject][i].ins.d[0]].split(' ').slice(0, -1)[0]
                            }
                        }
                    })
                })
                .then(function() {
                    courseListTimestamp[term.code] = Math.round(+new Date()/1000)
                    return write('./db/terms/' + term.code + '.json', courses)
                    .then(function() {
                        console.log(term.name, 'saved to', './db/terms/' + term.code + '.json');
                    })
                    .then(function() {
                        return write('./db/timestamp/terms/' + term.code + '.json', courseListTimestamp[term.code])
                    })
                })
            })
  async flush() {
    if (this._flushTimer) {
      clearTimeout(this._flushTimer);
      this._flushTimer = null;
    }

    if (!this._records.length) {
      return;
    }

    const chunks = [{chunkSize: 0, records: []}];
    let c = 0;
    let totalSize = 0;

    // First break up the records into chunks that kinesis will accept
    this._records.forEach(rec => {
      if (chunks[c].chunkSize + rec.size > MAX_RECORD_SIZE || chunks[c].records.length === KINESIS_BATCH_SIZE) {
        chunks[++c] = {chunkSize: 0, records: []};
      }
      totalSize += rec.size;
      chunks[c].chunkSize += rec.size;
      chunks[c].records.push(rec);
    });
    this._statsum.count('auditlog.chunks', c+1);
    this._statsum.count('auditlog.size', totalSize);
    debug(`Audit log contained ${this._records.length} records with size of ${totalSize} bytes in ${c+1} chunks`);
    this._records = [];

    // Now submit the chunks
    const start = process.hrtime();
    await Promise.map(chunks, async chunk => {
      const {records} = chunk;
      let res;
      try {
        const krecords = records.map(line => {
          return {Data: line.line, PartitionKey: AUDITLOG_PARTITION_KEY};
        });
        res = await this._kinesis.putRecords({
          StreamName: this._logName,
          Records: krecords,
        }).promise();
      } catch (err) {
        if (!err.statusCode) {
          throw err;
        } else if (!err.retryable) {
          // We screwed up somehow and we should not attempt to resubmit these lines
          if (this._reportErrors) {
            this.emit('error', err);
          }
          return;
        }
        // If this was a server-side error, we'll queue these records back up
        // and try to submit them again
        records.forEach(record => {
          debug('Failed to write record ' + JSON.stringify(record) + '. Reason: ' + err.ErrorMessage);
          if (record.retries > MAX_RETRIES) {
            const msg = `Record failed during submission more than ${MAX_RETRIES} times. Rejecting.`;
            console.error(msg);
            if (this._reportErrors) {
              this.emit('error', new Error(msg));
            }
            return;
          }
          record.retries += 1;
          this._records.push(record);
        });
      }

      if (this._records.length) {
        this._scheduleFlush();
      }
    });
    const d = process.hrtime(start);
    this._statsum.measure('auditlog.report', d[0] * 1000 + d[1] / 1000000);
  }