Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type Config = {
bonkMintAddress: string
solanaFeePayerWallets: Keypair[]
delegatePrivateKey: Buffer
ipdataApiKey: string | null
listensValidSigner: string
solanaSignerPrivateKey: string
identityRelayerPublicKey: string
Expand Down Expand Up @@ -136,10 +135,6 @@ const readConfig = (): Config => {
solana_relay_server_host: str({ default: '0.0.0.0' }),
solana_relay_server_port: num({ default: 6002 }),
audius_delegate_private_key: str({ default: '' }),
audius_ipdata_api_key: str({
// Throwaway test key
default: '01b633611c0b57babd56a6fdf7400b21340956e1840da6dd788f9c37'
}),
audius_solana_eth_registry_program: str({
default: 'testBgRfFcage1hN7zmTsktdQCJZkHEhM1eguYPaeKg'
}),
Expand Down Expand Up @@ -203,8 +198,6 @@ const readConfig = (): Config => {
bonkMintAddress: env.audius_solana_bonk_mint,
solanaFeePayerWallets,
delegatePrivateKey,
ipdataApiKey:
env.audius_ipdata_api_key === '' ? null : env.audius_ipdata_api_key,
listensValidSigner: env.audius_solana_listens_valid_signer,
ethRegistryProgramId: env.audius_solana_eth_registry_program,
solanaSignerPrivateKey: env.audius_solana_signer_private_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Request } from 'express'
import { Logger } from 'pino'
import { getClientIp } from 'request-ip'

import { config } from '../config'
import { logger } from '../logger'

export type LocationData = {
Expand All @@ -12,37 +11,21 @@ export type LocationData = {
country: string
} | null

// gets ip data from api.ipdata.co, returns an empty object {} if api key not configured or an error occurs
// gets ip data from a validator node
export const getIpData = async (
logger: Logger,
ip: string
): Promise<LocationData> => {
const ipdataApiKey = config.ipdataApiKey
if (ipdataApiKey === null) {
logger.warn({}, 'ip data requested but api key not configured')
return null
}
const url = `https://api.ipdata.co/${ip}?api-key=${ipdataApiKey}`
const url = `https://creatornode.audius.co/storage.v1.StorageService/GetIPData?ip=${ip}`
try {
const response = await axios
.get(url)
.then(
({
data: { city, region, country_name }
}: {
data: { city: string; region: string; country_name: string }
}) => {
return { city, region, country: country_name }
}
)
const { data: response } = await axios.get(url)
return response
} catch (e: unknown) {
logger.error({ error: e }, 'error requesting ip data')
return null
}
}

// gets ip data from api.ipdata.co, returns an empty object {} if api key not configured or an error occurs
export const getRequestIpData = async (
logger: Logger,
req: Request<unknown>
Expand Down
1 change: 0 additions & 1 deletion packages/identity-service/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"redisHost": "identity-redis",
"redisPort": 6379,
"logLevel": "debug",
"ipdataAPIKey": "",
"twitterAPIKey": "",
"twitterAPISecret": "",
"twitterBearerToken": "",
Expand Down
6 changes: 0 additions & 6 deletions packages/identity-service/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,6 @@ const config = convict({
env: 'hCaptchaSecret',
default: ''
},
ipdataAPIKey: {
doc: 'API Key for ipdata',
format: String,
env: 'ipdataAPIKey',
default: ''
},
plaidClientId: {
doc: 'Plaid client ID',
format: String,
Expand Down
46 changes: 39 additions & 7 deletions packages/identity-service/src/routes/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,39 @@ const {
const config = require('../config')
const { logger } = require('../logging')

const IP_API_KEY = config.get('ipdataAPIKey')
const isEU = (countryCode) => {
return [
'AT',
'BE',
'BG',
'HR',
'CY',
'CZ',
'DK',
'EE',
'FI',
'FR',
'DE',
'GR',
'HU',
'IE',
'IT',
'LV',
'LT',
'LU',
'MT',
'NL',
'PL',
'PT',
'RO',
'SK',
'SI',
'ES',
'SE',
'GB',
'UK'
].includes(countryCode)
}

module.exports = function (app) {
app.get(
Expand All @@ -22,16 +54,16 @@ module.exports = function (app) {
if (ip.startsWith('::ffff:')) {
ip = ip.slice(7)
}
const url = `https://api.ipdata.co/${ip}`
const url = `https://creatornode.audius.co/storage.v1.StorageService/GetIPData?ip=${ip}`
try {
const res = await axios({
method: 'get',
url,
params: {
'api-key': IP_API_KEY
}
url
})
return successResponse({
...res.data,
in_eu: isEU(res.data.countryCode)
})
return successResponse({ ...res.data, in_eu: res.data.is_eu })
} catch (e) {
logger.error(`Got error in location: ${e.response?.data}`)
return errorResponse(e.response?.status, e.response?.data)
Expand Down
11 changes: 2 additions & 9 deletions packages/identity-service/src/routes/trackListens.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,9 @@ module.exports = function (app) {
)
let location
try {
const url = `https://api.ipdata.co/${ip}?api-key=${config.get(
'ipdataAPIKey'
)}`
const url = `https://creatornode.audius.co/storage.v1.StorageService/GetIPData?ip=${ip}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit, and maybe not, but do we want to move the host to an env for easy changing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry a bit b/c identity runs on the old infra stack that we lose track of the env var. have thoughts on consolidating identity into the k8s stack and at that point, i think i'd go through and move a bunch of things to env (and remove others!)


const locationResponse = (await axios.get(url)).data
location = {
city: locationResponse.city,
region: locationResponse.region,
country: locationResponse.country_name
}
const location = (await axios.get(url)).data
} catch (e) {
req.logger.error(
`TrackListen location fetch failed: ${e}, trackId=${trackId} userId=${userId}, ${JSON.stringify(
Expand Down
9 changes: 1 addition & 8 deletions packages/identity-service/src/solana-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,11 @@ async function createTrackListenInstructions({
accInfo.data.toJSON().data.slice(1, 33)
) // cut off version and eth address from valid signer data

let sourceData
if (config.get('ipdataAPIKey')) {
sourceData = JSON.stringify({ source, location })
} else {
sourceData = source
}

// max sol tx size is 1232 bytes
const trackData = new TrackData({
userId,
trackId,
source: sourceData, // use api key as feature flag
source,
timestamp:
(await getListenTimestamp(connection)) ||
Math.round(new Date().getTime() / 1000)
Expand Down