Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
fix: new geo ip service
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-calavera committed Oct 23, 2019
1 parent 23f6ed2 commit 29899fb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 93 deletions.
27 changes: 22 additions & 5 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {filter, flow, map, uniq} from 'lodash/fp';
import _ from 'lodash';
import './inbound-stream';
import './uptime-crawler';
import geoip from 'geoip-lite';
import IPGeolocationAPI from 'ip-geolocation-api-javascript-sdk';
import GeolocationParams from 'ip-geolocation-api-javascript-sdk/GeolocationParams';
import YAML from 'yaml';
import fs from 'fs';
import assert from 'assert';
Expand All @@ -32,6 +33,14 @@ const CLUSTER_INFO_CACHE_TIME_SECS = 4500;
const CONFIG_PROGRAM_ID = 'Config1111111111111111111111111111111111111';
const MAX_KEYBASE_USER_LOOKUP = 50;

const GEOLOCATION_API_KEY = process.env.GEOLOCATION_API_KEY || '';
if (GEOLOCATION_API_KEY == '') {
console.error('GEOLOCATION_API_KEY not found in the environment');
console.error('Obtain an API key from https://ipgeolocation.io');
}

const ipgeolocationApi = new IPGeolocationAPI(GEOLOCATION_API_KEY, false);

const app = express();

const port = 3001;
Expand Down Expand Up @@ -382,11 +391,19 @@ if (fs.existsSync(geoipWhitelistFile)) {
}

function geoipLookup(ip) {
if (GEOLOCATION_API_KEY == '') {
return null;
}
if (geoipWhitelist[ip]) {
return geoipWhitelist[ip];
}

return geoip.lookup(ip);
return new Promise(resolve => {
const geolocationParams = new GeolocationParams();
geolocationParams.setIPAddress(ip);
ipgeolocationApi.getGeolocation(json => {
return resolve(json);
}, geolocationParams);
});
}

// DEPRECATED (should be unused, performed internally now)
Expand Down Expand Up @@ -609,8 +626,8 @@ async function getClusterInfo() {
}

let ip = tpu.split(':')[0];
const geoip = geoipLookup(ip);
let ll = geoip ? geoip.ll : null;
const geoip = await geoipLookup(ip);
let ll = geoip ? [geoip.latitude, geoip.longitude] : null;

// compute different but deterministic offsets
let offsetLat = randomOffset(ip);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"date-fns": "^2.6.0",
"express": "^4.17.1",
"express-ws": "^4.0.0",
"geoip-lite": "^1.3.8",
"google-map-react": "^1.1.5",
"http-proxy": "^1.18.0",
"humps": "^2.0.1",
"ip": "^1.1.5",
"ip-geolocation-api-javascript-sdk": "^1.0.7",
"localforage": "^1.7.3",
"lodash": "^4.17.15",
"material-table": "^1.52.0",
Expand Down
100 changes: 13 additions & 87 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2828,7 +2828,7 @@ async@^1.5.2:
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=

async@^2.1.1, async@^2.5.0:
async@^2.5.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.2.tgz#18330ea7e6e313887f5d2f2a904bac6fe4dd5381"
integrity sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==
Expand Down Expand Up @@ -3930,11 +3930,6 @@ btoa-lite@^1.0.0:
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
integrity sha1-M3dm2hWAEhD92VbCLpxokaudAzc=

buffer-crc32@~0.2.3:
version "0.2.13"
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
integrity sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
Expand Down Expand Up @@ -6907,13 +6902,6 @@ fbjs@^0.8.1:
setimmediate "^1.0.5"
ua-parser-js "^0.7.18"

fd-slicer@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e"
integrity sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=
dependencies:
pend "~1.2.0"

figgy-pudding@^3.0.0, figgy-pudding@^3.1.0, figgy-pudding@^3.4.1, figgy-pudding@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790"
Expand Down Expand Up @@ -7387,19 +7375,6 @@ gentle-fs@^2.0.0, gentle-fs@^2.0.1:
read-cmd-shim "^1.0.1"
slide "^1.1.6"

