@@ -3,6 +3,8 @@ import { Address4, Address6 } from 'ip-address';
3
3
import isCIDR from 'is-cidr' ;
4
4
import { isInSubnet } from 'is-in-subnet' ;
5
5
import * as Yup from 'yup' ;
6
+ import { head } from 'lodash-es' ;
7
+ import parseUrl from 'parse-url' ;
6
8
7
9
import { TFunction } from 'i18next' ;
8
10
import {
@@ -27,7 +29,6 @@ import {
27
29
} from './constants' ;
28
30
import { allSubnetsIPv4 , getAddress , trimCommaSeparatedList , trimSshPublicKey } from './utils' ;
29
31
import { selectApiVip , selectIngressVip } from '../../../selectors' ;
30
- import { head } from 'lodash-es' ;
31
32
import { ClusterDetailsValues } from '../../clusterWizard/types' ;
32
33
33
34
const ALPHANUMERIC_REGEX = / ^ [ a - z A - Z 0 - 9 ] + $ / ;
@@ -45,10 +46,6 @@ const IP_V4_ZERO = '0.0.0.0';
45
46
const IP_V6_ZERO = '0000:0000:0000:0000:0000:0000:0000:0000' ;
46
47
const MAC_REGEX = / ^ ( [ 0 - 9 A - F a - f ] { 2 } [: ] ) { 5 } ( [ 0 - 9 A - F a - f ] { 2 } ) $ / ;
47
48
const HOST_NAME_REGEX = / ^ [ ^ . ] { 1 , 63 } (?: [ . ] [ ^ . ] { 1 , 63 } ) * $ / ;
48
-
49
- // Source of information: https://github.com/metal3-io/baremetal-operator/blob/main/docs/api.md#baremetalhost-spec
50
- const BMC_REGEX =
51
- / ^ ( ( r e d f i s h - v i r t u a l m e d i a | i d r a c - v i r t u a l m e d i a ) ( \+ h t t p s ? ) ? : ( \/ \/ ( [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = ] + @ ) ? ( [ a - z 0 - 9 \- . _ ~ % ] + | \[ [ a - f 0 - 9 : . ] + \] | \[ v [ a - f 0 - 9 ] [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : ] + \] ) ( : [ 0 - 9 ] + ) ? ( \/ [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : @ ] + ) * \/ ? | ( \/ ? [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : @ ] + ( \/ [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : @ ] + ) * \/ ? ) ? ) | ( [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = @ ] + ( \/ [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : @ ] + ) * \/ ? | ( \/ [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : @ ] + ) + \/ ? ) ) ( \? [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : @ / ? ] * ) ? ( # [ a - z 0 - 9 \- . _ ~ % ! $ & ' ( ) * + , ; = : @ / ? ] * ) ? $ / i;
52
49
const LOCATION_CHARS_REGEX = / ^ [ a - z A - Z 0 - 9 - ._ ] * $ / ;
53
50
54
51
export const nameValidationSchema = (
@@ -643,10 +640,16 @@ export const day2ApiVipValidationSchema = Yup.string().test(
643
640
export const bmcAddressValidationSchema = ( t : TFunction ) => {
644
641
const bmcAddressValidationMessagesList = bmcAddressValidationMessages ( t ) ;
645
642
646
- return Yup . string ( ) . required ( ) . matches ( BMC_REGEX , {
647
- message : bmcAddressValidationMessagesList . INVALID_VALUE ,
648
- excludeEmptyString : true ,
649
- } ) ;
643
+ return Yup . string ( )
644
+ . required ( )
645
+ . test ( 'valid-bmc-address' , bmcAddressValidationMessagesList . INVALID_VALUE , ( val ) => {
646
+ try {
647
+ const url = parseUrl ( val ) ;
648
+ return [ 'redfish-virtualmedia' , 'idrac-virtualmedia' ] . includes ( url . protocol as string ) ;
649
+ } catch ( error ) {
650
+ return false ;
651
+ }
652
+ } ) ;
650
653
} ;
651
654
export const locationValidationSchema = ( t : TFunction ) => {
652
655
const locationValidationMessagesList = locationValidationMessages ( t ) ;
0 commit comments