diff --git a/pkg/schema/loader_cloudinit.go b/pkg/schema/loader_cloudinit.go index a129bca2..3f9230c2 100644 --- a/pkg/schema/loader_cloudinit.go +++ b/pkg/schema/loader_cloudinit.go @@ -29,7 +29,7 @@ type cloudInit struct{} // to a yip schema. // As Yip supports multi-stages, it is encoded in the supplied one. // fs is used to parse the user data required from /etc/passwd. -func (cloudInit) Load(s []byte, fs vfs.FS) (*YipConfig, error) { +func (cloudInit) Load(source string, s []byte, fs vfs.FS) (*YipConfig, error) { cc, err := cloudconfig.NewCloudConfig(string(s)) if err != nil { return nil, err @@ -114,7 +114,7 @@ func (cloudInit) Load(s []byte, fs vfs.FS) (*YipConfig, error) { } // optimistically load data as yip yaml - yipConfig, err := yipYAML{}.Load(s, fs) + yipConfig, err := yipYAML{}.Load(source, s, fs) if err == nil { for k, v := range yipConfig.Stages { result.Stages[k] = append(result.Stages[k], v...) diff --git a/pkg/schema/loader_yip.go b/pkg/schema/loader_yip.go index cd9495d1..8606dff4 100644 --- a/pkg/schema/loader_yip.go +++ b/pkg/schema/loader_yip.go @@ -8,12 +8,12 @@ import ( type yipYAML struct{} // LoadFromYaml loads a yip config from bytes -func (yipYAML) Load(b []byte, fs vfs.FS) (*YipConfig, error) { +func (yipYAML) Load(source string, b []byte, fs vfs.FS) (*YipConfig, error) { var yamlConfig YipConfig err := yaml.Unmarshal(b, &yamlConfig) if err != nil { return nil, err } - + yamlConfig.Source = source return &yamlConfig, nil } diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index d38854d2..763b58da 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -179,6 +179,7 @@ type DNS struct { } type YipConfig struct { + Source string `yaml:"-"` Name string `yaml:"name,omitempty"` Stages map[string][]Stage `yaml:"stages,omitempty"` } @@ -187,7 +188,7 @@ type Loader func(s string, fs vfs.FS, m Modifier) ([]byte, error) type Modifier func(s []byte) ([]byte, error) type yipLoader interface { - Load([]byte, vfs.FS) (*YipConfig, error) + Load(string, []byte, vfs.FS) (*YipConfig, error) } func Load(s string, fs vfs.FS, l Loader, m Modifier) (*YipConfig, error) { @@ -206,7 +207,7 @@ func Load(s string, fs vfs.FS, l Loader, m Modifier) (*YipConfig, error) { if err != nil { return nil, errors.Wrap(err, "invalid file type") } - return loader.Load(data, fs) + return loader.Load(s, data, fs) } func detect(b []byte) (yipLoader, error) {