-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip usebucketmutation in applyaction
- Loading branch information
1 parent
25c8342
commit 113adbb
Showing
4 changed files
with
191 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { useMutation } from 'react-query'; | ||
import { | ||
useAttachPolicyToUserMutation, | ||
useCreatePolicyMutation, | ||
usePutBucketTaggingMutation, | ||
} from '../../../js/mutations'; | ||
|
||
import { useCreateBucket } from '../../next-architecture/domain/business/buckets'; | ||
import { | ||
GET_VEEAM_IMMUTABLE_POLICY, | ||
GET_VEEAM_NON_IMMUTABLE_POLICY, | ||
} 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, | ||
Bucket: bucket.name, | ||
}); | ||
|
||
return createBucketArray; | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters