cloudConfig: save the aws configs

Save the AWS config modifications to the `osbuild-worker.toml` file.
This commit is contained in:
Gianluca Zuccarelli 2025-04-29 16:39:19 +00:00 committed by Sanne Raymaekers
parent ca6c59bfb8
commit 5afe1c1fc1
2 changed files with 21 additions and 5 deletions

View file

@ -23,10 +23,14 @@ import {
changeAWSBucketName,
changeAWSCredsPath,
reinitializeAWSConfig,
selectAWSConfig,
} from '../../store/cloudProviderConfigSlice';
import { useGetWorkerConfigQuery } from '../../store/cockpit/cockpitApi';
import {
useGetWorkerConfigQuery,
useUpdateWorkerConfigMutation,
} from '../../store/cockpit/cockpitApi';
import { AWSWorkerConfig } from '../../store/cockpit/types';
import { useAppDispatch } from '../../store/hooks';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import { resolveRelPath } from '../../Utilities/path';
import { ImageBuilderHeader } from '../sharedComponents/ImageBuilderHeader';
@ -62,8 +66,10 @@ const ConfigError = ({
export const CloudProviderConfig = () => {
const navigate = useNavigate();
const dispatch = useAppDispatch();
const config = useAppSelector(selectAWSConfig);
const handleClose = () => navigate(resolveRelPath(''));
const [updateConfig] = useUpdateWorkerConfigMutation();
const { data, error, refetch, isLoading } = useGetWorkerConfigQuery({});
const initAWSConfig = useCallback(
@ -109,6 +115,12 @@ export const CloudProviderConfig = () => {
nextButtonText: 'Submit',
isNextDisabled: !isAwsStepValid(config),
isBackDisabled: true,
onNext: () => {
updateConfig({
updateWorkerConfigRequest: { aws: config },
});
navigate(resolveRelPath(''));
},
}}
>
<AWSConfig

View file

@ -637,9 +637,13 @@ export const cockpitApi = contentSourcesApi.injectEndpoints({
const contents: WorkerConfigFile = {};
Object.keys(merged).forEach((key: string) => {
contents[key] = Section({
...merged[key],
});
// this check helps prevent saving empty objects
// into the osbuild-worker.toml config file.
if (merged[key] !== undefined) {
contents[key] = Section({
...merged[key],
});
}
});
return TOML.stringify(contents, {