import type { IApplicationNameValidator } from '@spinnaker/core' ; import { ApplicationNameValidator , FirewallLabels } from '@spinnaker/core' ; class TitusApplicationNameValidator implements IApplicationNameValidator { private validateSpecialCharacters ( name , errors ) { const pattern = /^[a-zA-Z_0-9.]*$/g ; if ( ! pattern . test ( name ) ) { errors . push ( 'Only dot(.) and underscore(_) special characters are allowed.' ) ; } } private validateLength ( name , warnings , errors ) { if ( name . length > 250 ) { errors . push ( 'The maximum length for an application in Titus is 250 characters.' ) ; return ; } if ( name . length > 240 ) { if ( name . length >= 248 ) { warnings . push ( `You will not be able to include a stack or detail field for clusters or ${ FirewallLabels . get ( 'firewalls' ) }.` ) ; } else { const remaining = 248 - name . length ; warnings . push ( `If you plan to include a stack or detail field for clusters, you will only
            have ~${ remaining } characters to do so.` ) ; } } } public validate ( name = '' ) { const warnings = [ ] ; const errors = [ ] ; if ( name && name . length ) { this . validateSpecialCharacters ( name , errors ) ; this . validateLength ( name , warnings , errors ) ; } return { warnings , errors } ; } } ApplicationNameValidator . registerValidator ( 'titus' , new TitusApplicationNameValidator ( ) ) ;