diff --git a/src/components/just-in-time-access/JustInTimeAccessPage.tsx b/src/components/just-in-time-access/JustInTimeAccessPage.tsx index 370ef7e..26a90ed 100644 --- a/src/components/just-in-time-access/JustInTimeAccessPage.tsx +++ b/src/components/just-in-time-access/JustInTimeAccessPage.tsx @@ -66,18 +66,28 @@ const JustInTimeAccessPage = () => { const resourceTypeList = ['DB', 'KUBERNETES', 'AWS', 'AWS-CUSTOM', 'GOCD']; let resourceActionList = Array(); - const k8sResourceActionList = ['read', 'write', 'admin']; - const dbResourceActionList = ['read', 'write', 'master', 'manager']; - const awsResourceActionList = ['App-Developers', 'App-Admin', 'App-Owner']; - const awsCustomResourceActionList = ['S3', 'DYNAMODB', 'RDS', 'DOCDB', 'ELASTICACHE', 'CUSTOM']; - const gocdResourceActionList = ['deploy-prod', 'prod-resource', 'hotfix']; + let awsCustomResourceTypeList = Array(); + const KUBERNETES_ACTION_LIST = ['read', 'write', 'admin']; + const DB_ACTION_LIST = ['read', 'write', 'master', 'manager']; + const AWS_ACTION_LIST = ['App-Developers', 'App-Admin', 'App-Owner']; + const AWS_CUSTOM_RESOURCE_TYPE = ['S3', 'DYNAMODB', 'RDS', 'DOCDB', 'ELASTICACHE']; + const GOCD_ACTION_LIST = ['deploy-prod', 'prod-resource', 'hotfix']; const resourceActionMap = { - KUBERNETES: k8sResourceActionList, - DB: dbResourceActionList, - AWS: awsResourceActionList, - 'AWS-CUSTOM': awsCustomResourceActionList, - GOCD: gocdResourceActionList, + KUBERNETES: KUBERNETES_ACTION_LIST, + DB: DB_ACTION_LIST, + AWS: AWS_ACTION_LIST, + 'AWS-CUSTOM': ['read'], + GOCD: GOCD_ACTION_LIST, }; + const customResourceActionListMap = { + S3: ['read', 'write'], + DYNAMODB: ['read'], + RDS: ['read', 'write'], + DOCDB: ['read', 'write'], + ELASTICACHE: ['read'], + // CUSTOM: ['read', 'write', 'custom'], + }; + const teamList = useSelector((state: RootState) => state.initial.teamList); const fetchAllVerticals = () => { @@ -105,12 +115,32 @@ const JustInTimeAccessPage = () => { fetchAllEnvironments(); }, []); - const DropDownList: React.FC = ({ label, fieldName, list }) => { + const isResourceTypeAWSCustom = () => { + const { values }: { values: any } = useFormikContext(); + console.log('values', values); + console.log('values', getIn(values, 'resourceType')); + if (getIn(values, 'resourceType') === 'AWS-CUSTOM') { + console.log('values', values['resourceType']); + return getIn(values, 'resourceType') === 'AWS-CUSTOM'; + } + return false; + }; + + // const getCustomResourceActionList = () => { + // const { values }: { values: any } = useFormikContext(); + // return customResourceActionListMap[getIn(values, 'awsResourceType')]; + // } + + const DropDownList: React.FC = ({ label, fieldName, list, style }) => { const classes = useStyles(); const { values }: { values: any } = useFormikContext(); const resourceTypeField = 'resourceType'; if (typeof getIn(values, resourceTypeField) !== undefined && values[resourceTypeField] !== '') { + if (values[resourceTypeField] === 'AWS-CUSTOM') { + resourceActionList = customResourceActionListMap[values['awsResourceType']]; + awsCustomResourceTypeList = AWS_CUSTOM_RESOURCE_TYPE; + } resourceActionList = resourceActionMap[values[resourceTypeField]]; } @@ -124,7 +154,7 @@ const JustInTimeAccessPage = () => { getOptionLabel={(option: string) => (_.isString(option) ? option : '')} options={list} autoSelect - className={classes.field} + className={style} /> ); @@ -140,7 +170,7 @@ const JustInTimeAccessPage = () => { enableReinitialize initialValues={jit} validateOnChange={true} - // validationSchema={justInTimeAccessValidationSchema} + validationSchema={justInTimeAccessValidationSchema} onSubmit={values => { values.grantAt = new Date(values.grantAt).getTime(); submitJustInTimeAccessRequest(values); @@ -159,26 +189,44 @@ const JustInTimeAccessPage = () => { label="Resource Owning Team" fieldName="team" list={teamList.map((team: any) => team.name)} + style={classes.field} /> vertical !== 'ALL')} + style={classes.field} /> + + { - return value !== '*'; - }), - methods: yup.array().min(1).required('is Required'), - validTill: yup - .string() - .test( - 'test', - 'Select a time greater than the current time,also, time selected should not be more than 30 days', - value => { - const validTillDays = 30; - return ( - value !== undefined && - Date.parse(value) - Date.now() <= validTillDays * 24 * 60 * 60 * 1000 && - Date.parse(value) - Date.now() > 0 - ); - }, - ) - .default(undefined), - description: yup.string().required('is Required'), + .positive('should be positive') + .integer('should be integer'), }); diff --git a/src/components/just-in-time-access/structs.tsx b/src/components/just-in-time-access/structs.tsx index 0c2bf7f..36bd711 100644 --- a/src/components/just-in-time-access/structs.tsx +++ b/src/components/just-in-time-access/structs.tsx @@ -2,6 +2,7 @@ export interface DropDownListProps { label: string; fieldName: string; list: any[]; + style: string; } export type JitRequest = { @@ -9,9 +10,9 @@ export type JitRequest = { vertical: string; environment: string; resourceType: string; + resourceAction: string; awsResourceType: string; awsResourceNames: Array; - resourceAction: string; justification: string; grantWindow: number; grantAt: number; diff --git a/src/components/just-in-time-access/styles.tsx b/src/components/just-in-time-access/styles.tsx index 0855c1c..29f94bb 100644 --- a/src/components/just-in-time-access/styles.tsx +++ b/src/components/just-in-time-access/styles.tsx @@ -6,6 +6,10 @@ export const useStyles = makeStyles(theme => ({ marginLeft: theme.spacing(2), marginBottom: theme.spacing(2), }, + formContainer: { + display: 'flex', + justifyContent: 'center', + }, buttonContainer: { display: 'flex', justifyContent: 'center', @@ -23,7 +27,7 @@ export const useStyles = makeStyles(theme => ({ marginTop: 60, }, bigCard: { - width: 350, + width: 400, height: 800, border: '5px solid #E8E8E8', padding: 5, @@ -48,9 +52,18 @@ export const useStyles = makeStyles(theme => ({ }, field: { marginTop: 20, - width: 300, + width: 350, padding: 5, }, + leftField: { + marginTop: 20, + width: 170, + marginRight: 10, + }, + rightField: { + marginTop: 20, + width: 170, + }, gridRow: { width: 1600, display: 'flex',