Skip to content

Commit

Permalink
Update Commvault ISV configuration with IAM user validation and advan…
Browse files Browse the repository at this point in the history
…ced settings
  • Loading branch information
ziyang-lin-404 committed Jan 31, 2025
1 parent e611d2c commit 11cc067
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 108 deletions.
217 changes: 110 additions & 107 deletions src/react/ISV/components/ISVConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,17 @@ const NameField = ({
const radioOptions = isAccount ? accountTypeOptions : IAMUserTypeOptions;

return (
<FormGroup
id={fieldName}
label={isAccount ? 'Account' : 'IAM User Management'}
required
labelHelpTooltip={
platform.fieldOverrides.find(
(field) => field.name === FORM_FIELDS.ACCOUNT_NAME,
).tooltip
}
helpErrorPosition="bottom"
error={
isExist && type === 'create'
? `${isAccount ? 'Account' : 'IAM User'} name already exists`
: errors[fieldName]?.message ?? ''
}
content={
<Stack gap="r8" direction="vertical">
<Stack gap="r8" direction="vertical">
<FormGroup
id={fieldName}
label={isAccount ? 'Account' : 'IAM User Management'}
required
labelHelpTooltip={
platform.fieldOverrides.find(
(field) => field.name === FORM_FIELDS.ACCOUNT_NAME,
).tooltip
}
content={
<Controller
name={typeFieldName}
control={control}
Expand All @@ -129,74 +123,87 @@ const NameField = ({
/>
)}
/>

{type === 'create' ? (
<Input
id={fieldName}
type="text"
autoComplete="off"
placeholder={
status === 'success' && options.length !== 0
? `${platform.id}-backup`
: undefined
}
{...register(fieldName)}
/>
) : (
<Controller
name={fieldName}
control={control}
defaultValue={options.length > 0 ? options[0].name : ''}
render={({ field: { onChange, value } }) => (
<Select
}
/>
{(isAccount || (!isAccount && type === 'existing')) && (
<FormGroup
id={fieldName}
label={isAccount ? 'Account Name' : 'IAM User Name'}
required
helpErrorPosition="bottom"
error={
isExist && type === 'create'
? `${isAccount ? 'Account' : 'IAM User'} name already exists`
: errors[fieldName]?.message ?? ''
}
content={
<Stack gap="r8" direction="vertical">
{type === 'create' ? (
<Input
id={fieldName}
onChange={(value) => {
if (getIAMUsersMutation) {
const roleArn = options.find(
(option) => option.name === value,
).preferredAssumableRoleArn;
getIAMUsersMutation.mutate(roleArn);
}
onChange(value);
}}
value={value}
placeholder={`Select existing ${
isAccount ? 'account' : 'user'
}`}
>
{options.map((item) => (
<Select.Option key={item.name} value={item.name}>
{item.name}
</Select.Option>
))}
</Select>
type="text"
autoComplete="off"
placeholder={
status === 'success' && options.length !== 0
? `${platform.id}-backup`
: undefined
}
{...register(fieldName)}
/>
) : (
<Controller
name={fieldName}
control={control}
defaultValue={options.length > 0 ? options[0].name : ''}
render={({ field: { onChange, value } }) => (
<Select
id={fieldName}
onChange={(value) => {
if (getIAMUsersMutation) {
const roleArn = options.find(
(option) => option.name === value,
).preferredAssumableRoleArn;
getIAMUsersMutation.mutate(roleArn);
}
onChange(value);
}}
value={value}
placeholder={`Select existing ${
isAccount ? 'account' : 'user'
}`}
>
{options.map((item) => (
<Select.Option key={item.name} value={item.name}>
{item.name}
</Select.Option>
))}
</Select>
)}
/>
)}
/>
)}

{!isAccount && (
<Controller
name={FORM_FIELDS.GENERATE_KEY}
control={control}
render={({ field: { onChange, value } }) => {
const isCreateMode = type === 'create';

return (
<Checkbox
id={FORM_FIELDS.GENERATE_KEY}
value={value}
label="Generate a new set of AK/SK"
onChange={(newValue) => !isCreateMode && onChange(newValue)}
disabled={isCreateMode}
checked={isCreateMode || value}
/>
);
}}
/>
)}
</Stack>
}
/>
{!isAccount && type === 'existing' && (
<Controller
name={FORM_FIELDS.GENERATE_KEY}
control={control}
render={({ field: { onChange, value } }) => {
return (
<Checkbox
id={FORM_FIELDS.GENERATE_KEY}
value={value}
label="Generate a new set of AK/SK"
onChange={onChange}
checked={value}
/>
);
}}
/>
)}
</Stack>
}
/>
)}
</Stack>
);
};

Expand Down Expand Up @@ -269,10 +276,10 @@ export const ISVConfiguration = () => {
setConfig(data);
next({
...data,
// capacityBytes: getCapacityBytes(
// data.buckets[0].capacity,
// data.buckets[0].capacityUnit,
// ),
capacityBytes: getCapacityBytes(
data.buckets[0].capacity,
data.buckets[0].capacityUnit,
),
enableImmutableBackup: isImmutableBackupEnabled(data.application)
? data.enableImmutableBackup
: false,
Expand Down Expand Up @@ -368,7 +375,7 @@ export const ISVConfiguration = () => {
variant="outline"
onClick={() => {
console.log(methods.getValues());
// setSkip(true);
setSkip(true);
}}
label="Skip Use case configuration"
/>
Expand Down Expand Up @@ -397,28 +404,24 @@ export const ISVConfiguration = () => {
platform={platform}
type={accountNameType}
fieldType="account"
getIAMUsersMutation={
platform.id === 'commvault' ? null : getIAMUsersMutation
}
getIAMUsersMutation={getIAMUsersMutation}
/>

{accountNameType === 'existing' &&
accountName &&
(platform.id === 'veeam' || platform.id === 'veeam-vbo') && (
<Accordion title="Advanced settings" id="advanced-settings">
<NameField
register={register}
control={control}
errors={errors}
isExist={isIAMUserExist}
status={IAMUsersStatus}
options={IAMUsers}
platform={platform}
type={IAMUserNameType}
fieldType="iamUser"
/>
</Accordion>
)}
{accountNameType === 'existing' && accountName && (
<Accordion title="Advanced settings" id="advanced-settings">
<NameField
register={register}
control={control}
errors={errors}
isExist={isIAMUserExist}
status={IAMUsersStatus}
options={IAMUsers}
platform={platform}
type={IAMUserNameType}
fieldType="iamUser"
/>
</Accordion>
)}

{platform.id === 'veeam-vbo' && renderVeeamApplication()}

Expand Down
5 changes: 4 additions & 1 deletion src/react/ISV/modules/commvault/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export const Commvault: ISVPlatformConfig = {
validator: Joi.object({
accountName: accountNameValidationSchema,
accountNameType: Joi.string().required(),
enableImmutableBackup: Joi.boolean().default(true),
IAMUserName: accountNameValidationSchema,
IAMUserNameType: Joi.string().required(),
generateKey: Joi.boolean().required(),
enableImmutableBackup: Joi.boolean().required(),
buckets: Joi.array().items(
Joi.object({
name: bucketNameValidationSchema.custom((value, helpers) => {
Expand Down

0 comments on commit 11cc067

Please sign in to comment.