@@ -83,9 +83,7 @@ func (c Config) ToIgn3_5Unvalidated(options common.TranslateOptions) (types.Conf
83
83
84
84
tr := translate .NewTranslator ("yaml" , "json" , options )
85
85
tr .AddCustomTranslator (translateIgnition )
86
- tr .AddCustomTranslator (translateFile )
87
- tr .AddCustomTranslator (translateDirectory )
88
- tr .AddCustomTranslator (translateLink )
86
+ tr .AddCustomTranslator (translateStorage )
89
87
tr .AddCustomTranslator (translateResource )
90
88
tr .AddCustomTranslator (translatePasswdUser )
91
89
tr .AddCustomTranslator (translateUnit )
@@ -99,7 +97,6 @@ func (c Config) ToIgn3_5Unvalidated(options common.TranslateOptions) (types.Conf
99
97
translate .MergeP (tr , tm , & r , "systemd" , & c .Systemd , & ret .Systemd )
100
98
101
99
c .addMountUnits (& ret , & tm )
102
-
103
100
tm2 , r2 := c .processTrees (& ret , options )
104
101
tm .Merge (tm2 )
105
102
r .Merge (r2 )
@@ -121,6 +118,71 @@ func translateIgnition(from Ignition, options common.TranslateOptions) (to types
121
118
return
122
119
}
123
120
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 i , file := range from .Files {
135
+ if util .NotEmpty (file .Parent .Path ) {
136
+ yamlPath := path .New ("yaml" , "files" , i , "parent" )
137
+ if ! strings .Contains (file .Path , * file .Parent .Path ) {
138
+ r .AddOnError (yamlPath , common .ErrInvalidParent )
139
+ continue
140
+ }
141
+
142
+ parentDirectory := types.Directory {
143
+ Node : types.Node {
144
+ Path : * file .Parent .Path ,
145
+ Group : types.NodeGroup {ID : file .Group .ID , Name : file .Group .Name },
146
+ User : types.NodeUser {ID : file .User .ID , Name : file .User .Name },
147
+ },
148
+ DirectoryEmbedded1 : types.DirectoryEmbedded1 {
149
+ Mode : file .Parent .Mode ,
150
+ },
151
+ }
152
+
153
+ to .Directories = append (to .Directories , parentDirectory )
154
+ // find what is between parent and file path
155
+ theInBetween := strings .Replace (file .Path , * file .Parent .Path , "" , 1 )
156
+
157
+ workingDirectory := * file .Parent .Path
158
+ // render all directories between the filepath and the parent with the parent's mode
159
+ // must be a goline for splitting on path.
160
+ arrayDirectory := strings .Split (theInBetween , "/" )
161
+ for i := 0 ; i < len (arrayDirectory )- 1 ; i ++ {
162
+ dirTobeCreated := arrayDirectory [i ]
163
+ if dirTobeCreated == "" {
164
+ continue
165
+ }
166
+ workingDirectory += "/" + dirTobeCreated
167
+ directoryToBeRendered := types.Directory {
168
+ Node : types.Node {
169
+ Path : workingDirectory ,
170
+ Group : types.NodeGroup {ID : file .Group .ID , Name : file .Group .Name },
171
+ User : types.NodeUser {ID : file .User .ID , Name : file .User .Name },
172
+ },
173
+ DirectoryEmbedded1 : types.DirectoryEmbedded1 {
174
+ Mode : file .Parent .Mode ,
175
+ },
176
+ }
177
+ to .Directories = append (to .Directories , directoryToBeRendered )
178
+ }
179
+ tm .AddFromCommonSource (yamlPath , path .New ("json" , "directories" ), to .Directories )
180
+ }
181
+
182
+ }
183
+ return
184
+ }
185
+
124
186
func translateFile (from File , options common.TranslateOptions ) (to types.File , tm translate.TranslationSet , r report.Report ) {
125
187
tr := translate .NewTranslator ("yaml" , "json" , options )
126
188
tr .AddCustomTranslator (translateResource )
@@ -134,6 +196,22 @@ func translateFile(from File, options common.TranslateOptions) (to types.File, t
134
196
return
135
197
}
136
198
199
+ func translateLuks (from Luks , options common.TranslateOptions ) (to types.Luks , tm translate.TranslationSet , r report.Report ) {
200
+ tr := translate .NewTranslator ("yaml" , "json" , options )
201
+ tr .AddCustomTranslator (translateResource )
202
+ tm , r = translate .Prefixed (tr , "clevis" , & from .Clevis , & to .Clevis )
203
+ translate .MergeP (tr , tm , & r , "device" , & from .Device , & to .Device )
204
+ translate .MergeP (tr , tm , & r , "discard" , & from .Discard , & to .Discard )
205
+ translate .MergeP2 (tr , tm , & r , "key_file" , & from .KeyFile , "keyFile" , & to .KeyFile )
206
+ translate .MergeP (tr , tm , & r , "label" , & from .Label , & to .Label )
207
+ translate .MergeP (tr , tm , & r , "name" , & from .Name , & to .Name )
208
+ translate .MergeP2 (tr , tm , & r , "open_options" , & from .OpenOptions , "openOptions" , & to .OpenOptions )
209
+ translate .MergeP (tr , tm , & r , "options" , & from .Options , & to .Options )
210
+ translate .MergeP (tr , tm , & r , "uuid" , & from .UUID , & to .UUID )
211
+ translate .MergeP2 (tr , tm , & r , "wipe_volume" , & from .WipeVolume , "wipeVolume" , & to .WipeVolume )
212
+ return
213
+ }
214
+
137
215
func translateResource (from Resource , options common.TranslateOptions ) (to types.Resource , tm translate.TranslationSet , r report.Report ) {
138
216
tr := translate .NewTranslator ("yaml" , "json" , options )
139
217
tm , r = translate .Prefixed (tr , "verification" , & from .Verification , & to .Verification )
@@ -294,7 +372,7 @@ func (c Config) processTrees(ret *types.Config, options common.TranslateOptions)
294
372
return ts , r
295
373
}
296
374
t := newNodeTracker (ret )
297
-
375
+ ts . AddTranslation ( path . New ( "yaml" , "storage" ), path . New ( "json" , "storage" ))
298
376
for i , tree := range c .Storage .Trees {
299
377
yamlPath := path .New ("yaml" , "storage" , "trees" , i )
300
378
if options .FilesDir == "" {
0 commit comments