/* * Parse docker-compose options */ const parseOptions = (opts = {}) => { const flags = _.map(composeFlags, (value, key) => _.get(opts, key, false) ? value : ''); const environment = _.flatMap(opts.environment, (value, key) => ['--env', `${key}=${value}`]); const user = (_.has(opts, 'user')) ? ['--user', opts.user] : []; const workdir = (_.has(opts, 'workdir')) ? ['--workdir', opts.workdir] : []; const entrypoint = _.map(opts.entrypoint, entrypoint => ['--entrypoint', entrypoint]); return _.compact(_.flatten([flags, environment, user, workdir, entrypoint])); }
const createPanelLayout = function (panelPosition, views) { const viewSummaryPosition = getSummaryPosition(views); let offsetPosition = { size: 0, grow: 0 }; return _.flatMap(views, (view) => { const viewPosition = { summary: viewSummaryPosition, offset: offsetPosition, position: view.position }; offsetPosition = concatPosition(view.position, offsetPosition); return createViewLayout(view, viewPosition, panelPosition); }); }
// Scan urls app.events.on('post-start', 10, () => { // Message to let the user know it could take a bit console.log('Scanning to determine which services are ready... Please standby...'); // Filter out any services where the scanner might be disabled return app.scanUrls(_.flatMap(getScannable(app), 'urls'), {max: 16}).then(urls => { // Get data about our scanned urls app.urls = urls; // Add in unscannable ones if we have them if (!_.isEmpty(getScannable(app, false))) { app.urls = app.urls.concat(_.map(_.flatMap(getScannable(app, false), 'urls'), url => ({ url, status: true, color: 'yellow', }))); } }); });
/** * 获取完整的省市区名称组成的字符串 * @param provinceId * @param cityId * @param districtId * @returns {Promise.<*>} */ async getFullRegionName(provinceId, cityId, districtId) { const isFullRegion = await this.checkFullRegion(provinceId, cityId, districtId); if (!isFullRegion) { return ''; } const regionList = await this.limit(3).order({'id': 'asc'}).where({id: {'in': [provinceId, cityId, districtId]}}).select(); if (think.isEmpty(regionList) || regionList.length !== 3) { return ''; } return _.flatMap(regionList, 'name').join(''); }
// Discover portforward true info app.events.on('ready', () => { app.log.verbose('discovering dynamic portforward info...'); const forwarders = _.filter(app.info, service => _.get(service, 'external_connection.port', false)); return lando.engine.list({project: app.project}) .filter(service => _.includes(_.flatMap(forwarders, service => service.service), service.service)) .map(service => ({ id: service.id, service: service.service, internal: _.get(_.find(app.info, {service: service.service}), 'internal_connection.port'), })) .map(service => lando.engine.scan(service).then(data => { const key = `NetworkSettings.Ports.${service.internal}/tcp`; const port = _.filter(_.get(data, key, []), forward => forward.HostIp === lando.config.bindAddress); if (_.has(port[0], 'HostPort')) { _.set(_.find(app.info, {service: service.service}), 'external_connection.port', port[0].HostPort); } })); });
stdout .trim() .split('\n') .map(l => JSON.parse(l)) .filter(l => l.type === 'auditAdvisory') .map(l => l.data.advisory) .map(adv => ({ offender: adv.module_name, code: `${adv.module_name}-${adv.id}`, description: adv.title, mitigation: `Ingested via ${_.uniq(_.flatMap(_.get(adv, 'findings', []).map(f => _.get(f, 'paths', ''))).map(f => f.split('>')[0])).join(', ')}`, level: mapSeverity(adv.severity) })) .reduce((results, res) => results[res.level](res), new ModuleResults(key))
matchesLabel(pr) { if (this.label.values.length > 0) { const result = _.some(this.label.values, (_label) => { return _.flatMap(pr.labels.nodes, (label) => label.name).includes(_label) }) return (this.label.inclusion ? result : !result) } else { return true } }
_.flatMap(pbTraces.tracesList, t => converter.toTraceJson(t).sort((s1, s2) => s1.startTime - s2.startTime))
Object.keys(advisories) .map(prop => advisories[prop]) .map(adv => ({ offender: adv.module_name, code: `${adv.module_name}-${adv.id}`, description: adv.title, mitigation: `Ingested via ${_.uniq(_.flatMap(_.get(adv, 'findings', []).map(f => _.get(f, 'paths', ''))).map(f => f.split('>')[0])).join(', ')}`, level: mapSeverity(adv.severity) })) .reduce((results, res) => results[res.level](res), new ModuleResults(key))
lodash.flatMap(options.directives, directive => { switch (directive.type) { case "disable": case "enable": return []; case "disable-line": return [ { type: "disable", line: directive.line, column: 1, ruleId: directive.ruleId, unprocessedDirective: directive }, { type: "enable", line: directive.line + 1, column: 0, ruleId: directive.ruleId, unprocessedDirective: directive } ]; case "disable-next-line": return [ { type: "disable", line: directive.line + 1, column: 1, ruleId: directive.ruleId, unprocessedDirective: directive }, { type: "enable", line: directive.line + 2, column: 0, ruleId: directive.ruleId, unprocessedDirective: directive } ]; default: throw new TypeError(`Unrecognized directive type '${directive.type}'`); } }).sort(compareLocations)
/** * @param {ModuleResult[]} moduleResultList * @return {ScanResults} */ static fromModuleResultsList (moduleResultList) { const results = moduleResultList .map(({ key, data }) => { const result = [] for (const level in threshold) { data[level].forEach(item => { const filteredItem = _.pick(item, ['code', 'offender', 'description', 'mitigation']) result.push({ module: key, level, ...filteredItem }) }) } return result }) return new ScanResults(_.flatMap(results)) }
function useMultiple(list) { // Use one or more map, concatAll, and filter calls to create an array with the following items // [ // {"id": 675465,"title": "Fracture","boxart":"http://cdn-0.nflximg.com/images/2891/Fracture150.jpg" }, // {"id": 65432445,"title": "The Chamber","boxart":"http://cdn-0.nflximg.com/images/2891/TheChamber150.jpg" }, // {"id": 654356453,"title": "Bad Boys","boxart":"http://cdn-0.nflximg.com/images/2891/BadBoys150.jpg" }, // {"id": 70111470,"title": "Die Hard","boxart":"http://cdn-0.nflximg.com/images/2891/DieHard150.jpg" } // ] let results = _.flatMap(list, l => _.map(l.videos, v => { return { id: v.id, title: v.title, boxart: _.filter(v.boxarts, function(boxc) { return boxc.width === 150 }).reduce(function(prev, curr) { return curr.url }, ''), } }), ) results = _.orderBy(results, ['id', 'title'], ['asc']) return results }
function calculateShadowDuration(spans) { if (!spans.length) return 0; const filteredSpans = spans.filter(span => !findTag(span.tags, 'X-HAYSTACK-AUTOGEN')); const shadows = _.flatMap(filteredSpans, span => [{time: span.startTime, value: 1}, {time: span.startTime + span.duration, value: -1}]); const sortedShadows = shadows.sort((a, b) => a.time - b.time); let runningCount = 0; let lastStartTimestamp = sortedShadows[0].time; let runningShadowDuration = 0; for (let i = 0; i < sortedShadows.length; i += 1) { if (runningCount === 1 && sortedShadows[i].value === -1) { runningShadowDuration += sortedShadows[i].time - lastStartTimestamp; } if (runningCount === 0 && sortedShadows[i].value === 1) { lastStartTimestamp = sortedShadows[i].time; } runningCount += sortedShadows[i].value; } return runningShadowDuration; }
matchesReviewer(pr) { if (this.reviewer.values.length > 0) { const result = _.some(this.reviewer.values, (_reviewer) => { // Reviewer could be a user or a team const matched = _reviewer.match(/^.+\/(.+)$/) const usernameOrTeamName = matched ? matched[1] : _reviewer return _.flatMap(pr.reviewRequests.nodes, (request) => { return request.requestedReviewer.login || request.requestedReviewer.name }).includes(usernameOrTeamName) }) return (this.reviewer.inclusion ? result : !result) } else { return true } }
matchesAssignee(pr) { if (this.assignee.values.length > 0) { const result = _.some(this.assignee.values, (_assignee) => { const matched = _assignee.match(/^.+\/(.+)$/) const username = matched ? matched[1] : _assignee return _.flatMap(pr.assignees.nodes, (assignee) => { return assignee.login }).includes(username) }) return (this.assignee.inclusion ? result : !result) } else { return true } }