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

export const azure = async () => {
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
  const { data } = await axios.get(
    "https://download.microsoft.com/download/7/1/D/71D86715-5596-4529-9B13-DA13A5DE5B63/ServiceTags_Public_20240513.json"
  );
  const ips = _.flatten(
    data.values.map(({ properties }) => properties.addressPrefixes)
  );
  await fs.promises.writeFile(
    path.join(__dirname, "../ip_ranges/AZURE.json"),
    JSON.stringify({
      NN: ips.map((prefix) => ({ prefix })),
    })
  );
};

// (async () => console.log(await azure()))();
