File tree 3 files changed +61
-5
lines changed
Components/CloudProviderConfig
3 files changed +61
-5
lines changed Original file line number Diff line number Diff line change 1
- import React from 'react' ;
1
+ import React , { useEffect } from 'react' ;
2
2
3
3
import { PageSection , Wizard , WizardStep } from '@patternfly/react-core' ;
4
4
import { useNavigate } from 'react-router-dom' ;
5
5
6
6
import { AWSConfig } from './AWSConfig' ;
7
7
import { useIsAwsStepValid } from './validators' ;
8
8
9
+ import { changeAWSConfig } from '../../store/cloudProviderConfigSlice' ;
10
+ import { useGetWorkerConfigQuery } from '../../store/cockpit/cockpitApi' ;
11
+ import { useAppDispatch } from '../../store/hooks' ;
9
12
import { resolveRelPath } from '../../Utilities/path' ;
10
13
import { ImageBuilderHeader } from '../sharedComponents/ImageBuilderHeader' ;
11
14
12
15
export const CloudProviderConfig = ( ) => {
13
16
const navigate = useNavigate ( ) ;
17
+ const dispatch = useAppDispatch ( ) ;
14
18
const handleClose = ( ) => navigate ( resolveRelPath ( '' ) ) ;
15
19
20
+ const { data, error } = useGetWorkerConfigQuery ( { } ) ;
16
21
const isAwsStepValid = useIsAwsStepValid ( ) ;
17
22
23
+ useEffect ( ( ) => {
24
+ dispatch ( changeAWSConfig ( data ?. aws ) ) ;
25
+ } , [ data , dispatch ] ) ;
26
+
27
+ if ( error ) {
28
+ // TODO: improve error alert
29
+ return (
30
+ < div >
31
+ There was an error reading the `/etc/osbuild-worker/osbuild-worker.toml`
32
+ config file
33
+ </ div >
34
+ ) ;
35
+ }
36
+
18
37
return (
19
38
< >
20
39
< ImageBuilderHeader />
Original file line number Diff line number Diff line change 1
1
import { PayloadAction , createSlice } from '@reduxjs/toolkit' ;
2
2
3
- import type { RootState } from '.' ;
3
+ import type {
4
+ AWSWorkerConfig ,
5
+ CloudProviderConfigState ,
6
+ } from './cockpit/types' ;
4
7
5
- import type { CloudProviderConfigState } from './cockpit/types ' ;
8
+ import type { RootState } from '.' ;
6
9
7
10
export const initialState : CloudProviderConfigState = {
8
11
aws : undefined ,
9
12
} ;
10
13
14
+ export const selectAWSConfig = ( state : RootState ) => {
15
+ return state . cloudConfig ?. aws ;
16
+ } ;
17
+
11
18
export const selectAWSBucketName = ( state : RootState ) => {
12
19
return state . cloudConfig ?. aws ?. bucket ;
13
20
} ;
@@ -24,6 +31,9 @@ export const cloudProviderConfigSlice = createSlice({
24
31
name : 'cloudConfig' ,
25
32
initialState,
26
33
reducers : {
34
+ changeAWSConfig : ( state , action : PayloadAction < AWSWorkerConfig > ) => {
35
+ state . aws = action . payload ;
36
+ } ,
27
37
changeAWSBucketName : ( state , action : PayloadAction < string > ) => {
28
38
if ( state . aws === undefined ) {
29
39
state . aws = { } ;
@@ -45,5 +55,9 @@ export const cloudProviderConfigSlice = createSlice({
45
55
} ,
46
56
} ) ;
47
57
48
- export const { changeAWSBucketName, changeAWSRegion, changeAWSCredsPath } =
49
- cloudProviderConfigSlice . actions ;
58
+ export const {
59
+ changeAWSConfig,
60
+ changeAWSBucketName,
61
+ changeAWSRegion,
62
+ changeAWSCredsPath,
63
+ } = cloudProviderConfigSlice . actions ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { v4 as uuidv4 } from 'uuid';
18
18
// the same unix socket. This allows us to split out the code a little
19
19
// bit so that the `cockpitApi` doesn't become a monolith.
20
20
import { contentSourcesApi } from './contentSourcesApi' ;
21
+ import type { WorkerConfigResponse } from './types' ;
21
22
22
23
import {
23
24
mapHostedToOnPrem ,
@@ -580,6 +581,27 @@ export const cockpitApi = contentSourcesApi.injectEndpoints({
580
581
}
581
582
} ,
582
583
} ) ,
584
+ getWorkerConfig : builder . query < WorkerConfigResponse , unknown > ( {
585
+ queryFn : async ( ) => {
586
+ try {
587
+ const workerConfig = cockpit . file (
588
+ '/etc/osbuild-worker/osbuild-worker.toml'
589
+ ) ;
590
+
591
+ const contents = await workerConfig . read ( ) ;
592
+ const parsed = TOML . parse ( contents ) ;
593
+
594
+ return { data : parsed } ;
595
+ } catch ( error ) {
596
+ // no worker file error message
597
+ if ( error . message === 'input is null' ) {
598
+ return { data : { } } ;
599
+ }
600
+
601
+ return { error } ;
602
+ }
603
+ } ,
604
+ } ) ,
583
605
} ;
584
606
} ,
585
607
// since we are inheriting some endpoints,
@@ -603,4 +625,5 @@ export const {
603
625
useGetComposesQuery,
604
626
useGetBlueprintComposesQuery,
605
627
useGetComposeStatusQuery,
628
+ useGetWorkerConfigQuery,
606
629
} = cockpitApi ;
You can’t perform that action at this time.
0 commit comments