Skip to content

Commit

Permalink
Store Yip source in the YipConfig
Browse files Browse the repository at this point in the history
Not used yet, but can be used down the line to identify the exact file
that its giving out errors

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Oct 4, 2024
1 parent 0558c50 commit 25003e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/schema/loader_cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions pkg/schema/loader_yip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 25003e4

Please sign in to comment.