Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACM-17263: Add a host using BMC form should have a validation for BMC address #2776

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Address4, Address6 } from 'ip-address';
import isCIDR from 'is-cidr';
import { isInSubnet } from 'is-in-subnet';
import * as Yup from 'yup';
import { head } from 'lodash-es';
import parseUrl from 'parse-url';

import { TFunction } from 'i18next';
import {
Expand All @@ -27,7 +29,6 @@ import {
} from './constants';
import { allSubnetsIPv4, getAddress, trimCommaSeparatedList, trimSshPublicKey } from './utils';
import { selectApiVip, selectIngressVip } from '../../../selectors';
import { head } from 'lodash-es';
import { ClusterDetailsValues } from '../../clusterWizard/types';

const ALPHANUMERIC_REGEX = /^[a-zA-Z0-9]+$/;
Expand All @@ -45,10 +46,6 @@ const IP_V4_ZERO = '0.0.0.0';
const IP_V6_ZERO = '0000:0000:0000:0000:0000:0000:0000:0000';
const MAC_REGEX = /^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$/;
const HOST_NAME_REGEX = /^[^.]{1,63}(?:[.][^.]{1,63})*$/;

// Source of information: https://github.com/metal3-io/baremetal-operator/blob/main/docs/api.md#baremetalhost-spec
const BMC_REGEX =
/^((redfish-virtualmedia|idrac-virtualmedia)(\+https?)?:(\/\/([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?|(\/?[a-z0-9\-._~%!$&'()*+,;=:@]+(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?)?)|([a-z0-9\-._~%!$&'()*+,;=@]+(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?|(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)+\/?))(\?[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?(#[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?$/i;
const LOCATION_CHARS_REGEX = /^[a-zA-Z0-9-._]*$/;

export const nameValidationSchema = (
Expand Down Expand Up @@ -643,10 +640,16 @@ export const day2ApiVipValidationSchema = Yup.string().test(
export const bmcAddressValidationSchema = (t: TFunction) => {
const bmcAddressValidationMessagesList = bmcAddressValidationMessages(t);

return Yup.string().required().matches(BMC_REGEX, {
message: bmcAddressValidationMessagesList.INVALID_VALUE,
excludeEmptyString: true,
});
return Yup.string()
.required()
.test('valid-bmc-address', bmcAddressValidationMessagesList.INVALID_VALUE, (val) => {
try {
const url = parseUrl(val);
return ['redfish-virtualmedia', 'idrac-virtualmedia'].includes(url.protocol as string);
} catch (error) {
return false;
}
});
};
export const locationValidationSchema = (t: TFunction) => {
const locationValidationMessagesList = locationValidationMessages(t);
Expand Down
1 change: 1 addition & 0 deletions libs/ui-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"is-in-subnet": "^4",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
"parse-url": "^9.2.0",
"prism-react-renderer": "^1.1.1",
"react-error-boundary": "^3.1.4",
"react-measure": "^2.5.2",
Expand Down
34 changes: 34 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ __metadata:
is-in-subnet: ^4
js-yaml: ^4.1.0
lodash-es: ^4.17.21
parse-url: ^9.2.0
prism-react-renderer: ^1.1.1
react-error-boundary: ^3.1.4
react-measure: ^2.5.2
Expand Down Expand Up @@ -1792,6 +1793,13 @@ __metadata:
languageName: node
linkType: hard

"@types/parse-path@npm:^7.0.0":
version: 7.0.3
resolution: "@types/parse-path@npm:7.0.3"
checksum: 21a12c228d38f5a75659dfd7cb127dc2001ed3f6acbd1b2e0575d1348c735594c0bab06a97fe849c151438384829f20ea5971cb045f7ecd37d53c76a9fcb9de3
languageName: node
linkType: hard

"@types/prop-types@npm:*":
version: 15.7.12
resolution: "@types/prop-types@npm:15.7.12"
Expand Down Expand Up @@ -7326,6 +7334,25 @@ __metadata:
languageName: node
linkType: hard

"parse-path@npm:^7.0.0":
version: 7.0.0
resolution: "parse-path@npm:7.0.0"
dependencies:
protocols: ^2.0.0
checksum: 244b46523a58181d251dda9b888efde35d8afb957436598d948852f416d8c76ddb4f2010f9fc94218b4be3e5c0f716aa0d2026194a781e3b8981924142009302
languageName: node
linkType: hard

"parse-url@npm:^9.2.0":
version: 9.2.0
resolution: "parse-url@npm:9.2.0"
dependencies:
"@types/parse-path": ^7.0.0
parse-path: ^7.0.0
checksum: 765d4beac7de59c88007018e2a4b95ed8ff96cdcd0ff510b1ad00ab3d17f63949c7664218685394fe35af52061516c5efbba520fb760d7104b8238a6196f28c4
languageName: node
linkType: hard

"parse5-htmlparser2-tree-adapter@npm:^7.0.0":
version: 7.0.0
resolution: "parse5-htmlparser2-tree-adapter@npm:7.0.0"
Expand Down Expand Up @@ -7653,6 +7680,13 @@ __metadata:
languageName: node
linkType: hard

"protocols@npm:^2.0.0":
version: 2.0.1
resolution: "protocols@npm:2.0.1"
checksum: 4a9bef6aa0449a0245ded319ac3cbfd032c3e76ebb562777037a3a832c99253d0e8bc2847f7be350236df620a11f7d4fe683ea7f59a2cc14c69f746b6259eda4
languageName: node
linkType: hard

"proxy-from-env@npm:1.0.0":
version: 1.0.0
resolution: "proxy-from-env@npm:1.0.0"
Expand Down
Loading