mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
feat(edge/templates): introduce custom templates [EE-6208] (#10561)
This commit is contained in:
parent
a0f583a17d
commit
68950fbb24
81 changed files with 2047 additions and 334 deletions
|
@ -0,0 +1,92 @@
|
|||
import { useMutation, useQueryClient } from 'react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import {
|
||||
mutationOptions,
|
||||
withGlobalError,
|
||||
withInvalidate,
|
||||
} from '@/react-tools/react-query';
|
||||
import { StackType } from '@/react/common/stacks/types';
|
||||
import { VariableDefinition } from '@/react/portainer/custom-templates/components/CustomTemplatesVariablesDefinitionField/CustomTemplatesVariablesDefinitionField';
|
||||
|
||||
import { CustomTemplate } from '../types';
|
||||
import { Platform } from '../../types';
|
||||
|
||||
import { buildUrl } from './build-url';
|
||||
|
||||
export function useUpdateTemplateMutation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
updateTemplate,
|
||||
mutationOptions(
|
||||
withInvalidate(queryClient, [['custom-templates']]),
|
||||
withGlobalError('Failed to update template')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload for updating a custom template
|
||||
*/
|
||||
interface CustomTemplateUpdatePayload {
|
||||
/** URL of the template's logo */
|
||||
Logo?: string;
|
||||
/** Title of the template */
|
||||
Title: string;
|
||||
/** Description of the template */
|
||||
Description: string;
|
||||
/** A note that will be displayed in the UI. Supports HTML content */
|
||||
Note?: string;
|
||||
/**
|
||||
* Platform associated to the template.
|
||||
* Required for Docker stacks
|
||||
*/
|
||||
Platform?: Platform;
|
||||
/**
|
||||
* Type of created stack
|
||||
* Required
|
||||
*/
|
||||
Type: StackType;
|
||||
/** URL of a Git repository hosting the Stack file */
|
||||
RepositoryURL?: string;
|
||||
/** Reference name of a Git repository hosting the Stack file */
|
||||
RepositoryReferenceName?: string;
|
||||
/** Use basic authentication to clone the Git repository */
|
||||
RepositoryAuthentication?: boolean;
|
||||
/** Username used in basic authentication. Required when RepositoryAuthentication is true */
|
||||
RepositoryUsername?: string;
|
||||
/** Password used in basic authentication. Required when RepositoryAuthentication is true */
|
||||
RepositoryPassword?: string;
|
||||
/**
|
||||
* GitCredentialID used to identify the bound git credential.
|
||||
* Required when RepositoryAuthentication is true and RepositoryUsername/RepositoryPassword are not provided
|
||||
*/
|
||||
RepositoryGitCredentialID?: number;
|
||||
/** Path to the Stack file inside the Git repository */
|
||||
ComposeFilePathInRepository?: string;
|
||||
/** Content of stack file */
|
||||
FileContent?: string;
|
||||
/** Definitions of variables in the stack file */
|
||||
Variables?: VariableDefinition[];
|
||||
/** TLSSkipVerify skips SSL verification when cloning the Git repository */
|
||||
TLSSkipVerify?: boolean;
|
||||
/** IsComposeFormat indicates if the Kubernetes template is created from a Docker Compose file */
|
||||
IsComposeFormat?: boolean;
|
||||
/** EdgeTemplate indicates if this template purpose for Edge Stack */
|
||||
EdgeTemplate?: boolean;
|
||||
}
|
||||
|
||||
async function updateTemplate(
|
||||
values: CustomTemplateUpdatePayload & { id: CustomTemplate['Id'] }
|
||||
) {
|
||||
try {
|
||||
const { data } = await axios.put<CustomTemplate>(
|
||||
buildUrl({ id: values.id }),
|
||||
values
|
||||
);
|
||||
return data;
|
||||
} catch (error) {
|
||||
throw parseAxiosError(error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue