diff --git a/src/API/index.js b/src/API/index.js index f8f018d8..62fec197 100644 --- a/src/API/index.js +++ b/src/API/index.js @@ -1,5 +1,5 @@ import axios from 'axios'; -import { AZURE_PROVIDER } from '../constants'; +import { AWS_PROVIDER, AZURE_PROVIDER } from '../constants'; import { imageBuilderURL, provisioningUrl } from './helpers'; const typesUrlForProvider = (provider, region) => { @@ -72,3 +72,12 @@ export const fetchLaunchTemplates = async (sourceID, region) => { } = await axios.get(provisioningUrl(`sources/${sourceID}/launch_templates?region=${region}`)); return data; }; + +export const checkPermissions = async (provider, sourceID, region) => { + switch (provider) { + case AWS_PROVIDER: { + 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/AccountCustomizations/aws.js b/src/Components/ProvisioningWizard/steps/AccountCustomizations/aws.js index a659067b..20873bd0 100644 --- a/src/Components/ProvisioningWizard/steps/AccountCustomizations/aws.js +++ b/src/Components/ProvisioningWizard/steps/AccountCustomizations/aws.js @@ -1,7 +1,8 @@ import PropTypes from 'prop-types'; import React from 'react'; -import { Form, FormGroup, Popover, Title, Button } from '@patternfly/react-core'; +import { Form, FormGroup, Popover, Title, Button, FormAlert, Alert } from '@patternfly/react-core'; import { HelpIcon } from '@patternfly/react-icons'; +import { useQuery } from 'react-query'; import { AWS_PROVIDER } from '../../../../constants'; import { imageProps } from '../../helpers'; @@ -11,12 +12,22 @@ import InstanceTypesSelect from '../../../InstanceTypesSelect'; import RegionsSelect from '../../../RegionsSelect'; import { useWizardContext } from '../../../Common/WizardContext'; import TemplatesSelect from '../../../TemplateSelect'; +import { checkPermissions } from '../../../../API'; const AccountCustomizationsAWS = ({ setStepValidated, image }) => { const [{ chosenSource, chosenRegion, chosenInstanceType }, setWizardContext] = useWizardContext(); + const { data: missingPermissions } = useQuery( + [`permissions`, `${chosenRegion}-${chosenSource}`], + () => checkPermissions(image.provider, chosenSource, chosenRegion), + { + select: (perm) => perm.missing_entities, + enabled: !!chosenRegion && !!chosenSource, + } + ); const [validations, setValidation] = React.useState({ - sources: chosenSource ? 'success' : 'default', + sources: chosenSource ? ((missingPermissions || []).length == 0 ? 'success' : 'warning') : 'default', types: chosenInstanceType ? 'success' : 'default', + region: 'default', }); const onRegionChange = ({ region, imageID }) => { @@ -33,18 +44,52 @@ const AccountCustomizationsAWS = ({ setStepValidated, image }) => { setStepValidated(!errorExists); }, [validations]); + React.useEffect(() => { + if ((missingPermissions || []).length != 0) { + if (validations.sources !== 'error') { + setValidation((prevValidations) => ({ + ...prevValidations, + sources: 'warning', + })); + } + if (validations.region !== 'error') { + setValidation((prevValidations) => ({ + ...prevValidations, + region: 'warning', + })); + } + } else { + setValidation((prevValidations) => ({ + ...prevValidations, + sources: chosenSource ? 'success' : 'default', + region: 'default', + })); + } + }, [missingPermissions]); + return (