geoip-lite@^1.3.8:
version "1.3.8"
resolved "https://registry.yarnpkg.com/geoip-lite/-/geoip-lite-1.3.8.tgz#f065424f338faaf85e0016ec93c25fd1bb97f611"
integrity sha512-K0YNaQlHRjdLymVfDr47UEy+NTw40WLVmaAKy8lCzIrwWvuS764ZeIDlDofdApFWVbwU3HgJoU4oSIJvsA09bg==
dependencies:
async "^2.1.1"
colors "^1.1.2"
iconv-lite "^0.4.13"
ip-address "^5.8.9"
lazy "^1.0.11"
rimraf "^2.5.2"
yauzl "^2.9.2"

get-caller-file@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"
Expand Down Expand Up @@ -8120,7 +8095,7 @@ hyphenate-style-name@^1.0.3:
resolved "https://registry.yarnpkg.com/hyphenate-style-name/-/hyphenate-style-name-1.0.3.tgz#097bb7fa0b8f1a9cf0bd5c734cf95899981a9b48"
integrity sha512-EcuixamT82oplpoJ2XU4pDtKGWQ7b00CD9f1ug9IaQ3p1bkHMiKCZ9ut9QDI6qsa6cpUuB+A/I+zLtdNK4n2DQ==

[email protected], iconv-lite@^0.4.13, iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13:
[email protected], iconv-lite@^0.4.24, iconv-lite@^0.4.4, iconv-lite@~0.4.13:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
Expand Down Expand Up @@ -8401,18 +8376,12 @@ invert-kv@^2.0.0:
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02"
integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==

ip-address@^5.8.9:
version "5.9.0"
resolved "https://registry.yarnpkg.com/ip-address/-/ip-address-5.9.0.tgz#e501b3a0da9e31d9a14ef7ccdc05c5552c465954"
integrity sha512-+4yKpEyent8IpjuDQVkIpzIDbxSlCHTPdmaXCRLH0ttt3YsrbNxuZJ6h+1wLPx10T7gWsLN7M6BXIHV2vZNOGw==
ip-geolocation-api-javascript-sdk@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/ip-geolocation-api-javascript-sdk/-/ip-geolocation-api-javascript-sdk-1.0.7.tgz#ea1a89b35a784ce9bf34f88d6a0b5ed25ef8ebd2"
integrity sha512-yzJd2Fz5Wja/0dN1rj4E1ZUK2VO9MInVxV9NHUUXLsQhUla3FiwjHBlLHfVLYkRhf3rxvpNiGF0YLslpvIXMlw==
dependencies:
jsbn "1.1.0"
lodash.find "^4.6.0"
lodash.max "^4.0.1"
lodash.merge "^4.6.1"
lodash.padstart "^4.6.1"
lodash.repeat "^4.1.0"
sprintf-js "1.1.1"
xmlhttprequest "^1.8.0"

ip-regex@^2.1.0:
version "2.1.0"
Expand Down Expand Up @@ -9481,11 +9450,6 @@ js-yaml@^3.13.1:
argparse "^1.0.7"
esprima "^4.0.0"

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-1.1.0.tgz#b01307cb29b618a1ed26ec79e911f803c4da0040"
integrity sha1-sBMHyym2GKHtJux56RH4A8TaAEA=

jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
Expand Down Expand Up @@ -9834,11 +9798,6 @@ lazy-property@~1.0.0:
resolved "https://registry.yarnpkg.com/lazy-property/-/lazy-property-1.0.0.tgz#84ddc4b370679ba8bd4cdcfa4c06b43d57111147"
integrity sha1-hN3Es3Bnm6i9TNz6TAa0PVcREUc=

