2023-09-07 14:19:03 +00:00
|
|
|
import { Node } from 'docker-types/generated/1.41';
|
|
|
|
import { useQuery } from 'react-query';
|
|
|
|
|
|
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
|
|
|
2024-10-08 15:13:14 +00:00
|
|
|
import { buildDockerProxyUrl } from '../buildDockerProxyUrl';
|
|
|
|
|
2023-09-07 14:19:03 +00:00
|
|
|
import { queryKeys } from './query-keys';
|
|
|
|
|
|
|
|
export function useNodes(environmentId: EnvironmentId) {
|
|
|
|
return useQuery(queryKeys.base(environmentId), () => getNodes(environmentId));
|
|
|
|
}
|
|
|
|
|
2024-10-08 15:13:14 +00:00
|
|
|
/**
|
|
|
|
* Raw docker API proxy
|
|
|
|
* @param environmentId
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export async function getNodes(environmentId: EnvironmentId) {
|
2023-09-07 14:19:03 +00:00
|
|
|
try {
|
2024-10-08 15:13:14 +00:00
|
|
|
const { data } = await axios.get<Array<Node>>(
|
|
|
|
buildDockerProxyUrl(environmentId, 'nodes')
|
|
|
|
);
|
2023-09-07 14:19:03 +00:00
|
|
|
return data;
|
|
|
|
} catch (error) {
|
|
|
|
throw parseAxiosError(error, 'Unable to retrieve nodes');
|
|
|
|
}
|
|
|
|
}
|