@@ -155,36 +155,23 @@ func getSigningConfigFromContext(ctx context.Context, client gwclient.Client, cf
155155 return pc .Signer , nil
156156}
157157
158- func getSourceFilterConfigFromContext (ctx context.Context , client gwclient.Client , cfgPath string , configState llb.State ) (dalec.SourceFilterConfig , error ) {
159- scDef , err := configState .Marshal (ctx )
160- if err != nil {
161- return dalec.SourceFilterConfig {}, err
162- }
163-
164- res , err := client .Solve (ctx , gwclient.SolveRequest {
165- Definition : scDef .ToPB (),
166- })
167- if err != nil {
168- return dalec.SourceFilterConfig {}, err
169- }
170-
171- ref , err := res .SingleRef ()
158+ func getSourceFilterConfigFromContext (ctx context.Context , client gwclient.Client , cfgPath string , configCtxName string , getContext func (string , ... llb.LocalOption ) (* llb.State , error ), opts ... llb.ConstraintsOpt ) (dalec.SourceFilterConfig , error ) {
159+ dt , err := readConfigFromContext (ctx , client , cfgPath , configCtxName , dalec.SourceOpts {
160+ GetContext : getContext ,
161+ SourceFilter : dalec .NoSourceFilter ,
162+ }, opts ... )
172163 if err != nil {
173164 return dalec.SourceFilterConfig {}, err
174165 }
175166
176- dt , err := ref .ReadFile (ctx , gwclient.ReadRequest {
177- Filename : cfgPath ,
178- })
179- if err != nil {
180- return dalec.SourceFilterConfig {}, err
181- }
167+ return decodeSourceFilterConfig (ctx , dt )
168+ }
182169
170+ func decodeSourceFilterConfig (ctx context.Context , dt []byte ) (dalec.SourceFilterConfig , error ) {
183171 var cfg dalec.SourceFilterConfig
184- if err := yaml .Unmarshal ( dt , & cfg ); err != nil {
172+ if err := yaml .UnmarshalContext ( ctx , dt , & cfg , yaml . Strict () ); err != nil {
185173 return dalec.SourceFilterConfig {}, err
186174 }
187-
188175 return cfg , nil
189176}
190177
@@ -291,22 +278,13 @@ func getSourceFilterContextNameWithDefault(client gwclient.Client) string {
291278 return configCtxName
292279}
293280
294- func loadSourceFilterConfig (ctx context.Context , client gwclient.Client , getContext func (string , ... llb.LocalOption ) (* llb.State , error ), opts ... llb. LocalOption ) (dalec.SourceFilterConfig , error ) {
281+ func loadSourceFilterConfig (ctx context.Context , client gwclient.Client , getContext func (string , ... llb.LocalOption ) (* llb.State , error )) (dalec.SourceFilterConfig , error ) {
295282 cfgPath := getSourceFilterConfigPath (client )
296283 if cfgPath == "" {
297284 return dalec.SourceFilterConfig {}, nil
298285 }
299286
300- configCtxName := getSourceFilterContextNameWithDefault (client )
301- configState , err := getContext (configCtxName , opts ... )
302- if err != nil {
303- return dalec.SourceFilterConfig {}, err
304- }
305- if configState == nil {
306- return dalec.SourceFilterConfig {}, errors .Errorf ("context %q not found" , configCtxName )
307- }
308-
309- return getSourceFilterConfigFromContext (ctx , client , cfgPath , * configState )
287+ return getSourceFilterConfigFromContext (ctx , client , cfgPath , getSourceFilterContextNameWithDefault (client ), getContext )
310288}
311289
312290func forwardToSigner (ctx context.Context , client gwclient.Client , cfg * dalec.PackageSigner , s llb.State , opts ... llb.ConstraintsOpt ) (llb.State , error ) {
0 commit comments