From 3a9e3aa2006f5c700ff9ebbd4ef69a637fbeb847 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Tue, 1 Jul 2025 16:15:26 +0100 Subject: [PATCH] requestMapper: add region to aws upload type The on-prem backend needs the aws region in order to upload the ami target to aws. In order to do this, we use some specific cockpit types that contain the region field, meaning that requests to image-builder-crc should be unchanged. This is essentialy the wiring commit to get this functionality into the `/composes` endpoint for on-prem. --- .../steps/Review/Footer/CreateDropdown.tsx | 17 +++++++++-- .../steps/Review/Footer/EditDropdown.tsx | 22 +++++++++++--- .../utilities/requestMapper.ts | 30 +++++++++++++++---- 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx b/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx index d9ee3d82..1f50f45f 100644 --- a/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx +++ b/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx @@ -22,6 +22,7 @@ import { useCreateBPWithNotification as useCreateBlueprintMutation, } from '../../../../../Hooks'; import { setBlueprintId } from '../../../../../store/BlueprintSlice'; +import { CockpitCreateBlueprintRequest } from '../../../../../store/cockpit/types'; import { useAppDispatch, useAppSelector } from '../../../../../store/hooks'; import { CreateBlueprintRequest, @@ -31,7 +32,9 @@ import { selectPackages } from '../../../../../store/wizardSlice'; import { createAnalytics } from '../../../../../Utilities/analytics'; type CreateDropdownProps = { - getBlueprintPayload: () => Promise<'' | CreateBlueprintRequest | undefined>; + getBlueprintPayload: () => Promise< + '' | CreateBlueprintRequest | CockpitCreateBlueprintRequest | undefined + >; setIsOpen: (isOpen: boolean) => void; isDisabled: boolean; }; @@ -62,7 +65,11 @@ export const CreateSaveAndBuildBtn = ({ setIsOpen(false); if (!process.env.IS_ON_PREMISE && requestBody) { - const analyticsData = createAnalytics(requestBody, packages, isBeta); + const analyticsData = createAnalytics( + requestBody as CreateBlueprintRequest, + packages, + isBeta + ); analytics.track(`${AMPLITUDE_MODULE_NAME} - Blueprint Created`, { ...analyticsData, type: 'createBlueprintAndBuildImages', @@ -161,7 +168,11 @@ export const CreateSaveButton = ({ setIsOpen(false); if (!process.env.IS_ON_PREMISE && requestBody) { - const analyticsData = createAnalytics(requestBody, packages, isBeta); + const analyticsData = createAnalytics( + requestBody as CreateBlueprintRequest, + packages, + isBeta + ); analytics.track(`${AMPLITUDE_MODULE_NAME} - Blueprint Created`, { ...analyticsData, type: 'createBlueprint', diff --git a/src/Components/CreateImageWizard/steps/Review/Footer/EditDropdown.tsx b/src/Components/CreateImageWizard/steps/Review/Footer/EditDropdown.tsx index b3325b13..132e4818 100644 --- a/src/Components/CreateImageWizard/steps/Review/Footer/EditDropdown.tsx +++ b/src/Components/CreateImageWizard/steps/Review/Footer/EditDropdown.tsx @@ -16,13 +16,16 @@ import { useComposeBPWithNotification as useComposeBlueprintMutation, useUpdateBPWithNotification as useUpdateBlueprintMutation, } from '../../../../../Hooks'; +import { CockpitCreateBlueprintRequest } from '../../../../../store/cockpit/types'; import { useAppSelector } from '../../../../../store/hooks'; import { CreateBlueprintRequest } from '../../../../../store/imageBuilderApi'; import { selectPackages } from '../../../../../store/wizardSlice'; import { createAnalytics } from '../../../../../Utilities/analytics'; type EditDropdownProps = { - getBlueprintPayload: () => Promise<'' | CreateBlueprintRequest | undefined>; + getBlueprintPayload: () => Promise< + '' | CreateBlueprintRequest | CockpitCreateBlueprintRequest | undefined + >; setIsOpen: (isOpen: boolean) => void; blueprintId: string; isDisabled: boolean; @@ -54,7 +57,11 @@ export const EditSaveAndBuildBtn = ({ const requestBody = await getBlueprintPayload(); if (!process.env.IS_ON_PREMISE && requestBody) { - const analyticsData = createAnalytics(requestBody, packages, isBeta); + const analyticsData = createAnalytics( + requestBody as CreateBlueprintRequest, + packages, + isBeta + ); analytics.track(`${AMPLITUDE_MODULE_NAME} - Blueprint Updated`, { ...analyticsData, type: 'editBlueprintAndBuildImages', @@ -111,7 +118,11 @@ export const EditSaveButton = ({ const requestBody = await getBlueprintPayload(); if (!process.env.IS_ON_PREMISE && requestBody) { - const analyticsData = createAnalytics(requestBody, packages, isBeta); + const analyticsData = createAnalytics( + requestBody as CreateBlueprintRequest, + packages, + isBeta + ); analytics.track(`${AMPLITUDE_MODULE_NAME} - Blueprint Updated`, { ...analyticsData, type: 'editBlueprint', @@ -120,7 +131,10 @@ export const EditSaveButton = ({ } setIsOpen(false); if (requestBody) { - updateBlueprint({ id: blueprintId, createBlueprintRequest: requestBody }); + updateBlueprint({ + id: blueprintId, + createBlueprintRequest: requestBody, + }); } }; return ( diff --git a/src/Components/CreateImageWizard/utilities/requestMapper.ts b/src/Components/CreateImageWizard/utilities/requestMapper.ts index 3b496da0..fc9756e1 100644 --- a/src/Components/CreateImageWizard/utilities/requestMapper.ts +++ b/src/Components/CreateImageWizard/utilities/requestMapper.ts @@ -18,6 +18,12 @@ import { SATELLITE_SERVICE_PATH, } from '../../../constants'; import { RootState } from '../../../store'; +import { + CockpitAwsUploadRequestOptions, + CockpitCreateBlueprintRequest, + CockpitImageRequest, + CockpitUploadTypes, +} from '../../../store/cockpit/types'; import { AwsUploadRequestOptions, AzureUploadRequestOptions, @@ -48,6 +54,7 @@ import { selectActivationKey, selectArchitecture, selectAwsAccountId, + selectAwsRegion, selectAwsShareMethod, selectAwsSourceId, selectAzureHyperVGeneration, @@ -122,7 +129,7 @@ import { GcpAccountType, GcpShareMethod } from '../steps/TargetEnvironment/Gcp'; export const mapRequestFromState = ( store: Store, orgID: string -): CreateBlueprintRequest => { +): CreateBlueprintRequest | CockpitCreateBlueprintRequest => { const state = store.getState(); const imageRequests = getImageRequests(state); const customizations = getCustomizations(state, orgID); @@ -456,7 +463,9 @@ const getFirstBootScript = (files?: File[]): string => { return firstBootFile?.data ? atob(firstBootFile.data) : ''; }; -const getImageRequests = (state: RootState): ImageRequest[] => { +const getImageRequests = ( + state: RootState +): ImageRequest[] | CockpitImageRequest[] => { const imageTypes = selectImageTypes(state); const snapshotDate = selectSnapshotDate(state); const useLatest = selectUseLatest(state); @@ -482,7 +491,9 @@ const getSatelliteCommand = (files?: File[]): string => { return satelliteCommandFile?.data ? atob(satelliteCommandFile.data) : ''; }; -const uploadTypeByTargetEnv = (imageType: ImageTypes): UploadTypes => { +const uploadTypeByTargetEnv = ( + imageType: ImageTypes +): UploadTypes | CockpitUploadTypes => { switch (imageType) { case 'aws': return 'aws'; @@ -516,12 +527,21 @@ const getImageOptions = ( ): | AwsUploadRequestOptions | AzureUploadRequestOptions - | GcpUploadRequestOptions => { + | GcpUploadRequestOptions + | CockpitAwsUploadRequestOptions => { switch (imageType) { case 'aws': if (selectAwsShareMethod(state) === 'sources') return { share_with_sources: [selectAwsSourceId(state) || ''] }; - return { share_with_accounts: [selectAwsAccountId(state)] }; + if (!process.env.IS_ON_PREMISE) + return { share_with_accounts: [selectAwsAccountId(state)] }; + + // TODO: we might want to update the image-builder-crc api + // to accept a region instead (with default us-east-1) + return { + share_with_accounts: [selectAwsAccountId(state)], + region: selectAwsRegion(state), + }; case 'azure': if (selectAzureShareMethod(state) === 'sources') return {