2024-01-03 08:17:54 +13:00
import { SchemaOf , array , bool , object , string } from 'yup' ;
import { EnvVar } from '@@/form-components/EnvironmentVariablesFieldset/types' ;
import { buildUniquenessTest } from '@@/form-components/validate-unique' ;
export function kubeEnvVarValidationSchema ( ) : SchemaOf < EnvVar [ ] > {
return array (
object ( {
name : string ( )
2024-01-15 10:56:53 +13:00
. required ( 'Environment variable name is required' )
2024-01-03 08:17:54 +13:00
. matches (
/^[a-zA-Z][a-zA-Z0-9_.-]*$/ ,
2024-01-15 10:56:53 +13:00
` This field must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name', or 'MY_ENV.NAME', or 'MyEnvName1' `
2024-01-03 08:17:54 +13:00
) ,
value : string ( ) . default ( '' ) ,
needsDeletion : bool ( ) . default ( false ) ,
2024-01-17 10:13:53 +13:00
isNew : bool ( ) . default ( false ) ,
2024-01-03 08:17:54 +13:00
} )
) . test (
'unique' ,
2024-01-15 10:56:53 +13:00
'This environment variable is already defined' ,
2024-01-03 08:17:54 +13:00
buildUniquenessTest (
2024-01-15 10:56:53 +13:00
( ) = > 'This environment variable is already defined' ,
2024-01-03 08:17:54 +13:00
'name'
)
) ;
}