type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get MOASes
* List all Multi-origin AS (MOAS) prefixes on the global routing tables.
*/
export async function main(
auth: Cloudflare,
origin: string | undefined,
prefix: string | undefined,
invalid_only: string | undefined,
format: "JSON" | "CSV" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/radar/bgp/routes/moas`
);
for (const [k, v] of [
["origin", origin],
["prefix", prefix],
["invalid_only", invalid_only],
["format", format],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get MOASes
* List all Multi-origin AS (MOAS) prefixes on the global routing tables.
*/
export async function main(
auth: Cloudflare,
origin: string | undefined,
prefix: string | undefined,
invalid_only: string | undefined,
format: "JSON" | "CSV" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/radar/bgp/routes/moas`
);
for (const [k, v] of [
["origin", origin],
["prefix", prefix],
["invalid_only", invalid_only],
["format", format],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago