import axios from "axios";
import fs from "fs";
import { fileURLToPath } from "url";
import path from "path";

export const aws = async () => {
  const { data } = await axios.get(
    "https://ip-ranges.amazonaws.com/ip-ranges.json"
  );
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
  await fs.promises.writeFile(
    path.join(__dirname, "../ip_ranges/AWS.json"),
    JSON.stringify({
      NN: [
        ...data.prefixes.map(({ ip_prefix }) => ip_prefix),
        ...data.ipv6_prefixes.map(({ ipv6_prefix }) => ipv6_prefix),
      ].map((prefix) => ({ prefix })),
    })
  );
};

// (async () => await aws())();
