Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions mmv1/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewLoader(config Config) *Loader {
return l
}

func (l *Loader) LoadProducts() {
func (l *Loader) LoadProducts() *Loader {
if l.version == "" {
log.Printf("No version specified, assuming ga")
l.version = "ga"
Expand Down Expand Up @@ -92,6 +92,8 @@ func (l *Loader) LoadProducts() {
}

l.Products = l.batchLoadProducts(allProductFiles)

return l
}

func (l *Loader) batchLoadProducts(productNames []string) map[string]*api.Product {
Expand Down Expand Up @@ -318,30 +320,19 @@ func (l *Loader) loadResource(product *api.Product, baseResourcePath string, ove
return resource
}

func (l *Loader) AddExtraFields() error {
func (l *Loader) AddExtraFields() *Loader {
if l.Products == nil {
return errors.New("products have not been loaded into memory")
log.Fatalln("products have not been loaded into memory")
}

for _, product := range l.Products {
for _, resource := range product.Objects {
resource.Properties = resource.AddExtraFields(resource.PropertiesWithExcluded(), nil)
// SetDefault after AddExtraFields to ensure relevant metadata is available for the newly generated fields
resource.SetDefault(product)
}
}

return nil
}

func (l *Loader) Validate() {
if l.Products == nil {
log.Fatalln("products have not been loaded into memory")
}

for _, product := range l.Products {
for _, resource := range product.Objects {
resource.Validate()
}
}

return l
}
4 changes: 1 addition & 3 deletions mmv1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ func GenerateProducts(product, resource, providerName, version, outputPath, base
}

loader := loader.NewLoader(loader.Config{Version: version, BaseDirectory: baseDirectory, OverrideDirectory: overrideDirectory, Sysfs: ofs})
loader.LoadProducts()
loader.AddExtraFields()
loader.Validate()
loader.LoadProducts().AddExtraFields()
loadedProducts := loader.Products

var productsToGenerate []string
Expand Down
Loading