1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 15:59:41 +02:00

refactor(docker): move components to react [EE-3348] (#7084)

This commit is contained in:
Chaim Lev-Ari 2022-06-26 17:16:50 +03:00 committed by GitHub
parent 7238372d8d
commit 46e1a01625
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 61 additions and 76 deletions

View file

@ -0,0 +1,129 @@
import { EnvironmentId } from '@/portainer/environments/types';
import PortainerError from '@/portainer/error';
import axios from '@/portainer/services/axios';
import { genericHandler } from '@/docker/rest/response/handlers';
import { NetworkId } from '../networks/types';
import { ContainerId, DockerContainer } from './types';
export interface Filters {
label?: string[];
network?: NetworkId[];
}
export async function startContainer(
endpointId: EnvironmentId,
id: ContainerId
) {
await axios.post<void>(
urlBuilder(endpointId, id, 'start'),
{},
{ transformResponse: genericHandler }
);
}
export async function stopContainer(
endpointId: EnvironmentId,
id: ContainerId
) {
await axios.post<void>(urlBuilder(endpointId, id, 'stop'), {});
}
export async function restartContainer(
endpointId: EnvironmentId,
id: ContainerId
) {
await axios.post<void>(urlBuilder(endpointId, id, 'restart'), {});
}
export async function killContainer(
endpointId: EnvironmentId,
id: ContainerId
) {
await axios.post<void>(urlBuilder(endpointId, id, 'kill'), {});
}
export async function pauseContainer(
endpointId: EnvironmentId,
id: ContainerId
) {
await axios.post<void>(urlBuilder(endpointId, id, 'pause'), {});
}
export async function resumeContainer(
endpointId: EnvironmentId,
id: ContainerId
) {
await axios.post<void>(urlBuilder(endpointId, id, 'unpause'), {});
}
export async function renameContainer(
endpointId: EnvironmentId,
id: ContainerId,
name: string
) {
await axios.post<void>(
urlBuilder(endpointId, id, 'rename'),
{},
{ params: { name }, transformResponse: genericHandler }
);
}
export async function removeContainer(
endpointId: EnvironmentId,
container: DockerContainer,
removeVolumes: boolean
) {
try {
const { data } = await axios.delete<null | { message: string }>(
urlBuilder(endpointId, container.Id),
{
params: { v: removeVolumes ? 1 : 0, force: true },
transformResponse: genericHandler,
}
);
if (data && data.message) {
throw new PortainerError(data.message);
}
} catch (e) {
throw new PortainerError('Unable to remove container', e as Error);
}
}
export async function getContainers(
environmentId: EnvironmentId,
filters?: Filters
) {
try {
const { data } = await axios.get<DockerContainer[]>(
urlBuilder(environmentId, '', 'json'),
{
params: { all: 0, filters },
}
);
return data;
} catch (e) {
throw new PortainerError('Unable to retrieve containers', e as Error);
}
}
function urlBuilder(
endpointId: EnvironmentId,
id?: ContainerId,
action?: string
) {
let url = `/endpoints/${endpointId}/docker/containers`;
if (id) {
url += `/${id}`;
}
if (action) {
url += `/${action}`;
}
return url;
}