Skip to content

Commit

Permalink
Merge pull request #19 from polarityio/develop
Browse files Browse the repository at this point in the history
Add page size option and bump dependencies
  • Loading branch information
sarus authored Sep 10, 2024
2 parents 6204dda + 17d253c commit 7e5b58d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
13 changes: 11 additions & 2 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,17 @@ module.exports = {
description: 'HYAS Api Key',
default: '',
type: 'password',
userCanEdit: true,
adminOnly: false
userCanEdit: false,
adminOnly: true
},
{
"key": "maxResults",
"name": "Maximum Results",
"description": "Maximum number of results to return.",
"default": 5,
"type": "number",
"userCanEdit": false,
"adminOnly": false
},
{
key: 'blocklist',
Expand Down
11 changes: 10 additions & 1 deletion config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@
"description": "HYAS Api Key",
"default": "",
"type": "password",
"userCanEdit": true,
"userCanEdit": false,
"adminOnly": true
},
{
"key": "maxResults",
"name": "Maximum Results",
"description": "Maximum number of results to return.",
"default": 5,
"type": "number",
"userCanEdit": false,
"adminOnly": false
},
{
Expand Down
29 changes: 14 additions & 15 deletions integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ let ipBlocklistRegex = null;
const MAX_DOMAIN_LABEL_LENGTH = 63;
const MAX_ENTITY_LENGTH = 100;
const MAX_PARALLEL_LOOKUPS = 10;
const PAGE_SIZE = 5;
const IGNORED_IPS = new Set(['127.0.0.1', '255.255.255.255', '0.0.0.0']);
const url = 'https://insight.hyas.com/api/ext';
const uiurl = 'https://apps.hyas.com';
Expand Down Expand Up @@ -98,7 +97,7 @@ function doLookup(entities, options, cb) {

tasks.push(function (done) {
requestWithDefaults(requestOptions, function (error, res, body) {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, res, body);

if (processedResult.error) {
Expand Down Expand Up @@ -136,7 +135,7 @@ function doLookup(entities, options, cb) {

tasks.push(function (done) {
requestWithDefaults(requestOptions, function (error, res, body) {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, res, body);

if (processedResult.error) {
Expand Down Expand Up @@ -173,7 +172,7 @@ function doLookup(entities, options, cb) {

tasks.push(function (done) {
requestWithDefaults(requestOptions, function (error, res, body) {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, res, body);
if (processedResult.error) {
done(processedResult);
Expand Down Expand Up @@ -211,7 +210,7 @@ function doLookup(entities, options, cb) {

tasks.push(function (done) {
requestWithDefaults(requestOptions, function (error, res, body) {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, res, body);
if (processedResult.error) {
done(processedResult);
Expand Down Expand Up @@ -247,7 +246,7 @@ function doLookup(entities, options, cb) {

tasks.push(function (done) {
requestWithDefaults(requestOptions, function (error, res, body) {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, res, body);
if (processedResult.error) {
done(processedResult);
Expand Down Expand Up @@ -322,7 +321,7 @@ function doLookup(entities, options, cb) {
details: {
result: resultWithFormatedPhoneNumber,
link: result.link,
pageSize: PAGE_SIZE
pageSize: options.maxResults
}
}
});
Expand Down Expand Up @@ -407,7 +406,7 @@ function doDeviceGeoIpLookup(entity, options) {
};

requestWithDefaults(requestOptions, (error, response, body) => {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, response, body);
if (processedResult.error) return done(processedResult);
done(null, processedResult.body);
Expand All @@ -432,13 +431,13 @@ function doDomainPassiveLookup(entity, options) {
applied_filters: {
domain: entity.value
},
paging: { order: 'desc', sort: 'datetime', page_number: 0, page_size: 10 }
paging: { order: 'desc', sort: 'datetime', page_number: 0, page_size: options.maxResults }
},
json: true
};

requestWithDefaults(requestOptions, (error, response, body) => {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, response, body);
if (processedResult.error) return done(processedResult);
done(null, processedResult.body);
Expand Down Expand Up @@ -468,7 +467,7 @@ function doIpSampleLookup(entity, options) {
};

requestWithDefaults(requestOptions, (error, response, body) => {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, response, body);
if (processedResult.error) return done(processedResult);
done(null, processedResult.body);
Expand Down Expand Up @@ -498,7 +497,7 @@ function doDomainSampleLookup(entity, options) {
};

requestWithDefaults(requestOptions, (error, response, body) => {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, response, body);
if (processedResult.error) return done(processedResult);
done(null, processedResult.body);
Expand Down Expand Up @@ -528,7 +527,7 @@ function doDomainSSlLookup(entity, options) {
};

requestWithDefaults(requestOptions, (error, response, body) => {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, response, body);
if (processedResult.error) return done(processedResult);
done(null, processedResult.body);
Expand Down Expand Up @@ -558,7 +557,7 @@ function doDynamicDNSLookup(entity, options) {
};

requestWithDefaults(requestOptions, (error, response, body) => {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, response, body);
if (processedResult.error) return done(processedResult);
done(null, processedResult.body);
Expand Down Expand Up @@ -593,7 +592,7 @@ function doDeviceGeoLookup(entity, options) {
Logger.trace({ options: requestOptions }, 'Request URI');

requestWithDefaults(requestOptions, (error, response, body) => {
body = body && _.isArray(body) && body.splice(0, PAGE_SIZE);
body = body && _.isArray(body) && body.splice(0, options.maxResults);
let processedResult = handleRestError(error, entity, response, body);
if (processedResult.error) return done(processedResult);

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "hyas-insight",
"version": "3.1.12",
"version": "3.1.13",
"main": "./integration.js",
"private": true,
"dependencies": {
"async": "^3.2.5",
"async": "^3.2.6",
"google-libphonenumber": "^3.2.38",
"postman-request": "^2.88.1-postman.39",
"postman-request": "^2.88.1-postman.40",
"lodash": "^4.17.21"
}
}

0 comments on commit 7e5b58d

Please sign in to comment.