cockpitApi: create worker config file

Create the `osbuild-worker.toml` file if it doesn't exist already.
This commit is contained in:
Gianluca Zuccarelli 2025-04-29 14:53:11 +00:00 committed by Sanne Raymaekers
parent afcc0126e4
commit c55706b931

View file

@ -588,17 +588,22 @@ export const cockpitApi = contentSourcesApi.injectEndpoints({
getWorkerConfig: builder.query<WorkerConfigResponse, unknown>({
queryFn: async () => {
try {
// we need to ensure that the file is created
await cockpit.spawn(['mkdir', '-p', '/etc/osbuild-worker'], {
superuser: 'require',
});
await cockpit.spawn(
['touch', '/etc/osbuild-worker/osbuild-worker.toml'],
{ superuser: 'require' }
);
const config = await cockpit
.file('/etc/osbuild-worker/osbuild-worker.toml')
.read();
return { data: TOML.parse(config) };
} catch (error) {
// no worker file error message
if (error.message === 'input is null') {
return { data: {} };
}
return { error };
}
},