From 472a382f761468f935380cecee091782571a05f9 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Fri, 1 Jan 2021 01:34:42 -0700 Subject: [PATCH] migrate ASN detail to caida, since bgpview no longer supports CORS headers [skip ci] --- hyperglass/ui/components/path/chart.tsx | 4 ++-- hyperglass/ui/hooks/useASNDetail.ts | 14 +++++++++---- hyperglass/ui/types/bgpview.ts | 26 ------------------------- hyperglass/ui/types/caida.ts | 9 +++++++++ hyperglass/ui/types/index.ts | 2 +- 5 files changed, 22 insertions(+), 33 deletions(-) delete mode 100644 hyperglass/ui/types/bgpview.ts create mode 100644 hyperglass/ui/types/caida.ts diff --git a/hyperglass/ui/components/path/chart.tsx b/hyperglass/ui/components/path/chart.tsx index 1df6a94..23020ab 100644 --- a/hyperglass/ui/components/path/chart.tsx +++ b/hyperglass/ui/components/path/chart.tsx @@ -57,8 +57,8 @@ const ASNode = (props: TNode) => { - ) : !isError && asnData?.data?.description_short ? ( - asnData.data.description_short + ) : !isError && asnData?.data?.asn.organization?.orgName ? ( + asnData.data.asn.organization.orgName ) : ( name )} diff --git a/hyperglass/ui/hooks/useASNDetail.ts b/hyperglass/ui/hooks/useASNDetail.ts index 5cddede..a7764d2 100644 --- a/hyperglass/ui/hooks/useASNDetail.ts +++ b/hyperglass/ui/hooks/useASNDetail.ts @@ -1,16 +1,22 @@ import { useQuery } from 'react-query'; -import type { TASNDetails } from '~/types'; +import type { TASNQuery } from '~/types'; import type { TUseASNDetailFn } from './types'; -async function query(ctx: TUseASNDetailFn): Promise { +async function query(ctx: TUseASNDetailFn): Promise { const [asn] = ctx.queryKey; - const res = await fetch(`https://api.bgpview.io/asn/${asn}`, { mode: 'cors' }); + const res = await fetch('https://api.asrank.caida.org/v2/graphql', { + mode: 'cors', + method: 'POST', + headers: { 'content-type': 'application/json' }, + body: JSON.stringify({ query: `{ asn(asn:\"${asn}\"){ organization { orgName } } }` }), + }); return await res.json(); } /** - * Query the bgpview.io API to get an ASN's organization name for the AS Path component. + * Query the Caida AS Rank API to get an ASN's organization name for the AS Path component. + * @see https://api.asrank.caida.org/v2/docs */ export function useASNDetail(asn: string) { return useQuery(asn, query, { diff --git a/hyperglass/ui/types/bgpview.ts b/hyperglass/ui/types/bgpview.ts deleted file mode 100644 index effc2f3..0000000 --- a/hyperglass/ui/types/bgpview.ts +++ /dev/null @@ -1,26 +0,0 @@ -interface TASNRIRAllocation { - rir_name: string | null; - country_code: string | null; - date_allocated: string | null; -} -interface TASNData { - asn: number; - name: string | null; - description_short: string | null; - description_full: string[]; - country_code: string; - website: string | null; - email_contacts: string[]; - abuse_contacts: string[]; - looking_glass: string | null; - traffic_estimation: string | null; - traffic_ratio: string | null; - owner_address: string[]; - rir_allocation: TASNRIRAllocation; - date_updated: string | null; -} -export interface TASNDetails { - status: string; - status_message: string; - data: TASNData; -} diff --git a/hyperglass/ui/types/caida.ts b/hyperglass/ui/types/caida.ts new file mode 100644 index 0000000..accd0a7 --- /dev/null +++ b/hyperglass/ui/types/caida.ts @@ -0,0 +1,9 @@ +export interface TASNQuery { + data: { + asn: { + organization: { + orgName: string; + } | null; + }; + }; +} diff --git a/hyperglass/ui/types/index.ts b/hyperglass/ui/types/index.ts index deb4caf..637512e 100644 --- a/hyperglass/ui/types/index.ts +++ b/hyperglass/ui/types/index.ts @@ -1,4 +1,4 @@ -export * from './bgpview'; +export * from './caida'; export * from './common'; export * from './config'; export * from './data';