2022-09-21 04:49:42 +00:00
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
2022-10-23 06:53:25 +00:00
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
2022-09-21 04:49:42 +00:00
|
|
|
|
|
|
|
import { Namespaces } from './types';
|
|
|
|
|
|
|
|
export async function getNamespace(
|
|
|
|
environmentId: EnvironmentId,
|
|
|
|
namespace: string
|
|
|
|
) {
|
|
|
|
try {
|
2022-10-27 03:14:54 +00:00
|
|
|
const { data: ns } = await axios.get<Namespaces>(
|
2022-09-21 04:49:42 +00:00
|
|
|
buildUrl(environmentId, namespace)
|
|
|
|
);
|
2022-10-27 03:14:54 +00:00
|
|
|
return ns;
|
2022-09-21 04:49:42 +00:00
|
|
|
} catch (e) {
|
2022-10-27 03:14:54 +00:00
|
|
|
throw parseAxiosError(e as Error, 'Unable to retrieve namespace');
|
2022-09-21 04:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getNamespaces(environmentId: EnvironmentId) {
|
|
|
|
try {
|
2022-10-27 03:14:54 +00:00
|
|
|
const { data: namespaces } = await axios.get<Namespaces>(
|
2022-09-21 04:49:42 +00:00
|
|
|
buildUrl(environmentId)
|
|
|
|
);
|
2022-10-27 03:14:54 +00:00
|
|
|
return namespaces;
|
2022-09-21 04:49:42 +00:00
|
|
|
} catch (e) {
|
2022-10-27 03:14:54 +00:00
|
|
|
throw parseAxiosError(e as Error, 'Unable to retrieve namespaces');
|
2022-09-21 04:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildUrl(environmentId: EnvironmentId, namespace?: string) {
|
|
|
|
let url = `kubernetes/${environmentId}/namespaces`;
|
|
|
|
|
|
|
|
if (namespace) {
|
|
|
|
url += `/${namespace}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|