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

export const oracle = async () => {
  const { data } = await axios.get(
    "https://docs.oracle.com/en-us/iaas/tools/public_ip_ranges.json"
  );

  const ips = _.flatten(
    data.regions.map(({ cidrs }) => cidrs.map(({ cidr }) => cidr))
  );
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
  await fs.promises.writeFile(
    path.join(__dirname, "../ip_ranges/ORACLE.json"),
    JSON.stringify({
      NN: ips.map((prefix) => ({ prefix })),
    })
  );
};
