add pdb
continuous-integration/drone/push Build is passing Details

This commit is contained in:
186526 2023-03-05 16:00:45 +08:00
parent 3e5b318cbe
commit 20433ae2d4
3 changed files with 34 additions and 7 deletions

View File

@ -16,6 +16,8 @@ steps:
environment:
RIPE_PASSWORD:
from_secret: ripe_password
PDB_TOKEN:
from_secret: pdb_token
commands:
- apk add bgpq4 --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing
- yarn

View File

@ -1,6 +1,7 @@
import bgpq4 from "./bgpq4";
import fs from "node:fs";
import YAML from "yaml";
import { getNetName } from "./pdb";
import axios from "axios";
import { env } from "node:process";
@ -86,18 +87,26 @@ const main = async () => {
i++;
console.log("");
}
const answer = asSets.map((k) => {
return `as-set: ${k["AS-SET"]}
const answer = await Promise.all(
asSets.map(
async (k) =>
`
as-set: ${k["AS-SET"]}
${k["MNT-BY"].map((k) => `mnt-by: ${k}`).join("\n")}
${k["TECH-C"].map((k) => `tech-c: ${k}`).join("\n")}
${k["ADMIN-C"].map((k) => `admin-c: ${k}`).join("\n")}
${k.remarks.map((k) => `remarks: ${k}`).join("\n")}
${k.members.map((k) => `members: AS${k}`).join("\n")}${k.include.map(
(k) => `\nmembers: ${k}`
)}
${(
await Promise.all(
k.members.map(
async (k) => `remarks: ${await getNetName(k)}\nmembers: AS${k}`
)
)
).join("\n")}${k.include.map((k) => `\nmembers: ${k}`)}
source: RIPE\npassword: ${env["RIPE_PASSWORD"]}\n
`;
});
`
)
);
console.log("INFO: sending update to RIPE Syncupdates...");
const update = await axios.post(
"https://syncupdates.db.ripe.net",

16
src/pdb.ts Normal file
View File

@ -0,0 +1,16 @@
import axios from "axios";
import { env } from "node:process";
const list = axios.get("https://www.peeringdb.com/api/net",{
headers: {
"User-Agent": "NET186-AS-SET/1.0.0",
"Authorization": `Api-Key ${env.PDB_TOKEN}`,
"Content-Type": "application/json"
}
});
export const getNetName = async (ASN: number): Promise<string> => {
const answer = (await list).data;
return (answer.data.find((k: any) => k.asn === ASN) ?? { name: `AS${ASN}` })
.name;
};