From b3e6ce98cb8d755ddff2fe0e1732df2cc1aee146 Mon Sep 17 00:00:00 2001 From: Anna Vitova Date: Tue, 1 Aug 2023 15:21:49 +0200 Subject: [PATCH] feat(HMS-1245): UI AWS permission check --- src/API/index.js | 5 +++++ src/API/queryKeys.js | 1 + .../steps/ReservationProgress/index.js | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/API/index.js b/src/API/index.js index b706fd9a..f002999c 100644 --- a/src/API/index.js +++ b/src/API/index.js @@ -64,3 +64,8 @@ export const fetchLaunchTemplates = async (sourceID, region) => { const { data } = await axios.get(provisioningUrl(`sources/${sourceID}/launch_templates?region=${region}`)); return data; }; + +export const checkAWSPermissions = async (sourceID, region) => { + const { data } = await axios.get(provisioningUrl(`sources/${sourceID}/validate_permissions?region=${region}`)); + return data; +}; diff --git a/src/API/queryKeys.js b/src/API/queryKeys.js index 10267d52..1db666e1 100644 --- a/src/API/queryKeys.js +++ b/src/API/queryKeys.js @@ -4,3 +4,4 @@ export const PUBKEYS_QUERY_KEY = 'pubkeys'; export const instanceTypesQueryKeys = (region) => ['instanceTypes', region]; export const IMAGE_REGIONS_KEY = 'image_region'; export const TEMPLATES_KEY = 'templates'; +export const PERMISSION_CHECK_KEY = 'permissions'; diff --git a/src/Components/ProvisioningWizard/steps/ReservationProgress/index.js b/src/Components/ProvisioningWizard/steps/ReservationProgress/index.js index fe465884..8f01a8b7 100644 --- a/src/Components/ProvisioningWizard/steps/ReservationProgress/index.js +++ b/src/Components/ProvisioningWizard/steps/ReservationProgress/index.js @@ -12,12 +12,13 @@ import { Popover, Button, WizardContextConsumer, + Alert, } from '@patternfly/react-core'; import { CogsIcon, PendingIcon, CheckCircleIcon } from '@patternfly/react-icons'; import { useMutation, useQuery } from 'react-query'; import { useWizardContext } from '../../../Common/WizardContext'; -import { createNewPublicKey, createReservation, fetchReservation } from '../../../../API'; +import { createNewPublicKey, createReservation, fetchReservation, checkAWSPermissions } from '../../../../API'; import useInterval from '../../../Common/Hooks/useInterval'; import { POLLING_BACKOFF_INTERVAL, PROVIDERS_INSTANCES_SUPPORT, SSH_STEP } from './constants'; @@ -50,6 +51,12 @@ const ReservationProgress = ({ setLaunchSuccess }) => { ] = useWizardContext(); const { nextInterval, currentInterval } = useInterval(POLLING_BACKOFF_INTERVAL); + // check AWS permissions + const { data } = useQuery([`permissions`, `${chosenRegion}-${chosenSource}`], () => checkAWSPermissions(chosenSource, chosenRegion), { + select: (perm) => perm.missing_entities, + }); + const missingPermissions = data || []; + const { mutate: mutateReservation, error: reservationError } = useMutation(createReservation(provider), { onSuccess: (res) => { stepUp(); @@ -178,6 +185,15 @@ const ReservationProgress = ({ setLaunchSuccess }) => { {polledReservation?.success && PROVIDERS_INSTANCES_SUPPORT.includes(provider) && ( )} + {currentError && missingPermissions.length != 0 && ( + + )} {currentError && (