2023-10-19 11:45:50 +00:00
|
|
|
import { boolean, object, SchemaOf, string } from 'yup';
|
|
|
|
|
|
|
|
import { validationSchema as accessControlSchema } from '@/react/portainer/access-control/AccessControlForm/AccessControlForm.validation';
|
|
|
|
|
|
|
|
import { imageConfigValidation } from '@@/ImageConfigFieldset';
|
|
|
|
|
|
|
|
import { Values } from './BaseForm';
|
|
|
|
import { validationSchema as portsSchema } from './PortsMappingField.validation';
|
|
|
|
|
|
|
|
export function validation(
|
|
|
|
{
|
|
|
|
isAdmin,
|
|
|
|
isDuplicating,
|
|
|
|
isDuplicatingPortainer,
|
|
|
|
isDockerhubRateLimited,
|
|
|
|
}: {
|
|
|
|
isAdmin: boolean;
|
|
|
|
isDuplicating: boolean | undefined;
|
|
|
|
isDuplicatingPortainer: boolean | undefined;
|
|
|
|
isDockerhubRateLimited: boolean;
|
|
|
|
} = {
|
|
|
|
isAdmin: false,
|
|
|
|
isDuplicating: false,
|
|
|
|
isDuplicatingPortainer: false,
|
|
|
|
isDockerhubRateLimited: false,
|
|
|
|
}
|
|
|
|
): SchemaOf<Values> {
|
|
|
|
return object({
|
|
|
|
name: string()
|
|
|
|
.default('')
|
|
|
|
.test('not-duplicate-portainer', () => !isDuplicatingPortainer),
|
2023-11-15 19:50:23 +00:00
|
|
|
alwaysPull: boolean()
|
|
|
|
.default(true)
|
|
|
|
.test('rate-limits', 'Rate limit exceeded', (alwaysPull: boolean) =>
|
|
|
|
alwaysPull ? !isDockerhubRateLimited : true
|
|
|
|
),
|
2023-10-19 11:45:50 +00:00
|
|
|
accessControl: accessControlSchema(isAdmin),
|
|
|
|
autoRemove: boolean().default(false),
|
|
|
|
enableWebhook: boolean().default(false),
|
|
|
|
nodeName: string().default(''),
|
|
|
|
ports: portsSchema(),
|
|
|
|
publishAllPorts: boolean().default(false),
|
2023-11-15 19:50:23 +00:00
|
|
|
image: imageConfigValidation().test(
|
2023-10-19 11:45:50 +00:00
|
|
|
'duplicate-must-have-registry',
|
|
|
|
'Duplicate is only possible when registry is selected',
|
|
|
|
(value) => !isDuplicating || typeof value.registryId !== 'undefined'
|
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|