import axios from "axios";
import type { Ingress } from "~/classes/Ingress";

export function getIngresses(namespace: string | undefined, onSuccess: (ingresses: Ingress[]) => void)
{
    axios.get<Ingress[]>(ApiConfig.getHttpBase() + '/ingresses', {
        headers: {
            Authorization: "Bearer " + requireToken()
        },
        params: getParams(namespace)
    })
    .then(response => {
        onSuccess(response.data);
    })
    .catch();
}

function getParams(namespace: string | undefined)
{
    if(namespace != undefined)
    {
        return {
            namespace: namespace
        }
    }
    return undefined;
}