Skip to content

Commit

Permalink
feat(HMS-1245): UI AWS permission check
Browse files Browse the repository at this point in the history
  • Loading branch information
avitova committed Aug 2, 2023
1 parent 1d94170 commit b3e6ce9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/API/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
1 change: 1 addition & 0 deletions src/API/queryKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -178,6 +185,15 @@ const ReservationProgress = ({ setLaunchSuccess }) => {
{polledReservation?.success && PROVIDERS_INSTANCES_SUPPORT.includes(provider) && (
<InstancesTable provider={provider} region={chosenRegion} reservationID={reservationID} />
)}
{currentError && missingPermissions.length != 0 && (
<Alert
data-testid="insufficient_permissions_alert"
ouiaId="insufficient_permissions_alert"
variant="warning"
isInline
title={`Warning: Insufficient permissions for AWS account, following permissions missing: ${missingPermissions}.`}
/>
)}
{currentError && (
<Button id="wizard-provisioning-failed-edit-button" onClick={() => goToStepById(1)} variant="primary">
Edit
Expand Down

0 comments on commit b3e6ce9

Please sign in to comment.