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.
This commit is contained in:
Gianluca Zuccarelli 2025-07-01 16:15:26 +01:00 committed by Klara Simickova
parent 4339420cb8
commit 3a9e3aa200
3 changed files with 57 additions and 12 deletions

View file

@ -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',

View file

@ -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 (

View file

@ -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 {