Skip to content

Commit

Permalink
wip usebucketmutation in applyaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMarcMilletScality committed Feb 14, 2025
1 parent 25c8342 commit 113adbb
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 29 deletions.
98 changes: 80 additions & 18 deletions src/react/ISV/components/ISVApplyActions.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Form, Icon, Stack, Text } from '@scality/core-ui';
import { useStepper } from '@scality/core-ui/dist/components/steppers/Stepper.component';
import {
Column,
Table,
} from '@scality/core-ui/dist/components/tablev2/Tablev2.component';
import { Column } from '@scality/core-ui/dist/components/tablev2/Tablev2.component';
import Table, * as T from '../../ui-elements/Table';
import { Box, Button } from '@scality/core-ui/dist/next';
import { useState, useMemo, useCallback } from 'react';
import { useQueryClient } from 'react-query';
Expand All @@ -22,12 +20,34 @@ export const ListItem = styled.li`
export type ISVApplyActionsProps = {
platform: ISVPlatformConfig;
accountName: string;
bucketName: string;
application: string;
capacityBytes: string;
buckets?: {
name: string;
tag: string;
capacity?: string;
capacityUnit?: string;
capacityBytes?: number;
}[];
enableImmutableBackup: boolean;
};

export type ISVConfig = {
accountName: string;
accountNameType?: 'create' | 'existing';
IAMUserName?: string;
IAMUserNameType?: 'create' | 'existing';
generateKey?: boolean;
application?: string;
enableImmutableBackup?: boolean;
buckets?: {
name: string;
tag: string;
capacity?: string;
capacityUnit?: string;
capacityBytes?: number;
}[];
};

type TableDataType = {
step: number;
action: string;
Expand Down Expand Up @@ -99,13 +119,8 @@ export default memo(function ISVApplyActions(
const queryClient = useQueryClient();
const { next } = useStepper(ISVStepsIndexes.ApplyActions, ISV_STEPS);

const {
bucketName,
enableImmutableBackup,
accountName,
application,
platform,
} = propsConfiguration;
const { buckets, enableImmutableBackup, accountName, application, platform } =
propsConfiguration;

const { data, accessKey, secretKey } = useMutationTableData({
propsConfiguration,
Expand All @@ -125,15 +140,15 @@ export default memo(function ISVApplyActions(
queryClient.invalidateQueries(['WebIdentityRoles']);
next({
accountName,
bucketName,
buckets,
enableImmutableBackup,
accessKey,
secretKey,
application,
});
}, [
accountName,
bucketName,
buckets,
enableImmutableBackup,
accessKey,
secretKey,
Expand Down Expand Up @@ -181,14 +196,61 @@ export default memo(function ISVApplyActions(
style={{ width: '50rem' }}
>
<div style={{ height: '32rem' }}>
<Table columns={columns} data={data}>
{/* <Table columns={columns} data={data}>
<Table.SingleSelectableContent
rowHeight="h32"
separationLineVariant="backgroundLevel3"
children={(Rows) => {
return <>{Rows}</>;
children={(rows) => {
console.log('DEBUG rows', rows);
return rows;
}}
/>
</Table> */}
<Table>
<T.Head>
<T.HeadRow>
<T.HeadCell>Step</T.HeadCell>
<T.HeadCell>Action</T.HeadCell>
<T.HeadCell>Status</T.HeadCell>
</T.HeadRow>
</T.Head>
<T.Body>
{data.map((row, index) => (
<T.Row key={index} style={{ display: 'flex' }}>
<T.Cell>{row.step}</T.Cell>
<T.Cell style={{ flex: 0.5 }}>
<div>
<Text>{row.action}</Text>
</div>
</T.Cell>
<T.Cell>
{row.status === 'success' ? (
<StatusBox>
<Icon name="Check" color={theme.statusHealthy} />
<span>Success</span>
</StatusBox>
) : row.status === 'error' ? (
<StatusBox>
<Icon
name="Exclamation-triangle"
color={theme.statusCritical}
/>
<span>Failed</span>
<Button
icon={<Icon name="Redo" />}
variant="secondary"
type="button"
label="Retry"
onClick={row.retry}
/>
</StatusBox>
) : (
<span>Pending...</span>
)}
</T.Cell>
</T.Row>
))}
</T.Body>
</Table>
</div>
</Form>
Expand Down
91 changes: 91 additions & 0 deletions src/react/ISV/hooks/useBucketMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { useMutation } from 'react-query';
import {
useAttachPolicyToUserMutation,

Check warning on line 3 in src/react/ISV/hooks/useBucketMutation.ts

View workflow job for this annotation

GitHub Actions / tests

'useAttachPolicyToUserMutation' is defined but never used
useCreatePolicyMutation,

Check warning on line 4 in src/react/ISV/hooks/useBucketMutation.ts

View workflow job for this annotation

GitHub Actions / tests

'useCreatePolicyMutation' is defined but never used
usePutBucketTaggingMutation,

Check warning on line 5 in src/react/ISV/hooks/useBucketMutation.ts

View workflow job for this annotation

GitHub Actions / tests

'usePutBucketTaggingMutation' is defined but never used
} from '../../../js/mutations';

import { useCreateBucket } from '../../next-architecture/domain/business/buckets';
import {
GET_VEEAM_IMMUTABLE_POLICY,

Check warning on line 10 in src/react/ISV/hooks/useBucketMutation.ts

View workflow job for this annotation

GitHub Actions / tests

'GET_VEEAM_IMMUTABLE_POLICY' is defined but never used
GET_VEEAM_NON_IMMUTABLE_POLICY,

Check warning on line 11 in src/react/ISV/hooks/useBucketMutation.ts

View workflow job for this annotation

GitHub Actions / tests

'GET_VEEAM_NON_IMMUTABLE_POLICY' is defined but never used
} from '../constants';

const GET_COMMVAULT_POLICY = (buckets: string[], isImmutable: boolean) =>
JSON.stringify({
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: isImmutable
? [
's3:GetObject',
's3:PutObject',
's3:DeleteObject',
's3:GetBucketLocation',
's3:GetBucketVersioning',
's3:GetBucketObjectLockConfiguration',
's3:ListBucketVersions',
's3:GetObjectVersion',
's3:GetObjectRetention',
's3:GetObjectLegalHold',
's3:PutObjectRetention',
's3:PutObjectLegalHold',
's3:DeleteObjectVersion',
]
: [
's3:GetObject',
's3:PutObject',
's3:DeleteObject',
's3:GetBucketLocation',
's3:GetBucketVersioning',
's3:GetBucketObjectLockConfiguration',
],
Resource: [
...buckets
.map((bucket) => [
`arn:aws:s3:::${bucket}/*`,
`arn:aws:s3:::${bucket}`,
])
.flat(),
],
},
{
Effect: 'Allow',
Action: ['s3:ListAllMyBuckets', 's3:ListBucket'],
Resource: '*',
},
],
});
export const GET_ISV_POLICY = (
buckets: string[],
application: string,
enableImmutableBackup: boolean,
) => {
switch (application) {
// case 'Veeam':
// return enableImmutableBackup
// ? GET_VEEAM_IMMUTABLE_POLICY(bucketName)
// : GET_VEEAM_NON_IMMUTABLE_POLICY(bucketName);
case 'Commvault':
return GET_COMMVAULT_POLICY(buckets, enableImmutableBackup);
default:
return 'Default Policy';
}
};

export const useBucketMutation = (bucket) => {
const { mutate: createBucket, error, data } = useCreateBucket();

return useMutation({
mutationFn: async (variables) => {
console.log('DEBUG useBucketMutation in mutationFn', variables);
const createBucketArray = createBucket({
ObjectLockEnabledForBucket: variables.ObjectLockEnabledForBucket,

Check failure on line 84 in src/react/ISV/hooks/useBucketMutation.ts

View workflow job for this annotation

GitHub Actions / build

Property 'ObjectLockEnabledForBucket' does not exist on type 'void'.
Bucket: bucket.name,
});

return createBucketArray;
},
});
};
10 changes: 9 additions & 1 deletion src/react/ISV/hooks/useMutationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAccountsLocationsEndpointsAdapter } from '../../../react/next-archit
import { useMutation } from 'react-query';
import { useSetAssumedRolePromise } from '../../../react/DataServiceRoleProvider';
import { useMemo } from 'react';
import { useBucketMutation } from './useBucketMutation';

type Result = {
data: {
Expand Down Expand Up @@ -59,6 +60,14 @@ export const useMutationActions = (props: ISVApplyActionsProps): Result => {
},
});

const bucketMutationArray =
props.buckets?.map((bucket) => {
return {
...useBucketMutation(bucket),
key: `bucketMutation`,
};
}) ?? [];

const steps = [
// 1. Create an Account
{ ...useCreateAccountMutation(), key: 'createAccount' },
Expand All @@ -76,7 +85,6 @@ export const useMutationActions = (props: ISVApplyActionsProps): Result => {
{ ...useCreateIAMUserMutation(), key: 'createIAMUser' },
// 6. Generate Access key and Secret key
{ ...useCreateUserAccessKeyMutation(), key: 'createUserAccessKey' },

] as const;

const { mutate, mutationsWithRetry } = useChainedMutations({
Expand Down
21 changes: 11 additions & 10 deletions src/react/ISV/modules/commvault/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const AccountTooltip = () => {
return (
<ul>
<ListItem>
Enter a unique ARTESCA account name, where your S3 & IAM Veeam resources
will be structured.
Enter a unique ARTESCA account name, where your S3 & IAM Commvault
resources will be structured.
</ListItem>
<ListItem>
This information won’t be required by the Veeam console.
This information won’t be required by the Commvault console.
</ListItem>
</ul>
);
Expand All @@ -24,9 +24,9 @@ const BucketNameTooltip = () => {
return (
<ul>
<ListItem>
This bucket is your future Veeam destination. You'll need it when
setting up your Veeam application. We'll also include this in the
summary provided by our Veeam assistant at the end.
This bucket is your future Commvault destination. You'll need it when
setting up your Commvault application. We'll also include this in the
summary provided by our Commvault assistant at the end.
</ListItem>
<ListItem>
The bucket name should follow few constraints:
Expand All @@ -47,15 +47,16 @@ const EnableImmutableBackupTooltip = () => {
return (
<ul>
<ListItem>
Veeam's Immutable Backup feature enhances data protection by using S3
Commvault's WORM feature enhances data protection by using S3
Object-lock technology.
</ListItem>
<ListItem>
By selecting the Immutable Backup feature, the ARTESCA bucket is created
with Object-lock enabled.
By selecting the WORM feature, the ARTESCA bucket is created with
Object-lock enabled.
</ListItem>
<ListItem>
Data backed up to your ARTESCA S3 bucket via Veeam will be immutable.
Data backed up to your ARTESCA S3 bucket via Commvault will be
immutable.
</ListItem>
</ul>
);
Expand Down

0 comments on commit 113adbb

Please sign in to comment.