import { ApplicationNameValidator } from '@spinnaker/core' ; export class KubernetesApplicationNameValidator { private static MAX_RESOURCE_NAME_LENGTH = 63 ; private static validateSpecialCharacters ( name , errors ) { const alphanumWithDashPattern = /^([a-zA-Z][a-zA-Z0-9-]*)?$/ ; if ( ! alphanumWithDashPattern . test ( name ) ) { errors . push ( 'The application name must begin with a letter and must contain only letters, digits, or dashes. ' + 'No special characters are allowed.' ) ; } } private static validateLength ( name , errors ) { if ( name . length > KubernetesApplicationNameValidator . MAX_RESOURCE_NAME_LENGTH ) { errors . push ( `The maximum length for an application in Kubernetes is ${ KubernetesApplicationNameValidator . MAX_RESOURCE_NAME_LENGTH } characters.` ) ; } } public validate ( name = '' ) { const warnings = [ ] ; const errors = [ ] ; if ( name && name . length ) { KubernetesApplicationNameValidator . validateSpecialCharacters ( name , errors ) ; KubernetesApplicationNameValidator . validateLength ( name , errors ) ; } return { warnings , errors , } ; } } ApplicationNameValidator . registerValidator ( 'kubernetes' , new KubernetesApplicationNameValidator ( ) ) ;