Skip to content

Commit

Permalink
Merge pull request #3769 from terascope/update-is-ip
Browse files Browse the repository at this point in the history
[data-mate, ts-transforms, utils] bump is-ip fr0m 3.1.0 to 5.0.1
  • Loading branch information
jsnoble authored Sep 27, 2024
2 parents 7c27d7d + f0d83b4 commit b3aaece
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/data-mate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ip6addr": "^0.2.5",
"ipaddr.js": "^2.2.0",
"is-cidr": "^4.0.2",
"is-ip": "^3.1.0",
"is-ip": "^5.0.1",
"jexl": "^2.2.2",
"lodash": "^4.17.21",
"mnemonist": "^0.39.8",
Expand Down
6 changes: 3 additions & 3 deletions packages/data-mate/src/data-frame/search/ip-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isCidr from 'is-cidr';
import ip6addr from 'ip6addr';
import isIP from 'is-ip';
import { isIP, isIPv6 } from 'is-ip';
import { isInfiniteMin, isInfiniteMax, ParsedRange } from 'xlucene-parser';
import { getTypeOf, isString, isNonZeroCidr } from '@terascope/utils';
import { MatchValueFn } from './interfaces.js';
Expand Down Expand Up @@ -53,15 +53,15 @@ function validateIPRange(rangeQuery: ParsedRange) {
let { minValue, maxValue } = values;

if (isInfiniteMin(minValue)) {
if (isIP.v6(maxValue)) {
if (isIPv6(maxValue)) {
minValue = MIN_IPV6_IP;
} else {
minValue = MIN_IPV4_IP;
}
}

if (isInfiniteMax(maxValue)) {
if (isIP.v6(minValue)) {
if (isIPv6(minValue)) {
maxValue = MAX_IPV6_IP;
} else {
maxValue = MAX_IPV4_IP;
Expand Down
15 changes: 8 additions & 7 deletions packages/data-mate/src/document-matcher/logic-builder/ip.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isCidr from 'is-cidr';
import ip6addr from 'ip6addr';
import isIP from 'is-ip';
import { isIP, isIPv6 } from 'is-ip';
import { isInfiniteMin, isInfiniteMax, ParsedRange } from 'xlucene-parser';
import { isString, isNonZeroCidr } from '@terascope/utils';
import { BooleanCB } from '../interfaces.js';
Expand Down Expand Up @@ -49,15 +49,15 @@ function validateIPRange(rangeQuery: ParsedRange) {
let { minValue, maxValue } = values;

if (isInfiniteMin(minValue)) {
if (isIP.v6(maxValue)) {
if (isIPv6(maxValue)) {
minValue = MIN_IPV6_IP;
} else {
minValue = MIN_IPV4_IP;
}
}

if (isInfiniteMax(maxValue)) {
if (isIP.v6(minValue)) {
if (isIPv6(minValue)) {
maxValue = MAX_IPV6_IP;
} else {
maxValue = MAX_IPV4_IP;
Expand Down Expand Up @@ -88,11 +88,12 @@ function checkCidr(ip: string, range: any) {
}

function pRangeTerm(range: any) {
return function checkIP(ip: string) {
if (isNonZeroCidr(ip)) {
return checkCidr(ip, range);
return function checkIP(ip: unknown) {
if (ip === null || ip === undefined) return false;
if (isNonZeroCidr(ip as any)) {
return checkCidr(ip as any, range);
}
if (isIP(ip)) return range.contains(ip);
if (isIP(ip as any)) return range.contains(ip);
return false;
};
}
Expand Down
8 changes: 4 additions & 4 deletions packages/data-mate/src/validations/field-validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from '@terascope/utils';
import ipaddr from 'ipaddr.js';
import _isIP from 'is-ip';
import { isIP as _isIP, isIPv6 } from 'is-ip';
import ip6addr from 'ip6addr';
import PhoneValidator from 'awesome-phonenumber';
import validator from 'validator';
Expand Down Expand Up @@ -645,11 +645,11 @@ function _inIPRange(input: unknown, args: { min?: string; max?: string; cidr?: s

// assign upper/lower bound even if min or max is missing
let { min, max } = args;
if (!min) min = _isIP.v6(input) ? MIN_IPV6_IP : MIN_IPV4_IP;
if (!max) max = _isIP.v6(input) ? MAX_IPV6_IP : MAX_IPV4_IP;
if (!min) min = isIPv6(input) ? MIN_IPV6_IP : MIN_IPV4_IP;
if (!max) max = isIPv6(input) ? MAX_IPV6_IP : MAX_IPV4_IP;

// min and max must be valid ips, same IP type, and min < max
if (!isIP(min) || !isIP(max) || _isIP.v6(min) !== _isIP.v6(max)
if (!isIP(min) || !isIP(max) || isIPv6(min) !== isIPv6(max)
|| ip6addr.compare(max, min) === -1) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-transforms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@terascope/utils": "^1.1.0",
"awesome-phonenumber": "^2.70.0",
"graphlib": "^2.1.8",
"is-ip": "^3.1.0",
"is-ip": "^5.0.1",
"jexl": "^2.2.2",
"nanoid": "^3.3.4",
"valid-url": "^1.0.9",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isIP from 'is-ip';
import { isIP } from 'is-ip';
import ValidationOpBase from './base.js';
import { PostProcessConfig } from '../../../interfaces.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"ip6addr": "^0.2.5",
"ipaddr.js": "^2.2.0",
"is-cidr": "^4.0.2",
"is-ip": "^3.1.0",
"is-ip": "^5.0.1",
"is-plain-object": "^5.0.0",
"js-string-escape": "^1.0.1",
"kind-of": "^6.0.3",
Expand Down
15 changes: 9 additions & 6 deletions packages/utils/src/ip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import _isIP from 'is-ip';
import {
isIP as _isIP, isIPv4 as _isIPv4,
isIPv6 as _isIPv6, ipVersion as _ipVersion
} from 'is-ip';
import IPCIDR from 'ip-cidr';
import isCidr from 'is-cidr';
import ipaddr, { IPv4, IPv6 } from 'ipaddr.js';
Expand Down Expand Up @@ -35,11 +38,11 @@ export function isIPOrThrow(input: unknown): string {
}

export function isIPv6(input: unknown): boolean {
return isString(input) && _isIP.v6(input);
return isString(input) && _isIPv6(input);
}

export function isIPv4(input: unknown): boolean {
return isString(input) && _isIP.v4(input);
return isString(input) && _isIPv4(input);
}

export function isMappedIPv4(input: unknown): boolean {
Expand Down Expand Up @@ -74,7 +77,7 @@ export function inIPRange(
return isCIDR(args.cidr) && ip6addr.createCIDR(args.cidr).contains(input as string);
}

const ipType = _isIP.version(input as string);
const ipType = _ipVersion(input as string);

const min = args.min || _assignMin(ipType as number);
const max = args.max || _assignMax(ipType as number);
Expand All @@ -101,7 +104,7 @@ function _assignMax(ipType: number, max?: string): string {

function _validMinAndMax(min: string, max: string): boolean {
return isIP(min) && isIP(max)
&& _isIP.version(min) === _isIP.version(max)
&& _ipVersion(min) === _ipVersion(max)
&& ip6addr.compare(min, max) === -1;
}

Expand Down Expand Up @@ -289,7 +292,7 @@ export function getCIDRNetwork(input: unknown): string {
}

export function toCIDR(input: unknown, suffix: string | number): string {
if (isIP(input) && _validSuffix(_isIP.version(input as string), suffix)) {
if (isIP(input) && _validSuffix(_ipVersion(input as string), suffix)) {
return createCIDR(input as string, toInteger(suffix) as number).toString();
}

Expand Down
53 changes: 52 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4665,6 +4665,13 @@ clone-regexp@^1.0.0:
is-regexp "^1.0.0"
is-supported-regexp-flag "^1.0.0"

clone-regexp@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/clone-regexp/-/clone-regexp-3.0.0.tgz#c6dd5c6b85482306778f3dc4ac2bb967079069c2"
integrity sha512-ujdnoq2Kxb8s3ItNBtnYeXdm07FcU0u8ARAT1lQ2YdMwQC+cdiXX8KoqMVuglztILivceTtp4ivqGSmEmhBUJw==
dependencies:
is-regexp "^3.0.0"

[email protected]:
version "1.0.2"
resolved "https://registry.yarnpkg.com/clone-response/-/clone-response-1.0.2.tgz#d1dc973920314df67fbeb94223b4ee350239e96b"
Expand Down Expand Up @@ -4910,6 +4917,11 @@ content-type@~1.0.4, content-type@~1.0.5:
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918"
integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==

convert-hrtime@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/convert-hrtime/-/convert-hrtime-5.0.0.tgz#f2131236d4598b95de856926a67100a0a97e9fa3"
integrity sha512-lOETlkIeYSJWcbbcvjRKGxVMXJR+8+OQb/mTPbA4ObPMytYIsUbuOE0Jzy60hjARYszq1id0j8KgVhC+WGZVTg==

convert-source-map@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a"
Expand Down Expand Up @@ -6548,6 +6560,11 @@ function-bind@^1.1.2:
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==

function-timeout@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/function-timeout/-/function-timeout-0.1.1.tgz#6bf71d3d24c894d43b2bec312cabb8c5add2e9da"
integrity sha512-0NVVC0TaP7dSTvn1yMiy6d6Q8gifzbvQafO46RtLG/kHJUBNd+pVRGOBoK44wNBvtSPUJRfdVvkFdD3p0xvyZg==

function.name@^1.0.3:
version "1.0.13"
resolved "https://registry.yarnpkg.com/function.name/-/function.name-1.0.13.tgz#eef045abc4b5ff4e3e9d001a53ce14e090c971c6"
Expand Down Expand Up @@ -7502,6 +7519,11 @@ ip-regex@^4.0.0, ip-regex@^4.1.0:
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-4.3.0.tgz#687275ab0f57fa76978ff8f4dddc8a23d5990db5"
integrity sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==

ip-regex@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-5.0.0.tgz#cd313b2ae9c80c07bd3851e12bf4fa4dc5480632"
integrity sha512-fOCG6lhoKKakwv+C6KdsOnGvgXnmgfmp0myi3bcNwj3qfwPAxRKWEuFhvEFF7ceYIz6+1jRZ+yguLFAmUNPEfw==

ip6addr@^0.2.5:
version "0.2.5"
resolved "https://registry.yarnpkg.com/ip6addr/-/ip6addr-0.2.5.tgz#06e134f44b4e1a684fd91b24035dca7a53b8f759"
Expand Down Expand Up @@ -7686,13 +7708,21 @@ is-interactive@^1.0.0:
resolved "https://registry.yarnpkg.com/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e"
integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==

[email protected], is-ip@^3.1.0:
[email protected]:
version "3.1.0"
resolved "https://registry.yarnpkg.com/is-ip/-/is-ip-3.1.0.tgz#2ae5ddfafaf05cb8008a62093cf29734f657c5d8"
integrity sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q==
dependencies:
ip-regex "^4.0.0"

is-ip@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/is-ip/-/is-ip-5.0.1.tgz#bec44442c823e591aa6f4d6fb9081d6a9be17e44"
integrity sha512-FCsGHdlrOnZQcp0+XT5a+pYowf33itBalCl+7ovNXC/7o5BhIpG14M3OrpPPdBSIQJCm+0M5+9mO7S9VVTTCFw==
dependencies:
ip-regex "^5.0.0"
super-regex "^0.2.0"

is-lambda@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-lambda/-/is-lambda-1.0.1.tgz#3d9877899e6a53efc0160504cde15f82e6f061d5"
Expand Down Expand Up @@ -7788,6 +7818,11 @@ is-regexp@^1.0.0:
resolved "https://registry.yarnpkg.com/is-regexp/-/is-regexp-1.0.0.tgz#fd2d883545c46bac5a633e7b9a09e87fa2cb5069"
integrity sha512-7zjFAPO4/gwyQAAgRRmqeEeyIICSdmCqa3tsVHMdBzaXXRiqopZL4Cyghg/XulGWrtABTpbnYYzzIRffLkP4oA==

is-regexp@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/is-regexp/-/is-regexp-3.1.0.tgz#0235eab9cda5b83f96ac4a263d8c32c9d5ad7422"
integrity sha512-rbku49cWloU5bSMI+zaRaXdQHXnthP6DZ/vLnfdSKyL4zUzuWnomtOEiZZOd+ioQ+avFo/qau3KPTc7Fjy1uPA==

is-retry-allowed@^1.0.0, is-retry-allowed@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz#d778488bd0a4666a3be8a1482b9f2baafedea8b4"
Expand Down Expand Up @@ -12031,6 +12066,15 @@ sudo-block@^1.1.0:
is-docker "^1.0.0"
is-root "^1.0.0"

super-regex@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/super-regex/-/super-regex-0.2.0.tgz#dc1e071e55cdcf56930eb6271f73653a655b2642"
integrity sha512-WZzIx3rC1CvbMDloLsVw0lkZVKJWbrkJ0k1ghKFmcnPrW1+jWbgTkTEWVtD9lMdmI4jZEz40+naBxl1dCUhXXw==
dependencies:
clone-regexp "^3.0.0"
function-timeout "^0.1.0"
time-span "^5.1.0"

supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
Expand Down Expand Up @@ -12198,6 +12242,13 @@ through@^2.3.6, through@^2.3.8:
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==

time-span@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/time-span/-/time-span-5.1.0.tgz#80c76cf5a0ca28e0842d3f10a4e99034ce94b90d"
integrity sha512-75voc/9G4rDIJleOo4jPvN4/YC4GRZrY8yy1uU4lwrB3XEQbWve8zXoO5No4eFrGcTAMYyoY67p8jRQdtA1HbA==
dependencies:
convert-hrtime "^5.0.0"

timed-out@^4.0.0, timed-out@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"
Expand Down

0 comments on commit b3aaece

Please sign in to comment.