6
6
"fmt"
7
7
"io"
8
8
"io/fs"
9
+ "path"
9
10
"path/filepath"
10
11
"strings"
11
12
@@ -83,7 +84,7 @@ func (p *Parser) ParseFS(ctx context.Context, fsys fs.FS, dir string) (FileConte
83
84
return contexts , nil
84
85
}
85
86
86
- func (p * Parser ) ParseFile (ctx context.Context , fsys fs.FS , path string ) (fctx * FileContext , err error ) {
87
+ func (p * Parser ) ParseFile (ctx context.Context , fsys fs.FS , filePath string ) (fctx * FileContext , err error ) {
87
88
defer func () {
88
89
if e := recover (); e != nil {
89
90
err = fmt .Errorf ("panic during parse: %s" , e )
@@ -105,15 +106,15 @@ func (p *Parser) ParseFile(ctx context.Context, fsys fs.FS, path string) (fctx *
105
106
}
106
107
107
108
sourceFmt := YamlSourceFormat
108
- if strings . HasSuffix ( strings . ToLower ( path ), ".json" ) {
109
+ if path . Ext ( filePath ) == ".json" {
109
110
sourceFmt = JsonSourceFormat
110
111
}
111
112
112
- f , err := fsys .Open (filepath . ToSlash ( path ) )
113
+ f , err := fsys .Open (filePath )
113
114
if err != nil {
114
115
return nil , err
115
116
}
116
- defer func () { _ = f .Close () } ()
117
+ defer f .Close ()
117
118
118
119
content , err := io .ReadAll (f )
119
120
if err != nil {
@@ -123,42 +124,44 @@ func (p *Parser) ParseFile(ctx context.Context, fsys fs.FS, path string) (fctx *
123
124
lines := strings .Split (string (content ), "\n " )
124
125
125
126
fctx = & FileContext {
126
- filepath : path ,
127
+ filepath : filePath ,
127
128
lines : lines ,
128
129
SourceFormat : sourceFmt ,
129
130
}
130
131
131
132
switch sourceFmt {
132
133
case YamlSourceFormat :
133
134
if err := yaml .Unmarshal (content , fctx ); err != nil {
134
- return nil , NewErrInvalidContent (path , err )
135
+ return nil , NewErrInvalidContent (filePath , err )
135
136
}
136
- fctx .Ignores = ignore .Parse (string (content ), path , "" )
137
+ fctx .Ignores = ignore .Parse (string (content ), filePath , "" )
137
138
case JsonSourceFormat :
138
139
if err := jfather .Unmarshal (content , fctx ); err != nil {
139
- return nil , NewErrInvalidContent (path , err )
140
+ return nil , NewErrInvalidContent (filePath , err )
140
141
}
141
142
}
142
143
144
+ fctx .stripNullProperties ()
145
+
143
146
fctx .overrideParameters (p .overridedParameters )
144
147
145
148
if params := fctx .missingParameterValues (); len (params ) > 0 {
146
- p .logger .Warn ("Missing parameter values" , log .FilePath (path ), log .String ("parameters" , strings .Join (params , ", " )))
149
+ p .logger .Warn ("Missing parameter values" , log .FilePath (filePath ), log .String ("parameters" , strings .Join (params , ", " )))
147
150
}
148
151
149
152
fctx .lines = lines
150
153
fctx .SourceFormat = sourceFmt
151
- fctx .filepath = path
154
+ fctx .filepath = filePath
152
155
153
- p .logger .Debug ("Context loaded from source" , log .FilePath (path ))
156
+ p .logger .Debug ("Context loaded from source" , log .FilePath (filePath ))
154
157
155
158
// the context must be set to conditions before resources
156
159
for _ , c := range fctx .Conditions {
157
160
c .setContext (fctx )
158
161
}
159
162
160
163
for name , r := range fctx .Resources {
161
- r .configureResource (name , fsys , path , fctx )
164
+ r .configureResource (name , fsys , filePath , fctx )
162
165
}
163
166
164
167
return fctx , nil
@@ -190,10 +193,10 @@ func (p *Parser) parseParams() error {
190
193
return nil
191
194
}
192
195
193
- func (p * Parser ) parseParametersFile (path string ) (Parameters , error ) {
194
- f , err := p .configsFS .Open (path )
196
+ func (p * Parser ) parseParametersFile (filePath string ) (Parameters , error ) {
197
+ f , err := p .configsFS .Open (filePath )
195
198
if err != nil {
196
- return nil , fmt .Errorf ("parameters file %q open error: %w" , path , err )
199
+ return nil , fmt .Errorf ("parameters file %q open error: %w" , filePath , err )
197
200
}
198
201
199
202
var parameters Parameters
0 commit comments