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 { Configuration } from './types';
|
|
|
|
|
2023-03-07 22:22:08 +00:00
|
|
|
// returns the formatted list of configmaps and secrets
|
|
|
|
export async function getConfigurations(
|
2022-09-21 04:49:42 +00:00
|
|
|
environmentId: EnvironmentId,
|
|
|
|
namespace: string
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
const { data: configmaps } = await axios.get<Configuration[]>(
|
2023-05-09 04:42:26 +00:00
|
|
|
`kubernetes/${environmentId}/namespaces/${namespace}/configuration`
|
2022-09-21 04:49:42 +00:00
|
|
|
);
|
|
|
|
return configmaps;
|
|
|
|
} catch (e) {
|
|
|
|
throw parseAxiosError(e as Error, 'Unable to retrieve configmaps');
|
|
|
|
}
|
|
|
|
}
|
2023-03-07 22:22:08 +00:00
|
|
|
|
|
|
|
export async function getConfigMapsForCluster(
|
|
|
|
environmentId: EnvironmentId,
|
|
|
|
namespaces: string[]
|
|
|
|
) {
|
|
|
|
try {
|
|
|
|
const configmaps = await Promise.all(
|
|
|
|
namespaces.map((namespace) => getConfigurations(environmentId, namespace))
|
|
|
|
);
|
|
|
|
return configmaps.flat();
|
|
|
|
} catch (e) {
|
|
|
|
throw parseAxiosError(
|
|
|
|
e as Error,
|
|
|
|
'Unable to retrieve ConfigMaps for cluster'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|