lazy@^1.0.11:
version "1.0.11"
resolved "https://registry.yarnpkg.com/lazy/-/lazy-1.0.11.tgz#daa068206282542c088288e975c297c1ae77b690"
integrity sha1-2qBoIGKCVCwIgojpdcKXwa53tpA=

lcid@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835"
Expand Down Expand Up @@ -10144,11 +10103,6 @@ lodash.filter@^4.4.0:
resolved "https://registry.yarnpkg.com/lodash.filter/-/lodash.filter-4.6.0.tgz#668b1d4981603ae1cc5a6fa760143e480b4c4ace"
integrity sha1-ZosdSYFgOuHMWm+nYBQ+SAtMSs4=

lodash.find@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1"
integrity sha1-ywcE1Hq3F4n/oN6Ll92Sb7iLE7E=

lodash.flatten@^4.2.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
Expand Down Expand Up @@ -10184,26 +10138,16 @@ lodash.map@^4.4.0:
resolved "https://registry.yarnpkg.com/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3"
integrity sha1-dx7Hg540c9nEzeKLGTlMNWL09tM=

lodash.max@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.max/-/lodash.max-4.0.1.tgz#8735566c618b35a9f760520b487ae79658af136a"
integrity sha1-hzVWbGGLNan3YFILSHrnllivE2o=

lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.merge@^4.4.0, lodash.merge@^4.6.1:
lodash.merge@^4.4.0:
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==

lodash.padstart@^4.6.1:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.padstart/-/lodash.padstart-4.6.1.tgz#d2e3eebff0d9d39ad50f5cbd1b52a7bce6bb611b"
integrity sha1-0uPuv/DZ05rVD1y9G1KnvOa7YRs=

lodash.pick@^4.2.1:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"
Expand All @@ -10219,11 +10163,6 @@ lodash.reject@^4.4.0:
resolved "https://registry.yarnpkg.com/lodash.reject/-/lodash.reject-4.6.0.tgz#80d6492dc1470864bbf583533b651f42a9f52415"
integrity sha1-gNZJLcFHCGS79YNTO2UfQqn1JBU=

lodash.repeat@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/lodash.repeat/-/lodash.repeat-4.1.0.tgz#fc7de8131d8c8ac07e4b49f74ffe829d1f2bec44"
integrity sha1-/H3oEx2MisB+S0n3T/6CnR8r7EQ=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
Expand Down Expand Up @@ -12274,11 +12213,6 @@ pem@^1.14.3:
os-tmpdir "^1.0.1"
which "^1.3.1"

pend@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"
integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA=

performance-now@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5"
Expand Down Expand Up @@ -15188,11 +15122,6 @@ split@^1.0.0:
dependencies:
through "2"

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.1.tgz#36be78320afe5801f6cea3ee78b6e5aab940ea0c"
integrity sha1-Nr54Mgr+WAH2zqPueLblqrlA6gw=

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
Expand Down Expand Up @@ -16850,6 +16779,11 @@ xmlchars@^1.3.1:
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-1.3.1.tgz#1dda035f833dbb4f86a0c28eaa6ca769214793cf"
integrity sha512-tGkGJkN8XqCod7OT+EvGYK5Z4SfDQGD30zAa58OcnAa0RRWgzUEK72tkXhsX1FZd+rgnhRxFtmO+ihkp8LHSkw==

xmlhttprequest@^1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc"
integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=

[email protected]:
version "4.0.0"
resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-4.0.0.tgz#e698189de49dd2a18cc5687b05e17c8e43943020"
Expand Down Expand Up @@ -17011,11 +16945,3 @@ yargs@^14.0.0, yargs@^14.2.0:
which-module "^2.0.0"
y18n "^4.0.0"
yargs-parser "^15.0.0"

yauzl@^2.9.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"
integrity sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=
dependencies:
buffer-crc32 "~0.2.3"
fd-slicer "~1.1.0"

0 comments on commit 29899fb

Please sign in to comment.