@@ -83,9 +83,7 @@ func (c Config) ToIgn3_5Unvalidated(options common.TranslateOptions) (types.Conf
8383
8484 tr := translate .NewTranslator ("yaml" , "json" , options )
8585 tr .AddCustomTranslator (translateIgnition )
86- tr .AddCustomTranslator (translateFile )
87- tr .AddCustomTranslator (translateDirectory )
88- tr .AddCustomTranslator (translateLink )
86+ tr .AddCustomTranslator (translateStorage )
8987 tr .AddCustomTranslator (translateResource )
9088 tr .AddCustomTranslator (translatePasswdUser )
9189 tr .AddCustomTranslator (translateUnit )
@@ -99,7 +97,6 @@ func (c Config) ToIgn3_5Unvalidated(options common.TranslateOptions) (types.Conf
9997 translate .MergeP (tr , tm , & r , "systemd" , & c .Systemd , & ret .Systemd )
10098
10199 c .addMountUnits (& ret , & tm )
102-
103100 tm2 , r2 := c .processTrees (& ret , options )
104101 tm .Merge (tm2 )
105102 r .Merge (r2 )
@@ -121,6 +118,64 @@ func translateIgnition(from Ignition, options common.TranslateOptions) (to types
121118 return
122119}
123120
121+ func translateStorage (from Storage , options common.TranslateOptions ) (to types.Storage , tm translate.TranslationSet , r report.Report ) {
122+ tr := translate .NewTranslator ("yaml" , "json" , options )
123+ tr .AddCustomTranslator (translateFile )
124+ tr .AddCustomTranslator (translateDirectory )
125+ tr .AddCustomTranslator (translateLink )
126+ tr .AddCustomTranslator (translateLuks )
127+ tm , r = translate .Prefixed (tr , "directories" , & from .Directories , & to .Directories )
128+ translate .MergeP (tr , tm , & r , "disks" , & from .Disks , & to .Disks )
129+ translate .MergeP (tr , tm , & r , "files" , & from .Files , & to .Files )
130+ translate .MergeP (tr , tm , & r , "filesystems" , & from .Filesystems , & to .Filesystems )
131+ translate .MergeP (tr , tm , & r , "links" , & from .Links , & to .Links )
132+ translate .MergeP (tr , tm , & r , "luks" , & from .Luks , & to .Luks )
133+ translate .MergeP (tr , tm , & r , "raid" , & from .Raid , & to .Raid )
134+ for _ , file := range from .Files {
135+ if util .NotEmpty (file .Parent .Path ) {
136+ c := path .New ("yaml" , "parent" )
137+ parentDirectory := types.Directory {
138+ Node : types.Node {
139+ Path : * file .Parent .Path ,
140+ Group : types.NodeGroup {ID : file .Group .ID , Name : file .Group .Name },
141+ User : types.NodeUser {ID : file .User .ID , Name : file .User .Name },
142+ },
143+ DirectoryEmbedded1 : types.DirectoryEmbedded1 {
144+ Mode : file .Parent .Mode ,
145+ },
146+ }
147+ to .Directories = append (to .Directories , parentDirectory )
148+ // find what is between parent and file path
149+ theInBetween := strings .Replace (file .Path , * file .Parent .Path , "" , 1 )
150+
151+ workingDirectory := * file .Parent .Path
152+ // render all directories between the filepath and the parent with the parent's mode
153+ arrayDirectory := strings .Split (theInBetween , "/" )
154+ for i := 0 ; i < len (arrayDirectory )- 1 ; i ++ {
155+ dirTobeCreated := arrayDirectory [i ]
156+ if dirTobeCreated == "" {
157+ continue
158+ }
159+ workingDirectory += "/" + dirTobeCreated
160+ directoryToBeRendered := types.Directory {
161+ Node : types.Node {
162+ Path : workingDirectory ,
163+ Group : types.NodeGroup {ID : file .Group .ID , Name : file .Group .Name },
164+ User : types.NodeUser {ID : file .User .ID , Name : file .User .Name },
165+ },
166+ DirectoryEmbedded1 : types.DirectoryEmbedded1 {
167+ Mode : file .Parent .Mode ,
168+ },
169+ }
170+ to .Directories = append (to .Directories , directoryToBeRendered )
171+ }
172+ tm .AddFromCommonSource (c , path .New ("json" , "directories" ), to .Directories )
173+ }
174+
175+ }
176+ return
177+ }
178+
124179func translateFile (from File , options common.TranslateOptions ) (to types.File , tm translate.TranslationSet , r report.Report ) {
125180 tr := translate .NewTranslator ("yaml" , "json" , options )
126181 tr .AddCustomTranslator (translateResource )
@@ -134,6 +189,15 @@ func translateFile(from File, options common.TranslateOptions) (to types.File, t
134189 return
135190}
136191
192+ func translateLuks (from Luks , options common.TranslateOptions ) (to types.Luks , tm translate.TranslationSet , r report.Report ) {
193+ tr := translate .NewTranslator ("yaml" , "json" , options )
194+ tm , r = translate .Prefixed (tr , "clevis" , & from .Clevis , & to .Clevis )
195+ translate .MergeP (tr , tm , & r , "device" , & from .Device , & to .Device )
196+ translate .MergeP (tr , tm , & r , "name" , & from .Name , & to .Name )
197+ translate .MergeP (tr , tm , & r , "wipe_volume" , & from .WipeVolume , & to .WipeVolume )
198+ return
199+ }
200+
137201func translateResource (from Resource , options common.TranslateOptions ) (to types.Resource , tm translate.TranslationSet , r report.Report ) {
138202 tr := translate .NewTranslator ("yaml" , "json" , options )
139203 tm , r = translate .Prefixed (tr , "verification" , & from .Verification , & to .Verification )
0 commit comments