Skip to content

Commit ef6c344

Browse files
committed
[mic][iso] Save input ISO configuration as yaml.
'SavedConfigs' is a subset of the Image Customizer input configurations that needs to be saved on the output media so that it can be used in subsequent runs of the Image Customizer against that same output media. This preservation of input configuration is necessary for subsequent runs if the configuration does not result in updating root file system. For example, if the user specifies a kernel argument that is specific to the ISO image, it will not be present in any of the grub config files on the root file system - only in the final ISO image grub.cfg. When that ISO image is further customized, the root file system grub.cfg migith get re-generated and we need to remember to add the ISO specific arguments from the previous runs. SavedConfigs is the place where we can store such arguments so we can re-apply them.
1 parent d8a5bb0 commit ef6c344

File tree

4 files changed

+206
-87
lines changed

4 files changed

+206
-87
lines changed

toolkit/tools/imagecustomizerapi/utils.go

+39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package imagecustomizerapi
55

66
import (
77
"bytes"
8+
"fmt"
89
"os"
910

1011
"gopkg.in/yaml.v3"
@@ -51,3 +52,41 @@ func UnmarshalYaml[ValueType HasIsValid](yamlData []byte, value ValueType) error
5152

5253
return nil
5354
}
55+
56+
func MarshalYamlFile[ValueType HasIsValid](yamlfilePath string, value ValueType) (err error) {
57+
yamlString, err := MarshalYaml(value)
58+
if err != nil {
59+
return err
60+
}
61+
62+
file, err := os.Create(yamlfilePath)
63+
if err != nil {
64+
return err
65+
}
66+
defer func() {
67+
closeErr := file.Close()
68+
if closeErr != nil {
69+
if err != nil {
70+
err = fmt.Errorf("%w:\nfailed to close (%s): %w", err, yamlfilePath, closeErr)
71+
} else {
72+
err = fmt.Errorf("failed to close (%s): %w", yamlfilePath, closeErr)
73+
}
74+
}
75+
}()
76+
77+
_, err = file.WriteString(yamlString)
78+
if err != nil {
79+
return err
80+
}
81+
82+
return nil
83+
}
84+
85+
func MarshalYaml[ValueType HasIsValid](value ValueType) (string, error) {
86+
yamlData, err := yaml.Marshal(value)
87+
if err != nil {
88+
return "", err
89+
}
90+
91+
return string(yamlData), nil
92+
}

0 commit comments

Comments
 (0)