1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

migrate ASN detail to caida, since bgpview no longer supports CORS headers [skip ci]

This commit is contained in:
checktheroads
2021-01-01 01:34:42 -07:00
parent c9c6f39226
commit 472a382f76
5 changed files with 22 additions and 33 deletions

View File

@@ -57,8 +57,8 @@ const ASNode = (props: TNode<TNodeData>) => {
<Box h={2} w={24}>
<SkeletonText noOfLines={1} color={color} />
</Box>
) : !isError && asnData?.data?.description_short ? (
asnData.data.description_short
) : !isError && asnData?.data?.asn.organization?.orgName ? (
asnData.data.asn.organization.orgName
) : (
name
)}

View File

@@ -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<TASNDetails> {
async function query(ctx: TUseASNDetailFn): Promise<TASNQuery> {
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, {

View File

@@ -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;
}

View File

@@ -0,0 +1,9 @@
export interface TASNQuery {
data: {
asn: {
organization: {
orgName: string;
} | null;
};
};
}

View File

@@ -1,4 +1,4 @@
export * from './bgpview';
export * from './caida';
export * from './common';
export * from './config';
export * from './data';