wizrad: add validation to ssh key field (HMS-5349)
this commit add validation to ssh key field JIRA: HMS-5349
This commit is contained in:
parent
0f86336af6
commit
7d34d30b08
3 changed files with 115 additions and 113 deletions
|
|
@ -34,6 +34,7 @@ import {
|
|||
isHostnameValid,
|
||||
isKernelNameValid,
|
||||
isUserNameValid,
|
||||
isSshKeyValid,
|
||||
} from '../validators';
|
||||
|
||||
export type StepValidation = {
|
||||
|
|
@ -192,12 +193,20 @@ export function useUsersValidation(): StepValidation {
|
|||
users.length === 0 ||
|
||||
// Case 2: All fields are empty
|
||||
(userName === '' && userPassword === '' && userSshKey === '') ||
|
||||
// Case 3: userName is valid
|
||||
(userName && isUserNameValid(userName));
|
||||
// Case 3: userName is valid and SshKey is valid
|
||||
(userName &&
|
||||
isUserNameValid(userName) &&
|
||||
userSshKey &&
|
||||
isSshKeyValid(userSshKey));
|
||||
|
||||
return {
|
||||
errors: {
|
||||
userName: !isUserNameValid(userName) ? 'Invalid user name' : '',
|
||||
userSshKey: !userSshKey
|
||||
? ''
|
||||
: !isSshKeyValid(userSshKey)
|
||||
? 'Invalid SSH key'
|
||||
: '',
|
||||
},
|
||||
disabledNext: !canProceed,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -68,6 +68,17 @@ export const isUserNameValid = (userName: string) => {
|
|||
return isLengthValid && isNotNumericOnly && isPatternValid;
|
||||
};
|
||||
|
||||
export const isSshKeyValid = (sshKey: string) => {
|
||||
// 1. Key types: ssh-rsa, ssh-dss, ssh-ed25519, or ecdsa-sha2-nistp(256|384|521).
|
||||
// 2. Base64-encoded key material.
|
||||
// 3. Optional comment at the end.
|
||||
const isPatternValid =
|
||||
/^(ssh-(rsa|dss|ed25519)|ecdsa-sha2-nistp(256|384|521))\s+[A-Za-z0-9+/=]+(\s+\S+)?$/.test(
|
||||
sshKey
|
||||
);
|
||||
return isPatternValid;
|
||||
};
|
||||
|
||||
export const getDuplicateMountPoints = (partitions: Partition[]): string[] => {
|
||||
const mountPointSet: Set<string> = new Set();
|
||||
const duplicates: string[] = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue