Skip to content

Commit

Permalink
export parsed composite specs
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Keister <[email protected]>
  • Loading branch information
grokspawn committed Sep 5, 2023
1 parent 56771f7 commit 0327319
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions alpha/template/composite/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type Template struct {
registeredBuilders map[string]builderFunc
}

type Specs struct {
CatalogSpec *CatalogConfig
ContributionSpec *CompositeConfig
}

type TemplateOption func(t *Template)

func WithCatalogFile(catalogFile io.Reader) TemplateOption {
Expand Down Expand Up @@ -111,26 +116,38 @@ func FetchCatalogConfig(path string, httpGetter HttpGetter) (io.ReadCloser, erro
return tempCatalog, nil
}

// TODO(everettraven): do we need the context here? If so, how should it be used?
func (t *Template) Render(ctx context.Context, validate bool) error {
func (t *Template) Parse() (*Specs, error) {
var s Specs

catalogFile, err := t.parseCatalogsSpec()
catalogSpec, err := t.parseCatalogsSpec()
if err != nil {
return err
return nil, err
}
s.CatalogSpec = catalogSpec

contributionSpec, err := t.parseContributionSpec()
if err != nil {
return nil, err
}
s.ContributionSpec = contributionSpec

return &s, nil
}

func (t *Template) Render(ctx context.Context, validate bool) error {

contributionFile, err := t.parseContributionSpec()
specs, err := t.Parse()
if err != nil {
return err
}

catalogBuilderMap, err := t.newCatalogBuilderMap(catalogFile.Catalogs, t.outputType)
catalogBuilderMap, err := t.newCatalogBuilderMap(specs.CatalogSpec.Catalogs, t.outputType)
if err != nil {
return err
}

// TODO(everettraven): should we return aggregated errors?
for _, component := range contributionFile.Components {
for _, component := range specs.ContributionSpec.Components {
if builderMap, ok := (*catalogBuilderMap)[component.Name]; ok {
if builder, ok := builderMap[component.Strategy.Template.Schema]; ok {
// run the builder corresponding to the schema
Expand Down

0 comments on commit 0327319

Please sign in to comment.